You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by be...@apache.org on 2014/12/05 17:51:38 UTC

fauxton commit: updated refs/heads/master to 6de9948

Repository: couchdb-fauxton
Updated Branches:
  refs/heads/master 8bafa7451 -> 6de99480d


Replication addon code cleanup

This is a housekeeping ticket. It removes an unnecessary dependency
on Active Tasks but mostly just contains style fixes, a little JS
rewrite and the odd markup bug fix.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/6de99480
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/6de99480
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/6de99480

Branch: refs/heads/master
Commit: 6de99480da5e66964d07195ff6dcc43cb5431996
Parents: 8bafa74
Author: Benjamin Keen <be...@gmail.com>
Authored: Thu Dec 4 08:54:19 2014 -0800
Committer: Benjamin Keen <be...@gmail.com>
Committed: Thu Dec 4 08:54:19 2014 -0800

----------------------------------------------------------------------
 app/addons/replication/base.js                 |   8 +-
 app/addons/replication/resources.js            |  17 +-
 app/addons/replication/route.js                |  32 +--
 app/addons/replication/templates/form.html     |  74 ++++---
 app/addons/replication/templates/progress.html |   6 +-
 app/addons/replication/views.js                | 223 +++++++++++---------
 6 files changed, 193 insertions(+), 167 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/6de99480/app/addons/replication/base.js
