chore: add projects routes
This commit is contained in:
27 files changed
+451
-8
No files matched your search
@@ -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');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import Controller from '@ember/controller';
|
||||
|
||||
export default class ScopesScopeProjectsProjectController extends Controller {
|
||||
|
||||
// =attributes
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
get breadCrumb() {
|
||||
return this.model.displayName;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 () {
|
||||
|
||||
@@ -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 });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 });
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import Route from '@ember/routing/route';
|
||||
|
||||
export default class ScopesScopeProjectsIndexRoute extends Route {
|
||||
}
|
||||
@@ -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
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import Route from '@ember/routing/route';
|
||||
|
||||
export default class ScopesScopeProjectsProjectIndexRoute extends Route {
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
<HeadLayout />
|
||||
{{title (app-name)}}
|
||||
|
||||
<Rose::Layout::Global as |layout|>
|
||||
|
||||
<layout.header>
|
||||
|
||||
@@ -1 +1,37 @@
|
||||
{{outlet}}
|
||||
<Rose::Layout::Sidebar as |sidebarLayout|>
|
||||
|
||||
<sidebarLayout.sidebar>
|
||||
|
||||
<Rose::Nav::Sidebar @title={{t "titles.general"}} as |nav|>
|
||||
<nav.link @route="scopes.scope.projects">
|
||||
{{t "resources.projects"}}
|
||||
</nav.link>
|
||||
</Rose::Nav::Sidebar>
|
||||
|
||||
{{outlet "sidebar"}}
|
||||
|
||||
{{!--
|
||||
<Rose::Nav::Sidebar @title={{t "titles.iam"}} as |nav|>
|
||||
<nav.link @route="orgs.org.users">
|
||||
{{t "resources.users"}}
|
||||
</nav.link>
|
||||
|
||||
<nav.link @route="orgs.org.groups">
|
||||
{{t "resources.groups"}}
|
||||
</nav.link>
|
||||
|
||||
<nav.link @route="orgs.org.roles">
|
||||
{{t "resources.roles"}}
|
||||
</nav.link>
|
||||
</Rose::Nav::Sidebar>
|
||||
--}}
|
||||
|
||||
</sidebarLayout.sidebar>
|
||||
|
||||
<sidebarLayout.body>
|
||||
<main>
|
||||
{{outlet}}
|
||||
</main>
|
||||
</sidebarLayout.body>
|
||||
|
||||
</Rose::Layout::Sidebar>
|
||||
@@ -0,0 +1,3 @@
|
||||
{{title (t "resources.projects")}}
|
||||
|
||||
{{outlet}}
|
||||
@@ -0,0 +1,56 @@
|
||||
<Rose::Layout::Page as |page|>
|
||||
|
||||
<page.breadcrumbs>
|
||||
<BreadCrumbs />
|
||||
</page.breadcrumbs>
|
||||
|
||||
<page.header>
|
||||
<h2>{{t "resources.projects"}}</h2>
|
||||
</page.header>
|
||||
|
||||
<page.actions>
|
||||
{{#if @model}}
|
||||
<Rose::LinkButton
|
||||
@route="scopes.scope.projects.new"
|
||||
@style="primary"
|
||||
>
|
||||
{{t 'titles.new'}}
|
||||
</Rose::LinkButton>
|
||||
{{/if}}
|
||||
</page.actions>
|
||||
|
||||
<page.body>
|
||||
|
||||
{{#if @model}}
|
||||
|
||||
<Rose::Cards as |cards|>
|
||||
{{#each @model as |project|}}
|
||||
<cards.link
|
||||
@title={{project.name}}
|
||||
@subtitle={{project.id}}
|
||||
@description={{project.description}}
|
||||
@route="scopes.scope.projects.project"
|
||||
@model={{project}}
|
||||
/>
|
||||
{{/each}}
|
||||
</Rose::Cards>
|
||||
|
||||
{{else}}
|
||||
|
||||
<Rose::Layout::Centered>
|
||||
<Rose::Message @title={{t 'titles.projects-welcome'}} as |message|>
|
||||
<message.description>
|
||||
{{t 'descriptions.projects-welcome'}}
|
||||
</message.description>
|
||||
<message.link @route="scopes.scope.projects.new">
|
||||
<Rose::Icon @name="plus-circle-outline" />
|
||||
{{t 'titles.new'}}
|
||||
</message.link>
|
||||
</Rose::Message>
|
||||
</Rose::Layout::Centered>
|
||||
|
||||
{{/if}}
|
||||
|
||||
</page.body>
|
||||
|
||||
</Rose::Layout::Page>
|
||||
@@ -0,0 +1,21 @@
|
||||
{{title (t 'titles.new')}}
|
||||
|
||||
<Rose::Layout::Page as |page|>
|
||||
|
||||
<page.breadcrumbs>
|
||||
<BreadCrumbs />
|
||||
</page.breadcrumbs>
|
||||
|
||||
<page.header>
|
||||
<h2>{{t "titles.new"}}</h2>
|
||||
</page.header>
|
||||
|
||||
<page.body>
|
||||
<Form::Project
|
||||
@model={{@model}}
|
||||
@submit={{route-action "save" @model}}
|
||||
@cancel={{route-action "cancel" @model}}
|
||||
/>
|
||||
</page.body>
|
||||
|
||||
</Rose::Layout::Page>
|
||||
@@ -0,0 +1,3 @@
|
||||
{{title @model.displayName}}
|
||||
|
||||
{{outlet}}
|
||||
@@ -0,0 +1,35 @@
|
||||
<Rose::Layout::Page as |page|>
|
||||
|
||||
<page.breadcrumbs>
|
||||
<BreadCrumbs />
|
||||
</page.breadcrumbs>
|
||||
|
||||
<page.header>
|
||||
<h2>{{t "resources.project"}}</h2>
|
||||
</page.header>
|
||||
|
||||
<page.navigation>
|
||||
<Rose::Nav::Tabs as |nav|>
|
||||
<nav.link @route='scopes.scope.projects.project'>
|
||||
{{t 'titles.details'}}
|
||||
</nav.link>
|
||||
</Rose::Nav::Tabs>
|
||||
</page.navigation>
|
||||
|
||||
<page.body>
|
||||
<Form::Project
|
||||
@model={{@model}}
|
||||
@submit={{route-action "save" @model}}
|
||||
@cancel={{route-action "cancel" @model}}
|
||||
/>
|
||||
<Rose::Separator />
|
||||
<Rose::Button
|
||||
@style="warning"
|
||||
@disabled={{@model.canSave}}
|
||||
{{on "click" (route-action "delete" @model)}}
|
||||
>
|
||||
{{t 'actions.delete'}}
|
||||
</Rose::Button>
|
||||
</page.body>
|
||||
|
||||
</Rose::Layout::Page>
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user