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

    https://github.com/apache/couchdb-fauxton/pull/362#discussion_r28773683
  
    --- Diff: app/addons/documents/index-results/stores.js ---
    @@ -96,17 +132,74 @@ function (FauxtonAPI, ActionTypes, HeaderActionTypes, 
Documents) {
           return '';
         },
     
    -    getResults: function () {
    -      return this._collection.map(function (doc) {
    +    getMangoDocContent: function (originalDoc) {
    +      var doc = originalDoc.toJSON();
    +
    +      delete doc.ddoc;
    +      delete doc.name;
    +
    +      return this.isCollapsed(originalDoc.id) ? '' : JSON.stringify(doc, 
null, ' ');
    +    },
    +
    +    getMangoDoc: function (doc, index) {
    +      var header = [],
    +          selector,
    +          indexes;
    +
    +      if (doc.get('def') && doc.get('def').fields) {
    +        header = doc.get('def').fields.reduce(function (acc, el) {
    +          acc.push(Object.keys(el)[0]);
    +          return acc;
    +        }, []);
    +
    +        if (!header.length) {
    +          indexes = FauxtonAPI.getExtensions('mango:additionalIndexes')[0];
    +          header = indexes.createHeader(doc);
    +        }
    +
             return {
    -          content: this.getDocContent(doc),
    +          content: this.getMangoDocContent(doc),
    +          header: header.join(', '),
               id: this.getDocId(doc),
    -          keylabel: doc.isFromView() ? 'key' : 'id',
    +          keylabel: '',
               url: doc.isFromView() ? doc.url('app') : doc.url('web-index'),
               isDeletable: this.isDeletable(doc),
               isEditable: this.isEditable(doc)
             };
    -      }, this);
    +      }
    +
    +      // we filtered away our content with the fields param
    +      return {
    +        content: ' ',
    +        header: header.join(', '),
    +        id: this.getDocId(doc) + index,
    +        keylabel: '',
    +        url: this.isEditable(doc) ? doc.url('app') : null,
    +        isDeletable: this.isDeletable(doc),
    +        isEditable: this.isEditable(doc)
    +      };
    +
    +    },
    +
    +    getResults: function () {
    +      return this._collection
    +        .filter(function (doc) {
    +          return doc.get('language') !== 'query';
    +        })
    +        .map(function (doc, i) {
    +          if (doc.get('def') || !Object.keys(doc.attributes).length) {
    --- End diff --
    
    Sadly it is not that easy and i would keep it like this (after some 
additional refactoring)
    
    We have many different collections in this store (mangoIndexResults, 
AllDocs/Docs, MangoIndexes).
    
    I just took a look how I could move that method to the corresponding 
collections. Many menthods called in the code that I would have to move to the 
collection is implemented in this store and depends on state in this store, 
e.g. `this.isCollapsed`.
    
    Don't say it is impossible but it would be a major refactor of this store 
which I would like to avoid in this PR for the mango feature.
    
    Maybe we should decide on moving away from collections completely and just 
use stores for our state/data-layer instead of mixing both collections and 
stores.


---
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