diff options
| author | suelockwood <deathbearbrown@gmail.com> | 2013-07-26 13:53:16 -0400 |
|---|---|---|
| committer | Garren Smith <garren.smith@gmail.com> | 2013-08-05 18:18:47 +0200 |
| commit | 3d644287373a4f53ecd817204e3f5fca197f9a19 (patch) | |
| tree | 03f2e9d86516d7850ecd2f81022a96158b9eec07 | |
| parent | c843cef7e90036bb91c3e066d32143d46e80e322 (diff) | |
| download | couchdb-3d644287373a4f53ecd817204e3f5fca197f9a19.tar.gz | |
Fauxton: Add Active tasks
View all active tasks with polling interval, Sort in table. filter by
type.
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | src/fauxton/app/addons/activetasks/assets/less/activetasks.less | 4 | ||||
| -rw-r--r-- | src/fauxton/app/addons/activetasks/base.js | 26 | ||||
| -rw-r--r-- | src/fauxton/app/addons/activetasks/resources.js | 108 | ||||
| -rw-r--r-- | src/fauxton/app/addons/activetasks/routes.js | 52 | ||||
| -rw-r--r-- | src/fauxton/app/addons/activetasks/templates/detail.html | 21 | ||||
| -rw-r--r-- | src/fauxton/app/addons/activetasks/templates/table.html | 52 | ||||
| -rw-r--r-- | src/fauxton/app/addons/activetasks/templates/tabledetail.html | 36 | ||||
| -rw-r--r-- | src/fauxton/app/addons/activetasks/templates/tabs.html | 28 | ||||
| -rw-r--r-- | src/fauxton/app/addons/activetasks/views.js | 165 | ||||
| -rw-r--r-- | src/fauxton/app/helpers.js | 5 | ||||
| -rw-r--r-- | src/fauxton/assets/less/database.less | 6 | ||||
| -rw-r--r-- | src/fauxton/assets/less/fauxton.less | 2 | ||||
| -rw-r--r-- | src/fauxton/settings.json.default | 1 |
14 files changed, 507 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore index c1ece0940..43d4773ad 100644 --- a/.gitignore +++ b/.gitignore @@ -87,6 +87,7 @@ src/fauxton/build src/fauxton/app/load_addons.js !src/fauxton/app/addons/ src/fauxton/app/addons/* +!src/fauxton/app/addons/activetasks !src/fauxton/app/addons/config !src/fauxton/app/addons/logs !src/fauxton/app/addons/stats diff --git a/src/fauxton/app/addons/activetasks/assets/less/activetasks.less b/src/fauxton/app/addons/activetasks/assets/less/activetasks.less new file mode 100644 index 000000000..5cb9d4732 --- /dev/null +++ b/src/fauxton/app/addons/activetasks/assets/less/activetasks.less @@ -0,0 +1,4 @@ +.task-tabs li { + cursor: pointer; + padding: 5px 0; +} diff --git a/src/fauxton/app/addons/activetasks/base.js b/src/fauxton/app/addons/activetasks/base.js new file mode 100644 index 000000000..c7b8fb014 --- /dev/null +++ b/src/fauxton/app/addons/activetasks/base.js @@ -0,0 +1,26 @@ +// 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/routes" +], + +function (app, FauxtonAPI, Activetasks) { + + Activetasks.initialize = function() { + FauxtonAPI.addHeaderLink({title: "Active Tasks", href: "#/activetasks"}); + }; + + return Activetasks; +}); diff --git a/src/fauxton/app/addons/activetasks/resources.js b/src/fauxton/app/addons/activetasks/resources.js new file mode 100644 index 000000000..6d892dd94 --- /dev/null +++ b/src/fauxton/app/addons/activetasks/resources.js @@ -0,0 +1,108 @@ +// 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", + "backbone", + "modules/fauxton/base", + "d3" +], + +function (app, backbone, Fauxton) { + var Active = {}, + apiv = app.versionAPI; + app.taskSortBy = 'type'; + + Active.Task = Backbone.Model.extend({ + initialize: function() { + this.set({"id": this.get('pid')}); + } + }); + +// ALL THE TASKS + Active.Tasks = Backbone.Model.extend({ + alltypes: { + "all": "All tasks", + "replication": "Replication", + "database_compaction":" Database Compaction", + "indexer": "Indexer", + "view_compaction": "View Compaction" + }, + url: function () { + return app.host + '/_active_tasks'; + }, + parse: function(resp){ + var types = this.getUniqueTypes(resp), + that = this; + + var typeCollections = _.reduce(types, function (collection, val, key) { + collection[key] = new Active.AllTasks(that.sortThis(resp, key)); + return collection; + }, {}); + + typeCollections.all = new Active.AllTasks(resp); + + this.set(typeCollections); //now set them all to the model + }, + getUniqueTypes: function(resp){ + var types = this.alltypes; + + _.each(resp, function(type){ + if( typeof(types[type.type]) === "undefined"){ + types[type.type] = type.type.replace(/_/g,' '); + } + },this); + + this.alltypes = types; + return types; + }, + sortThis: function(resp, type){ + return _.filter(resp, function(item) { return item.type === type; }); + }, + changeView: function (view){ + this.set({ + "currentView": view + }); + }, + getCurrentViewData: function(){ + var currentView = this.get('currentView'); + return this.get(currentView); + }, + getDatabaseCompactions: function(){ + return this.get('databaseCompactions'); + }, + getIndexes: function(){ + return this.get('indexes'); + }, + getViewCompactions: function(){ + return this.get('viewCompactions'); + } + }); + +//ALL TASKS + +//NEW IDEA. Lets make this extremely generic, so if there are new weird tasks, they get sorted and collected. + + Active.AllTasks = Backbone.Collection.extend({ + model: Active.Task, + sortByColumn: function(colName) { + app.taskSortBy = colName; + this.sort(); + }, + comparator: function(item) { + return item.get(app.taskSortBy); + } + }); + + + return Active; +}); diff --git a/src/fauxton/app/addons/activetasks/routes.js b/src/fauxton/app/addons/activetasks/routes.js new file mode 100644 index 000000000..027beee7f --- /dev/null +++ b/src/fauxton/app/addons/activetasks/routes.js @@ -0,0 +1,52 @@ +// 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", + "addons/activetasks/views" +], + +function (app, FauxtonAPI, Activetasks, Views) { + + var ActiveTasksRouteObject = FauxtonAPI.RouteObject.extend({ + layout: "with_sidebar", + routes: { + "activetasks/:id": "defaultView", + "activetasks": "defaultView" + }, + crumbs: [], + apiUrl: function(){ + return app.host+"/_active_tasks"; + }, + defaultView: function(id){ + var newtasks = new Activetasks.Tasks({ + currentView: "all", + id:'activeTasks' + }); + this.setView("#sidebar-content", new Views.TabMenu({ + currentView: "all", + model: newtasks + })); + + this.setView("#dashboard-content", new Views.DataSection({ + model: newtasks, + currentView: "all" + })); + } + }); + + Activetasks.RouteObjects = [ActiveTasksRouteObject]; + + return Activetasks; +}); diff --git a/src/fauxton/app/addons/activetasks/templates/detail.html b/src/fauxton/app/addons/activetasks/templates/detail.html new file mode 100644 index 000000000..5e53129b8 --- /dev/null +++ b/src/fauxton/app/addons/activetasks/templates/detail.html @@ -0,0 +1,21 @@ +<!-- +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. +--> + +<div class="progress progress-striped active"> + <div class="bar" style="width: <%=model.get("progress")%>%;"><%=model.get("progress")%>%</div> +</div> +<p> + <%= model.get("type").replace('_',' ')%> on + <%= model.get("node")%> +</p> diff --git a/src/fauxton/app/addons/activetasks/templates/table.html b/src/fauxton/app/addons/activetasks/templates/table.html new file mode 100644 index 000000000..ee88e7521 --- /dev/null +++ b/src/fauxton/app/addons/activetasks/templates/table.html @@ -0,0 +1,52 @@ +<!-- +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. +--> + +<!-- +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. +--> + +<% if (collection.length === 0){%> + <tr> + <td> + <p>There are no active tasks for <%=currentView%> right now.</p> + </td> + </tr> +<%}else{%> + + <thead> + <tr> + <th data-type="type">Type</th> + <th data-type="node">Object</th> + <th data-type="started_on">Started on</th> + <th data-type="updated_on">Last updated on</th> + <th data-type="pid">PID</th> + <th data-type="progress" width="200">Status</th> + </tr> + </thead> + + <tbody id="tasks_go_here"> + + </tbody> + +<% } %> diff --git a/src/fauxton/app/addons/activetasks/templates/tabledetail.html b/src/fauxton/app/addons/activetasks/templates/tabledetail.html new file mode 100644 index 000000000..67c0dc837 --- /dev/null +++ b/src/fauxton/app/addons/activetasks/templates/tabledetail.html @@ -0,0 +1,36 @@ +<!-- +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. +--> + +<td> + <%= model.get("type")%> +</td> +<td> + <%= objectField %> +</td> +<td> + <%= formatDate(model.get("started_on")) %> +</td> +<td> + <%= formatDate(model.get("updated_on")) %> +</td> +<td> + <%= model.get("pid")%> +</td> +<td> + <div class="progress progress-striped active"> + <div class="bar" style="width: <%=model.get("progress")%>%;"><%=model.get("progress")%>%</div> + + </div> + <p><%=progress%> </p> +</td> diff --git a/src/fauxton/app/addons/activetasks/templates/tabs.html b/src/fauxton/app/addons/activetasks/templates/tabs.html new file mode 100644 index 000000000..47c5843f6 --- /dev/null +++ b/src/fauxton/app/addons/activetasks/templates/tabs.html @@ -0,0 +1,28 @@ +<!-- +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. +--> + +<h3>Filter by: </h3> +<ul class="task-tabs nav nav-tabs nav-stacked"> + <% for (var filter in filters) { %> + <li data-type="<%=filter%>"><%=filters[filter]%></li> + <% } %> +</ul> + +<h4>Polling interval</h4> +<input id="pollingRange" type="range" + min="1" + max="30" + step="1" + value="5"/> +<label for="pollingRange"><span>5</span> second(s)</label> diff --git a/src/fauxton/app/addons/activetasks/views.js b/src/fauxton/app/addons/activetasks/views.js new file mode 100644 index 000000000..f38aea2fd --- /dev/null +++ b/src/fauxton/app/addons/activetasks/views.js @@ -0,0 +1,165 @@ +// 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 Views = {}, + Events = {}, + pollingInfo ={ + rate: "5", + intervalId: null + }; + + + _.extend(Events, Backbone.Events); + + Views.TabMenu = FauxtonAPI.View.extend({ + template: "addons/activetasks/templates/tabs", + events: { + "click .task-tabs li": "requestByType", + "change #pollingRange": "changePollInterval" + }, + establish: function(){ + return [this.model.fetch({reset: true})]; + }, + serialize: function(){ + return { + filters: this.model.alltypes + }; + }, + afterRender: function(){ + $('.task-tabs').find('li').eq(0).addClass('active'); + }, + changePollInterval: function(e){ + var range = $(e.currentTarget).val(); + $('label[for="pollingRange"] span').text(range); + pollingInfo.rate = range; + clearInterval(pollingInfo.intervalId); + Events.trigger('update:poll'); + }, + requestByType: function(e){ + var currentTarget = e.currentTarget; + datatype = $(currentTarget).attr("data-type"); + + $('.task-tabs').find('li').removeClass('active'); + $(currentTarget).addClass('active'); + this.model.changeView(datatype); + } + }); + + Views.DataSection = FauxtonAPI.View.extend({ + initialize: function(){ + this.listenToOnce(this.model, "change", this.showData); //check why I needed to do this + }, + showData: function(){ + var that = this, + currentData = this.model.getCurrentViewData(); + //remove the old stuff in a nice clean way + if (this.dataView) { + this.dataView.remove(); + } + + //add the new stuff + this.dataView = that.insertView( new Views.tableData({ + collection: currentData, + currentView: this.model.get('currentView').replace('_',' ') + })); + + this.dataView.render(); + }, + establish: function(){ + return [this.model.fetch()]; + }, + setPolling: function(){ + var that = this; + pollingInfo.intervalId = setInterval(function() { + that.establish(); + }, pollingInfo.rate*1000); + }, + afterRender: function(){ + this.listenTo(this.model, "change", this.showData); + Events.bind('update:poll', this.setPolling, this); + this.setPolling(); + } + }); + + Views.tableData = FauxtonAPI.View.extend({ + tagName: "table", + className: "table table-bordered table-striped active-tasks", + template: "addons/activetasks/templates/table", + events: { + "click th": "sortByType" + }, + initialize: function(){ + currentView = this.options.currentView; + }, + sortByType: function(e){ + var currentTarget = e.currentTarget; + datatype = $(currentTarget).attr("data-type"); + this.collection.sortByColumn(datatype); + this.render(); + }, + serialize: function(){ + return { + currentView: currentView, + collection: this.collection + }; + }, + beforeRender: function(){ + //iterate over the collection to add each + this.collection.forEach(function(item) { + this.insertView("#tasks_go_here", new Views.TableDetail({ + model: item + })); + }, this); + } + }); + + Views.TableDetail = FauxtonAPI.View.extend({ + tagName: 'tr', + template: "addons/activetasks/templates/tabledetail", + initialize: function(){ + this.type = this.model.get('type'); + }, + getObject: function(){ + var objectField = this.model.get('database'); + if (this.type === "replication"){ + objectField = this.model.get('source') + " to " + this.model.get('target'); + } + return objectField; + }, + getProgress: function(){ + var progress = ""; + if (this.type === "indexer"){ + progress = "Processed " +this.model.get('changes_done')+ " of "+this.model.get('total_changes')+ ' changes'; + } + return progress; + }, + serialize: function(){ + return { + model: this.model, + objectField: this.getObject(), + progress: this.getProgress() + }; + } + }); + + + + return Views; +}); diff --git a/src/fauxton/app/helpers.js b/src/fauxton/app/helpers.js index 2ffe2fd8b..6408afc56 100644 --- a/src/fauxton/app/helpers.js +++ b/src/fauxton/app/helpers.js @@ -19,6 +19,7 @@ define([ + "d3" ], function() { @@ -43,6 +44,10 @@ function() { return size.toFixed(1) + ' ' + units[i - 1]; }; + Helpers.formatDate = function(timestamp){ + format = d3.time.format("%b. %e at %H:%M%p"); + return format(new Date(timestamp*1000)); + }; return Helpers; }); diff --git a/src/fauxton/assets/less/database.less b/src/fauxton/assets/less/database.less index 4ce41f80a..b96e73049 100644 --- a/src/fauxton/assets/less/database.less +++ b/src/fauxton/assets/less/database.less @@ -166,3 +166,9 @@ padding-right: 10px; float: right; } + +table.active-tasks{ + th { + cursor: pointer; + } +} diff --git a/src/fauxton/assets/less/fauxton.less b/src/fauxton/assets/less/fauxton.less index 445b815a2..cef163866 100644 --- a/src/fauxton/assets/less/fauxton.less +++ b/src/fauxton/assets/less/fauxton.less @@ -98,3 +98,5 @@ pre.view-code-error { background: url('../img/loader.gif') center center no-repeat; min-height: 100px; } + + diff --git a/src/fauxton/settings.json.default b/src/fauxton/settings.json.default index 910488b2f..2b7fe892c 100644 --- a/src/fauxton/settings.json.default +++ b/src/fauxton/settings.json.default @@ -1,5 +1,6 @@ { "deps": [ + { "name": "activetasks" }, { "name": "config" }, { "name": "logs" }, { "name": "stats" }, |
