Skip to content

Commit cce8de9

Browse files
committed
add user-tag-graph to profile
1 parent 8d5a660 commit cce8de9

File tree

5 files changed

+84
-0
lines changed

5 files changed

+84
-0
lines changed

app/models/user-tag.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Ember from 'ember';
2+
import DS from 'ember-data';
3+
const { Model } = DS;
4+
5+
export default Model.extend({
6+
tag: DS.attr(),
7+
rating: DS.attr()
8+
});
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import Component from '@ember/component';
2+
import { inject as service } from '@ember/service';
3+
import { computed } from '@ember/object';
4+
import { task } from 'ember-concurrency-decorators';
5+
import { alias } from '@ember/object/computed';
6+
7+
export default class UserTagComponent extends Component {
8+
@service store
9+
10+
@alias('fetchUserTagsTask.lastSuccessful.value') userTags
11+
12+
13+
get chartData() {
14+
const userTags = this.get('userTags')
15+
if(userTags) {
16+
return userTags.map(ut => {
17+
return {
18+
x: ut.get('tag.name'),
19+
y: Math.round(ut.get('rating'))
20+
}
21+
})
22+
} else {
23+
return []
24+
}
25+
}
26+
27+
didReceiveAttrs() {
28+
this.fetchUserTagsTask.perform()
29+
}
30+
31+
@task fetchUserTagsTask = function* () {
32+
return yield this.store.query('user-tag', {
33+
filter: {
34+
user_id: this.userId
35+
},
36+
page: {
37+
limit: 200
38+
}
39+
})
40+
}
41+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<div class="border-card">
2+
<h4 class="t-align-c mb-4">Topic-Vise Performance</h4>
3+
4+
{{#if chartData}}
5+
<BarChart @data={{chartData}} />
6+
{{/if}}
7+
</div>

app/pods/users/id/template.hbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
@setOffset={{action 'setOffset'}}>
1313
</SubmissionsHeatMapView>
1414

15+
<UserTagGraph class="mb-5" @userId="{{user.id}}" />
16+
1517
<ProfileBadges
1618
@userId={{user.id}} />
1719

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { module, test } from 'qunit';
2+
import { setupRenderingTest } from 'ember-qunit';
3+
import { render } from '@ember/test-helpers';
4+
import hbs from 'htmlbars-inline-precompile';
5+
6+
module('Integration | Component | user-tag-graph', function(hooks) {
7+
setupRenderingTest(hooks);
8+
9+
test('it renders', async function(assert) {
10+
// Set any properties with this.set('myProperty', 'value');
11+
// Handle any actions with this.set('myAction', function(val) { ... });
12+
13+
await render(hbs`<UserTagGraph />`);
14+
15+
assert.equal(this.element.textContent.trim(), '');
16+
17+
// Template block usage:
18+
await render(hbs`
19+
<UserTagGraph>
20+
template block text
21+
</UserTagGraph>
22+
`);
23+
24+
assert.equal(this.element.textContent.trim(), 'template block text');
25+
});
26+
});

0 commit comments

Comments
 (0)