From e0e385838e562111c0c9b41cfc2649b1a52e92f8 Mon Sep 17 00:00:00 2001 From: suelockwood Date: Mon, 9 Sep 2013 15:38:56 -0400 Subject: Replication addon sans tests Fixes from code review Should use _.filter, not _.map when pulling out all the replication active tasks. fixing CSS overrides on the form Fixed Create target. Change swap to icon, added tooltips, made inputs wider. Fixed continuous, scrubbed whitepaces from db names, updated layout --- .gitignore | 1 + .../replication/assets/less/replication.less | 175 ++++++++++++ src/fauxton/app/addons/replication/base.js | 24 ++ src/fauxton/app/addons/replication/resources.js | 68 +++++ src/fauxton/app/addons/replication/route.js | 47 ++++ .../app/addons/replication/templates/form.html | 74 +++++ .../app/addons/replication/templates/progress.html | 22 ++ .../addons/replication/tests/replicationSpec.js | 28 ++ src/fauxton/app/addons/replication/views.js | 311 +++++++++++++++++++++ src/fauxton/assets/less/fauxton.less | 4 +- src/fauxton/settings.json.default | 1 + 11 files changed, 753 insertions(+), 2 deletions(-) create mode 100644 src/fauxton/app/addons/replication/assets/less/replication.less create mode 100644 src/fauxton/app/addons/replication/base.js create mode 100644 src/fauxton/app/addons/replication/resources.js create mode 100644 src/fauxton/app/addons/replication/route.js create mode 100644 src/fauxton/app/addons/replication/templates/form.html create mode 100644 src/fauxton/app/addons/replication/templates/progress.html create mode 100644 src/fauxton/app/addons/replication/tests/replicationSpec.js create mode 100644 src/fauxton/app/addons/replication/views.js diff --git a/.gitignore b/.gitignore index a022b1412..a4798c913 100644 --- a/.gitignore +++ b/.gitignore @@ -91,6 +91,7 @@ src/fauxton/app/addons/* !src/fauxton/app/addons/config !src/fauxton/app/addons/logs !src/fauxton/app/addons/stats +!src/fauxton/app/addons/replication !src/fauxton/app/addons/contribute !src/fauxton/app/addons/auth !src/fauxton/app/addons/exampleAuth diff --git a/src/fauxton/app/addons/replication/assets/less/replication.less b/src/fauxton/app/addons/replication/assets/less/replication.less new file mode 100644 index 000000000..ec3b71822 --- /dev/null +++ b/src/fauxton/app/addons/replication/assets/less/replication.less @@ -0,0 +1,175 @@ +/**/ + +@brown: #3A2C2B; +@red: #E33F3B; +@darkRed: #AF2D24; +@linkRed: #DA4F49; +@greyBrown: #A59D9D; +@fontGrey: #808080; +@secondarySidebar: #E4DFDC; + + +form#replication { + position: relative; + max-width: none; + width: auto; + + .form_set{ + width: 350px; + display: inline-block; + border: 1px solid @greyBrown; + padding: 15px 10px 0; + margin-bottom: 20px; + &.middle{ + width: 100px; + border: none; + position: relative; + height: 100px; + margin: 0; + } + input, select { + margin: 0 0 16px 5px; + height: 40px; + width: 318px; + } + .btn-group{ + margin: 0 0 16px 5px; + .btn { + padding: 10px 57px; + } + } + &.local{ + .local_option{ + display: block; + } + .remote_option{ + display: none; + } + .local-btn{ + background-color: @red; + color: #fff; + } + .remote-btn{ + background-color: #f5f5f5; + color: @fontGrey; + } + } + .local_option{ + display: none; + } + .remote-btn{ + background-color: @red; + color: #fff; + } + } + + + .options { + position: relative; + &:after{ + content: ''; + display: block; + position: absolute; + right: -16px; + top: 9px; + width: 0; + height: 0; + border-left: 5px solid transparent; + border-right: 5px solid transparent; + border-bottom: 5px solid black; + border-top: none; + } + &.off { + &:after{ + content: ''; + display: block; + position: absolute; + right: -16px; + top: 9px; + width: 0; + height: 0; + border-left: 5px solid transparent; + border-right: 5px solid transparent; + border-bottom: none; + border-top: 5px solid black; + } + } + } + .control-group{ + label{ + float: left; + min-height: 30px; + vertical-align: top; + padding-right: 5px; + min-width: 130px; + padding-left: 0px; + } + input[type=radio], + input[type=checkbox]{ + margin: 0 0 2px 0; + } + } + + .circle{ + z-index: 0; + position: absolute; + top: 20px; + left: 15px; + + &:after { + width: 70px; + height: 70px; + content: ''; + display: block; + position: relative; + margin: 0 auto; + border: 1px solid @greyBrown; + -webkit-border-radius: 40px; + -moz-border-radius: 40px; + border-radius:40px; + } + } + .swap { + text-decoration: none; + z-index: 30; + cursor: pointer; + position: absolute; + font-size: 40px; + width: 27px; + height: 12px; + top: 31px; + left: 30px; + &:hover { + color: @greyBrown; + } + } + +} +#replicationStatus{ + &.showHeader{ + li.header{ + display: block; + border: none; + } + ul { + border:1px solid @greyBrown; + } + } + li.header{ + display: none; + } + ul{ + margin: 0; + li{ + .progress, + p{ + margin: 0px; + vertical-align: bottom; + } + padding: 10px 10px; + margin: 0; + list-style: none; + border-top: 1px solid @greyBrown; + } + } +} diff --git a/src/fauxton/app/addons/replication/base.js b/src/fauxton/app/addons/replication/base.js new file mode 100644 index 000000000..93965c1c8 --- /dev/null +++ b/src/fauxton/app/addons/replication/base.js @@ -0,0 +1,24 @@ +// 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 +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// 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. + +define([ + "app", + "api", + "addons/replication/route" +], + +function(app, FauxtonAPI, replication) { + replication.initialize = function() { + FauxtonAPI.addHeaderLink({title: "Replication", href: "#/replication", icon: "fonticon-replicate",}); + }; + return replication; +}); diff --git a/src/fauxton/app/addons/replication/resources.js b/src/fauxton/app/addons/replication/resources.js new file mode 100644 index 000000000..38ae13988 --- /dev/null +++ b/src/fauxton/app/addons/replication/resources.js @@ -0,0 +1,68 @@ +// 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 +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// 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. + +define([ + "app", + "api", + 'addons/activetasks/resources' +], + +function (app, FauxtonAPI, ActiveTasks) { + var Replication = {}; + + //these are probably dupes from the database modules. I'm going to keep them seperate for now. + Replication.DBModel = Backbone.Model.extend({ + label: function () { + //for autocomplete + return this.get("name"); + } + }); + + Replication.DBList = Backbone.Collection.extend({ + model: Replication.DBModel, + url: function() { + return app.host + "/_all_dbs"; + }, + parse: function(resp) { + // TODO: pagination! + return _.map(resp, function(database) { + return { + id: database, + name: database + }; + }); + } + }); + + Replication.Task = Backbone.Model.extend({}); + + Replication.Tasks = Backbone.Collection.extend({ + model: Replication.Task, + url: function () { + return app.host + '/_active_tasks'; + }, + parse: function(resp){ + //only want replication tasks to return + return _.filter(resp, function(task){ + return task.type === "replication"; + }); + } + }); + + Replication.Replicate = Backbone.Model.extend({ + url: function(){ + return app.host + "/_replicate"; + } + }); + + return Replication; +}); diff --git a/src/fauxton/app/addons/replication/route.js b/src/fauxton/app/addons/replication/route.js new file mode 100644 index 000000000..8c45d6ff9 --- /dev/null +++ b/src/fauxton/app/addons/replication/route.js @@ -0,0 +1,47 @@ +// 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 +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// 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. + +define([ + "app", + "api", + "addons/replication/resources", + "addons/replication/views" +], +function(app, FauxtonAPI, Replication, Views) { + var RepRouteObject = FauxtonAPI.RouteObject.extend({ + layout: "one_pane", + roles: ["_admin"], + routes: { + "replication": "defaultView" + }, + selectedHeader: "Replication", + apiUrl: function() { + return app.host+"/_replication"; + }, + crumbs: [ + {"name": "Replicate changes from: ", "link": "replication"} + ], + defaultView: function(){ + this.databases = new Replication.DBList({}); + this.tasks = new Replication.Tasks({id: "ReplicationTasks"}); + this.setView("#dashboard-content", new Views.ReplicationForm({ + collection: this.databases, + status: this.tasks + })); + } + }); + + + Replication.RouteObjects = [RepRouteObject]; + + return Replication; +}); diff --git a/src/fauxton/app/addons/replication/templates/form.html b/src/fauxton/app/addons/replication/templates/form.html new file mode 100644 index 000000000..eeb308153 --- /dev/null +++ b/src/fauxton/app/addons/replication/templates/form.html @@ -0,0 +1,74 @@ + + +
+
+
+ + +
+ +
+ +
+
+ +
+
+ +
+ + + + + +
+ +
+
+ + +
+
+ +
+ +
+ +
+
+ + +
+
+ + + +
+ + +
+
+ +
diff --git a/src/fauxton/app/addons/replication/templates/progress.html b/src/fauxton/app/addons/replication/templates/progress.html new file mode 100644 index 000000000..02c47f282 --- /dev/null +++ b/src/fauxton/app/addons/replication/templates/progress.html @@ -0,0 +1,22 @@ + +

Replicating <%=source%> to <%=target%>

+ +
+
<%=progress || "0"%>%
+
+ + +