diff --git a/app/components/badge.hbs b/app/components/badge.hbs new file mode 100644 index 0000000..30924b8 --- /dev/null +++ b/app/components/badge.hbs @@ -0,0 +1,13 @@ +{{#let + 'inline-flex items-center px-3 py-0.5 rounded-full text-sm font-medium bg-gray-light text-gray-dark' + (hash + success='bg-green-light text-green-dark' + ) as |commonClasses variableClasses| +}} + + {{#if @icon}} + <@icon class="mr-1" @size={{16}} /> + {{/if}} + {{@label}} + +{{/let}} diff --git a/app/controllers/admin/indexes/item/settings.js b/app/controllers/admin/indexes/item/settings.js index 7f48fb3..7081c46 100644 --- a/app/controllers/admin/indexes/item/settings.js +++ b/app/controllers/admin/indexes/item/settings.js @@ -1,11 +1,13 @@ import Controller from '@ember/controller'; import { action, get, set } from '@ember/object'; import arrayEquals from 'meilisearch-admin/utils/array-equals'; -import { ContentSaveOutline } from 'ember-mdi/icons'; +import { ContentSaveOutline, Check, CircleMedium } from 'ember-mdi/icons'; export default class AdminIndexesItemSettingsController extends Controller { emptyObj = {}; ContentSaveOutline = ContentSaveOutline; + Check = Check; + CircleMedium = CircleMedium; get rankingRulesFields() { const arr = []; @@ -65,4 +67,17 @@ export default class AdminIndexesItemSettingsController extends Controller { reorderItems(itemModels) { set(this.model.settings, 'rankingRules', itemModels); } + + @action + setAttributeValue(arr, item) { + if (arr.length === 0 && arr[0] === '*') { + arr = []; + } + + if (arr.includes(item)) { + arr = arr.filter((i) => i !== item); + } else { + arr.push(item); + } + } } diff --git a/app/models/index.js b/app/models/index.js index 231d9f6..b560ff0 100644 --- a/app/models/index.js +++ b/app/models/index.js @@ -1,7 +1,13 @@ import query from '../utils/query'; import { TrackedArray } from 'tracked-built-ins'; +import { trackedFunction } from 'ember-resources/util/function'; export default class Index { + stats = trackedFunction(this, () => query(`${this.indexPath}/stats`)); + displayedAttributes = trackedFunction(this, () => + query(`${this.indexPath}/settings/displayed-attributes`) + ); + constructor(data) { for (const key in data) { this[key] = data[key]; @@ -12,6 +18,14 @@ export default class Index { return `indexes/${this.uid}`; } + get allAttributesAreDisplayed() { + return ( + this.displayedAttributes.value && + this.displayedAttributes.value.length === 1 && + this.displayedAttributes.value[0] === '*' + ); + } + getSortableAttributes() { return query(`${this.indexPath}/settings/sortable-attributes`).then( (result) => new TrackedArray(result) @@ -34,4 +48,10 @@ export default class Index { body: JSON.stringify(options), }); } + + get fields() { + return this.stats.value + ? Object.keys(this.stats.value.fieldDistribution) + : []; + } } diff --git a/app/routes/admin/indexes/item/settings.js b/app/routes/admin/indexes/item/settings.js index 28e8ea3..1b9c6fd 100644 --- a/app/routes/admin/indexes/item/settings.js +++ b/app/routes/admin/indexes/item/settings.js @@ -37,25 +37,26 @@ class IndexAttribute { export default class AdminIndexesItemSettingsRoute extends Route { async model() { const index = this.modelFor('admin.indexes.item'); - const settings = index.getSettings(); - const stats = index.getStats(); + // const settings = index.getSettings(); + const stats = index.stats; - return hash({ index, settings, stats }).then((result) => { - // Some settings properties may to be ["*"] (all attributes) - // this convert it to [attr1, attr2, ...] - ['displayedAttributes', 'searchableAttributes'].forEach((prop) => { - if ( - result.settings[prop].length === 1 && - result.settings[prop][0] === '*' - ) { - result.settings[prop] = Object.keys(result.stats.fieldDistribution); - } - }); - result.attributes = Object.keys(result.stats.fieldDistribution).map( - (name) => new IndexAttribute(name, result.settings) - ); + return hash({ index, stats }); + // .then((result) => { + // // Some settings properties may to be ["*"] (all attributes) + // // this convert it to [attr1, attr2, ...] + // ['displayedAttributes', 'searchableAttributes'].forEach((prop) => { + // if ( + // result.settings[prop].length === 1 && + // result.settings[prop][0] === '*' + // ) { + // result.settings[prop] = Object.keys(result.stats.fieldDistribution); + // } + // }); + // result.attributes = Object.keys(result.stats.fieldDistribution).map( + // (name) => new IndexAttribute(name, result.settings) + // ); - return result; - }); + // return result; + // }); } } diff --git a/app/templates/admin/indexes/item/settings.hbs b/app/templates/admin/indexes/item/settings.hbs index c1ba7b4..b759d67 100644 --- a/app/templates/admin/indexes/item/settings.hbs +++ b/app/templates/admin/indexes/item/settings.hbs @@ -1,7 +1,31 @@ {{page-title 'Settings'}} -