diff --git a/app/models/index.js b/app/models/index.js index 1e15243..5a28adb 100644 --- a/app/models/index.js +++ b/app/models/index.js @@ -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), }); } diff --git a/app/router.js b/app/router.js index ff15728..cb7a1c8 100644 --- a/app/router.js +++ b/app/router.js @@ -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' }); diff --git a/app/routes/admin/indexes/new.js b/app/routes/admin/indexes/new.js new file mode 100644 index 0000000..55082b7 --- /dev/null +++ b/app/routes/admin/indexes/new.js @@ -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(); + } +} diff --git a/app/templates/admin/indexes/index.hbs b/app/templates/admin/indexes/index.hbs index 692989f..9bdd930 100644 --- a/app/templates/admin/indexes/index.hbs +++ b/app/templates/admin/indexes/index.hbs @@ -1,5 +1,9 @@

Indexes

+ + Create new index + + diff --git a/app/templates/admin/indexes/item/edit.hbs b/app/templates/admin/indexes/item/edit.hbs index 24f4a28..0445ba9 100644 --- a/app/templates/admin/indexes/item/edit.hbs +++ b/app/templates/admin/indexes/item/edit.hbs @@ -1,6 +1,21 @@ -Edit {{@model.uid}} + + {{#if @model.isNew}} + Create new index + {{else}} + Edit + {{@model.uid}} + {{/if}} +
+ {{#if @model.isNew}} + + {{/if}} + -