Add creation new document

This commit is contained in:
Stanislav Romanov 2022-09-01 12:14:56 +03:00
parent b2613455bd
commit b00c7eef15
9 changed files with 48 additions and 29 deletions

View file

@ -6,6 +6,9 @@ export default class AdminIndexesItemDocumentsDocumentController extends Control
save(event) {
event.preventDefault();
this.model.index.saveDocument(this.model.document);
const formData = new FormData(event.currentTarget);
const data = formData.get('document');
this.model.index.saveDocument(data);
}
}

View file

@ -1,3 +1,4 @@
import jsonParse from '../helpers/json-parse';
import query from '../utils/query';
// import { TrackedArray } from 'tracked-built-ins';
// import { trackedFunction } from 'ember-resources/util/function';
@ -40,8 +41,8 @@ export default class Index {
saveDocument(document) {
return query(`${this.path}/documents`, {
method: 'PUT',
body: JSON.stringify(document),
method: 'POST',
body: JSON.stringify([JSON.parse(document)]),
});
}

View file

@ -15,6 +15,7 @@ Router.map(function () {
this.route('edit');
this.route('documents', function () {
this.route('document', { path: '/:document_id' });
this.route('new');
});
});
this.route('new');

View file

@ -0,0 +1,17 @@
import Route from '@ember/routing/route';
import Document from '../../../../../models/document';
import { hash } from 'rsvp';
export default class AdminIndexesItemDocumentsNewRoute extends Route {
templateName = 'admin.indexes.item.documents.document';
controllerName = 'admin.indexes.item.documents.document';
model() {
const index = this.modelFor('admin.indexes.item');
return hash({
index,
document: new Document(),
});
}
}

View file

@ -1,29 +1,5 @@
<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}}
<InputTextarea @name='document' @value={{stringify @model.document}} />
<Button type='submit' @text='Save' @style='primary' />
</form>

View file

@ -17,6 +17,10 @@
</div>
</div> --}}
<LinkTo @route='admin.indexes.item.documents.new' @model={{@model.index}} class='block mb-4'>
Create new document
</LinkTo>
{{#if (gt @model.data.estimatedTotalHits 0)}}
<RoyalTable
@data={{@model.data.hits}}

View file

@ -0,0 +1 @@
{{outlet}}

View file

@ -6,7 +6,12 @@
<Column @prop='indexUid' />
<Column @prop='status' />
<Column @prop='type' />
<Column @prop='details' />
<Column @prop='details'>
{{stringify data.details}}
</Column>
<Column @prop='error'>
{{stringify data.error}}
</Column>
<Column @prop='duration' />
<Column @prop='enqueuedAt'>
{{date-time-format

View file

@ -0,0 +1,11 @@
import { module, test } from 'qunit';
import { setupTest } from 'meiliadmin/tests/helpers';
module('Unit | Route | admin/indexes/item/documents/new', function (hooks) {
setupTest(hooks);
test('it exists', function (assert) {
let route = this.owner.lookup('route:admin/indexes/item/documents/new');
assert.ok(route);
});
});