Skip to content

Commit

Permalink
feat: introduce new columns for session ratings
Browse files Browse the repository at this point in the history
add ratedSessions to controllers

update ratedSessions and remove extra vars
  • Loading branch information
shreyanshdwivedi committed Jul 7, 2019
1 parent 93f9157 commit 7765d38
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 26 deletions.
58 changes: 36 additions & 22 deletions app/controllers/events/view/sessions/list.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import Controller from '@ember/controller';
import { mapBy } from '@ember/object/computed';

export default Controller.extend({
ratedSessions: mapBy('model.feedbacks', 'session.id'),

columns: [
{
propertyName : 'state',
Expand All @@ -21,11 +24,20 @@ export default Controller.extend({
disableSorting : true
},
{
propertyName : 'average_rating',
template : 'components/ui-table/cell/events/view/sessions/cell-rating',
title : 'Rating',
disableSorting : false
},
{
propertyName : 'averageRating',
title : 'Avg Rating',
disableSorting : false
},
{
propertyName : 'feedbacks.length',
title : 'No. of ratings',
disableSorting : false
},
{
propertyName : 'track.name',
title : 'Track'
Expand Down Expand Up @@ -169,31 +181,33 @@ export default Controller.extend({
this.set('isLoading', false);
});
},
async updateRating(session, rating) {
async updateRating(rating, feedback) {
try {
if (session.feedbacks.length) {
this.set('isLoading', true);
const user = this.authManager.currentUser;
let feedback = session.feedbacks.firstObject;
feedback.setProperties({
user,
rating
});
this.set('isLoading', true);
if (rating) {
feedback.set('rating', rating);
await feedback.save();
this.notify.success(this.l10n.t('Session feedback has been updated successfully.'));
} else {
this.set('isLoading', true);
const user = this.authManager.currentUser;
const comment = '';
let feedback = await this.store.createRecord('feedback', {
rating,
comment,
session,
user
});
await feedback.save();
this.notify.success(this.l10n.t('Session feedback has been created successfully.'));
await feedback.destroyRecord();
}
this.notify.success(this.l10n.t('Session feedback has been updated successfully.'));
} catch (error) {
this.notify.error(this.l10n.t(error.message));
}
this.send('refreshRoute');
this.set('isLoading', false);
},
async addRating(rating, session) {
try {
this.set('isLoading', true);
let feedback = await this.store.createRecord('feedback', {
rating,
session,
comment : '',
user : this.authManager.currentUser
});
await feedback.save();
this.notify.success(this.l10n.t('Session feedback has been created successfully.'));
} catch (error) {
this.notify.error(this.l10n.t(error.message));
}
Expand Down
1 change: 1 addition & 0 deletions app/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default ModelBase.extend({
orders : hasMany('order'),
events : hasMany('event', { inverse: 'user' }),
sessions : hasMany('session'),
feedbacks : hasMany('feedback'),
invoice : hasMany('event-invoice'),
attendees : hasMany('attendee'),
speakers : hasMany('speaker'),
Expand Down
22 changes: 21 additions & 1 deletion app/routes/events/view/sessions/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,32 @@ export default Route.extend({
'page[size]' : 10
};

let store = this.modelFor('events.view');

let store = this.modelFor('events.view');
let data = await store.query('sessions', queryObject);

let feedbacks = await this.authManager.currentUser.query('feedbacks', {
include : 'session',
filter : [
{
name : 'session',
op : 'has',
val : {
name : 'event',
op : 'has',
val : {
name : 'identifier',
op : 'eq',
val : store.id
}
}
}
]
});

return {
data,
feedbacks,
store,
query : queryObject,
objectType : 'sessions'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
{{ui-rating
rating=(if record.averageRating record.averageRating '0')
{{#if (includes ratedSessions record.id)}}
{{#each record.feedbacks as |feedback|}}
{{#if (eq feedback.user.email authManager.currentUser.email)}}
{{ui-rating
initialRating=feedback.rating
rating=feedback.rating
maxRating=5
onRate=(pipe-action (action (mut feedback.rating)) (action updateRating feedback.rating feedback))
clearable=true}}
{{/if}}
{{/each}}
{{else}}
{{ui-rating
initialRating=0
rating=record.rating
maxRating=5
onRate=(pipe-action (action (mut record.averageRating)) (action updateRating record record.averageRating))
onRate=(pipe-action (action (mut record.rating)) (action addRating record.rating record))
clearable=true}}
{{/if}}
2 changes: 2 additions & 0 deletions app/templates/events/view/sessions/list.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<div class="sixteen wide column">
{{events/events-table
columns=columns
ratedSessions=ratedSessions
data=model.data
store=model.store
query=model.query
Expand All @@ -18,6 +19,7 @@
rejectProposal=(action 'rejectProposal')
confirmProposal=(action 'confirmProposal')
updateRating=(action 'updateRating')
addRating=(action 'addRating')
customGlobalFilter='title'
}}
</div>

0 comments on commit 7765d38

Please sign in to comment.