Skip to content

Commit af6fe0d

Browse files
committed
minor enhancements
1 parent 4b6046e commit af6fe0d

File tree

12 files changed

+101
-12
lines changed

12 files changed

+101
-12
lines changed

app/pods/components/nav-bar/template.hbs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,20 @@
1010
</span>
1111

1212
<ul class="nav-list">
13+
14+
{{#if (eq currentUser.user.role 'ADMIN')}}
15+
{{#link-to 'questions'}}
16+
<li class="nav-items pointer">
17+
Questions
18+
</li>
19+
{{/link-to}}
1320

14-
{{#link-to 'questions'}}
15-
<li class="nav-items pointer">
16-
Questions
17-
</li>
18-
{{/link-to}}
19-
20-
{{#link-to 'quiz'}}
21-
<li class="nav-items pointer">
22-
Quiz
23-
</li>
24-
{{/link-to}}
21+
{{#link-to 'quiz'}}
22+
<li class="nav-items pointer">
23+
Quiz
24+
</li>
25+
{{/link-to}}
26+
{{/if}}
2527

2628
{{!--
2729
<a href="https://online.codingblocks.com/">

app/pods/err/route.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Route from '@ember/routing/route';
2+
3+
const errorMsg = {
4+
'ADMIN_ONLY': 'You must be an admin to view this page.'
5+
}
6+
7+
export default Route.extend({
8+
model (params) {
9+
return errorMsg[params.code]
10+
}
11+
});

app/pods/err/template.hbs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div class="info-text">
2+
{{model}}
3+
</div>

app/pods/index/controller.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Controller from '@ember/controller';
2+
import { inject as service } from '@ember/service'
3+
import { computed } from '@ember/object';
4+
5+
export default Controller.extend({
6+
currentUser: service(),
7+
user: computed.alias('currentUser.user')
8+
});

app/pods/index/route.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Route from '@ember/routing/route';
2+
3+
export default Route.extend({
4+
5+
});

app/pods/index/template.hbs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<div class="info-text">
2+
{{#if user.id}}
3+
Welcome {{user.firstname}}
4+
{{else}}
5+
Login to continue.
6+
{{/if}}
7+
</div>

app/router.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Router.map(function() {
1616
this.route('new');
1717
this.route('id', {path: '/:id'});
1818
});
19+
this.route('err', {path: '/:code'});
1920
});
2021

2122
export default Router;

app/services/current-user.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,19 @@ export default Service.extend({
55
user: null,
66
session: service(),
77
api: service(),
8+
router: service(),
89
load () {
10+
if (this.get('user.id')) {
11+
return this.get('user')
12+
}
913
if (this.get('session.isAuthenticated')) {
1014
return this.get('api').request('/users/me').then(data => {
11-
this.set('user', data);
15+
if (data.role == 'ADMIN') {
16+
this.set('user', data);
17+
} else {
18+
this.set('user', data)
19+
this.get('router').transitionTo('err', 'ADMIN_ONLY')
20+
}
1221
}).catch(err => {
1322
this.get('session').invalidate()
1423
})

app/styles/app.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,13 @@
5353

5454
.c-datepicker__header-date {
5555
height: 165px;
56+
}
57+
58+
.info-text {
59+
display: flex;
60+
font-weight: bold;
61+
font-size: 2rem;
62+
justify-content: center;
63+
align-items: center;
64+
padding: 4rem;
5665
}

tests/unit/pods/err/route-test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { module, test } from 'qunit';
2+
import { setupTest } from 'ember-qunit';
3+
4+
module('Unit | Route | err', function(hooks) {
5+
setupTest(hooks);
6+
7+
test('it exists', function(assert) {
8+
let route = this.owner.lookup('route:err');
9+
assert.ok(route);
10+
});
11+
});

0 commit comments

Comments
 (0)