meilisearch-admin/app/controllers/admin/indexes/item/documents/document/edit.js
2022-11-17 14:32:38 +03:00

47 lines
1 KiB
JavaScript

import Controller from '@ember/controller';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import { tracked } from '@glimmer/tracking';
import ActionInvoker from 'meiliadmin/lib/action-invoker';
export default class AdminIndexesItemDocumentsDocumentEditController extends Controller {
@service router;
@service toaster;
@tracked errors = [];
@tracked isSaving;
constructor() {
super(...arguments);
this.invoker = new ActionInvoker();
}
@action
async save(value) {
this.errors = [];
this.isSaving = true;
try {
const task = await this.model.index.saveDocument(JSON.parse(value));
this.isSaving = false;
if (task) {
this.toaster.taskToast(task);
}
} catch (error) {
this.errors = [error.error || error];
}
}
@action
cancel() {
const newRouteName = this.router.currentRouteName.replace(
/\.(new|edit|delete)$/,
''
);
this.router.transitionTo(newRouteName);
}
}