Add editing document

This commit is contained in:
Stanislav Romanov 2022-09-01 11:29:15 +03:00
parent 901c00557d
commit 303a34ad48
5 changed files with 65 additions and 1 deletions

View file

@ -16,7 +16,7 @@
placeholder={{@placeholder}}
{{on 'change' this.onChange}}
>
{{@value}}
{{~@value~}}
</textarea>
</div>
{{#if @helper}}

View file

@ -0,0 +1,11 @@
import Controller from '@ember/controller';
import { action } from '@ember/object';
export default class AdminIndexesItemDocumentsDocumentController extends Controller {
@action
save(event) {
event.preventDefault();
this.model.index.saveDocument(this.model.document);
}
}

View file

@ -38,6 +38,13 @@ export default class Index {
);
}
saveDocument(document) {
return query(`${this.path}/documents`, {
method: 'PUT',
body: JSON.stringify(document),
});
}
search(q, options = {}) {
options.q = q;

View file

@ -0,0 +1,29 @@
<form {{on 'submit' this.save}}>
{{#each-in @model.document as |key value|}}
{{#let (type-of value) as |type|}}
{{#if (eq 'number' type)}}
<InputText
@label={{capitalize key}}
@value={{value}}
@onChange={{set @model.document key}}
/>
{{else if (eq 'boolean' type)}}
<InputCheckbox
@label={{capitalize key}}
@checked={{value}}
@onChange={{set @model.document key}}
/>
{{else if (eq '_geo' key)}}
{{!-- TODO: add map --}}
{{else}}
<InputTextarea
@label={{capitalize key}}
@value={{value}}
@onChange={{set @model.document key}}
/>
{{/if}}
{{/let}}
{{/each-in}}
<Button type='submit' @text='Save' @style='primary' />
</form>

View file

@ -0,0 +1,17 @@
import { module, test } from 'qunit';
import { setupTest } from 'meiliadmin/tests/helpers';
module(
'Unit | Controller | admin/indexes/item/documents/document',
function (hooks) {
setupTest(hooks);
// TODO: Replace this with your real tests.
test('it exists', function (assert) {
let controller = this.owner.lookup(
'controller:admin/indexes/item/documents/document'
);
assert.ok(controller);
});
}
);