couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robertkowal...@apache.org
Subject [3/4] New Query Options tray added
Date Thu, 16 Oct 2014 10:03:10 GMT
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/332c7b53/app/addons/documents/views.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/views.js b/app/addons/documents/views.js
index 23720f4..683a05b 100644
--- a/app/addons/documents/views.js
+++ b/app/addons/documents/views.js
@@ -12,23 +12,23 @@
 
 define([
   "app",
-
   "api",
   "addons/fauxton/components",
   "addons/documents/resources",
   "addons/databases/resources",
 
-  //Views
+  // Views
   "addons/documents/views-sidebar",
-  "addons/documents/views-advancedopts",
+  "addons/documents/views-queryoptions",
+
   // Libs
   "addons/fauxton/resizeColumns",
+
   //plugins
   "plugins/prettify"
 ],
 
-function(app, FauxtonAPI, Components, Documents, Databases, Views, QueryOptions,
-         resizeColumns, prettify) {
+function(app, FauxtonAPI, Components, Documents, Databases, Views, QueryOptions) {
 
   function showError (msg) {
     FauxtonAPI.addNotification({
@@ -45,105 +45,81 @@ function(app, FauxtonAPI, Components, Documents, Databases, Views, QueryOptions,
       'click .toggle-select-menu': 'selectAllMenu'
     },
 
-    initialize: function(options){
-      //adding the database to the object
+    initialize: function(options) {
       this.database = options.database;
+      this.params = options.params;
+
       _.bindAll(this);
       this.selectVisible = false;
-      FauxtonAPI.Events.on('advancedOptions:updateView', this.updateAllDocs);
       FauxtonAPI.Events.on('success:bulkDelete', this.selectAllMenu);
-    },
-
-    cleanup:function(){
-      FauxtonAPI.Events.unbind('advancedOptions:updateView');
-      FauxtonAPI.Events.unbind('success:bulkDelete');
-    },
-
-    selectAllMenu: function(e){
-      FauxtonAPI.triggerRouteEvent("toggleSelectHeader");
-      FauxtonAPI.Events.trigger("documents:showSelectAll",this.selectVisible);
-    },
 
-    addAllDocsMenu: function(){
-      //search docs
+      // insert the Search Docs field
       this.headerSearch = this.insertView("#header-search", new Views.JumpToDoc({
         database: this.database,
         collection: this.database.allDocs
       }));
-      //insert queryoptions
-      //that file is included in require() above and the argument is QueryOptions
-      // and it wants all these params:
-      /* Sooooo I searched this file for where Advanced options was originally inserted to
see what the hell
-         is happening.  and it's in AllDocsLayout.  So I'm going to move some of those functions
over here
-
-        These are required:
-        this.database = options.database;
-        this.updateViewFn = options.updateViewFn;
-        this.previewFn = options.previewFn;
-
-        these are booleans:
-        this.showStale = _.isUndefined(options.showStale) ? false : options.showStale;
-        this.hasReduce = _.isUndefined(options.hasReduce) ? true : options.hasReduce;
-
-        these you only need for view indexes, not all docs because they are about
-        specific views and design docs (ddocs, also views live inside a ddoc):
-        this.viewName = options.viewName;
-        this.ddocName = options.ddocName;
-      */
-
-      /*this.queryOptions = this.insertView("#query-options", new QueryOptions.AdvancedOptions({
-        database: this.database,
+
+      // add the Query Options modal + header link
+      this.queryOptions = this.insertView("#query-options", new QueryOptions.QueryOptionsTray({
         hasReduce: false,
-        showPreview: false,
-      }));*/
+        showStale: false
+      }));
     },
 
-    serialize: function() {
-      //basically if you want something in a template, You can define it here
-      return {
-        database: this.database.get('id')
-      };
+    afterRender: function() {
+      this.toggleQueryOptionsHeader(this.isHidden);
     },
 
-    beforeRender:function(){
-      this.addAllDocsMenu();
+    cleanup: function() {
+      FauxtonAPI.Events.unbind('success:bulkDelete');
     },
 
-    //moved from alldocs layout
-    updateAllDocs: function (event, paramInfo) {
-      event.preventDefault();
+    selectAllMenu: function(e) {
+      FauxtonAPI.triggerRouteEvent("toggleSelectHeader");
+      FauxtonAPI.Events.trigger("documents:showSelectAll",this.selectVisible);
+    },
 
-      var errorParams = paramInfo.errorParams,
-          params = paramInfo.params;
+    // updates the API bar when the route changes
+    updateApiUrl: function(api) {
+      this.apiBar && this.apiBar.update(api);
+    },
 
-      if (_.any(errorParams)) {
-        _.map(errorParams, function(param) {
-          return FauxtonAPI.addNotification({
-            msg: "JSON Parse Error on field: "+param.name,
-            type: "error",
-            clear:  true
-          });
-        });
-        FauxtonAPI.addNotification({
-          msg: "Make sure that strings are properly quoted and any other values are valid
JSON structures",
-          type: "warning",
-          clear:  true
-        });
+    // these are similar, but different! resetQueryOptions() completely resets the settings
then overlays the new ones;
+    // updateQueryOptions() just updates the existing settings with whatever is specified.
Between them, the
+    resetQueryOptions: function(options) {
+      this.queryOptions.resetQueryOptions(options);
+    },
 
-        return false;
-      }
+    updateQueryOptions: function(options) {
+      this.queryOptions.updateQueryOptions(options);
+    },
 
-      var fragment = window.location.hash.replace(/\?.*$/, '');
+    hideQueryOptions: function() {
+      this.isHidden = true;
+      if (this.hasRendered) {
+        this.toggleQueryOptionsHeader(this.isHidden);
+      }
+    },
 
-      if (!_.isEmpty(params)) {
-        fragment = fragment + '?' + $.param(params);
+    showQueryOptions: function() {
+      this.isHidden = false;
+      if (this.hasRendered) {
+        this.toggleQueryOptionsHeader(this.isHidden);
       }
+    },
+
+    toggleQueryOptionsHeader: function(hide) {
+      $("#header-query-options").toggleClass("hide", hide);
+    },
 
-      FauxtonAPI.navigate(fragment, {trigger: false});
-      FauxtonAPI.triggerRouteEvent('updateAllDocs', {allDocs: true});
+    serialize: function() {
+      return {
+        database: this.database.get('id')
+      };
     }
   });
 
+
   Views.DeleteDBModal = Components.ModalView.extend({
     template: "addons/documents/templates/delete_database_modal",
     initialize: function (options) {
@@ -155,7 +131,7 @@ function(app, FauxtonAPI, Components, Documents, Databases, Views, QueryOptions,
       this.showModal();
     },
 
-    cleanup: function () {
+    cleanup: function() {
       FauxtonAPI.Events.off('database:delete', this.showDeleteDatabase);
     },
 
@@ -167,11 +143,12 @@ function(app, FauxtonAPI, Components, Documents, Databases, Views, QueryOptions,
     deleteDatabase: function (event) {
       event.preventDefault();
 
-      var enterredName = this.$('#db_name')[0].value;
-      if (this.database.id != enterredName) {
-        this.set_error_msg(enterredName + " does not match database id - are you sure you
want to delete " + this.database.id + "?");
+      var enteredName = $('#db_name').val();
+      if (this.database.id != enteredName) {
+        this.set_error_msg(enteredName + " does not match database id - are you sure you
want to delete " + this.database.id + "?");
         return;
       }
+
       this.hideModal();
       var databaseName = this.database.id;
       FauxtonAPI.addNotification({
@@ -243,7 +220,7 @@ function(app, FauxtonAPI, Components, Documents, Databases, Views, QueryOptions,
 
       this.model.destroy().then(function(resp) {
         FauxtonAPI.addNotification({
-          msg: "Succesfully deleted your doc",
+          msg: "Successfully deleted your doc",
           clear:  true
         });
         that.$el.fadeOut(function () {
@@ -274,7 +251,6 @@ function(app, FauxtonAPI, Components, Documents, Databases, Views, QueryOptions,
 
     destroy: function (event) {
       event.preventDefault();
-
       window.alert('Cannot delete a document generated from a view.');
     },
 
@@ -345,92 +321,8 @@ function(app, FauxtonAPI, Components, Documents, Databases, Views, QueryOptions,
     setCollection: function (collection) {
       this.collection = collection;
     }
-
   });
 
-  Views.AllDocsLayout = FauxtonAPI.View.extend({
-    template: "addons/documents/templates/all_docs_layout",
-
-    initialize: function (options) {
-      this.database = options.database;
-      this.params = options.params;
-    },
-
-    events: {
-      'click #toggle-query': "toggleQuery"
-    },
-
-    toggleQuery: function (event) {
-      $('#dashboard-content').scrollTop(0);
-      this.$('#query').toggle('slow');
-    },
-
-    beforeRender: function () {
-      this.advancedOptions = this.insertView('#query', new QueryOptions.AdvancedOptions({
-        updateViewFn: this.updateAllDocs,
-        previewFn: this.previewView,
-        hasReduce: false,
-        showPreview: false,
-        database: this.database,
-      }));
-
-      //disable for now. Will enable with new documents PR that will come next
-      /*this.toolsView = this.setView(".js-search", new Views.JumpToDoc({
-        database: this.database,
-        collection: this.database.allDocs
-        }));*/
-    },
-
-    afterRender: function () {
-      if (this.params) {
-        this.advancedOptions.updateFromParams(this.params);
-      }
-    },
-
-    updateAllDocs: function (event, paramInfo) {
-      event.preventDefault();
-
-      var errorParams = paramInfo.errorParams,
-          params = paramInfo.params;
-
-      if (_.any(errorParams)) {
-        _.map(errorParams, function(param) {
-
-          // TODO: Where to add this error?
-          // bootstrap wants the error on a control-group div, but we're not using that
-          //$('form.view-query-update input[name='+param+'], form.view-query-update select[name='+param+']').addClass('error');
-          return FauxtonAPI.addNotification({
-            msg: "JSON Parse Error on field: "+param.name,
-            type: "error",
-            selector: ".advanced-options .errors-container",
-            clear:  true
-          });
-        });
-        FauxtonAPI.addNotification({
-          msg: "Make sure that strings are properly quoted and any other values are valid
JSON structures",
-          type: "warning",
-          selector: ".advanced-options .errors-container",
-          clear:  true
-        });
-
-        return false;
-      }
-
-      var fragment = window.location.hash.replace(/\?.*$/, '');
-
-      if (!_.isEmpty(params)) {
-        fragment = fragment + '?' + $.param(params);
-      }
-
-      FauxtonAPI.navigate(fragment, {trigger: false});
-      FauxtonAPI.triggerRouteEvent('updateAllDocs', {allDocs: true});
-    },
-
-    previewView: function (event) {
-      event.preventDefault();
-    }
-
-  });
 
   // TODO: Rename to reflect that this is a list of rows or documents
   Views.AllDocsList = FauxtonAPI.View.extend({
@@ -440,7 +332,7 @@ function(app, FauxtonAPI, Components, Documents, Databases, Views, QueryOptions,
       "click button.js-bulk-delete": "bulkDelete",
       "click #collapse": "collapse",
       "click .all-docs-item": "toggleDocument",
-      "click #js-end-results": "scrollToQuery"
+      "click #js-end-results": "openQueryOptionsTray"
     },
 
     initialize: function (options) {
@@ -522,8 +414,9 @@ function(app, FauxtonAPI, Components, Documents, Databases, Views, QueryOptions,
       }
     },
 
-    scrollToQuery: function () {
-      $('#dashboard-content').animate({ scrollTop: 0 }, 'slow');
+    openQueryOptionsTray: function(e) {
+      e.preventDefault();
+      FauxtonAPI.Events.trigger("QueryOptions:openTray");
     },
 
     establish: function() {
@@ -696,6 +589,8 @@ function(app, FauxtonAPI, Components, Documents, Databases, Views, QueryOptions,
     },
 
     afterRender: function () {
+      $("#dashboard-content").scrollTop(0);
+
       prettyPrint();
 
       if (this.bulkDeleteDocsCollection) {
@@ -740,7 +635,6 @@ function(app, FauxtonAPI, Components, Documents, Databases, Views, QueryOptions,
 
 
 
-
   Views.DdocInfo = FauxtonAPI.View.extend({
     template: "addons/documents/templates/ddoc_info",
 
@@ -786,5 +680,6 @@ function(app, FauxtonAPI, Components, Documents, Databases, Views, QueryOptions,
   });
 
   Documents.Views = Views;
+
   return Documents;
 });

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/332c7b53/app/addons/fauxton/base.js
----------------------------------------------------------------------
diff --git a/app/addons/fauxton/base.js b/app/addons/fauxton/base.js
index 1114c50..3add6e5 100644
--- a/app/addons/fauxton/base.js
+++ b/app/addons/fauxton/base.js
@@ -86,7 +86,8 @@ function(app, FauxtonAPI, resizeColumns, Components, ZeroClipboard) {
 
     FauxtonAPI.RouteObject.on('renderComplete', function (routeObject) {
       var masterLayout = FauxtonAPI.masterLayout;
-      if (routeObject.get('apiUrl')){
+
+      if (routeObject.get('apiUrl')) {
         masterLayout.apiBar.show();
         masterLayout.apiBar.update(routeObject.get('apiUrl'));
       } else {

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/332c7b53/app/addons/fauxton/components.js
----------------------------------------------------------------------
diff --git a/app/addons/fauxton/components.js b/app/addons/fauxton/components.js
index 8499299..21fb2bd 100644
--- a/app/addons/fauxton/components.js
+++ b/app/addons/fauxton/components.js
@@ -105,7 +105,7 @@ function(app, FauxtonAPI, ace, spin, ZeroClipboard) {
     events:  {
       "click .api-url-btn" : "showAPIbar"
     },
-    
+
     initialize: function (options) {
       var _options = options || {};
       this.endpoint = _options.endpoint || '_all_docs';
@@ -167,9 +167,11 @@ function(app, FauxtonAPI, ace, spin, ZeroClipboard) {
     update: function(endpoint) {
       this.endpoint = endpoint[0];
       this.documentation = endpoint[1];
+
       this.render();
     },
-    afterRender: function(){
+
+    afterRender: function() {
       var client = new Components.Clipboard({
         $el: this.$('.copy-url')
       });

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/332c7b53/app/addons/fauxton/templates/api_bar.html
----------------------------------------------------------------------
diff --git a/app/addons/fauxton/templates/api_bar.html b/app/addons/fauxton/templates/api_bar.html
index 86332fe..dbc10d5 100644
--- a/app/addons/fauxton/templates/api_bar.html
+++ b/app/addons/fauxton/templates/api_bar.html
@@ -13,7 +13,7 @@ the License.
 -->
 
 <a class="btn btn-primary pull-right api-url-btn">
-  <i class="fonticon-link icon"></i>
+  <i class="fonticon-link header-icon"></i>
   API URL
 </a>
 <div class="clearfix"></div>

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/332c7b53/app/core/routeObject.js
----------------------------------------------------------------------
diff --git a/app/core/routeObject.js b/app/core/routeObject.js
index 6b43fa1..1a09298 100644
--- a/app/core/routeObject.js
+++ b/app/core/routeObject.js
@@ -85,7 +85,8 @@ function(FauxtonAPI, Backbone) {
   }, {
 
     renderWith: function(route, masterLayout, args) {
-      //set the options for this render
+
+      // set the options for this render
       var options = {
         masterLayout: masterLayout,
         route: route,
@@ -112,7 +113,9 @@ function(FauxtonAPI, Backbone) {
     },
 
     setTemplateOnFullRender: function(masterLayout){
+
       var promise = $.Deferred();
+
       // Only want to redo the template if its a full render
       if (!this.renderedState) {
         this.triggerBroadcast('beforeFullRender');
@@ -175,7 +178,7 @@ function(FauxtonAPI, Backbone) {
     establishError: function(resp){
       if (!resp || !resp.responseText) { return; }
       FauxtonAPI.addNotification({
-            msg: 'An Error occurred' + JSON.parse(resp.responseText).reason,
+            msg: 'An Error occurred: ' + JSON.parse(resp.responseText).reason,
             type: 'error',
             clear: true
       });

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/332c7b53/app/core/router.js
----------------------------------------------------------------------
diff --git a/app/core/router.js b/app/core/router.js
index bef4ced..5281343 100644
--- a/app/core/router.js
+++ b/app/core/router.js
@@ -102,7 +102,8 @@ function(FauxtonAPI, Auth, Backbone) {
     triggerRouteEvent: function(event, args) {
       if (this.activeRouteObject) {
         var eventArgs = [event].concat(args);
-        this.activeRouteObject.trigger.apply(this.activeRouteObject, eventArgs );
+
+        this.activeRouteObject.trigger.apply(this.activeRouteObject, eventArgs);
         this.activeRouteObject.renderWith(eventArgs, FauxtonAPI.masterLayout, args);
       }
     }

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/332c7b53/app/core/utils.js
----------------------------------------------------------------------
diff --git a/app/core/utils.js b/app/core/utils.js
index 9c4fb39..0ea6770 100644
--- a/app/core/utils.js
+++ b/app/core/utils.js
@@ -28,6 +28,7 @@ function ($, _) {
   var onWindowResize = {};
 
   var utils = {
+
     // Thanks to: http://stackoverflow.com/a/2880929
     getParams: function(queryString) {
       if (queryString) {
@@ -56,6 +57,15 @@ function ($, _) {
       return urlParams;
     },
 
+    // this takes the current URL and replaces all ?x=x with whatever new params are passed
+    replaceQueryParams: function(params) {
+      var fragment = window.location.hash.replace(/\?.*$/, "");
+      if (!_.isEmpty(params)) {
+        fragment = fragment + "?" + $.param(params);
+      }
+      return fragment;
+    },
+
     addWindowResize: function(fun, key){
       onWindowResize[key]=fun;
       // You shouldn't need to call it here. Just define it at startup and each time it will
loop

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/332c7b53/assets/fonts/fauxtonicon.eot
----------------------------------------------------------------------
diff --git a/assets/fonts/fauxtonicon.eot b/assets/fonts/fauxtonicon.eot
index 85d7c01..6f6bab6 100644
Binary files a/assets/fonts/fauxtonicon.eot and b/assets/fonts/fauxtonicon.eot differ


Mime
View raw message