Add editing document
This commit is contained in:
parent
901c00557d
commit
303a34ad48
5 changed files with 65 additions and 1 deletions
|
|
@ -16,7 +16,7 @@
|
|||
placeholder={{@placeholder}}
|
||||
{{on 'change' this.onChange}}
|
||||
>
|
||||
{{@value}}
|
||||
{{~@value~}}
|
||||
</textarea>
|
||||
</div>
|
||||
{{#if @helper}}
|
||||
|
|
|
|||
11
app/controllers/admin/indexes/item/documents/document.js
Normal file
11
app/controllers/admin/indexes/item/documents/document.js
Normal 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
);
|
||||
Loading…
Reference in a new issue