Add saving settings
This commit is contained in:
parent
a25f6caa10
commit
8306c6efa6
5 changed files with 67 additions and 2 deletions
19
app/controllers/admin/indexes/item/settings.js
Normal file
19
app/controllers/admin/indexes/item/settings.js
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import Controller from '@ember/controller';
|
||||
import { action } from '@ember/object';
|
||||
import arrayEquals from 'meilisearch-admin/utils/array-equals';
|
||||
|
||||
export default class AdminIndexesItemSettingsController extends Controller {
|
||||
@action
|
||||
save() {
|
||||
const fields = Object.keys(this.model.stats.fieldDistribution);
|
||||
const settings = Object.assign({}, this.model.settings);
|
||||
|
||||
['displayedAttributes', 'searchableAttributes'].forEach((prop) => {
|
||||
if (arrayEquals(settings[prop].sort(), fields.sort())) {
|
||||
settings[prop] = ['*'];
|
||||
}
|
||||
});
|
||||
|
||||
return this.model.index.updateSettings(settings);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
{{page-title "Settings"}}
|
||||
|
||||
{{#let (hash td="px-4 py-2 text-left whitespace-nowrap") as |classes|}}
|
||||
<h2 class="text-xl">Attributes</h2>
|
||||
<table class="table-auto">
|
||||
<h2 class="text-xl mb-4">Attributes</h2>
|
||||
<table class="mb-4 table-auto">
|
||||
<thead>
|
||||
<tr class="bg-gray-50">
|
||||
<th class={{classes.td}}>#</th>
|
||||
|
|
@ -45,3 +45,17 @@
|
|||
</tbody>
|
||||
</table>
|
||||
{{/let}}
|
||||
|
||||
<Button
|
||||
@text="Save"
|
||||
@pendingText="Saving"
|
||||
@fulfilledText="Done"
|
||||
@rejectedText="Error"
|
||||
|
||||
@icon="database-arrow-up-outline"
|
||||
@pendingIcon="clock-outline"
|
||||
@fulfilledIcon="check"
|
||||
@rejectedIcon="alert-circle-outline"
|
||||
|
||||
@onClick={{this.save}}
|
||||
/>
|
||||
|
|
|
|||
8
app/utils/array-equals.js
Normal file
8
app/utils/array-equals.js
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
export default function arrayEquals(a, b) {
|
||||
return (
|
||||
Array.isArray(a) &&
|
||||
Array.isArray(b) &&
|
||||
a.length === b.length &&
|
||||
a.every((val, index) => val === b[index])
|
||||
);
|
||||
}
|
||||
14
tests/unit/controllers/admin/indexes/item/settings-test.js
Normal file
14
tests/unit/controllers/admin/indexes/item/settings-test.js
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Controller | admin/indexes/item/settings', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
// TODO: Replace this with your real tests.
|
||||
test('it exists', function (assert) {
|
||||
let controller = this.owner.lookup(
|
||||
'controller:admin/indexes/item/settings'
|
||||
);
|
||||
assert.ok(controller);
|
||||
});
|
||||
});
|
||||
10
tests/unit/utils/array-equals-test.js
Normal file
10
tests/unit/utils/array-equals-test.js
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import arrayEquals from 'meilisearch-admin/utils/array-equals';
|
||||
import { module, test } from 'qunit';
|
||||
|
||||
module('Unit | Utility | arrayEquals', function () {
|
||||
// TODO: Replace this with your real tests.
|
||||
test('it works', function (assert) {
|
||||
let result = arrayEquals();
|
||||
assert.ok(result);
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue