Add form for create new indexes

This commit is contained in:
Stanislav Romanov 2022-08-30 13:15:36 +03:00
parent cff4a195ba
commit 0c4f4e690e
7 changed files with 56 additions and 9 deletions

View file

@ -10,7 +10,7 @@ export default class Index {
// )
// );
constructor(data) {
constructor(data = {}) {
for (const key in data) {
this[key] = data[key];
}
@ -20,6 +20,10 @@ export default class Index {
return `indexes/${this.uid}`;
}
get isNew() {
return Boolean(!this.uid);
}
// get allAttributesAreDisplayed() {
// return (
// this.displayedAttributes.value &&
@ -90,8 +94,11 @@ export default class Index {
// }
save(data) {
return query(this.indexPath, {
method: 'PATCH',
const path = this.isNew ? 'indexes' : this.indexPath;
const method = this.isNew ? 'POST' : 'PATCH';
return query(path, {
method: method,
body: JSON.stringify(data),
});
}

View file

@ -15,6 +15,7 @@ Router.map(function () {
this.route('info');
this.route('edit');
});
this.route('new');
});
this.route('keys', function () {
this.route('key', { path: '/:uid' });

View file

@ -0,0 +1,11 @@
import Route from '@ember/routing/route';
import Index from '../../../models/index';
export default class AdminIndexesNewRoute extends Route {
templateName = 'admin.indexes.item.edit';
controllerName = 'admin.indexes.item.edit';
model() {
return new Index();
}
}

View file

@ -1,5 +1,9 @@
<h1 class='text-3xl mb-4'>Indexes</h1>
<LinkTo @route='admin.indexes.new' class='block mb-4'>
Create new index
</LinkTo>
<RoyalTable @data={{@model.results}} class='w-full' as |Row data|>
<Row as |Column|>
<Column @prop='uid'>

View file

@ -1,6 +1,21 @@
<Headers::H1>Edit {{@model.uid}}</Headers::H1>
<Headers::H1>
{{#if @model.isNew}}
Create new index
{{else}}
Edit
{{@model.uid}}
{{/if}}
</Headers::H1>
<form {{on 'submit' this.save}}>
{{#if @model.isNew}}
<InputText
@label='UID'
@name='uid'
@required={{true}}
/>
{{/if}}
<InputText
@label='Primary key'
@name='primaryKey'
@ -8,9 +23,5 @@
@required={{true}}
/>
<Button
type='submit'
@text='Save'
@style='primary'
/>
<Button type='submit' @text='Save' @style='primary' />
</form>

View file

@ -0,0 +1,2 @@
{{page-title "New"}}
{{outlet}}

View file

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