Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 15AC6109A5 for ; Wed, 7 Aug 2013 16:04:50 +0000 (UTC) Received: (qmail 74931 invoked by uid 500); 7 Aug 2013 16:04:38 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 74761 invoked by uid 500); 7 Aug 2013 16:04:37 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 74132 invoked by uid 99); 7 Aug 2013 16:04:34 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Aug 2013 16:04:34 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id BD88D1D0E6; Wed, 7 Aug 2013 16:04:33 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: djc@apache.org To: commits@couchdb.apache.org Date: Wed, 07 Aug 2013 16:04:55 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [24/26] Remove fauxton from 1.4.x branch. http://git-wip-us.apache.org/repos/asf/couchdb/blob/a2b7d6a1/src/fauxton/app/addons/logs/resources.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/logs/resources.js b/src/fauxton/app/addons/logs/resources.js deleted file mode 100644 index 072290b..0000000 --- a/src/fauxton/app/addons/logs/resources.js +++ /dev/null @@ -1,223 +0,0 @@ -// 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", - "backbone" -], - -function (app, FauxtonAPI, Backbone) { - - var Log = FauxtonAPI.addon(); - - Log.Model = Backbone.Model.extend({ - - date: function () { - var date = new Date(this.get('date')); - - var formatted_time = date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(); - var formatted_date = date.toDateString().slice(4, 10); - - return formatted_date + ' ' + formatted_time; - }, - - logLevel: function () { - return this.get('log_level').replace(/ /g,''); - }, - - pid: function () { - return _.escape(this.get('pid')); - }, - - args: function () { - return _.escape(this.get('args')); - } - - }); - - Log.Collection = Backbone.Collection.extend({ - model: Log.Model, - - initialize: function (options) { - this.params = {bytes: 5000}; - }, - - url: function () { - query = "?" + $.param(this.params); - return app.host + '/_log' + query; - }, - - // override fetch because backbone expects json and couchdb sends text/html for logs, - // I think its more elegant to set the dataType here than where ever fetch is called - fetch: function (options) { - options = options ? options : {}; - - return Backbone.Collection.prototype.fetch.call(this, _.extend(options, {dataType: "html"})); - }, - - parse: function (resp) { - var lines = resp.split(/\n/); - return _.foldr(lines, function (acc, logLine) { - var match = logLine.match(/^\[(.*?)\]\s\[(.*?)\]\s\[(.*?)\]\s(.*)/); - - if (!match) { return acc;} - - acc.push({ - date: match[1], - log_level: match[2], - pid: match[3], - args: match[4] - }); - - return acc; - }, []); - } - }); - - Log.events = {}; - _.extend(Log.events, Backbone.Events); - - Log.Views.View = FauxtonAPI.View.extend({ - template: "addons/logs/templates/dashboard", - - initialize: function (options) { - this.refreshTime = options.refreshTime || 5000; - - Log.events.on("log:filter", this.filterLogs, this); - Log.events.on("log:remove", this.removeFilterLogs, this); - - this.filters = []; - - this.collection.on("add", function () { - this.render(); - }, this); - }, - - establish: function () { - return [this.collection.fetch()]; - }, - - serialize: function () { - return { logs: new Log.Collection(this.createFilteredCollection())}; - }, - - afterRender: function () { - this.startRefreshInterval(); - }, - - cleanup: function () { - this.stopRefreshInterval(); - }, - - filterLogs: function (filter) { - this.filters.push(filter); - this.render(); - }, - - createFilteredCollection: function () { - var that = this; - - return _.reduce(this.filters, function (logs, filter) { - - return _.filter(logs, function (log) { - var match = false; - - _.each(log, function (value) { - if (value.toString().match(new RegExp(filter))) { - match = true; - } - }); - return match; - }); - - - }, this.collection.toJSON(), this); - - }, - - removeFilterLogs: function (filter) { - this.filters.splice(this.filters.indexOf(filter), 1); - this.render(); - }, - - startRefreshInterval: function () { - var collection = this.collection; - - // Interval already set - if (this.intervalId) { return ; } - - this.intervalId = setInterval(function () { - collection.fetch(); - }, this.refreshTime); - - }, - - stopRefreshInterval: function () { - clearInterval(this.intervalId); - } - }); - - Log.Views.FilterView = FauxtonAPI.View.extend({ - template: "addons/logs/templates/sidebar", - - events: { - "submit #log-filter-form": "filterLogs" - }, - - filterLogs: function (event) { - event.preventDefault(); - var $filter = this.$('input[name="filter"]'), - filter = $filter.val(); - - Log.events.trigger("log:filter", filter); - - this.insertView("#filter-list", new Log.Views.FilterItemView({ - filter: filter - })).render(); - - $filter.val(''); - } - - }); - - Log.Views.FilterItemView = FauxtonAPI.View.extend({ - template: "addons/logs/templates/filterItem", - tagName: "li", - - initialize: function (options) { - this.filter = options.filter; - }, - - events: { - "click .remove-filter": "removeFilter" - }, - - serialize: function () { - return { - filter: this.filter - }; - }, - - removeFilter: function (event) { - event.preventDefault(); - - Log.events.trigger("log:remove", this.filter); - this.remove(); - } - - }); - - - return Log; - -}); http://git-wip-us.apache.org/repos/asf/couchdb/blob/a2b7d6a1/src/fauxton/app/addons/logs/routes.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/logs/routes.js b/src/fauxton/app/addons/logs/routes.js deleted file mode 100644 index 7c498b0..0000000 --- a/src/fauxton/app/addons/logs/routes.js +++ /dev/null @@ -1,58 +0,0 @@ -// 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", - - // Modules - "addons/logs/resources" -], - -function(app, FauxtonAPI, Log) { - - var LogRouteObject = FauxtonAPI.RouteObject.extend({ - layout: "with_sidebar", - - crumbs: [ - {"name": "Logs", "link": "_log"} - ], - - routes: { - "_log": "showLog" - }, - - selectedHeader: "Log", - - roles: ["_admin"], - - apiUrl: function() { - return this.logs.url(); - }, - - initialize: function () { - this.logs = new Log.Collection(); - this.setView("#sidebar-content", new Log.Views.FilterView({})); - }, - - showLog: function () { - this.setView("#dashboard-content", new Log.Views.View({collection: this.logs})); - } - }); - - Log.RouteObjects = [LogRouteObject]; - - return Log; - -}); - http://git-wip-us.apache.org/repos/asf/couchdb/blob/a2b7d6a1/src/fauxton/app/addons/logs/templates/dashboard.html ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/logs/templates/dashboard.html b/src/fauxton/app/addons/logs/templates/dashboard.html deleted file mode 100644 index 14969c8..0000000 --- a/src/fauxton/app/addons/logs/templates/dashboard.html +++ /dev/null @@ -1,46 +0,0 @@ - - -

Couchdb Logs

