couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From garrensmith <...@git.apache.org>
Subject [GitHub] couchdb-fauxton pull request: New Query Options tray added
Date Mon, 06 Oct 2014 09:46:47 GMT
Github user garrensmith commented on a diff in the pull request:

    https://github.com/apache/couchdb-fauxton/pull/78#discussion_r18448293
  
    --- Diff: app/addons/documents/views-queryoptions.js ---
    @@ -0,0 +1,525 @@
    +// 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",
    +
    +  // libs
    +  "addons/fauxton/resizeColumns"
    +],
    +
    +function(app, FauxtonAPI) {
    +
    +
    +  // our default settings for the Query Options tray
    +  var defaultOptions = {
    +    showStale: false,
    +    hasReduce: false,
    +
    +    // all the possible query search params. Ultimately these should probably be moved
higher-up (route object?),
    +    // because they also apply to the actual search results. Seems better to place them
there, then use them in
    +    // both places
    +    queryParams: {
    +      include_docs: "false",
    +      keys: "",
    +      limit: "",
    +      descending: "false",
    +      skip: "",
    +      update_seq: "false",
    +      startkey: "",
    +      endkey: "",
    +      inclusive_end: "true",
    +      reduce: "false",
    +      stale: "",
    +      group_level: "999"
    +    }
    +  };
    +
    +
    +  var Views = {};
    +
    +  // our main View. This is the only View exposed externally
    +  Views.QueryOptionsTray = FauxtonAPI.View.extend({
    +    template: "addons/documents/templates/query_options",
    +    className: "query-options",
    +
    +    initialize: function(options) {
    +
    +      // overlays whatever custom options were passed with defaultOptions above, so this.options
    +      // always contains all options. [This does a deep copy: we never overwrite defaultOptions!]
    +      this.options = $.extend(true, {}, defaultOptions, options);
    +
    +      // add any general events relating to the Query Options tray
    +      this.addEvents();
    +
    +      // add the sub-views
    +      this.mainFieldsView       = this.setView("#query-options-main-fields", new MainFieldsView(this.options));
    +      this.keySearchFieldsView  = this.setView("#query-options-key-search", new KeySearchFieldsView(this.options));
    +      this.additionalParamsView = this.setView("#query-options-additional-params", new
AdditionalParamsView(this.options));
    +    },
    +
    +    addEvents: function() {
    +      var self = this;
    +
    +      FauxtonAPI.Events.on('QueryOptions:closeTray', self.closeTray);
    +
    +      // very bizarre. Need the anonymous function + "self" for this to work (?!)
    +      FauxtonAPI.Events.on('QueryOptions:openTray', function() { self.toggleQueryOptionsTray();
});
    +
    +      // if the user just clicked outside the tray, close it [TODO be nice to generalize
for all trays]
    +      $("body").on("click.queryOptions", function(e) {
    +        if (!self.trayIsVisible()) { return; }
    +        if ($(e.target).closest("#query-options-tray").length === 0) {
    +          self.closeTray();
    +        }
    +      });
    +
    +      $(window).on("resize", self.onResize);
    +    },
    +
    +    afterRender: function() {
    +      this.onResize();
    +    },
    +
    +    cleanup: function() {
    +      FauxtonAPI.Events.unbind("QueryOptions:closeTray");
    +      FauxtonAPI.Events.unbind("QueryOptions:openTray");
    +      $(window).off("resize", this.onResize);
    +    },
    +
    +    events: {
    +      "click #toggle-query": "toggleQueryOptionsTray", // hide/show the Query Options
tray
    +      "submit form.js-view-query-update": "onSubmit",  // submits the form
    +      "click .btn-cancel": "onCancel"                  // closes the tray (doesn't reset
the fields)
    +    },
    +
    +    toggleQueryOptionsTray: function() {
    +      if (!this.trayIsVisible()) {
    +        $("#query-options-tray").velocity("transition.slideDownIn", 250); // TODO constant
    +        FauxtonAPI.Events.trigger("APIbar:closeTray");
    +      }
    +    },
    +
    +    // returns all applicable query parameters for the Query Options tray
    +    getQueryParams: function() {
    +      var mainFieldParams = this.mainFieldsView.getParams();
    +      var keySearchParams = this.keySearchFieldsView.getParams();
    +      var additionalParams = this.additionalParamsView.getParams();
    +
    +      // assumption: there aren't conflicting keys
    +      return $.extend({}, mainFieldParams, keySearchParams, additionalParams);
    --- End diff --
    
    Could you change to `_.extend`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message