From cd0c15a41fb76a6cd24f0ff65cf57f7860d4dfb2 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Tue, 28 Jul 2020 11:06:06 -0400 Subject: [PATCH] chore: add initial host catalogs index --- ui/core/app/router.js | 7 +- .../scope/projects/project/host-catalogs.js | 73 +++++++++++++++++++ .../project/host-catalogs/host-catalog.js | 4 + .../host-catalogs/host-catalog/index.js | 4 + .../projects/project/host-catalogs/index.js | 4 + .../projects/project/host-catalogs/new.js | 4 + .../scope/projects/project/host-catalogs.hbs | 3 + .../project/host-catalogs/host-catalog.hbs | 1 + .../host-catalogs/host-catalog/index.hbs | 1 + .../projects/project/host-catalogs/index.hbs | 68 +++++++++++++++++ .../projects/project/host-catalogs/new.hbs | 1 + ui/core/mirage/scenarios/default.js | 17 +---- .../projects/project/host-catalogs-test.js | 11 +++ .../host-catalogs/host-catalog-test.js | 11 +++ .../host-catalogs/host-catalog/index-test.js | 11 +++ .../project/host-catalogs/index-test.js | 11 +++ .../project/host-catalogs/new-test.js | 11 +++ 17 files changed, 228 insertions(+), 14 deletions(-) create mode 100644 ui/core/app/routes/scopes/scope/projects/project/host-catalogs.js create mode 100644 ui/core/app/routes/scopes/scope/projects/project/host-catalogs/host-catalog.js create mode 100644 ui/core/app/routes/scopes/scope/projects/project/host-catalogs/host-catalog/index.js create mode 100644 ui/core/app/routes/scopes/scope/projects/project/host-catalogs/index.js create mode 100644 ui/core/app/routes/scopes/scope/projects/project/host-catalogs/new.js create mode 100644 ui/core/app/templates/scopes/scope/projects/project/host-catalogs.hbs create mode 100644 ui/core/app/templates/scopes/scope/projects/project/host-catalogs/host-catalog.hbs create mode 100644 ui/core/app/templates/scopes/scope/projects/project/host-catalogs/host-catalog/index.hbs create mode 100644 ui/core/app/templates/scopes/scope/projects/project/host-catalogs/index.hbs create mode 100644 ui/core/app/templates/scopes/scope/projects/project/host-catalogs/new.hbs create mode 100644 ui/core/tests/unit/routes/scopes/scope/projects/project/host-catalogs-test.js create mode 100644 ui/core/tests/unit/routes/scopes/scope/projects/project/host-catalogs/host-catalog-test.js create mode 100644 ui/core/tests/unit/routes/scopes/scope/projects/project/host-catalogs/host-catalog/index-test.js create mode 100644 ui/core/tests/unit/routes/scopes/scope/projects/project/host-catalogs/index-test.js create mode 100644 ui/core/tests/unit/routes/scopes/scope/projects/project/host-catalogs/new-test.js diff --git a/ui/core/app/router.js b/ui/core/app/router.js index ef3536c60..4385741d0 100644 --- a/ui/core/app/router.js +++ b/ui/core/app/router.js @@ -14,7 +14,12 @@ Router.map(function () { this.route('method', { path: ':auth_method_id'}); }); this.route('projects', function() { - this.route('project', { path: ':project_id' }, function() {}); + this.route('project', { path: ':project_id' }, function() { + this.route('host-catalogs', function() { + this.route('new'); + this.route('host-catalog', { path: ':host_catalog_id' }, function() {}); + }); + }); this.route('new'); }); }); diff --git a/ui/core/app/routes/scopes/scope/projects/project/host-catalogs.js b/ui/core/app/routes/scopes/scope/projects/project/host-catalogs.js new file mode 100644 index 000000000..de945f71c --- /dev/null +++ b/ui/core/app/routes/scopes/scope/projects/project/host-catalogs.js @@ -0,0 +1,73 @@ +import Route from '@ember/routing/route'; +import { inject as service } from '@ember/service'; +import { action } from '@ember/object'; + +export default class ScopesScopeProjectsProjectHostCatalogsRoute extends Route { + + // =services + + @service notify; + + // =methods + + + /** + * Loads all scopes under the current scope. + * @return {Promise{[HostCatalogModel]}} + */ + async model() { + const scopeID = this.modelFor('scopes.scope.projects.project').id; + return this.store.findAll('host-catalog', { adapterOptions: { scopeID } }); + } + + // =actions + + /** + * Rollback changes on project. + * @param {HostCatalogModel} hostCatalog + */ + @action + cancel(hostCatalog) { + const { isNew } = hostCatalog; + hostCatalog.rollbackAttributes(); + if (isNew) this.transitionTo('scopes.scope.projects.project.host-catalogs'); + } + + /** + * Handle save. + * @param {HostCatalogModel} hostCatalog + * @param {Event} e + */ + @action + async save(hostCatalog) { + try { + await hostCatalog.save(); + this.refresh(); + // TODO: replace with translated strings + this.notify.success('Save succeeded.'); + this.transitionTo('scopes.scope.projects.project.host-catalogs.host-catalog', hostCatalog); + } catch (error) { + // TODO: replace with translated strings + this.notify.error(error.message, { closeAfter: null }); + } + } + + /** + * Deletes the host catalog and redirects to index. + * @param {ProjectModel} project + */ + @action + async delete(project) { + try { + await project.destroyRecord(); + this.refresh(); + this.transitionTo('scopes.scope.projects.project.host-catalogs'); + // TODO: replace with translated strings + this.notify.success('Deleted host catalog succesfully.'); + } catch (error) { + // TODO: replace with translated strings + this.notify.error(error.message, { closeAfter: null }); + } + } + +} diff --git a/ui/core/app/routes/scopes/scope/projects/project/host-catalogs/host-catalog.js b/ui/core/app/routes/scopes/scope/projects/project/host-catalogs/host-catalog.js new file mode 100644 index 000000000..f54947470 --- /dev/null +++ b/ui/core/app/routes/scopes/scope/projects/project/host-catalogs/host-catalog.js @@ -0,0 +1,4 @@ +import Route from '@ember/routing/route'; + +export default class ScopesScopeProjectsProjectHostCatalogsHostCatalogRoute extends Route { +} diff --git a/ui/core/app/routes/scopes/scope/projects/project/host-catalogs/host-catalog/index.js b/ui/core/app/routes/scopes/scope/projects/project/host-catalogs/host-catalog/index.js new file mode 100644 index 000000000..34bccc035 --- /dev/null +++ b/ui/core/app/routes/scopes/scope/projects/project/host-catalogs/host-catalog/index.js @@ -0,0 +1,4 @@ +import Route from '@ember/routing/route'; + +export default class ScopesScopeProjectsProjectHostCatalogsHostCatalogIndexRoute extends Route { +} diff --git a/ui/core/app/routes/scopes/scope/projects/project/host-catalogs/index.js b/ui/core/app/routes/scopes/scope/projects/project/host-catalogs/index.js new file mode 100644 index 000000000..b01277c47 --- /dev/null +++ b/ui/core/app/routes/scopes/scope/projects/project/host-catalogs/index.js @@ -0,0 +1,4 @@ +import Route from '@ember/routing/route'; + +export default class ScopesScopeProjectsProjectHostCatalogsIndexRoute extends Route { +} diff --git a/ui/core/app/routes/scopes/scope/projects/project/host-catalogs/new.js b/ui/core/app/routes/scopes/scope/projects/project/host-catalogs/new.js new file mode 100644 index 000000000..9e076cd1d --- /dev/null +++ b/ui/core/app/routes/scopes/scope/projects/project/host-catalogs/new.js @@ -0,0 +1,4 @@ +import Route from '@ember/routing/route'; + +export default class ScopesScopeProjectsProjectHostCatalogsNewRoute extends Route { +} diff --git a/ui/core/app/templates/scopes/scope/projects/project/host-catalogs.hbs b/ui/core/app/templates/scopes/scope/projects/project/host-catalogs.hbs new file mode 100644 index 000000000..6ad0035fb --- /dev/null +++ b/ui/core/app/templates/scopes/scope/projects/project/host-catalogs.hbs @@ -0,0 +1,3 @@ +{{title (t "resources.host-catalogs")}} + +{{outlet}} diff --git a/ui/core/app/templates/scopes/scope/projects/project/host-catalogs/host-catalog.hbs b/ui/core/app/templates/scopes/scope/projects/project/host-catalogs/host-catalog.hbs new file mode 100644 index 000000000..e2147cab0 --- /dev/null +++ b/ui/core/app/templates/scopes/scope/projects/project/host-catalogs/host-catalog.hbs @@ -0,0 +1 @@ +{{outlet}} \ No newline at end of file diff --git a/ui/core/app/templates/scopes/scope/projects/project/host-catalogs/host-catalog/index.hbs b/ui/core/app/templates/scopes/scope/projects/project/host-catalogs/host-catalog/index.hbs new file mode 100644 index 000000000..e2147cab0 --- /dev/null +++ b/ui/core/app/templates/scopes/scope/projects/project/host-catalogs/host-catalog/index.hbs @@ -0,0 +1 @@ +{{outlet}} \ No newline at end of file diff --git a/ui/core/app/templates/scopes/scope/projects/project/host-catalogs/index.hbs b/ui/core/app/templates/scopes/scope/projects/project/host-catalogs/index.hbs new file mode 100644 index 000000000..935cf9f30 --- /dev/null +++ b/ui/core/app/templates/scopes/scope/projects/project/host-catalogs/index.hbs @@ -0,0 +1,68 @@ + + + + + + + +

{{t "resources.host-catalogs"}}

+

{{t "descriptions.host-catalogs"}}

+
+ + + {{#if @model}} + + {{t "titles.new"}} + + {{/if}} + + + + + {{#if @model}} + + + + + {{t "form.label.name"}} + {{t "form.label.type"}} + {{t "form.label.description"}} + + + + {{#each @model as |hostCatalog|}} + + + + {{hostCatalog.name}} + + + {{hostCatalog.type}} + {{hostCatalog.description}} + + {{/each}} + + + + {{else}} + + + + + {{t "descriptions.host-catalogs-welcome"}} + + + + {{t "titles.new"}} + + + + + {{/if}} + + + +
diff --git a/ui/core/app/templates/scopes/scope/projects/project/host-catalogs/new.hbs b/ui/core/app/templates/scopes/scope/projects/project/host-catalogs/new.hbs new file mode 100644 index 000000000..e2147cab0 --- /dev/null +++ b/ui/core/app/templates/scopes/scope/projects/project/host-catalogs/new.hbs @@ -0,0 +1 @@ +{{outlet}} \ No newline at end of file diff --git a/ui/core/mirage/scenarios/default.js b/ui/core/mirage/scenarios/default.js index 1bbae80d5..f5727e195 100644 --- a/ui/core/mirage/scenarios/default.js +++ b/ui/core/mirage/scenarios/default.js @@ -7,20 +7,8 @@ export default function(server) { type: 'org', scope: { id: globalScope.id, type: globalScope.type } }, 'withChildren'); - const scope = { id: orgScope.id, type: orgScope.type }; - // Create additional scopes for authentication organization selection - server.create('scope', { - type: 'org', - scope: { id: globalScope.id, type: globalScope.type } - }, 'withChildren'); - - server.create('scope', { - type: 'org', - scope: { id: globalScope.id, type: globalScope.type } - }, 'withChildren'); - // Auth // Auth methods exist both at the global scope and the org scope. @@ -38,6 +26,9 @@ export default function(server) { // Other resources - server.createList('host-catalog', 6); + server.db.scopes.where({type: 'project'}).forEach(projectScope => { + const scope = { id: projectScope.id, type: projectScope.type }; + server.createList('host-catalog', 2, { scope }); + }); } diff --git a/ui/core/tests/unit/routes/scopes/scope/projects/project/host-catalogs-test.js b/ui/core/tests/unit/routes/scopes/scope/projects/project/host-catalogs-test.js new file mode 100644 index 000000000..dde4328e4 --- /dev/null +++ b/ui/core/tests/unit/routes/scopes/scope/projects/project/host-catalogs-test.js @@ -0,0 +1,11 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +module('Unit | Route | scopes/scope/projects/project/host-catalogs', function(hooks) { + setupTest(hooks); + + test('it exists', function(assert) { + let route = this.owner.lookup('route:scopes/scope/projects/project/host-catalogs'); + assert.ok(route); + }); +}); diff --git a/ui/core/tests/unit/routes/scopes/scope/projects/project/host-catalogs/host-catalog-test.js b/ui/core/tests/unit/routes/scopes/scope/projects/project/host-catalogs/host-catalog-test.js new file mode 100644 index 000000000..9cdc47735 --- /dev/null +++ b/ui/core/tests/unit/routes/scopes/scope/projects/project/host-catalogs/host-catalog-test.js @@ -0,0 +1,11 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +module('Unit | Route | scopes/scope/projects/project/host-catalogs/host-catalog', function(hooks) { + setupTest(hooks); + + test('it exists', function(assert) { + let route = this.owner.lookup('route:scopes/scope/projects/project/host-catalogs/host-catalog'); + assert.ok(route); + }); +}); diff --git a/ui/core/tests/unit/routes/scopes/scope/projects/project/host-catalogs/host-catalog/index-test.js b/ui/core/tests/unit/routes/scopes/scope/projects/project/host-catalogs/host-catalog/index-test.js new file mode 100644 index 000000000..92f1aa677 --- /dev/null +++ b/ui/core/tests/unit/routes/scopes/scope/projects/project/host-catalogs/host-catalog/index-test.js @@ -0,0 +1,11 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +module('Unit | Route | scopes/scope/projects/project/host-catalogs/host-catalog/index', function(hooks) { + setupTest(hooks); + + test('it exists', function(assert) { + let route = this.owner.lookup('route:scopes/scope/projects/project/host-catalogs/host-catalog/index'); + assert.ok(route); + }); +}); diff --git a/ui/core/tests/unit/routes/scopes/scope/projects/project/host-catalogs/index-test.js b/ui/core/tests/unit/routes/scopes/scope/projects/project/host-catalogs/index-test.js new file mode 100644 index 000000000..5cc1d842c --- /dev/null +++ b/ui/core/tests/unit/routes/scopes/scope/projects/project/host-catalogs/index-test.js @@ -0,0 +1,11 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +module('Unit | Route | scopes/scope/projects/project/host-catalogs/index', function(hooks) { + setupTest(hooks); + + test('it exists', function(assert) { + let route = this.owner.lookup('route:scopes/scope/projects/project/host-catalogs/index'); + assert.ok(route); + }); +}); diff --git a/ui/core/tests/unit/routes/scopes/scope/projects/project/host-catalogs/new-test.js b/ui/core/tests/unit/routes/scopes/scope/projects/project/host-catalogs/new-test.js new file mode 100644 index 000000000..96ccdff8b --- /dev/null +++ b/ui/core/tests/unit/routes/scopes/scope/projects/project/host-catalogs/new-test.js @@ -0,0 +1,11 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +module('Unit | Route | scopes/scope/projects/project/host-catalogs/new', function(hooks) { + setupTest(hooks); + + test('it exists', function(assert) { + let route = this.owner.lookup('route:scopes/scope/projects/project/host-catalogs/new'); + assert.ok(route); + }); +});