- - - - - - - - - - - - <% logs.each(function (log) { %> - - - - - - - <% }); %> - -
DateLog ValuePidUrl
- - <%= log.date() %> - - <%= log.logLevel() %> - - <%= log.pid() %> - - - <%= log.args() %> -
http://git-wip-us.apache.org/repos/asf/couchdb/blob/a2b7d6a1/src/fauxton/app/addons/logs/templates/filterItem.html ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/logs/templates/filterItem.html b/src/fauxton/app/addons/logs/templates/filterItem.html deleted file mode 100644 index c4e885a..0000000 --- a/src/fauxton/app/addons/logs/templates/filterItem.html +++ /dev/null @@ -1,16 +0,0 @@ - - - <%= filter %> -× http://git-wip-us.apache.org/repos/asf/couchdb/blob/a2b7d6a1/src/fauxton/app/addons/logs/templates/sidebar.html ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/logs/templates/sidebar.html b/src/fauxton/app/addons/logs/templates/sidebar.html deleted file mode 100644 index 91822e0..0000000 --- a/src/fauxton/app/addons/logs/templates/sidebar.html +++ /dev/null @@ -1,27 +0,0 @@ - - -
-
-
- Log Filter - - - - -
Eg. debug or <1.4.1> or any regex
-
-
-
    -
    http://git-wip-us.apache.org/repos/asf/couchdb/blob/a2b7d6a1/src/fauxton/app/addons/logs/tests/logSpec.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/logs/tests/logSpec.js b/src/fauxton/app/addons/logs/tests/logSpec.js deleted file mode 100644 index 621cc9b..0000000 --- a/src/fauxton/app/addons/logs/tests/logSpec.js +++ /dev/null @@ -1,38 +0,0 @@ -// 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([ - 'addons/logs/base', - 'chai' -], function (Log, chai) { - var expect = chai.expect; - - describe('Logs Addon', function(){ - - describe('Log Model', function () { - var log; - - beforeEach(function () { - log = new Log.Model({ - log_level: 'DEBUG', - pid: '1234', - args: 'testing 123', - date: (new Date()).toString() - }); - }); - - it('should have a log level', function () { - expect(log.logLevel()).to.equal('DEBUG'); - }); - - }); - }); -}); http://git-wip-us.apache.org/repos/asf/couchdb/blob/a2b7d6a1/src/fauxton/app/addons/stats/assets/less/stats.less ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/stats/assets/less/stats.less b/src/fauxton/app/addons/stats/assets/less/stats.less deleted file mode 100644 index 8c81f86..0000000 --- a/src/fauxton/app/addons/stats/assets/less/stats.less +++ /dev/null @@ -1,20 +0,0 @@ -/* 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. - */ - -.datatypes { - border: #d3d3d3 1px solid; - -webkit-border-radius: 5px; - -moz-border-radius: 5px; - border-radius: 5px; - padding: 15px; -} http://git-wip-us.apache.org/repos/asf/couchdb/blob/a2b7d6a1/src/fauxton/app/addons/stats/base.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/stats/base.js b/src/fauxton/app/addons/stats/base.js deleted file mode 100644 index 4721399..0000000 --- a/src/fauxton/app/addons/stats/base.js +++ /dev/null @@ -1,26 +0,0 @@ -// 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/stats/routes" -], - -function(app, FauxtonAPI, Stats) { - - Stats.initialize = function() { - FauxtonAPI.addHeaderLink({title: "Statistics", href: "#stats"}); - }; - - return Stats; -}); http://git-wip-us.apache.org/repos/asf/couchdb/blob/a2b7d6a1/src/fauxton/app/addons/stats/resources.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/stats/resources.js b/src/fauxton/app/addons/stats/resources.js deleted file mode 100644 index 94be6bb..0000000 --- a/src/fauxton/app/addons/stats/resources.js +++ /dev/null @@ -1,37 +0,0 @@ -// 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", - "backbone", - "lodash", - "modules/fauxton/base" -], - -function (app, FauxtonAPI, backbone, _, Fauxton) { - var Stats = new FauxtonAPI.addon(); - - Stats.Collection = Backbone.Collection.extend({ - model: Backbone.Model, - url: "/_stats", - parse: function(resp) { - return _.flatten(_.map(resp, function(doc, key) { - return _.map(doc, function(v, k){ - return _.extend({id: k, type: key}, v); - }); - }), true); - } - }); - - return Stats; -}); http://git-wip-us.apache.org/repos/asf/couchdb/blob/a2b7d6a1/src/fauxton/app/addons/stats/routes.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/stats/routes.js b/src/fauxton/app/addons/stats/routes.js deleted file mode 100644 index 5f1affe..0000000 --- a/src/fauxton/app/addons/stats/routes.js +++ /dev/null @@ -1,56 +0,0 @@ -// 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/stats/views" -], - -function(app, FauxtonAPI, Stats) { - - var StatsRouteObject = FauxtonAPI.RouteObject.extend({ - layout: "with_sidebar", - - routes: { - "stats":"showStats", - "_stats": "showStats" - }, - - selectedHeader: "Statistics", - - initialize: function () { - this.stats = new Stats.Collection(); - - this.setView("#sidebar-content", new Views.StatSelect({ - collection: this.stats - })); - - }, - - showStats: function () { - this.setView("#dashboard-content", new Views.Statistics({ - collection: this.stats - })); - }, - - establish: function() { - return [this.stats.fetch()]; - }, - - apiUrl: "_stats" - }); - - Stats.RouteObjects = [StatsRouteObject]; - - return Stats; -}); http://git-wip-us.apache.org/repos/asf/couchdb/blob/a2b7d6a1/src/fauxton/app/addons/stats/templates/by_method.html ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/stats/templates/by_method.html b/src/fauxton/app/addons/stats/templates/by_method.html deleted file mode 100644 index 099d737..0000000 --- a/src/fauxton/app/addons/stats/templates/by_method.html +++ /dev/null @@ -1,16 +0,0 @@ - - -

    By Method GET, POST, PUT, DELETE

    -
    http://git-wip-us.apache.org/repos/asf/couchdb/blob/a2b7d6a1/src/fauxton/app/addons/stats/templates/pie_table.html ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/stats/templates/pie_table.html b/src/fauxton/app/addons/stats/templates/pie_table.html deleted file mode 100644 index fba4717..0000000 --- a/src/fauxton/app/addons/stats/templates/pie_table.html +++ /dev/null @@ -1,56 +0,0 @@ - - -
    -
    -

    <%= datatype %>

    -
    -
    - -
    -
    - - - - - - - - - - - - - <% _.each (statistics, function (stat_line) { - if (stat_line.get("sum")){ - %> - - - - - - - - - - <% }}) %> -
    Description current sum mean stddev min max
    <%= stat_line.get("description") %><%= stat_line.get("current") %><%= stat_line.get("sum") %><%= stat_line.get("mean") %><%= stat_line.get("stddev") %><%= stat_line.get("min") %><%= stat_line.get("max") %>
    -
    - -
    -
    - -
    -
    -
    http://git-wip-us.apache.org/repos/asf/couchdb/blob/a2b7d6a1/src/fauxton/app/addons/stats/templates/stats.html ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/stats/templates/stats.html b/src/fauxton/app/addons/stats/templates/stats.html deleted file mode 100644 index ae7ce14..0000000 --- a/src/fauxton/app/addons/stats/templates/stats.html +++ /dev/null @@ -1,16 +0,0 @@ - - -
    -
    http://git-wip-us.apache.org/repos/asf/couchdb/blob/a2b7d6a1/src/fauxton/app/addons/stats/templates/statselect.html ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/stats/templates/statselect.html b/src/fauxton/app/addons/stats/templates/statselect.html deleted file mode 100644 index ef1133c..0000000 --- a/src/fauxton/app/addons/stats/templates/statselect.html +++ /dev/null @@ -1,22 +0,0 @@ - - -<% _.each(datatypes, function (datatype) { %> -
  • - - <%= datatype %> - - -
  • -<% }); %> http://git-wip-us.apache.org/repos/asf/couchdb/blob/a2b7d6a1/src/fauxton/app/addons/stats/views.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/stats/views.js b/src/fauxton/app/addons/stats/views.js deleted file mode 100644 index 9dd9cbc..0000000 --- a/src/fauxton/app/addons/stats/views.js +++ /dev/null @@ -1,171 +0,0 @@ -// 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/stats/resources', - "d3", - "nv.d3" - -], - -function(app, FauxtonAPI,Stats) { - Views = {}; - - datatypeEventer = {}; - _.extend(datatypeEventer, Backbone.Events); - - Views.Legend = FauxtonAPI.View.extend({ - tagName: 'ul', - template: "addons/stats/templates/legend", - - serialize: function () { - return { - legend_items: this.collection.toJSON() - }; - } - }); - - Views.Pie = FauxtonAPI.View.extend({ - className: "datatype-section", - template: 'addons/stats/templates/pie_table', - - initialize: function(args){ - this.datatype = args.datatype; - }, - - serialize: function() { - return { - statistics: this.collection.where({type: this.datatype}), - datatype: this.datatype - }; - }, - - afterRender: function(){ - var collection = this.collection, - chartelem = "#" + this.datatype + '_graph', - series = _.map(this.collection.where({type: this.datatype}), - function(d, counter){ - // TODO: x should be a counter - var point = { - y: d.get("sum") || 0, - key: d.id - }; - return point; - } - ); - - series = _.filter(series, function(d){return d.y > 0;}); - series = _.sortBy(series, function(d){return -d.y;}); - - nv.addGraph(function() { - var width = 550, - height = 400; - - var chart = nv.models.pieChart() - .x(function(d) { return d.key; }) - .y(function(d) { return d.y; }) - .showLabels(true) - .showLegend(false) - .values(function(d) { return d; }) - .color(d3.scale.category10().range()) - .width(width) - .height(height); - - d3.select(chartelem) - .datum([series]) - .transition().duration(300) - .attr('width', width) - .attr('height', height) - .call(chart); - - return chart; - }); - - this.$el.addClass(this.datatype + '_section'); - } - }); - - Views.StatSelect = FauxtonAPI.View.extend({ - className: 'nav nav-tabs nav-stacked', - tagName: 'ul', - - template: "addons/stats/templates/statselect", - - initialize: function (options) { - this.rows = []; - }, - - events: { - 'click .datatype-select': "datatype_selected" - }, - - serialize: function () { - return { - datatypes: _.uniq(this.collection.pluck("type")) - }; - }, - - afterRender: function () { - this.$('.datatype-select').first().addClass('active'); - }, - - datatype_selected: function (event) { - var $target = $(event.currentTarget); - - event.preventDefault(); - event.stopPropagation(); - this.$('.datatype-select').removeClass('active'); - $target.addClass('active'); - datatypeEventer.trigger('datatype-select', $target.attr('data-type-select')); - } - }); - - Views.Statistics = FauxtonAPI.View.extend({ - template: "addons/stats/templates/stats", - - initialize: function (options) { - this.rows = []; - datatypeEventer.on('datatype-select', this.display_datatype, this); - }, - - serialize: function () { - return { - datatypes: _.uniq(this.collection.pluck("type")) - }; - }, - - beforeRender: function () { - _.each(_.uniq(this.collection.pluck("type")), function(datatype) { - this.rows[datatype] = this.insertView(".datatypes", new Views.Pie({ - collection: this.collection, - datatype: datatype - })); - }, this); - }, - - afterRender: function () { - this.$('.datatype-section').hide().first().toggle(); - }, - - display_datatype: function (datatype) { - this.$('.datatype-section').hide(); - this.$('.' + datatype + '_section').show(); - } - }); - - Stats.Views = Views; - - return Stats; -}); http://git-wip-us.apache.org/repos/asf/couchdb/blob/a2b7d6a1/src/fauxton/app/api.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/api.js b/src/fauxton/app/api.js deleted file mode 100644 index c4aaaf4..0000000 --- a/src/fauxton/app/api.js +++ /dev/null @@ -1,390 +0,0 @@ -// 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", - - // Modules - "modules/fauxton/base" -], - -function(app, Fauxton) { - var FauxtonAPI = app.module(); - - FauxtonAPI.moduleExtensions = { - Routes: { - } - }; - - FauxtonAPI.addonExtensions = { - initialize: function() {} - }; - - // List of JSHINT errors to ignore - // Gets around problem of anonymous functions not being a valid statement - FauxtonAPI.excludedViewErrors = [ - "Missing name in function declaration.", - "['{a}'] is better written in dot notation." - ]; - - FauxtonAPI.isIgnorableError = function(msg) { - return _.contains(FauxtonAPI.excludedViewErrors, msg); - }; - - FauxtonAPI.View = Backbone.View.extend({ - // This should return an array of promises, an empty array, or null - establish: function() { - return null; - }, - - loaderClassname: 'loader', - - disableLoader: false, - - hasRendered: function () { - return !!this.__manager__.hasRendered; - }, - - forceRender: function () { - this.__manager__.hasRendered = false; - } - }); - - FauxtonAPI.navigate = function(url, _opts) { - var options = _.extend({trigger: true}, _opts ); - app.router.navigate(url,options); - }; - - FauxtonAPI.addHeaderLink = function(link) { - app.masterLayout.navBar.addLink(link); - }; - - FauxtonAPI.Deferred = function() { - return $.Deferred(); - }; - - FauxtonAPI.when = function (deferreds) { - if (deferreds instanceof Array) { - return $.when.apply(null, deferreds); - } - - return $.when(deferreds); - }; - - FauxtonAPI.addRoute = function(route) { - app.router.route(route.route, route.name, route.callback); - }; - - FauxtonAPI.triggerRouteEvent = function (routeEvent, args) { - app.router.triggerRouteEvent("route:"+routeEvent, args); - }; - - FauxtonAPI.module = function(extra) { - return app.module(_.extend(FauxtonAPI.moduleExtensions, extra)); - }; - - FauxtonAPI.addon = function(extra) { - return FauxtonAPI.module(FauxtonAPI.addonExtensions, extra); - }; - - FauxtonAPI.addNotification = function(options) { - options = _.extend({ - msg: "Notification Event Triggered!", - type: "info", - selector: "#global-notifications" - }, options); - var view = new Fauxton.Notification(options); - - return view.renderNotification(); - }; - - FauxtonAPI.UUID = Backbone.Model.extend({ - initialize: function(options) { - options = _.extend({count: 1}, options); - this.count = options.count; - }, - - url: function() { - return app.host + "/_uuids?count=" + this.count; - }, - - next: function() { - return this.get("uuids").pop(); - } - }); - - FauxtonAPI.Session = Backbone.Model.extend({ - url: '/_session', - - user: function () { - var userCtx = this.get('userCtx'); - - if (!userCtx || !userCtx.name) { return null; } - - return { - name: userCtx.name, - roles: userCtx.roles - }; - }, - - fetchOnce: function (opt) { - var options = _.extend({}, opt); - - if (!this._deferred || this._deferred.state() === "rejected" || options.forceFetch ) { - this._deferred = this.fetch(); - } - - return this._deferred; - }, - - fetchUser: function (opt) { - var that = this, - currentUser = this.user(); - - return this.fetchOnce(opt).then(function () { - var user = that.user(); - - // Notify anyone listening on these events that either a user has changed - // or current user is the same - if (currentUser !== user) { - that.trigger('session:userChanged'); - } else { - that.trigger('session:userFetched'); - } - - // this will return the user as a value to all function that calls done on this - // eg. session.fetchUser().done(user) { .. do something with user ..} - return user; - }); - } - }); - - FauxtonAPI.setSession = function (newSession) { - app.session = FauxtonAPI.session = newSession; - return FauxtonAPI.session.fetchUser(); - }; - - FauxtonAPI.setSession(new FauxtonAPI.Session()); - - // This is not exposed externally as it should not need to be accessed or overridden - var Auth = function (options) { - this._options = options; - this.initialize.apply(this, arguments); - }; - - // Piggy-back on Backbone's self-propagating extend function, - Auth.extend = Backbone.Model.extend; - - _.extend(Auth.prototype, Backbone.Events, { - authDeniedCb: function() {}, - - initialize: function() { - var that = this; - }, - - authHandlerCb : function (roles) { - var deferred = $.Deferred(); - deferred.resolve(); - return deferred; - }, - - registerAuth: function (authHandlerCb) { - this.authHandlerCb = authHandlerCb; - }, - - registerAuthDenied: function (authDeniedCb) { - this.authDeniedCb = authDeniedCb; - }, - - checkAccess: function (roles) { - var requiredRoles = roles || [], - that = this; - - return FauxtonAPI.session.fetchUser().then(function (user) { - return FauxtonAPI.when(that.authHandlerCb(FauxtonAPI.session, requiredRoles)); - }); - } - }); - - FauxtonAPI.auth = new Auth(); - - FauxtonAPI.RouteObject = function(options) { - this._options = options; - - this._configure(options || {}); - this.initialize.apply(this, arguments); - this.addEvents(); - }; - - // Piggy-back on Backbone's self-propagating extend function - FauxtonAPI.RouteObject.extend = Backbone.Model.extend; - - var routeObjectOptions = ["views", "routes", "events", "roles", "crumbs", "layout", "apiUrl", "establish"]; - - _.extend(FauxtonAPI.RouteObject.prototype, Backbone.Events, { - // Should these be default vals or empty funcs? - views: {}, - routes: {}, - events: {}, - crumbs: [], - layout: "with_sidebar", - apiUrl: null, - disableLoader: false, - loaderClassname: 'loader', - renderedState: false, - establish: function() {}, - route: function() {}, - roles: [], - initialize: function() {} - }, { - - renderWith: function(route, masterLayout, args) { - var routeObject = this; - - // TODO: Can look at replacing this with events eg beforeRender, afterRender function and events - this.route.call(this, route, args); - - // Only want to redo the template if its a full render - if (!this.renderedState) { - masterLayout.setTemplate(this.layout); - $('#nav-links li').removeClass('active'); - - if (this.selectedHeader) { - $('#nav-links li[data-nav-name="' + this.selectedHeader + '"]').addClass('active'); - } - } - - //add page loader. "app-container" shouldn't be overwritten. Even if a new index.underscore is provided in settings.json - if (!this.disableLoader) { - $('#app-container').addClass(this.loaderClassname); - } - - masterLayout.clearBreadcrumbs(); - var crumbs = this.get('crumbs'); - - if (crumbs.length) { - masterLayout.setBreadcrumbs(new Fauxton.Breadcrumbs({ - crumbs: crumbs - })); - } - - FauxtonAPI.when(this.establish()).done(function(resp) { - if (!this.disableLoader) { - $('#app-container').removeClass(this.loaderClassname); - } - _.each(routeObject.getViews(), function(view, selector) { - if(view.hasRendered()) { return; } - if (!view.disableLoader){ $(selector).addClass(view.loaderClassname);} - FauxtonAPI.when(view.establish()).then(function(resp) { - masterLayout.setView(selector, view); - if (!view.disableLoader) $(selector).removeClass(view.loaderClassname); - masterLayout.renderView(selector); - }, function(resp) { - view.establishError = { - error: true, - reason: resp - }; - masterLayout.renderView(selector); - }); - - var hooks = masterLayout.hooks[selector]; - var boundRoute = route; - - _.each(hooks, function(hook){ - if (_.any(hook.routes, function(route){return route == boundRoute;})){ - hook.callback(view); - } - }); - }); - }.bind(this)); - - if (this.get('apiUrl')) masterLayout.apiBar.update(this.get('apiUrl')); - - // Track that we've done a full initial render - this.renderedState = true; - }, - - get: function(key) { - return _.isFunction(this[key]) ? this[key]() : this[key]; - }, - - addEvents: function(events) { - events = events || this.get('events'); - _.each(events, function(method, event) { - if (!_.isFunction(method) && !_.isFunction(this[method])) { - throw new Error("Invalid method: "+method); - } - method = _.isFunction(method) ? method : this[method]; - - this.on(event, method); - }, this); - }, - - _configure: function(options) { - _.each(_.intersection(_.keys(options), routeObjectOptions), function(key) { - this[key] = options[key]; - }, this); - }, - - getView: function(selector) { - return this.views[selector]; - }, - - setView: function(selector, view) { - this.views[selector] = view; - return view; - }, - - getViews: function() { - return this.views; - }, - - getRouteUrls: function () { - return _.keys(this.get('routes')); - }, - - hasRoute: function (route) { - if (this.get('routes')[route]) { - return true; - } - return false; - }, - - routeCallback: function (route, args) { - var routes = this.get('routes'), - routeObj = routes[route], - routeCallback; - - if (typeof routeObj === 'object') { - routeCallback = this[routeObj.route]; - } else { - routeCallback = this[routeObj]; - } - - routeCallback.apply(this, args); - }, - - getRouteRoles: function (routeUrl) { - var route = this.get('routes')[routeUrl]; - - if ((typeof route === 'object') && route.roles) { - return route.roles; - } - - return this.roles; - } - - }); - - app.fauxtonAPI = FauxtonAPI; - return app.fauxtonAPI; -}); http://git-wip-us.apache.org/repos/asf/couchdb/blob/a2b7d6a1/src/fauxton/app/app.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/app.js b/src/fauxton/app/app.js deleted file mode 100644 index df0894a..0000000 --- a/src/fauxton/app/app.js +++ /dev/null @@ -1,75 +0,0 @@ -define([ - // Libraries. - "jquery", - "lodash", - "backbone", - - "helpers", - - // Plugins. - "plugins/backbone.layoutmanager", - "plugins/jquery.form" -], - -function($, _, Backbone, Helpers) { - - // Make sure we have a console.log - if (typeof console == "undefined") { - console = { - log: function(){} - }; - } - - // Provide a global location to place configuration settings and module - // creation. - var app = { - // The root path to run the application. - root: "/", - version: "0.0.1" - }; - - // Localize or create a new JavaScript Template object. - var JST = window.JST = window.JST || {}; - - // Configure LayoutManager with Backbone Boilerplate defaults. - Backbone.Layout.configure({ - // Allow LayoutManager to augment Backbone.View.prototype. - manage: true, - - prefix: "app/", - - // Inject app/helper.js for shared functionality across all html templates - render: function(template, context) { - return template(_.extend(Helpers, context)); - }, - - fetch: function(path) { - // Initialize done for use in async-mode - var done; - - // Concatenate the file extension. - path = path + ".html"; - - // If cached, use the compiled template. - if (JST[path]) { - return JST[path]; - } else { - // Put fetch into `async-mode`. - done = this.async(); - // Seek out the template asynchronously. - return $.ajax({ url: app.root + path }).then(function(contents) { - done(JST[path] = _.template(contents)); - }); - } - } - }); - - // Mix Backbone.Events, and modules into the app object. - return _.extend(app, { - // Create a custom object with a nested Views object. - module: function(additionalProps) { - return _.extend({ Views: {} }, additionalProps); - } - }, Backbone.Events); - -}); http://git-wip-us.apache.org/repos/asf/couchdb/blob/a2b7d6a1/src/fauxton/app/config.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/config.js b/src/fauxton/app/config.js deleted file mode 100644 index d7d3b40..0000000 --- a/src/fauxton/app/config.js +++ /dev/null @@ -1,56 +0,0 @@ -// Set the require.js configuration for your application. -require.config({ - - // Initialize the application with the main application file. - deps: ["main"], - - paths: { - // JavaScript folders. - libs: "../assets/js/libs", - plugins: "../assets/js/plugins", - - // Libraries. - jquery: "../assets/js/libs/jquery", - lodash: "../assets/js/libs/lodash", - backbone: "../assets/js/libs/backbone", - bootstrap: "../assets/js/libs/bootstrap", - codemirror: "../assets/js/libs/codemirror", - jshint: "../assets/js/libs/jshint", - d3: "../assets/js/libs/d3", - "nv.d3": "../assets/js/libs/nv.d3" - }, - - baseUrl: '/', - - shim: { - // Backbone library depends on lodash and jQuery. - backbone: { - deps: ["lodash", "jquery"], - exports: "Backbone" - }, - - bootstrap: { - deps: ["jquery"], - exports: "Bootstrap" - }, - - codemirror: { - deps: ["jquery"], - exports: "CodeMirror" - }, - - jshint: { - deps: ["jquery"], - exports: "JSHINT" - }, - - // Backbone.LayoutManager depends on Backbone. - "plugins/backbone.layoutmanager": ["backbone"], - - "plugins/codemirror-javascript": ["codemirror"], - - "plugins/prettify": [], - - "plugins/jquery.form": ["jquery"] - } -}); http://git-wip-us.apache.org/repos/asf/couchdb/blob/a2b7d6a1/src/fauxton/app/helpers.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/helpers.js b/src/fauxton/app/helpers.js deleted file mode 100644 index 6408afc..0000000 --- a/src/fauxton/app/helpers.js +++ /dev/null @@ -1,54 +0,0 @@ -// 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. - - -// This file creates a set of helper functions that will be loaded for all html -// templates. These functions should be self contained and not rely on any -// external dependencies as they are loaded prior to the application. We may -// want to change this later, but for now this should be thought of as a -// "purely functional" helper system. - - -define([ - "d3" -], - -function() { - - var Helpers = {}; - - Helpers.imageUrl = function(path) { - // TODO: add dynamic path for different deploy targets - return path; - }; - - // File size pretty printing, taken from futon.format.js - Helpers.formatSize = function(size) { - var jump = 512; - if (size < jump) return size + " bytes"; - var units = ["KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]; - var i = 0; - while (size >= jump && i < units.length) { - i += 1; - size /= 1024; - } - 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; -}); - http://git-wip-us.apache.org/repos/asf/couchdb/blob/a2b7d6a1/src/fauxton/app/initialize.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/initialize.js b/src/fauxton/app/initialize.js deleted file mode 100644 index 6fed729..0000000 --- a/src/fauxton/app/initialize.js +++ /dev/null @@ -1,66 +0,0 @@ -// 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([ - // Application. - "app", - - // Libraries - "lodash", - "bootstrap" -], - -function(app, _, Bootstrap) { - - // Provide a global location to place configuration settings and module - // creation. - _.extend(app, { - // The root path to run the application through. - // TODO: pick this up wither at build time or from the browser - root: "/_utils/fauxton/", - - host: window.location.protocol + "//" + window.location.host, - - renderView: function(baseView, selector, view, options, callback) { - baseView.setView(selector, new view(options)).render().then(callback); - }, - - // Thanks to: http://stackoverflow.com/a/2880929 - getParams: function(queryString) { - if (typeof queryString !== "undefined") { - // I think this could be combined into one if - if (queryString.substring(0,1) === "?") { - queryString = queryString.substring(1); - } else if (queryString.indexOf('?') > -1) { - queryString = queryString.split('?')[1]; - } - } - var hash = window.location.hash.split('?')[1]; - queryString = queryString || hash || window.location.search.substring(1); - var match, - urlParams = {}, - pl = /\+/g, // Regex for replacing addition symbol with a space - search = /([^&=]+)=?([^&]*)/g, - decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); }, - query = queryString; - - if (queryString) { - while ((match = search.exec(query))) { - urlParams[decode(match[1])] = decode(match[2]); - } - } - - return urlParams; - } - }); - -}); http://git-wip-us.apache.org/repos/asf/couchdb/blob/a2b7d6a1/src/fauxton/app/load_addons.js.underscore ---------------------------------------------------------------------- diff --git a/src/fauxton/app/load_addons.js.underscore b/src/fauxton/app/load_addons.js.underscore deleted file mode 100644 index 9686ad7..0000000 --- a/src/fauxton/app/load_addons.js.underscore +++ /dev/null @@ -1,27 +0,0 @@ -// 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. - - -/* - * ::WARNING:: - * THIS IS A GENERATED FILE. DO NOT EDIT. - */ -define([ - <%= '"' + deps.join('","') + '"' %> -], -function() { - var LoadAddons = { - addons: arguments - }; - - return LoadAddons; -}); http://git-wip-us.apache.org/repos/asf/couchdb/blob/a2b7d6a1/src/fauxton/app/main.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/main.js b/src/fauxton/app/main.js deleted file mode 100644 index fba4f6e..0000000 --- a/src/fauxton/app/main.js +++ /dev/null @@ -1,38 +0,0 @@ -require([ - // Application. - "app", - - // Main Router. - "router" -], - -function(app, Router) { - - // Define your master router on the application namespace and trigger all - // navigation from this instance. - app.router = new Router(); - // Trigger the initial route and enable HTML5 History API support, set the - // root folder to '/' by default. Change in app.js. - Backbone.history.start({ pushState: false, root: app.root }); - // All navigation that is relative should be passed through the navigate - // method, to be processed by the router. If the link has a `data-bypass` - // attribute, bypass the delegation completely. - $(document).on("click", "a:not([data-bypass])", function(evt) { - // Get the absolute anchor href. - var href = { prop: $(this).prop("href"), attr: $(this).attr("href") }; - // Get the absolute root. - var root = location.protocol + "//" + location.host + app.root; - // Ensure the root is part of the anchor href, meaning it's relative. - if (href.prop && href.prop.slice(0, root.length) === root) { - // Stop the default event to ensure the link will not cause a page - // refresh. - evt.preventDefault(); - - // `Backbone.history.navigate` is sufficient for all Routers and will - // trigger the correct events. The Router's internal `navigate` method - // calls this anyways. The fragment is sliced from the root. - Backbone.history.navigate(href.attr, true); - } - - }); -}); http://git-wip-us.apache.org/repos/asf/couchdb/blob/a2b7d6a1/src/fauxton/app/modules/databases/base.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/modules/databases/base.js b/src/fauxton/app/modules/databases/base.js deleted file mode 100644 index a5b4542..0000000 --- a/src/fauxton/app/modules/databases/base.js +++ /dev/null @@ -1,36 +0,0 @@ -// 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", - - // Modules - "modules/databases/routes", - // Views - "modules/databases/views" - -], - -function(app, FauxtonAPI, Databases, Views) { - Databases.Views = Views; - - // Utility functions - Databases.databaseUrl = function(database) { - var name = _.isObject(database) ? database.id : database; - - return ["/database/", name, "/_all_docs?limit=10"].join(''); - }; - - return Databases; -}); http://git-wip-us.apache.org/repos/asf/couchdb/blob/a2b7d6a1/src/fauxton/app/modules/databases/resources.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/modules/databases/resources.js b/src/fauxton/app/modules/databases/resources.js deleted file mode 100644 index 04e6c1e..0000000 --- a/src/fauxton/app/modules/databases/resources.js +++ /dev/null @@ -1,148 +0,0 @@ -// 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", - - // Modules - "modules/documents/resources" -], - -function(app, FauxtonAPI, Documents) { - var Databases = FauxtonAPI.module(); - - Databases.Model = Backbone.Model.extend({ - initialize: function(options) { - this.status = new Databases.Status({ - database: this - }); - }, - - buildAllDocs: function(params) { - this.allDocs = new Documents.AllDocs(null, { - database: this, - params: params - }); - - return this.allDocs; - }, - - isNew: function(){ - // Databases are never new, to make Backbone do a PUT - return false; - }, - - url: function(context) { - if (context === "index") { - return "/database/" + this.id + "/_all_docs"; - } else if (context === "changes") { - return "/database/" + this.id + "/_changes?descending=true&limit=100&include_docs=true"; - } else if (context === "app") { - return "/database/" + this.id; - } else { - return app.host + "/" + this.id; - } - }, - - buildChanges: function (params) { - this.changes = new Databases.Changes({ - database: this, - params: params - }); - - return this.changes; - } - }); - - Databases.Changes = Backbone.Collection.extend({ - - initialize: function(options) { - this.database = options.database; - this.params = options.params; - }, - - url: function () { - var query = ""; - if (this.params) { - query = "?" + $.param(this.params); - } - - return app.host + '/' + this.database.id + '/_changes' + query; - }, - - parse: function (resp) { - this.last_seq = resp.last_seq; - return resp.results; - } - }); - - Databases.Status = Backbone.Model.extend({ - url: function() { - return app.host + "/" + this.database.id; - }, - - initialize: function(options) { - this.database = options.database; - }, - - numDocs: function() { - return this.get("doc_count"); - }, - - updateSeq: function(full) { - var updateSeq = this.get("update_seq"); - if (full || (typeof(updateSeq) === 'number')) { - return updateSeq; - } else if (updateSeq) { - return updateSeq.split('-')[0]; - } else { - return 0; - } - }, - - humanSize: function() { - // cribbed from http://stackoverflow.com/questions/10420352/converting-file-size-in-bytes-to-human-readable - var i = -1; - var byteUnits = [' kB', ' MB', ' GB', ' TB', 'PB', 'EB', 'ZB', 'YB']; - var fileSizeInBytes = this.get("disk_size"); - do { - fileSizeInBytes = fileSizeInBytes / 1024; - i++; - } while (fileSizeInBytes > 1024); - - return Math.max(fileSizeInBytes, 0.1).toFixed(1) + byteUnits[i]; - } - }); - - // TODO: shared databases - read from the user doc - Databases.List = Backbone.Collection.extend({ - model: Databases.Model, - - url: function() { - return app.host + "/_all_dbs"; - }, - - parse: function(resp) { - // TODO: pagination! - return _.map(resp, function(database) { - return { - id: encodeURIComponent(database), - name: database - }; - }); - } - }); - - return Databases; -}); http://git-wip-us.apache.org/repos/asf/couchdb/blob/a2b7d6a1/src/fauxton/app/modules/databases/routes.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/modules/databases/routes.js b/src/fauxton/app/modules/databases/routes.js deleted file mode 100644 index fe1a441..0000000 --- a/src/fauxton/app/modules/databases/routes.js +++ /dev/null @@ -1,84 +0,0 @@ -// 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", - - // Modules - "modules/databases/resources", - // TODO:: fix the include flow modules so we don't have to require views here - "modules/databases/views" -], - -function(app, FauxtonAPI, Databases, Views) { - - var AllDbsRouteObject = FauxtonAPI.RouteObject.extend({ - layout: "with_sidebar", - - crumbs: [ - {"name": "Databases", "link": "/_all_dbs"} - ], - - routes: { - "": "allDatabases", - "index.html": "allDatabases", - "_all_dbs(:params)": "allDatabases" - }, - - apiUrl: function() { - return this.databases.url(); - }, - - selectedHeader: "Databases", - - initialize: function() { - this.databases = new Databases.List(); - this.deferred = FauxtonAPI.Deferred(); - - this.sidebarView = this.setView("#sidebar-content", new Views.Sidebar({ - collection: this.databases - })); - }, - - allDatabases: function() { - var params = app.getParams(), - dbPage = params.page; - - this.databasesView = this.setView("#dashboard-content", new Views.List({ - collection: this.databases - })); - - this.databasesView.setPage(dbPage); - }, - - establish: function() { - var databases = this.databases; - var deferred = this.deferred; - - databases.fetch().done(function(resp) { - FauxtonAPI.when(databases.map(function(database) { - return database.status.fetch(); - })).done(function(resp) { - deferred.resolve(); - }); - }); - - return [deferred]; - } - }); - - Databases.RouteObjects = [AllDbsRouteObject]; - - return Databases; -}); http://git-wip-us.apache.org/repos/asf/couchdb/blob/a2b7d6a1/src/fauxton/app/modules/databases/views.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/modules/databases/views.js b/src/fauxton/app/modules/databases/views.js deleted file mode 100644 index c1b9bb7..0000000 --- a/src/fauxton/app/modules/databases/views.js +++ /dev/null @@ -1,190 +0,0 @@ -// 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", - - "modules/fauxton/base", - "api" -], - -function(app, Fauxton, FauxtonAPI) { - var Views = {}; - - Views.Item = FauxtonAPI.View.extend({ - template: "templates/databases/item", - tagName: "tr", - - serialize: function() { - return { - database: this.model - }; - } - }); - - Views.List = FauxtonAPI.View.extend({ - dbLimit: 10, - perPage: 10, - template: "templates/databases/list", - events: { - "click button.all": "selectAll", - "submit form.database-search": "switchDatabase" - }, - - initialize: function(options) { - var params = app.getParams(); - this.page = params.page ? parseInt(params.page, 10) : 1; - }, - - serialize: function() { - return { - databases: this.collection - }; - }, - - switchDatabase: function(event) { - event.preventDefault(); - var dbname = this.$el.find("input.search-query").val(); - - if (dbname) { - // TODO: switch to using a model, or Databases.databaseUrl() - // Neither of which are in scope right now - // var db = new Database.Model({id: dbname}); - var url = ["/database/", dbname, "/_all_docs?limit=10"].join(''); - FauxtonAPI.navigate(url); - } - }, - - paginated: function() { - var start = (this.page - 1) * this.perPage; - var end = this.page * this.perPage; - return this.collection.slice(start, end); - }, - - beforeRender: function() { - _.each(this.paginated(), function(database) { - this.insertView("table.databases tbody", new Views.Item({ - model: database - })); - }, this); - - this.insertView("#database-pagination", new Fauxton.Pagination({ - page: this.page, - perPage: this.perPage, - total: this.collection.length, - urlFun: function(page) { - return "#/_all_dbs?page=" + page; - } - })); - }, - - setPage: function(page) { - this.page = page || 1; - }, - - afterRender: function() { - var dbLimit = this.dbLimit; - var ajaxReq; - - this.$el.find("input.search-query").typeahead({ - source: function(query, process) { - var url = [ - app.host, - "/_all_dbs?startkey=%22", - query, - "%22&endkey=%22", - query, - "\u9999%22&limit=", - dbLimit - ].join(''); - if (ajaxReq) ajaxReq.abort(); - ajaxReq = $.ajax({ - url: url, - dataType: 'json', - success: function(data) { - process(data); - } - }); - } - }); - }, - - selectAll: function(evt){ - $("input:checkbox").attr('checked', !$(evt.target).hasClass('active')); - } - }); - - Views.Sidebar = FauxtonAPI.View.extend({ - template: "templates/databases/sidebar", - events: { - "click a#new": "newDatabase", - "click a#owned": "showMine", - "click a#shared": "showShared" - }, - - newDatabase: function() { - var notification; - var db; - // TODO: use a modal here instead of the prompt - var name = prompt('Name of database', 'newdatabase'); - if (name === null) { - return; - } else if (name.length === 0) { - notification = FauxtonAPI.addNotification({ - msg: "Please enter a valid database name", - type: "error", - clear: true - }); - return; - } - db = new this.collection.model({ - id: encodeURIComponent(name), - name: name - }); - notification = FauxtonAPI.addNotification({msg: "Creating database."}); - db.save().done(function() { - notification = FauxtonAPI.addNotification({ - msg: "Database created successfully", - type: "success", - clear: true - }); - var route = "#/database/" + name + "/_all_docs?limit=100"; - app.router.navigate(route, { trigger: true }); - } - ).error(function(xhr) { - var responseText = JSON.parse(xhr.responseText).reason; - notification = FauxtonAPI.addNotification({ - msg: "Create database failed: " + responseText, - type: "error", - clear: true - }); - } - ); - }, - - showMine: function(){ - $.contribute( - 'Show unshared databases', - 'app/addons/databases/views.js' - ); - }, - - showShared: function(){ - $.contribute( - 'Show shared databases (e.g. continuous replications to/from the database)', - 'app/addons/databases/views.js' - ); - } - }); - - return Views; -}); http://git-wip-us.apache.org/repos/asf/couchdb/blob/a2b7d6a1/src/fauxton/app/modules/documents/base.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/modules/documents/base.js b/src/fauxton/app/modules/documents/base.js deleted file mode 100644 index 96e4ada..0000000 --- a/src/fauxton/app/modules/documents/base.js +++ /dev/null @@ -1,24 +0,0 @@ -// 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", - - // Modules - "modules/documents/routes" -], - -function(app, FauxtonAPI, Documents) { - return Documents; -}); http://git-wip-us.apache.org/repos/asf/couchdb/blob/a2b7d6a1/src/fauxton/app/modules/documents/resources.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/modules/documents/resources.js b/src/fauxton/app/modules/documents/resources.js deleted file mode 100644 index 0ec44ea..0000000 --- a/src/fauxton/app/modules/documents/resources.js +++ /dev/null @@ -1,435 +0,0 @@ -// 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" -], - -function(app, FauxtonAPI) { - var Documents = app.module(); - - Documents.Doc = Backbone.Model.extend({ - idAttribute: "_id", - - url: function(context) { - if (context === "app") { - return this.getDatabase().url("app") + "/" + this.safeID(); - } else { - return app.host + "/" + this.getDatabase().id + "/" + this.id; - } - }, - - initialize: function(_attrs, options) { - if (this.collection && this.collection.database) { - this.database = this.collection.database; - } else if (options.database) { - this.database = options.database; - } - }, - - // HACK: the doc needs to know about the database, but it may be - // set directly or indirectly in all docs - getDatabase: function() { - return this.database ? this.database : this.collection.database; - }, - - docType: function() { - return this.id.match(/^_design/) ? "design doc" : "doc"; - }, - - isEditable: function() { - return this.docType() != "reduction"; - }, - - isDdoc: function() { - return this.docType() === "design doc"; - }, - - hasViews: function() { - if (!this.isDdoc()) return false; - var doc = this.get('doc'); - if (doc) { - return doc && doc.views && _.keys(doc.views).length > 0; - } - - var views = this.get('views'); - return views && _.keys(views).length > 0; - }, - - hasAttachments: function () { - return !!this.get('_attachments'); - }, - - getDdocView: function(view) { - if (!this.isDdoc() || !this.hasViews()) return false; - - var doc = this.get('doc'); - if (doc) { - return doc.views[view]; - } - - return this.get('views')[view]; - }, - - setDdocView: function (view, map, reduce) { - if (!this.isDdoc()) return false; - var views = this.get('views'); - - if (reduce) { - views[view] = { - map: map, - reduce: reduce - }; - } else { - views[view].map = map; - } - - this.set({views: views}); - - return true; - }, - - removeDdocView: function (viewName) { - if (!this.isDdoc()) return false; - var views = this.get('views'); - - delete views[viewName]; - this.set({views: views}); - }, - - dDocModel: function () { - if (!this.isDdoc()) return false; - var doc = this.get('doc'); - - if (doc) { - return new Documents.Doc(doc, {database: this.database}); - } - - return this; - }, - - viewHasReduce: function(viewName) { - var view = this.getDdocView(viewName); - - return view && view.reduce; - }, - - // Need this to work around backbone router thinking _design/foo - // is a separate route. Alternatively, maybe these should be - // treated separately. For instance, we could default into the - // json editor for docs, or into a ddoc specific page. - safeID: function() { - return this.id.replace('/', '%2F'); - }, - - destroy: function() { - var url = this.url() + "?rev=" + this.get('_rev'); - return $.ajax({ - url: url, - dataType: 'json', - type: 'DELETE' - }); - }, - - parse: function(resp) { - if (resp.rev) { - resp._rev = resp.rev; - delete resp.rev; - } - if (resp.id) { - if (typeof(this.id) === "undefined") { - resp._id = resp.id; - } - delete resp.id; - } - if (resp.ok) { - delete resp.ok; - } - - return resp; - }, - - prettyJSON: function() { - var data = this.get("doc") ? this.get("doc") : this; - - return JSON.stringify(data, null, " "); - }, - - copy: function (copyId) { - return $.ajax({ - type: 'COPY', - url: '/' + this.database.id + '/' + this.id, - headers: {Destination: copyId} - }); - }, - - isNewDoc: function () { - return this.get('_rev') ? false : true; - } - }); - - Documents.DdocInfo = Backbone.Model.extend({ - idAttribute: "_id", - - initialize: function (_attrs, options) { - this.database = options.database; - }, - - url: function(context) { - if (context === "app") { - return this.database.url("app") + "/" + this.safeID() + '/_info'; - } else { - return app.host + "/" + this.database.id + "/" + this.id + '/_info'; - } - }, - - // Need this to work around backbone router thinking _design/foo - // is a separate route. Alternatively, maybe these should be - // treated separately. For instance, we could default into the - // json editor for docs, or into a ddoc specific page. - safeID: function() { - return this.id.replace('/', '%2F'); - } - - }); - - Documents.ViewRow = Backbone.Model.extend({ - docType: function() { - if (!this.id) return "reduction"; - - return this.id.match(/^_design/) ? "design doc" : "doc"; - }, - - url: function(context) { - if (!this.isEditable()) return false; - - return this.collection.database.url(context) + "/" + this.id; - }, - - isEditable: function() { - return this.docType() != "reduction"; - }, - - prettyJSON: function() { - //var data = this.get("doc") ? this.get("doc") : this; - return JSON.stringify(this, null, " "); - } - }); - - Documents.NewDoc = Documents.Doc.extend({ - fetch: function() { - var uuid = new FauxtonAPI.UUID(); - var deferred = this.deferred = $.Deferred(); - var that = this; - - uuid.fetch().done(function() { - that.set("_id", uuid.next()); - deferred.resolve(); - }); - - return deferred.promise(); - }, - - }); - - Documents.AllDocs = Backbone.Collection.extend({ - model: Documents.Doc, - - initialize: function(_models, options) { - this.database = options.database; - this.params = options.params; - }, - - url: function() { - var query = ""; - if (this.params) { - query = "?" + $.param(this.params); - } - return app.host + "/" + this.database.id + "/_all_docs" + query; - }, - - totalRows: function() { - return this.viewMeta.total_rows || "unknown"; - }, - - updateSeq: function() { - return this.viewMeta.update_seq || false; - }, - - parse: function(resp) { - that = this; - this.viewMeta = { - total_rows: resp.total_rows, - offest: resp.offest, - update_seq: resp.update_seq - }; - return _.map(resp.rows, function(row) { - return { - _id: row.id, - _rev: row.value.rev, - value: row.value, - key: row.key, - doc: row.doc || undefined - }; - }); - } - }); - - Documents.IndexCollection = Backbone.Collection.extend({ - model: Documents.ViewRow, - - initialize: function(_models, options) { - this.database = options.database; - this.params = _.extend({limit: 10, reduce: false}, options.params); - this.idxType = "_view"; - this.view = options.view; - this.design = options.design.replace('_design/',''); - }, - - url: function() { - var query = ""; - if (this.params) { - query = "?" + $.param(this.params); - } - var url = [app.host, this.database.id, "_design", this.design, this.idxType, this.view]; - return url.join("/") + query; - }, - - totalRows: function() { - return this.viewMeta.total_rows || "unknown"; - }, - - updateSeq: function() { - return this.viewMeta.update_seq || false; - }, - - parse: function(resp) { - this.endTime = new Date().getTime(); - this.requestDuration = (this.endTime - this.startTime); - - this.viewMeta = { - total_rows: resp.total_rows, - offest: resp.offest, - update_seq: resp.update_seq - }; - return _.map(resp.rows, function(row) { - return { - value: row.value, - key: row.key, - doc: row.doc, - id: row.id - }; - }); - }, - - buildAllDocs: function(){ - this.fetch(); - }, - - // We implement our own fetch to store the starttime so we that - // we can get the request duration - fetch: function () { - this.startTime = new Date().getTime(); - return Backbone.Collection.prototype.fetch.call(this); - }, - - allDocs: function(){ - return this.models; - }, - - // This is taken from futon.browse.js $.timeString - requestDurationInString: function () { - var ms, sec, min, h, timeString, milliseconds = this.requestDuration; - - sec = Math.floor(milliseconds / 1000.0); - min = Math.floor(sec / 60.0); - sec = (sec % 60.0).toString(); - if (sec.length < 2) { - sec = "0" + sec; - } - - h = (Math.floor(min / 60.0)).toString(); - if (h.length < 2) { - h = "0" + h; - } - - min = (min % 60.0).toString(); - if (min.length < 2) { - min = "0" + min; - } - - timeString = h + ":" + min + ":" + sec; - - ms = (milliseconds % 1000.0).toString(); - while (ms.length < 3) { - ms = "0" + ms; - } - timeString += "." + ms; - - return timeString; - } - }); - - - Documents.PouchIndexCollection = Backbone.Collection.extend({ - model: Documents.ViewRow, - - initialize: function(_models, options) { - this.database = options.database; - this.rows = options.rows; - this.view = options.view; - this.design = options.design.replace('_design/',''); - this.params = _.extend({limit: 10, reduce: false}, options.params); - this.idxType = "_view"; - }, - - url: function () { - return ''; - }, - - fetch: function() { - var deferred = FauxtonAPI.Deferred(); - this.reset(this.rows, {silent: true}); - - this.viewMeta = { - total_rows: this.rows.length, - offest: 0, - update_seq: false - }; - - deferred.resolve(); - return deferred; - }, - - totalRows: function() { - return this.viewMeta.total_rows || "unknown"; - }, - - updateSeq: function() { - return this.viewMeta.update_seq || false; - }, - - buildAllDocs: function(){ - this.fetch(); - }, - - allDocs: function(){ - return this.models; - } - }); - - - - return Documents; -});