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

58 lines
1.2 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-09-15 10:30:58 +00:00
import ActionInvoker from '../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;
@tracked error;
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
this.setInitialValue();
}
@action
save(newValue) {
this.error = null;
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) {
this.error = error.error || error;
}
2022-09-02 08:53:33 +00:00
}
@action
async setInitialValue() {
2022-10-14 08:59:34 +00:00
this.value = await this.args.index.getSetting(this.args.setting.name);
this.error = null;
2022-09-02 08:53:33 +00:00
}
@action
2022-09-15 11:05:51 +00:00
reset() {
this.error = null;
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) {
this.error = error.error || error;
}
2022-09-02 08:53:33 +00:00
}
2022-10-15 06:55:37 +00:00
@action
onDidChangeValidation(error) {
this.error = error;
}
2022-09-02 08:53:33 +00:00
}