Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-fauxton/pull/543#discussion_r42348949
  
    --- Diff: app/addons/documents/index-results/stores.js ---
    @@ -199,6 +216,91 @@ function (FauxtonAPI, ActionTypes, HeaderActionTypes, 
Documents, MangoHelper) {
                 isEditable: this.isEditable(doc)
               };
             }, this);
    +
    +      hasEditableAndDeleteableDoc = 
this.getHasEditableAndDeleteableDoc(res);
    +
    +      return {
    +        hasEditableAndDeleteableDoc: hasEditableAndDeleteableDoc,
    +        results: res
    +      };
    +    },
    +
    +    getPseudoSchema: function (data) {
    +      var cache = [];
    +
    +      data.forEach(function (el) {
    +        Object.keys(el).forEach(function (k) {
    +          cache.push(k);
    +        });
    +      });
    +
    +      return _.uniq(cache);
    +    },
    +
    +    // filter out cruft and JSONify strings
    +    normalizeTableData: function (data) {
    +      // include_docs enabled
    +      if (data[0] && data[0].doc && data[0].doc._rev) {
    +        return data.map(function (el) {
    +          el = el.doc;
    +          return el;
    +        });
    +      }
    +
    +      return data;
    +    },
    +
    +    getTableViewData: function (data, hasEditableAndDeleteableDoc) {
    +      var res;
    +      var schema;
    +      var database;
    +
    +      data = this.normalizeTableData(data);
    +      schema = this.getPseudoSchema(data);
    +      database = this.getDatabase().safeID();
    +
    +      res = data.map(function (doc) {
    +        var safeId = app.utils.getSafeIdForDoc(doc._id);
    +        var url;
    +
    +        if (safeId) {
    +          url = FauxtonAPI.urls('document', 'app', database, safeId);
    +        }
    +
    +        return {
    +          content: doc,
    +          id: safeId,
    +          header: '',
    +          keylabel: '',
    +          url: url,
    +          isDeletable: !!safeId,
    +          isEditable: !!safeId
    +        };
    +      });
    +
    +      hasEditableAndDeleteableDoc = 
this.getHasEditableAndDeleteableDoc(res);
    +
    +      return {
    +        hasEditableAndDeleteableDoc: hasEditableAndDeleteableDoc,
    +        schema: schema,
    +        results: res
    +      };
    +    },
    +
    +    getHasEditableAndDeleteableDoc: function (data) {
    +      var found = false;
    +      var i = 0;
    +      var length = data.length;
    +
    +      // use a for loop here as we can end it once we found the first id
    +      for (; i < length; i++) {
    --- End diff --
    
    good point, readability and making it easy to can the code fast is super 
important. fixed!


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to