Skip to content

Commit

Permalink
user profile page #28
Browse files Browse the repository at this point in the history
  • Loading branch information
ashokaditya committed May 31, 2018
1 parent b07465b commit 05bedf4
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 21 deletions.
11 changes: 11 additions & 0 deletions app/helpers/calc-ips.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Ember from 'ember'
import cidr from 'npm:cidr-range'
import { formatPrefix } from 'd3'

export function calcIps (params/*, hash */) {
let f = formatPrefix(',.1', 1e3)
let l = cidr(params[0]).length
return l > 999 ? f(l) : l
}

export default Ember.Helper.helper(calcIps)
1 change: 1 addition & 0 deletions app/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default DS.Model.extend({
lastpasswordchange: DS.attr('date', {readonly: true}),
valid: DS.attr('string'),
usrnets: DS.attr(),
networks: DS.hasMany('network'),

firstname: Ember.computed('name', function () {
let fn = this.get('name').split(' ')[0]
Expand Down
7 changes: 1 addition & 6 deletions app/routes/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {

model () {
return Ember.RSVP.hash({
user: this.store.findRecord('user', this.get('session.data.authenticated.uid')),
customers: this.store.findAll('customer'),
networks: this.store.findAll('network')
user: this.store.findRecord('user', this.get('session.data.authenticated.uid'), {include: 'networks'})
})
},

Expand All @@ -18,10 +16,7 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {

setupController (controller, model) {
this._super(...arguments)

Ember.set(controller, 'profile', model.user)
Ember.set(controller, 'customers', model.customers)
Ember.set(controller, 'networks', model.networks)
}

})
13 changes: 6 additions & 7 deletions app/templates/components/user-profile.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<div class="raised profile card usr-{{u.username}}" >
<div class="image">
{{!-- {{ember-initials name=u.name size=600}} --}}
<div class="avatar">{{user-initials u.name}}</div>
</div>
<div class="content">
Expand Down Expand Up @@ -28,22 +27,22 @@
</div>
<div class="content">
<div class="ui sub header">Assigned Networks</div>
<div class="ui relaxed divided list">
{{#each networks as |net|}}
{{#if (eq (is-user-network u.usrnets net.id) true)}}
<div class="ui relaxed list">
{{#each u.networks as |net|}}
<div class="item">
<i class="fork icon"></i>
<div class="content">
<div class="header">{{net.net}}</div>
<div class="header">
{{net.net}} ({{calc-ips net.net}})
</div>
<div class="meta">{{net.name}}</div>
</div>
</div>
{{/if}}
{{/each}}
</div>
</div>
<div class="content">
<i class="sign in icon"></i>
<span class="description">Last seen {{moment-from-now (moment-format u.lastlogin) hidePrefix=true interval=86400}}</span>
<span class="description">Logged in {{moment-from-now (moment-format u.lastlogin) hidePrefix=true interval=86400}}</span>
</div>
</div>
14 changes: 14 additions & 0 deletions tests/integration/helpers/calc-ips-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

import { moduleForComponent, test } from 'ember-qunit'
import hbs from 'htmlbars-inline-precompile'

moduleForComponent('calc-ips', 'helper:calc-ips', {
integration: true
})

// Replace this with your real tests.
test('it renders', function (assert) {
this.set('cidr', '10.33.6.0/24')
this.render(hbs`{{calc-ips cidr}}`)
assert.equal(this.$().text().trim(), '256')
})
14 changes: 7 additions & 7 deletions tests/unit/models/user-test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { moduleForModel, test } from 'ember-qunit';
import { moduleForModel, test } from 'ember-qunit'

moduleForModel('user', 'Unit | Model | user', {
// Specify the other units that are required for this test.
needs: []
});
needs: ['model:network']
})

test('it exists', function(assert) {
let model = this.subject();
test('it exists', function (assert) {
let model = this.subject()
// let store = this.store();
assert.ok(!!model);
});
assert.ok(!!model)
})
2 changes: 1 addition & 1 deletion tests/unit/serializers/user-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { moduleForModel, test } from 'ember-qunit'

moduleForModel('user', 'Unit | Serializer | user', {
// Specify the other units that are required for this test.
needs: ['serializer:user']
needs: ['serializer:user', 'model:network']
})

// Replace this with your real tests.
Expand Down

0 comments on commit 05bedf4

Please sign in to comment.