----------------------------------------------------------------------
diff --git a/app/addons/replication/base.js b/app/addons/replication/base.js
index 93965c1..a0de0de 100644
--- a/app/addons/replication/base.js
+++ b/app/addons/replication/base.js
@@ -11,14 +11,14 @@
 // the License.
 
 define([
-  "app",
-  "api",
-  "addons/replication/route"
+  'app',
+  'api',
+  'addons/replication/route'
 ],
 
 function(app, FauxtonAPI, replication) {
 	replication.initialize = function() {
-    FauxtonAPI.addHeaderLink({title: "Replication", href: "#/replication", icon: "fonticon-replicate",});
+    FauxtonAPI.addHeaderLink({ title: 'Replication', href: '#/replication', icon: 'fonticon-replicate' });
   };
   return replication;
 });

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/6de99480/app/addons/replication/resources.js
----------------------------------------------------------------------
diff --git a/app/addons/replication/resources.js b/app/addons/replication/resources.js
index 73a8cc5..dc74650 100644
--- a/app/addons/replication/resources.js
+++ b/app/addons/replication/resources.js
@@ -12,25 +12,24 @@
 
 define([
   "app",
-  "api",
-  'addons/activetasks/resources'
+  "api"
 ],
 
-function (app, FauxtonAPI, ActiveTasks) {
+function (app, FauxtonAPI) {
   var Replication = {};
 
-  //these are probably dupes from the database modules. I'm going to keep them seperate for now.
+  // these are probably dupes from the database modules. I'm going to keep them separate for now
   Replication.DBModel = Backbone.Model.extend({
     label: function () {
-      //for autocomplete
-        return this.get("name");
+      // for autocomplete
+      return this.get('name');
     }
   });
 
   Replication.DBList = Backbone.Collection.extend({
     model: Replication.DBModel,
     url: function() {
-      return app.host + "/_all_dbs";
+      return app.host + '/_all_dbs';
     },
     parse: function(resp) {
       // TODO: pagination!
@@ -53,7 +52,7 @@ function (app, FauxtonAPI, ActiveTasks) {
     parse: function(resp){
       //only want replication tasks to return
       return _.filter(resp, function(task){
-        return task.type === "replication";
+        return task.type === 'replication';
       });
     }
   });
@@ -61,7 +60,7 @@ function (app, FauxtonAPI, ActiveTasks) {
   Replication.Replicate = Backbone.Model.extend({
     documentation: FauxtonAPI.constants.DOC_URLS.REPLICATION,
     url: function(){
-      return window.location.origin + "/_replicate";
+      return window.location.origin + '/_replicate';
     }
   });
 

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/6de99480/app/addons/replication/route.js
----------------------------------------------------------------------
diff --git a/app/addons/replication/route.js b/app/addons/replication/route.js
index 1b9ba91..a40f0b8 100644
--- a/app/addons/replication/route.js
+++ b/app/addons/replication/route.js
@@ -11,24 +11,24 @@
 // the License.
 
 define([
-  "app",
-  "api",
-  "addons/replication/resources",
-  "addons/replication/views"
+  'app',
+  'api',
+  'addons/replication/resources',
+  'addons/replication/views'
 ],
 function(app, FauxtonAPI, Replication, Views) {
-  var  RepRouteObject = FauxtonAPI.RouteObject.extend({
-    layout: "one_pane",
+  var RepRouteObject = FauxtonAPI.RouteObject.extend({
+    layout: 'one_pane',
     routes: {
-      "replication": "defaultView",
-      "replication/:dbname": "defaultView"
+      "replication": 'defaultView',
+      "replication/:dbname": 'defaultView'
     },
-    selectedHeader: "Replication",
-    apiUrl: function() {
+    selectedHeader: 'Replication',
+    apiUrl: function () {
       return [this.replication.url(), this.replication.documentation];
     },
     crumbs: [
-      {"name": "Replicate changes from: ", "link": "replication"}
+      { "name": 'Replicate changes from: ', 'link': 'replication' }
     ],
     defaultView: function(dbname){
       var isAdmin = FauxtonAPI.session.isAdmin();
@@ -38,16 +38,16 @@ function(app, FauxtonAPI, Replication, Views) {
       this.replication = new Replication.Replicate({});
 
       if (isAdmin) {
-        this.tasks = new Replication.Tasks({id: "ReplicationTasks"});
-        this.setView("#dashboard-content", new Views.ReplicationFormForAdmins({
-          selectedDB: dbname ||"",
+        this.tasks = new Replication.Tasks({ id: 'ReplicationTasks' });
+        this.setView('#dashboard-content', new Views.ReplicationFormForAdmins({
+          selectedDB: dbname || '',
           collection: this.databases,
           status: this.tasks
         }));
         return;
       }
-      this.setView("#dashboard-content", new Views.ReplicationForm({
-        selectedDB: dbname ||"",
+      this.setView('#dashboard-content', new Views.ReplicationForm({
+        selectedDB: dbname || '',
         collection: this.databases,
         status: this.tasks
       }));

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/6de99480/app/addons/replication/templates/form.html
----------------------------------------------------------------------
diff --git a/app/addons/replication/templates/form.html b/app/addons/replication/templates/form.html
index 7bd1bfa..60de499 100644
--- a/app/addons/replication/templates/form.html
+++ b/app/addons/replication/templates/form.html
@@ -1,4 +1,4 @@
-<!--
+<% /*
 Licensed under the Apache License, Version 2.0 (the "License"); you may not
 use this file except in compliance with the License. You may obtain a copy of
 the License at
@@ -10,49 +10,47 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 License for the specific language governing permissions and limitations under
 the License.
--->
+*/ %>
 
 <form id="replication" class="form-horizontal">
-		<div class="from form_set  local">
-			<div class="btn-group">
-			  <button class="btn local-btn" type="button" value="local">Local</button>
-			  <button class="btn remote-btn" type="button" value="remote">Remote</button>
-			</div>
+  <div class="from form_set local">
+    <div class="btn-group">
+      <button class="btn local-btn" type="button" value="local">Local</button>
+      <button class="btn remote-btn" type="button" value="remote">Remote</button>
+    </div>
 
-			<div class="from_local local_option">
-				<select id="from_name" name="source">
-					<% _.each( databases, function( db, i ){ %>
-					   <option value="<%- db.name %>" <% if(selectedDB == db.name){%>selected<%}%> ><%- db.name %></option>
-					<% }); %>
-				</select>
-			</div>
-			<div class="from_to_remote remote_option">
-				<input type="text" id="from_url" name="source" size="30" value="http://">
-			</div>
-		</div>
-
-		<div class="form_set middle">
-			<span class="circle "></span>
-				<a href="#" title="Switch Target and Source" class="swap">
-					<span class="fonticon-swap-arrows"></span>
-				</a>
-			</span>
-		</div>
+    <div class="from_local local_option">
+      <select id="from_name" name="source">
+        <% _.each( databases, function( db, i ){ %>
+           <option value="<%- db.name %>" <% if(selectedDB == db.name){%>selected<%}%> ><%- db.name %></option>
+        <% }); %>
+      </select>
+    </div>
+    <div class="from_to_remote remote_option">
+      <input type="text" id="from_url" name="source" size="30" value="http://">
+    </div>
+  </div>
 
-		<div class="to form_set local">
-			<div class="btn-group">
-			  <button class="btn local-btn" type="button" value="local">Local</button>
-			  <button class="btn remote-btn" type="button" value="remote">Remote</button>
-			</div>
-			<div class="to_local local_option">
-				<input type="text" id="to_name" name="target" size="30" placeholder="database name">
-			</div>
+  <div class="form_set middle">
+    <span class="circle"></span>
+    <a href="#" title="Switch Target and Source" class="swap">
+      <span class="fonticon-swap-arrows"></span>
+    </a>
+  </div>
 
-			<div class="to_remote remote_option">
-				<input type="text" id="to_url" name="target" size="30" value="http://">
-			</div>
-		</div>
+  <div class="to form_set local">
+    <div class="btn-group">
+      <button class="btn local-btn" type="button" value="local">Local</button>
+      <button class="btn remote-btn" type="button" value="remote">Remote</button>
+    </div>
+    <div class="to_local local_option">
+      <input type="text" id="to_name" name="target" size="30" placeholder="database name">
+    </div>
 
+    <div class="to_remote remote_option">
+      <input type="text" id="to_url" name="target" size="30" value="http://">
+    </div>
+  </div>
 
 	<div class="actions">
 		<div class="control-group">

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/6de99480/app/addons/replication/templates/progress.html
----------------------------------------------------------------------
diff --git a/app/addons/replication/templates/progress.html b/app/addons/replication/templates/progress.html
index 76c8e9f..20ba471 100644
--- a/app/addons/replication/templates/progress.html
+++ b/app/addons/replication/templates/progress.html
@@ -1,4 +1,4 @@
-<!--
+<% /*
 Licensed under the Apache License, Version 2.0 (the "License"); you may not
 use this file except in compliance with the License. You may obtain a copy of
 the License at
@@ -10,7 +10,7 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 License for the specific language governing permissions and limitations under
 the License.
--->
+*/ %>
 <p class="span6 break">Replicating <strong><%-source%></strong> to <strong><%-target%></strong></p>
 
 <div class="span4 progress progress-striped active">
@@ -18,5 +18,5 @@ the License.
 </div>
 
 <span class="span1">
-	<button class="cancel btn btn-danger btn-large delete task-cancel-button" data-source="<%-source%>"  data-rep-id="<%-repid%>" data-continuous="<%-continuous%>" data-target="<%-target%>">Cancel</a>
+	<button class="cancel btn btn-danger btn-large delete task-cancel-button" data-source="<%-source%>"  data-rep-id="<%-repid%>" data-continuous="<%-continuous%>" data-target="<%-target%>">Cancel</button>
 </span>

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/6de99480/app/addons/replication/views.js
----------------------------------------------------------------------
diff --git a/app/addons/replication/views.js b/app/addons/replication/views.js
index 7eb4a7e..dbb226d 100644
--- a/app/addons/replication/views.js
+++ b/app/addons/replication/views.js
@@ -11,18 +11,18 @@
 // the License.
 
 define([
-       "app",
-       "api",
-       "addons/fauxton/components",
-       "addons/replication/resources"
+  'app',
+  'api',
+  'addons/fauxton/components',
+  'addons/replication/resources'
 ],
 function(app, FauxtonAPI, Components, Replication) {
   var View = {},
-  Events ={},
-  pollingInfo ={
-    rate: 5,
-    intervalId: null
-  };
+    Events = {},
+    pollingInfo = {
+      rate: 5,
+      intervalId: null
+    };
 
   _.extend(Events, Backbone.Events);
 
@@ -43,111 +43,124 @@ function(app, FauxtonAPI, Components, Replication) {
   // toggleAdvancedOptions:  toggle advanced
 
   View.ReplicationFormForAdmins = FauxtonAPI.View.extend({
-    template: "addons/replication/templates/form",
+    template: 'addons/replication/templates/form',
     events:  {
-      "submit #replication": "validate",
-      "click .btn-group .btn": "showFields",
-      "click .swap": "swapFields",
-      "click .options": "toggleAdvancedOptions"
+      'submit #replication': 'validate',
+      'click .btn-group .btn': 'showFields',
+      'click .swap': 'swapFields',
+      'click .options': 'toggleAdvancedOptions'
     },
-    initialize: function(options){
+
+    initialize: function (options) {
       this.status = options.status;
       this.selectedDB = options.selectedDB;
       this.newRepModel = new Replication.Replicate({});
     },
-    afterRender: function(){
+
+    afterRender: function () {
       this.dbSearchTypeahead = new Components.DbSearchTypeahead({
         dbLimit: 30,
-        el: "input#to_name"
+        el: 'input#to_name'
       });
 
       this.dbSearchTypeahead.render();
-
     },
 
-    beforeRender:  function(){
-      this.insertView("#replicationStatus", new View.ReplicationListForAdmins({
+    beforeRender: function () {
+      this.insertView('#replicationStatus', new View.ReplicationListForAdmins({
         collection: this.status
       }));
     },
-    cleanup: function(){
+
+    cleanup: function () {
       clearInterval(pollingInfo.intervalId);
     },
-    enableFields: function(){
-      this.$el.find('input','select').attr('disabled',false);
+
+    enableFields: function () {
+      this.$el.find('input','select').attr('disabled', false);
     },
-    disableFields: function(){
-      this.$el.find('input:hidden','select:hidden').attr('disabled',true);
+
+    disableFields: function () {
+      this.$el.find('input:hidden','select:hidden').attr('disabled', true);
     },
-    showFields: function(e){
+
+    showFields: function (e) {
       var $currentTarget = this.$(e.currentTarget),
       targetVal = $currentTarget.val();
 
-      if (targetVal === "local"){
+      if (targetVal === 'local') {
         $currentTarget.parents('.form_set').addClass('local');
       }else{
         $currentTarget.parents('.form_set').removeClass('local');
       }
     },
-    establish: function(){
+
+    establish: function () {
       return [this.collection.fetch(), this.status.fetch()];
     },
-    validate: function(e){
+
+    validate: function (e) {
       e.preventDefault();
-      var notification;
-      if (this.formValidation()){
-        notification = FauxtonAPI.addNotification({
-          msg: "Please enter every field.",
-          type: "error",
+      if (this.formValidation()) {
+        FauxtonAPI.addNotification({
+          msg: 'Please enter every field.',
+          type: 'error',
           clear: true
         });
         return;
-      }else if (this.$('input#to_name').is(':visible') && !this.$('input[name=create_target]').is(':checked')){
-        var alreadyExists = this.collection.where({"name":this.$('input#to_name').val()});
+
+      } else if (this.$('input#to_name').is(':visible') && !this.$('input[name=create_target]').is(':checked')) {
+        var alreadyExists = this.collection.where({
+          "name": this.$('input#to_name').val()
+        });
         if (alreadyExists.length === 0) {
           FauxtonAPI.addNotification({
-            msg: "This database doesn't exist. Check create target if you want to create it.",
-            type: "error",
+            msg: 'This database doesn\'t exist. Check create target if you want to create it.',
+            type: 'error',
             clear: true
           });
           return;
         }
       }
+
       this.submit(e);
     },
-    formValidation: function(e){
+
+    formValidation: function () {
       var $remote = this.$el.find('input:visible'),
-      error = false;
-      for(var i=0; i<$remote.length; i++){
-        if ($remote[i].value =="http://" || $remote[i].value ===""){
+          error = false;
+      _.each($remote, function(item) {
+        if (item.value === 'http://' || item.value === '') {
           error = true;
         }
-      }
+      });
       return error;
     },
+
     serialize: function(){
       return {
         databases:  this.collection.toJSON(),
         selectedDB: this.selectedDB
       };
     },
-    startReplication: function(json){
+
+    startReplication: function (json) {
       var that = this;
-      this.newRepModel.save(json,{
-        success: function(resp){
-          var notification = FauxtonAPI.addNotification({
-            msg: "Replication from "+resp.get('source')+" to "+ resp.get('target')+" has begun.",
-            type: "success",
+      this.newRepModel.save(json, {
+        success: function (resp) {
+          FauxtonAPI.addNotification({
+            msg: 'Replication from ' + resp.get('source') + ' to ' + resp.get('target') + ' has begun.',
+            type: 'success',
             clear: true
           });
           that.updateButtonText(false);
           Events.trigger('update:tasks');
         },
-        error: function(model, xhr, options){
+        error: function (model, xhr, options) {
           var errorMessage = JSON.parse(xhr.responseText);
-          var notification = FauxtonAPI.addNotification({
+          FauxtonAPI.addNotification({
             msg: errorMessage.reason,
-            type: "error",
+            type: 'error',
             clear: true
           });
           that.updateButtonText(false);
@@ -155,28 +168,31 @@ function(app, FauxtonAPI, Components, Replication) {
       });
       this.enableFields();
     },
+
     updateButtonText: function(wait){
       var $button = this.$('#replication button[type=submit]');
-      if(wait){
+      if (wait) {
         $button.text('Starting replication...').attr('disabled', true);
       } else {
         $button.text('Replication').attr('disabled', false);
       }
     },
-    submit: function(e){
+
+    submit: function (e) {
       this.disableFields();
       var formJSON = {};
-      _.map(this.$(e.currentTarget).serializeArray(), function(formData){
-        if(formData.value !== ''){
-          formJSON[formData.name] = (formData.value ==="true"? true: formData.value.replace(/\s/g, '').toLowerCase());
+      _.map(this.$(e.currentTarget).serializeArray(), function (formData) {
+        if (formData.value !== '') {
+          formJSON[formData.name] = (formData.value === "true" ? true : formData.value.replace(/\s/g, '').toLowerCase());
         }
       });
 
       this.updateButtonText(true);
       this.startReplication(formJSON);
     },
-    swapFields: function(e){
-      //WALL O' VARIABLES
+
+    swapFields: function (e) {
+      // WALL O' VARIABLES
       var $fromSelect = this.$('#from_name'),
           $toSelect = this.$('#to_name'),
           $toInput = this.$('#to_url'),
@@ -198,13 +214,13 @@ function(app, FauxtonAPI, Components, Replication) {
   });
 
   View.ReplicationForm = View.ReplicationFormForAdmins.extend({
-    template: "addons/replication/templates/form",
+    template: 'addons/replication/templates/form',
 
     events: {
-      "submit #replication": "validate",
-      "click .btn-group .btn": "showFields",
-      "click .swap": "swapFields",
-      "click .options": "toggleAdvancedOptions"
+      'submit #replication': 'validate',
+      'click .btn-group .btn': 'showFields',
+      'click .swap': 'swapFields',
+      'click .options': 'toggleAdvancedOptions'
     },
 
     initialize: function (options) {
@@ -216,42 +232,49 @@ function(app, FauxtonAPI, Components, Replication) {
 
     establish: function () {
       return [this.collection.fetch()];
-    },
+    }
   });
 
   View.ReplicationListForAdmins = FauxtonAPI.View.extend({
-    tagName: "ul",
-    initialize:  function(){
+    tagName: 'ul',
+
+    initialize: function () {
       Events.bind('update:tasks', this.establish, this);
-      this.listenTo(this.collection, "reset", this.render);
-      this.$el.prepend("<li class='header'><h4>Active Replication Tasks</h4></li>");
+      this.listenTo(this.collection, 'reset', this.render);
+      this.$el.prepend('<li class="header"><h4>Active Replication Tasks</h4></li>');
     },
-    establish: function(){
-      return [this.collection.fetch({reset: true})];
+
+    establish: function () {
+      return [this.collection.fetch({ reset: true })];
     },
-    setPolling: function(){
+
+    setPolling: function () {
       var that = this;
       this.cleanup();
-      pollingInfo.intervalId = setInterval(function() {
+      pollingInfo.intervalId = setInterval(function () {
         that.establish();
-      }, pollingInfo.rate*1000);
+      }, pollingInfo.rate * 1000);
     },
-    cleanup: function(){
+
+    cleanup: function () {
       Events.unbind('update:tasks');
       clearInterval(pollingInfo.intervalId);
     },
-    beforeRender:  function(){
+
+    beforeRender: function () {
       this.collection.forEach(function(item) {
         this.insertView(new View.replicationItem({
           model: item
         }));
       }, this);
     },
-    showHeader: function(){
+
+    showHeader: function () {
       this.$el.parent()
         .toggleClass('showHeader', this.collection.length > 0);
     },
-    afterRender: function(){
+
+    afterRender: function () {
       this.showHeader();
       this.setPolling();
     }
@@ -259,50 +282,56 @@ function(app, FauxtonAPI, Components, Replication) {
 
   //make this a table row item.
   View.replicationItem = FauxtonAPI.View.extend({
-    tagName: "li",
-    className: "row",
-    template: "addons/replication/templates/progress",
+    tagName: 'li',
+    className: 'row',
+    template: 'addons/replication/templates/progress',
     events: {
-      "click .cancel": "cancelReplication"
+      'click .cancel': 'cancelReplication'
     },
-    initialize: function(){
+
+    initialize: function () {
       this.newRepModel = new Replication.Replicate({});
     },
-    establish: function(){
+
+    establish: function () {
       return [this.model.fetch()];
     },
-    cancelReplication: function(e){
-      //need to pass "cancel": true with source & target
+
+    cancelReplication: function (e) {
+      // need to pass "cancel": true with source & target
       var $currentTarget = this.$(e.currentTarget),
-      repID = $currentTarget.attr('data-rep-id');
+          repID = $currentTarget.attr('data-rep-id');
+
       this.newRepModel.save({
         "replication_id": repID,
         "cancel": true
       },
       {
-        success: function(model, xhr, options){
-          var notification = FauxtonAPI.addNotification({
-            msg: "Replication stopped.",
-            type: "success",
+        success: function(model, xhr, options) {
+          FauxtonAPI.addNotification({
+            msg: 'Replication stopped.',
+            type: 'success',
             clear: true
           });
         },
-        error: function(model, xhr, options){
+        error: function(model, xhr, options) {
           var errorMessage = JSON.parse(xhr.responseText);
-          var notification = FauxtonAPI.addNotification({
+          FauxtonAPI.addNotification({
             msg: errorMessage.reason,
-            type: "error",
+            type: 'error',
             clear: true
           });
         }
       });
     },
-    afterRender: function(){
-      if (this.model.get('continuous')){
+
+    afterRender: function () {
+      if (this.model.get('continuous')) {
         this.$el.addClass('continuous');
       }
     },
-    serialize: function(){
+
+    serialize: function () {
       return {
         progress:  this.model.get('progress'),
         target: this.model.get('target'),