From c743cc17168a0d86fc01370c431c81e6d5de2c15 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Thu, 23 Jul 2020 09:37:06 -0400 Subject: [PATCH] chore: add projects routes --- .../app/controllers/scopes/scope/projects.js | 19 +++++ .../controllers/scopes/scope/projects/new.js | 19 +++++ .../scopes/scope/projects/project.js | 14 ++++ ui/core/app/router.js | 7 +- ui/core/app/routes/scopes/scope.js | 12 +-- ui/core/app/routes/scopes/scope/projects.js | 84 +++++++++++++++++++ .../app/routes/scopes/scope/projects/index.js | 4 + .../app/routes/scopes/scope/projects/new.js | 19 +++++ .../routes/scopes/scope/projects/project.js | 17 ++++ .../scopes/scope/projects/project/index.js | 4 + ui/core/app/templates/application.hbs | 3 + ui/core/app/templates/scopes/scope.hbs | 38 ++++++++- .../app/templates/scopes/scope/projects.hbs | 3 + .../templates/scopes/scope/projects/index.hbs | 56 +++++++++++++ .../templates/scopes/scope/projects/new.hbs | 21 +++++ .../scopes/scope/projects/project.hbs | 3 + .../scopes/scope/projects/project/index.hbs | 35 ++++++++ ui/core/mirage/config.js | 7 ++ .../controllers/scopes/scope/projects-test.js | 12 +++ .../scopes/scope/projects/new-test.js | 12 +++ .../scopes/scope/projects/project-test.js | 12 +++ .../unit/routes/scopes/scope/projects-test.js | 11 +++ .../scopes/scope/projects/index-test.js | 11 +++ .../routes/scopes/scope/projects/new-test.js | 11 +++ .../scopes/scope/projects/project-test.js | 11 +++ .../scope/projects/project/index-test.js | 11 +++ ui/core/translations/en-us.yaml | 3 +- 27 files changed, 451 insertions(+), 8 deletions(-) create mode 100644 ui/core/app/controllers/scopes/scope/projects.js create mode 100644 ui/core/app/controllers/scopes/scope/projects/new.js create mode 100644 ui/core/app/controllers/scopes/scope/projects/project.js create mode 100644 ui/core/app/routes/scopes/scope/projects.js create mode 100644 ui/core/app/routes/scopes/scope/projects/index.js create mode 100644 ui/core/app/routes/scopes/scope/projects/new.js create mode 100644 ui/core/app/routes/scopes/scope/projects/project.js create mode 100644 ui/core/app/routes/scopes/scope/projects/project/index.js create mode 100644 ui/core/app/templates/scopes/scope/projects.hbs create mode 100644 ui/core/app/templates/scopes/scope/projects/index.hbs create mode 100644 ui/core/app/templates/scopes/scope/projects/new.hbs create mode 100644 ui/core/app/templates/scopes/scope/projects/project.hbs create mode 100644 ui/core/app/templates/scopes/scope/projects/project/index.hbs create mode 100644 ui/core/tests/unit/controllers/scopes/scope/projects-test.js create mode 100644 ui/core/tests/unit/controllers/scopes/scope/projects/new-test.js create mode 100644 ui/core/tests/unit/controllers/scopes/scope/projects/project-test.js create mode 100644 ui/core/tests/unit/routes/scopes/scope/projects-test.js create mode 100644 ui/core/tests/unit/routes/scopes/scope/projects/index-test.js create mode 100644 ui/core/tests/unit/routes/scopes/scope/projects/new-test.js create mode 100644 ui/core/tests/unit/routes/scopes/scope/projects/project-test.js create mode 100644 ui/core/tests/unit/routes/scopes/scope/projects/project/index-test.js diff --git a/ui/core/app/controllers/scopes/scope/projects.js b/ui/core/app/controllers/scopes/scope/projects.js new file mode 100644 index 000000000..cdd9bda8a --- /dev/null +++ b/ui/core/app/controllers/scopes/scope/projects.js @@ -0,0 +1,19 @@ +import Controller from '@ember/controller'; +import { inject as service } from '@ember/service'; + +export default class ScopesScopeProjectsController extends Controller { + + // =services + + @service intl; + + // =attributes + + /** + * @type {string} + */ + get breadCrumb() { + return this.intl.t('resources.projects'); + } + +} diff --git a/ui/core/app/controllers/scopes/scope/projects/new.js b/ui/core/app/controllers/scopes/scope/projects/new.js new file mode 100644 index 000000000..50b30d187 --- /dev/null +++ b/ui/core/app/controllers/scopes/scope/projects/new.js @@ -0,0 +1,19 @@ +import Controller from '@ember/controller'; +import { inject as service } from '@ember/service'; + +export default class ScopesScopeProjectsNewController extends Controller { + + // =services + + @service intl; + + // =attributes + + /** + * @type {string} + */ + get breadCrumb() { + return this.intl.t('titles.new'); + } + +} diff --git a/ui/core/app/controllers/scopes/scope/projects/project.js b/ui/core/app/controllers/scopes/scope/projects/project.js new file mode 100644 index 000000000..8fc8bbb1c --- /dev/null +++ b/ui/core/app/controllers/scopes/scope/projects/project.js @@ -0,0 +1,14 @@ +import Controller from '@ember/controller'; + +export default class ScopesScopeProjectsProjectController extends Controller { + + // =attributes + + /** + * @type {string} + */ + get breadCrumb() { + return this.model.displayName; + } + +} diff --git a/ui/core/app/router.js b/ui/core/app/router.js index 6dbe00b3b..e07a9ee94 100644 --- a/ui/core/app/router.js +++ b/ui/core/app/router.js @@ -9,7 +9,12 @@ export default class Router extends EmberRouter { Router.map(function () { this.route('scopes', function() { - this.route('scope', { path: ':scope_id' }); + this.route('scope', { path: ':scope_id' }, function() { + this.route('projects', function() { + this.route('project', { path: ':project_id' }, function() {}); + this.route('new'); + }); + }); }); this.route('orgs', function () { diff --git a/ui/core/app/routes/scopes/scope.js b/ui/core/app/routes/scopes/scope.js index 68201166e..8cde487bd 100644 --- a/ui/core/app/routes/scopes/scope.js +++ b/ui/core/app/routes/scopes/scope.js @@ -2,10 +2,12 @@ import Route from '@ember/routing/route'; export default class ScopesScopeRoute extends Route { + // =methods + /** - * Attempts to load the specified scope from the API. This is allowed + * Attempt to load the specified scope from the API. This is allowed * to fail, since in some cases the user may not have permission to read a - * scope directly, but may have permission to read its resources. + * scope directly, but may have permission to read resources under it. * If the scope fails to load, we still proceed using a temporary scope object * consisting of only the specified ID. * @param {object} params @@ -16,10 +18,10 @@ export default class ScopesScopeRoute extends Route { try { return await this.store.findRecord('scope', id); } catch { - const maybeExisting = this.store.peekRecord('scope', id); - // TODO it's unclear if this is reliable... + const maybeExistingScope = this.store.peekRecord('scope', id); + // TODO it's unclear if creating a temporary unsaved scope is reliable... // we may need to revert to a POJO. - return maybeExisting || this.store.createRecord('scope', { id }); + return maybeExistingScope || this.store.createRecord('scope', { id }); } } diff --git a/ui/core/app/routes/scopes/scope/projects.js b/ui/core/app/routes/scopes/scope/projects.js new file mode 100644 index 000000000..f2a5fa77b --- /dev/null +++ b/ui/core/app/routes/scopes/scope/projects.js @@ -0,0 +1,84 @@ +import Route from '@ember/routing/route'; +import { inject as service } from '@ember/service'; +import { action } from '@ember/object'; + +export default class ScopesScopeProjectsRoute extends Route { + + // =services + + @service notify; + + // =methods + + /** + * Loads all scopes under the current scope. + * @return {Promise{[ScopeModel]}} + */ + async model() { + const { id: scope_id } = this.modelFor('scopes.scope'); + return this.store.query('scope', { scope_id }); + } + + /** + * If arriving here within a verifiable project scope, redirect to its + * parent, which is necessarily an org, in order to list projects. + * + * TODO: this conditional redirect based on the scope type is probably + * necessary for many routes directly under scope, so we may want + * to move this into a mixin. + * @param {ScopeModel} + */ + redirect() { + const { isProject, scopeID } = this.modelFor('scopes.scope'); + if (isProject) this.transitionTo('scopes.scope.projects', scopeID); + } + + // =actions + + /** + * Rollback changes on project. + * @param {ProjectModel} project + */ + @action + cancel(project) { + const { isNew } = project; + project.rollbackAttributes(); + if (isNew) this.transitionTo('scopes.scope.projects'); + } + + /** + * Handle save project. + * @param {ProjectModel} project + * @param {Event} e + */ + @action + async save(project) { + try { + await project.save(); + // TODO: replace with translated strings + this.notify.success('Save succeeded.'); + this.transitionTo('scopes.scope.projects.project', project); + } catch (error) { + // TODO: replace with translated strings + this.notify.error(error.message, { closeAfter: null }); + } + } + + /** + * Deletes the project and redirects to index. + * @param {ProjectModel} project + */ + @action + async delete(project) { + try { + await project.destroyRecord(); + this.transitionTo('orgs.org.projects'); + // TODO: replace with translated strings + this.notify.success('Deleted project 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/index.js b/ui/core/app/routes/scopes/scope/projects/index.js new file mode 100644 index 000000000..294371052 --- /dev/null +++ b/ui/core/app/routes/scopes/scope/projects/index.js @@ -0,0 +1,4 @@ +import Route from '@ember/routing/route'; + +export default class ScopesScopeProjectsIndexRoute extends Route { +} diff --git a/ui/core/app/routes/scopes/scope/projects/new.js b/ui/core/app/routes/scopes/scope/projects/new.js new file mode 100644 index 000000000..1781f5269 --- /dev/null +++ b/ui/core/app/routes/scopes/scope/projects/new.js @@ -0,0 +1,19 @@ +import Route from '@ember/routing/route'; + +export default class ScopesScopeProjectsNewRoute extends Route { + + // =methods + + /** + * Creates a new unsaved project scope belonging to the current org scope. + * @return {ScopeModel} + */ + model() { + const { id } = this.modelFor('scopes.scope'); + return this.store.createRecord('scope', { + type: 'project', + scopeID: id + }); + } + +} diff --git a/ui/core/app/routes/scopes/scope/projects/project.js b/ui/core/app/routes/scopes/scope/projects/project.js new file mode 100644 index 000000000..c2aee8ed3 --- /dev/null +++ b/ui/core/app/routes/scopes/scope/projects/project.js @@ -0,0 +1,17 @@ +import Route from '@ember/routing/route'; + +export default class ScopesScopeProjectsProjectRoute extends Route { + + // =methods + + /** + * Loads a scope by ID (ostensibly a project scope). + * @param {object} params + * @param {string} params.project_id + * @return {ScopeModel} + */ + model({ project_id }) { + return this.store.findRecord('scope', project_id); + } + +} diff --git a/ui/core/app/routes/scopes/scope/projects/project/index.js b/ui/core/app/routes/scopes/scope/projects/project/index.js new file mode 100644 index 000000000..f5511f2e7 --- /dev/null +++ b/ui/core/app/routes/scopes/scope/projects/project/index.js @@ -0,0 +1,4 @@ +import Route from '@ember/routing/route'; + +export default class ScopesScopeProjectsProjectIndexRoute extends Route { +} diff --git a/ui/core/app/templates/application.hbs b/ui/core/app/templates/application.hbs index 576e7875a..fbbecf1e7 100644 --- a/ui/core/app/templates/application.hbs +++ b/ui/core/app/templates/application.hbs @@ -1,3 +1,6 @@ + +{{title (app-name)}} + diff --git a/ui/core/app/templates/scopes/scope.hbs b/ui/core/app/templates/scopes/scope.hbs index e2147cab0..2d1a73607 100644 --- a/ui/core/app/templates/scopes/scope.hbs +++ b/ui/core/app/templates/scopes/scope.hbs @@ -1 +1,37 @@ -{{outlet}} \ No newline at end of file + + + + + + + {{t "resources.projects"}} + + + + {{outlet "sidebar"}} + + {{!-- + + + {{t "resources.users"}} + + + + {{t "resources.groups"}} + + + + {{t "resources.roles"}} + + + --}} + + + + +
+ {{outlet}} +
+
+ +
diff --git a/ui/core/app/templates/scopes/scope/projects.hbs b/ui/core/app/templates/scopes/scope/projects.hbs new file mode 100644 index 000000000..1f709c7f7 --- /dev/null +++ b/ui/core/app/templates/scopes/scope/projects.hbs @@ -0,0 +1,3 @@ +{{title (t "resources.projects")}} + +{{outlet}} diff --git a/ui/core/app/templates/scopes/scope/projects/index.hbs b/ui/core/app/templates/scopes/scope/projects/index.hbs new file mode 100644 index 000000000..c07e265ec --- /dev/null +++ b/ui/core/app/templates/scopes/scope/projects/index.hbs @@ -0,0 +1,56 @@ + + + + + + + +

{{t "resources.projects"}}

+
+ + + {{#if @model}} + + {{t 'titles.new'}} + + {{/if}} + + + + + {{#if @model}} + + + {{#each @model as |project|}} + + {{/each}} + + + {{else}} + + + + + {{t 'descriptions.projects-welcome'}} + + + + {{t 'titles.new'}} + + + + + {{/if}} + + + +
diff --git a/ui/core/app/templates/scopes/scope/projects/new.hbs b/ui/core/app/templates/scopes/scope/projects/new.hbs new file mode 100644 index 000000000..a8758e3c0 --- /dev/null +++ b/ui/core/app/templates/scopes/scope/projects/new.hbs @@ -0,0 +1,21 @@ +{{title (t 'titles.new')}} + + + + + + + + +

{{t "titles.new"}}

+
+ + + + + +
diff --git a/ui/core/app/templates/scopes/scope/projects/project.hbs b/ui/core/app/templates/scopes/scope/projects/project.hbs new file mode 100644 index 000000000..d66e83390 --- /dev/null +++ b/ui/core/app/templates/scopes/scope/projects/project.hbs @@ -0,0 +1,3 @@ +{{title @model.displayName}} + +{{outlet}} diff --git a/ui/core/app/templates/scopes/scope/projects/project/index.hbs b/ui/core/app/templates/scopes/scope/projects/project/index.hbs new file mode 100644 index 000000000..5dccae834 --- /dev/null +++ b/ui/core/app/templates/scopes/scope/projects/project/index.hbs @@ -0,0 +1,35 @@ + + + + + + + +

{{t "resources.project"}}

+
+ + + + + {{t 'titles.details'}} + + + + + + + + + {{t 'actions.delete'}} + + + +
diff --git a/ui/core/mirage/config.js b/ui/core/mirage/config.js index 421f87a8f..d27476462 100644 --- a/ui/core/mirage/config.js +++ b/ui/core/mirage/config.js @@ -17,6 +17,13 @@ export default function() { // Scope resources + this.get('/scopes', ({ scopes }, { queryParams: { scope_id } }) => { + // Default parent scope is global + if (!scope_id) scope_id = 'global'; + return scopes.where(scope => { + return scope.scope ? scope.scope.id === scope_id : false + }); + }); this.post('/scopes'); // To simulate a possible real-world case, org scopes are not returned, // but project scopes are. diff --git a/ui/core/tests/unit/controllers/scopes/scope/projects-test.js b/ui/core/tests/unit/controllers/scopes/scope/projects-test.js new file mode 100644 index 000000000..21125f233 --- /dev/null +++ b/ui/core/tests/unit/controllers/scopes/scope/projects-test.js @@ -0,0 +1,12 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +module('Unit | Controller | scopes/scope/projects', function(hooks) { + setupTest(hooks); + + // Replace this with your real tests. + test('it exists', function(assert) { + let controller = this.owner.lookup('controller:scopes/scope/projects'); + assert.ok(controller); + }); +}); diff --git a/ui/core/tests/unit/controllers/scopes/scope/projects/new-test.js b/ui/core/tests/unit/controllers/scopes/scope/projects/new-test.js new file mode 100644 index 000000000..eeb857274 --- /dev/null +++ b/ui/core/tests/unit/controllers/scopes/scope/projects/new-test.js @@ -0,0 +1,12 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +module('Unit | Controller | scopes/scope/projects/new', function(hooks) { + setupTest(hooks); + + // Replace this with your real tests. + test('it exists', function(assert) { + let controller = this.owner.lookup('controller:scopes/scope/projects/new'); + assert.ok(controller); + }); +}); diff --git a/ui/core/tests/unit/controllers/scopes/scope/projects/project-test.js b/ui/core/tests/unit/controllers/scopes/scope/projects/project-test.js new file mode 100644 index 000000000..26a255430 --- /dev/null +++ b/ui/core/tests/unit/controllers/scopes/scope/projects/project-test.js @@ -0,0 +1,12 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +module('Unit | Controller | scopes/scope/projects/project', function(hooks) { + setupTest(hooks); + + // Replace this with your real tests. + test('it exists', function(assert) { + let controller = this.owner.lookup('controller:scopes/scope/projects/project'); + assert.ok(controller); + }); +}); diff --git a/ui/core/tests/unit/routes/scopes/scope/projects-test.js b/ui/core/tests/unit/routes/scopes/scope/projects-test.js new file mode 100644 index 000000000..4a8dde55f --- /dev/null +++ b/ui/core/tests/unit/routes/scopes/scope/projects-test.js @@ -0,0 +1,11 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +module('Unit | Route | scopes/scope/projects', function(hooks) { + setupTest(hooks); + + test('it exists', function(assert) { + let route = this.owner.lookup('route:scopes/scope/projects'); + assert.ok(route); + }); +}); diff --git a/ui/core/tests/unit/routes/scopes/scope/projects/index-test.js b/ui/core/tests/unit/routes/scopes/scope/projects/index-test.js new file mode 100644 index 000000000..71c813a35 --- /dev/null +++ b/ui/core/tests/unit/routes/scopes/scope/projects/index-test.js @@ -0,0 +1,11 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +module('Unit | Route | scopes/scope/projects/index', function(hooks) { + setupTest(hooks); + + test('it exists', function(assert) { + let route = this.owner.lookup('route:scopes/scope/projects/index'); + assert.ok(route); + }); +}); diff --git a/ui/core/tests/unit/routes/scopes/scope/projects/new-test.js b/ui/core/tests/unit/routes/scopes/scope/projects/new-test.js new file mode 100644 index 000000000..6d22e1fa7 --- /dev/null +++ b/ui/core/tests/unit/routes/scopes/scope/projects/new-test.js @@ -0,0 +1,11 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +module('Unit | Route | scopes/scope/projects/new', function(hooks) { + setupTest(hooks); + + test('it exists', function(assert) { + let route = this.owner.lookup('route:scopes/scope/projects/new'); + assert.ok(route); + }); +}); diff --git a/ui/core/tests/unit/routes/scopes/scope/projects/project-test.js b/ui/core/tests/unit/routes/scopes/scope/projects/project-test.js new file mode 100644 index 000000000..54555a07c --- /dev/null +++ b/ui/core/tests/unit/routes/scopes/scope/projects/project-test.js @@ -0,0 +1,11 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +module('Unit | Route | scopes/scope/projects/project', function(hooks) { + setupTest(hooks); + + test('it exists', function(assert) { + let route = this.owner.lookup('route:scopes/scope/projects/project'); + assert.ok(route); + }); +}); diff --git a/ui/core/tests/unit/routes/scopes/scope/projects/project/index-test.js b/ui/core/tests/unit/routes/scopes/scope/projects/project/index-test.js new file mode 100644 index 000000000..c81b2f5a7 --- /dev/null +++ b/ui/core/tests/unit/routes/scopes/scope/projects/project/index-test.js @@ -0,0 +1,11 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +module('Unit | Route | scopes/scope/projects/project/index', function(hooks) { + setupTest(hooks); + + test('it exists', function(assert) { + let route = this.owner.lookup('route:scopes/scope/projects/project/index'); + assert.ok(route); + }); +}); diff --git a/ui/core/translations/en-us.yaml b/ui/core/translations/en-us.yaml index bda14642a..e770de25c 100644 --- a/ui/core/translations/en-us.yaml +++ b/ui/core/translations/en-us.yaml @@ -6,7 +6,7 @@ actions: help: Need help? resources: user: User - users: Users + users: Users role: Role roles: Roles group: Group @@ -18,6 +18,7 @@ resources: titles: iam: IAM new: New + details: Details general: General overview: Overview settings: Settings