meilisearch-admin/app/controllers/admin/indexes/item/documents/document/edit.js

48 lines
1 KiB
JavaScript
Raw Permalink Normal View History

2022-09-01 10:02:37 +00:00
import Controller from '@ember/controller';
import { action } from '@ember/object';
2022-09-06 11:44:03 +00:00
import { inject as service } from '@ember/service';
2022-09-15 04:26:25 +00:00
import { tracked } from '@glimmer/tracking';
2022-09-15 10:38:24 +00:00
import ActionInvoker from 'meiliadmin/lib/action-invoker';
2022-09-01 10:02:37 +00:00
export default class AdminIndexesItemDocumentsDocumentEditController extends Controller {
2022-09-06 11:44:03 +00:00
@service router;
2022-09-19 12:36:40 +00:00
@service toaster;
2022-09-06 11:44:03 +00:00
2022-10-15 12:13:34 +00:00
@tracked errors = [];
2022-09-15 11:05:51 +00:00
@tracked isSaving;
2022-09-15 04:26:25 +00:00
2022-09-15 10:38:24 +00:00
constructor() {
super(...arguments);
this.invoker = new ActionInvoker();
}
2022-09-01 10:02:37 +00:00
@action
2022-09-15 11:05:51 +00:00
async save(value) {
2022-10-15 12:13:34 +00:00
this.errors = [];
2022-09-15 04:26:25 +00:00
2022-09-15 11:05:51 +00:00
this.isSaving = true;
2022-09-15 04:26:25 +00:00
try {
2022-09-15 11:05:51 +00:00
const task = await this.model.index.saveDocument(JSON.parse(value));
this.isSaving = false;
2022-11-17 11:32:38 +00:00
if (task) {
this.toaster.taskToast(task);
}
2022-09-15 04:26:25 +00:00
} catch (error) {
2022-10-15 12:13:34 +00:00
this.errors = [error.error || error];
2022-09-15 04:26:25 +00:00
}
2022-09-01 10:02:37 +00:00
}
2022-09-06 11:44:03 +00:00
@action
cancel() {
const newRouteName = this.router.currentRouteName.replace(
/\.(new|edit|delete)$/,
''
);
this.router.transitionTo(newRouteName);
}
2022-09-01 10:02:37 +00:00
}