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

53 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-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-15 11:05:51 +00:00
@service toasts;
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
.updateSetting(this.args.name, JSON.parse(newValue))
.then(this.toasts.taskToast);
} catch (error) {
this.error = error.error || error;
}
2022-09-02 08:53:33 +00:00
}
@action
async setInitialValue() {
this.value = await this.args.index.getSetting(this.args.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
.resetSetting(this.args.name)
.then(this.toasts.taskToast);
} catch (error) {
this.error = error.error || error;
}
2022-09-02 08:53:33 +00:00
}
}