meilisearch-admin/app/components/index-setting.js

51 lines
1.1 KiB
JavaScript
Raw Normal View History

2022-09-02 08:53:33 +00:00
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
2022-10-22 14:56:53 +00:00
import ActionInvoker from 'meiliadmin/lib/action-invoker';
2022-09-15 11:05:51 +00:00
import { inject as service } from '@ember/service';
2022-09-02 08:53:33 +00:00
export default class FormIndexSettingComponent extends Component {
2022-09-19 12:36:40 +00:00
@service toaster;
2022-09-15 11:05:51 +00:00
2022-09-02 08:53:33 +00:00
@tracked value;
2022-10-15 10:27:45 +00:00
@tracked errors = [];
2022-09-02 08:53:33 +00:00
constructor() {
super(...arguments);
2022-09-15 10:30:58 +00:00
this.invoker = new ActionInvoker();
2022-09-02 08:53:33 +00:00
}
@action
save(newValue) {
2022-10-15 10:27:45 +00:00
this.errors = [];
try {
2022-09-15 11:05:51 +00:00
return this.args.index
2022-10-14 08:59:34 +00:00
.updateSetting(JSON.parse(newValue), this.args.setting.name)
2022-09-19 12:36:40 +00:00
.then(this.toaster.taskToast);
} catch (error) {
2022-10-15 10:27:45 +00:00
this.errors = [error.error || error];
}
2022-09-02 08:53:33 +00:00
}
@action
2022-10-15 09:45:36 +00:00
async setValue() {
2022-10-14 08:59:34 +00:00
this.value = await this.args.index.getSetting(this.args.setting.name);
2022-10-15 12:13:34 +00:00
this.errors = [];
2022-09-02 08:53:33 +00:00
}
@action
2022-09-15 11:05:51 +00:00
reset() {
2022-10-15 12:13:34 +00:00
this.errors = [];
2022-09-15 11:05:51 +00:00
try {
return this.args.index
2022-10-14 08:59:34 +00:00
.resetSetting(this.args.setting.name)
2022-09-19 12:36:40 +00:00
.then(this.toaster.taskToast);
2022-09-15 11:05:51 +00:00
} catch (error) {
2022-10-15 10:27:45 +00:00
this.errors = [error.error || error];
2022-09-15 11:05:51 +00:00
}
2022-09-02 08:53:33 +00:00
}
}