Skip to content

Commit

Permalink
Playing with models
Browse files Browse the repository at this point in the history
  • Loading branch information
nadnoslen committed Oct 29, 2018
1 parent 224390a commit 1f6eb55
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 19 deletions.
4 changes: 2 additions & 2 deletions app/adapters/application.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import DS from 'ember-data';
import EmberSimpleAuthTokenHeaders from 'ember-simple-auth-token/addon/mixins/token-authorizer';
import EmberSimpleAuthTokenHeaders from 'ember-simple-auth-token/mixins/token-authorizer';

export default DS.JSONAPIAdapter.extend(EmberSimpleAuthTokenHeaders, {
namespace: 'api/v1'
namespace: 'api/v1/protected'
});
8 changes: 8 additions & 0 deletions app/models/role.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import BaseModel from './-base';
import DS from 'ember-data';

export default BaseModel.extend({
key: DS.attr('string'),
name: DS.attr('string'),
notes: DS.attr('string')
});
2 changes: 2 additions & 0 deletions app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Router.map(function () {
this.route('login');
this.route('protected', function () {
this.route('configuration', function () {
this.route('roles', function () {
});
});
});
});
Expand Down
3 changes: 3 additions & 0 deletions app/routes/protected/configuration/roles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Route from '@ember/routing/route';

export default Route.extend({});
10 changes: 10 additions & 0 deletions app/routes/protected/configuration/roles/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {hash} from 'rsvp';
import Route from '@ember/routing/route';

export default Route.extend({
model() {
return hash({
roles: this.get('store').query('role', {sort: 'name'})
});
}
});
2 changes: 1 addition & 1 deletion app/templates/application.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{{#if session.isAuthenticated}}
<button
{{action "logout" session on="click"}}
class="btn btn-outline-secondary btn-sm" type="button">
class="btn btn-outline-primary btn-sm" type="button">
Logout
</button>

Expand Down
22 changes: 16 additions & 6 deletions app/templates/protected/configuration/index.hbs
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
<section class="my-3">
<div class="container">
<h1>Configuration</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consequatur dignissimos, et fuga magnam provident
quibusdam sequi velit veniam? Dolore eveniet excepturi expedita officia placeat. Accusamus deserunt esse iusto
nulla quaerat?
</p>

<div class="d-flex my-3">
<h1 class="flex-fill">Configuration</h1>
<div class="align-self-center">
{{#link-to "protected.index" class="btn btn-outline-secondary"}}Home{{/link-to}}
</div>
</div>

<div class="list-group">
{{#link-to "protected.configuration.roles.index" class="list-group-item list-group-item-action"}}
<h5 class="mb-0">
Roles
</h5>
{{/link-to}}
</div>

</div>
</section>
1 change: 1 addition & 0 deletions app/templates/protected/configuration/roles.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{outlet}}
27 changes: 27 additions & 0 deletions app/templates/protected/configuration/roles/index.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<section class="my-3">
<div class="container">

<div class="d-flex my-3">
<h1 class="flex-fill">Roles</h1>
<div class="align-self-center">
{{#link-to "protected.configuration.index" class="btn btn-outline-secondary"}}
Configuration
{{/link-to}}
</div>
</div>

<div class="list-group">
{{#each model.roles as |role|}}
<div class="list-group-item">
<h5 class="mb-0">
{{role.name}}
{{#if role.notes}}
<small class="text-muted">{{role.notes}}</small>
{{/if}}
</h5>
</div>
{{/each}}
</div>

</div>
</section>
33 changes: 23 additions & 10 deletions app/templates/protected/index.hbs
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
<section class="my-3">
<div class="container">
<h1>Welcome To The <span class="text-success">Protected</span> Index Page</h1>
<p>
You can only get to the <code>/protected/*</code> paths if you have logged in.
</p>
<p>
{{#link-to "protected.configuration.index"}}Configuration Page{{/link-to}}
</p>
<p>
{{#link-to "index"}}Public Page{{/link-to}}
</p>

<div class="d-flex my-3">
<h1 class="flex-fill"><span class="text-success">Protected</span> Path</h1>
<div class="align-self-center">
<div class="btn-group">
{{#link-to "protected.configuration.index" class="btn btn-outline-secondary"}}Configuration{{/link-to}}
</div>
</div>
</div>

<div>
<p>
Welcome to the protected index page that you can only get to once you have logged in. Check
your address bar, everything under <code>/protected/*</code> requires authentication.
</p>
<p>
{{#link-to "protected.configuration.index"}}Configuration Page{{/link-to}}
</p>
<p>
{{#link-to "index"}}Public Page{{/link-to}}
</p>
</div>

</div>
</section>
13 changes: 13 additions & 0 deletions tests/unit/models/role-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {module, test} from 'qunit';
import {setupTest} from 'ember-qunit';

module('Unit | Model | role', function (hooks) {
setupTest(hooks);

// Replace this with your real tests.
test('it exists', function (assert) {
let store = this.owner.lookup('service:store');
let model = store.createRecord('role', {});
assert.ok(model);
});
});
11 changes: 11 additions & 0 deletions tests/unit/routes/protected/configuration/roles-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {module, test} from 'qunit';
import {setupTest} from 'ember-qunit';

module('Unit | Route | protected/configuration/roles', function (hooks) {
setupTest(hooks);

test('it exists', function (assert) {
let route = this.owner.lookup('route:protected/configuration/roles');
assert.ok(route);
});
});
11 changes: 11 additions & 0 deletions tests/unit/routes/protected/configuration/roles/index-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {module, test} from 'qunit';
import {setupTest} from 'ember-qunit';

module('Unit | Route | protected/configuration/roles/index', function (hooks) {
setupTest(hooks);

test('it exists', function (assert) {
let route = this.owner.lookup('route:protected/configuration/roles/index');
assert.ok(route);
});
});

0 comments on commit 1f6eb55

Please sign in to comment.