diff --git a/app/controllers/admin/indexes/item/documents/index.js b/app/controllers/admin/indexes/item/documents/index.js index bd5ffd7..e693632 100644 --- a/app/controllers/admin/indexes/item/documents/index.js +++ b/app/controllers/admin/indexes/item/documents/index.js @@ -10,7 +10,7 @@ export default class AdminIndexesItemDocumentsIndexController extends Controller @tracked dataView = 'table'; @tracked sort; @tracked hiddenFields = []; - @tracked attributes; + @tracked attributesToRetrieve = []; queryParams = ['q', 'page', 'limit', 'sort']; @@ -22,6 +22,25 @@ export default class AdminIndexesItemDocumentsIndexController extends Controller map: MapOutline, }; + get attributes() { + if (this.attributesToRetrieve.length > 0) { + return this.attributesToRetrieve; + } else { + return this.originalAttributes; + } + } + + get originalAttributes() { + if ( + this.model.displayedAttributes.length > 0 && + this.model.displayedAttributes[0] !== '*' + ) { + return this.model.displayedAttributes; + } else { + return Object.keys(this.model.stats.fieldDistribution); + } + } + get fromHits() { return 1 + this.model.data.offset; } @@ -41,11 +60,13 @@ export default class AdminIndexesItemDocumentsIndexController extends Controller } @action - toggleHiddenField(name) { - if (this.hiddenFields.includes(name)) { - this.hiddenFields = this.hiddenFields.filter((item) => item !== name); + toggleAttribute(name) { + if (this.attributes.includes(name)) { + this.attributesToRetrieve = this.attributes.filter( + (item) => item !== name + ); } else { - this.hiddenFields = this.hiddenFields.concat([name]); + this.attributesToRetrieve = this.attributes.concat([name]); } } diff --git a/app/routes/admin/indexes/item/documents/index.js b/app/routes/admin/indexes/item/documents/index.js index 51e6953..afcde12 100644 --- a/app/routes/admin/indexes/item/documents/index.js +++ b/app/routes/admin/indexes/item/documents/index.js @@ -3,21 +3,14 @@ import { hash } from 'rsvp'; export default class AdminIndexesItemDocumentsIndexRoute extends Route { queryParams = { - q: { - refreshModel: true, - }, - limit: { - refreshModel: true, - }, - page: { - refreshModel: true, - }, - sort: { - refreshModel: true, - }, + q: { refreshModel: true }, + limit: { refreshModel: true }, + page: { refreshModel: true }, + sort: { refreshModel: true }, + attributesToRetrieve: { refreshModel: true }, }; - async model({ q, page, limit, sort }) { + async model({ q, page, limit, sort, attributesToRetrieve }) { const offset = limit * --page; const index = this.modelFor('admin.indexes.item'); const options = { offset, limit }; @@ -26,6 +19,10 @@ export default class AdminIndexesItemDocumentsIndexRoute extends Route { options.sort = [sort]; } + if (attributesToRetrieve.length > 0) { + options.attributesToRetrieve = attributesToRetrieve; + } + return hash({ index, data: index.search(q, options), @@ -35,23 +32,27 @@ export default class AdminIndexesItemDocumentsIndexRoute extends Route { }); } - setupController(controller, model) { - super.setupController(controller, model); + // setupController(controller, model) { + // super.setupController(controller, model); - if ( - model.displayedAttributes.length > 1 && - model.displayedAttributes[0] !== '*' - ) { - controller.attributes = model.displayedAttributes; - } else { - controller.attributes = Object.keys(model.stats.fieldDistribution); - } - } + // if (controller.attributesToRetrieve.length === 0) { + // if ( + // model.displayedAttributes.length > 1 && + // model.displayedAttributes[0] !== '*' + // ) { + // controller.attributes = model.displayedAttributes; + // } else { + // controller.attributes = Object.keys(model.stats.fieldDistribution); + // } + // } + // } resetController(controller, isExiting) { + // console.log('resetController', isExiting); if (isExiting) { controller.q = null; controller.page = 1; + // controller.attributes = []; } window.scrollTo(0, 0); diff --git a/app/templates/admin/indexes/item/documents/index.hbs b/app/templates/admin/indexes/item/documents/index.hbs index ece98a0..4de68c4 100644 --- a/app/templates/admin/indexes/item/documents/index.hbs +++ b/app/templates/admin/indexes/item/documents/index.hbs @@ -18,13 +18,14 @@ {{! sort }} {{#if this.sortValues.length}} -