From 09649c43ba774393904ea0ec047976e75c6f1b3f Mon Sep 17 00:00:00 2001 From: Stanislav Romanov Date: Sat, 10 Sep 2022 19:07:58 +0300 Subject: [PATCH] Add resort fileds in document table --- app/components/icons/drag-horizontal.js | 1 + .../admin/indexes/item/documents/index.js | 32 +---- .../admin/indexes/item/documents/index.js | 13 ++ .../admin/indexes/item/documents/index.hbs | 34 ++--- package.json | 2 +- yarn.lock | 128 +++++------------- 6 files changed, 58 insertions(+), 152 deletions(-) create mode 100644 app/components/icons/drag-horizontal.js diff --git a/app/components/icons/drag-horizontal.js b/app/components/icons/drag-horizontal.js new file mode 100644 index 0000000..4833715 --- /dev/null +++ b/app/components/icons/drag-horizontal.js @@ -0,0 +1 @@ +export { DragHorizontal as default } from 'ember-mdi'; diff --git a/app/controllers/admin/indexes/item/documents/index.js b/app/controllers/admin/indexes/item/documents/index.js index 8775cca..bd5ffd7 100644 --- a/app/controllers/admin/indexes/item/documents/index.js +++ b/app/controllers/admin/indexes/item/documents/index.js @@ -10,6 +10,7 @@ export default class AdminIndexesItemDocumentsIndexController extends Controller @tracked dataView = 'table'; @tracked sort; @tracked hiddenFields = []; + @tracked attributes; queryParams = ['q', 'page', 'limit', 'sort']; @@ -21,17 +22,6 @@ export default class AdminIndexesItemDocumentsIndexController extends Controller map: MapOutline, }; - get attributes() { - if ( - this.model.displayedAttributes.length > 1 && - this.model.displayedAttributes[0] !== '*' - ) { - return this.model.displayedAttributes; - } else { - return Object.keys(this.model.stats.fieldDistribution); - } - } - get fromHits() { return 1 + this.model.data.offset; } @@ -50,26 +40,6 @@ export default class AdminIndexesItemDocumentsIndexController extends Controller return result; } - // get sortedFields() { - // const fields = Object.keys(this.model.stats.fieldDistribution); - // const primaryKey = this.model.index.primaryKey ?? 'id'; - // const sortedArray = fields - // .filter((item) => item !== primaryKey) - // .sort((a, b) => { - // if (a > b || a.charAt(0) === '_') { - // return 1; - // } - - // if (a < b) { - // return -1; - // } - - // return 0; - // }); - - // return [primaryKey].concat(sortedArray); - // } - @action toggleHiddenField(name) { if (this.hiddenFields.includes(name)) { diff --git a/app/routes/admin/indexes/item/documents/index.js b/app/routes/admin/indexes/item/documents/index.js index d445671..51e6953 100644 --- a/app/routes/admin/indexes/item/documents/index.js +++ b/app/routes/admin/indexes/item/documents/index.js @@ -35,6 +35,19 @@ export default class AdminIndexesItemDocumentsIndexRoute extends Route { }); } + 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); + } + } + resetController(controller, isExiting) { if (isExiting) { controller.q = null; diff --git a/app/templates/admin/indexes/item/documents/index.hbs b/app/templates/admin/indexes/item/documents/index.hbs index e9376af..17bae23 100644 --- a/app/templates/admin/indexes/item/documents/index.hbs +++ b/app/templates/admin/indexes/item/documents/index.hbs @@ -15,7 +15,7 @@ /> {{#if this.sortValues.length}} -
+
{{/each}} - +
{{/if}} -
+
+ {{#each this.attributes as |item|}}
+ - {{#if (not (includes @model.index.primaryKey this.hiddenFields))}} - - - {{get data @model.index.primaryKey}} - - - {{/if}} {{#each this.attributes as |field|}} - {{#if - (and - (not-eq field @model.index.primaryKey) - (not (includes field this.hiddenFields)) - ) - }} + {{#if (not (includes field this.hiddenFields))}}