Skip to content

Commit

Permalink
fix: view/edit/delete sometimes pass unexpected values in session table
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyanshdwivedi committed Aug 20, 2019
1 parent f1fcb70 commit 121a072
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 108 deletions.
244 changes: 139 additions & 105 deletions app/controllers/events/view/sessions/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class extends Controller.extend(EmberTableControllerMixin) {
{
name : 'Title',
valuePath : 'title',
extraValuePaths : ['event', 'isLocked'],
extraValuePaths : ['id', 'event', 'isLocked'],
isSortable : true,
headerComponent : 'tables/headers/sort',
cellComponent : 'ui-table/cell/events/view/sessions/cell-session-title',
Expand Down Expand Up @@ -114,15 +114,18 @@ export default class extends Controller.extend(EmberTableControllerMixin) {
@action
async deleteSession(session_id) {
this.set('isLoading', true);
try {
let session = this.store.peekRecord('session', session_id, { backgroundReload: false });
await session.destroyRecord();
this.notify.success(this.l10n.t('Session has been deleted successfully.'));
} catch (e) {
console.warn(e);
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
}
this.set('isLoading', false);
let session = this.store.peekRecord('session', session_id, { backgroundReload: false });
session.destroyRecord()
.then(() => {
this.notify.success(this.l10n.t('Session has been deleted successfully.'));
this.refreshModel.bind(this)();
})
.catch(() => {
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
})
.finally(() => {
this.set('isLoading', false);
});
}

@action
Expand All @@ -137,129 +140,160 @@ export default class extends Controller.extend(EmberTableControllerMixin) {

@action
async lockSession(session_id) {
try {
let session = this.store.peekRecord('session', session_id, { backgroundReload: false });
session.set('isLocked', true);
this.set('isLoading', true);
await session.save();
this.notify.success(this.l10n.t('Session has been locked successfully.'));
} catch (error) {
this.notify.error(this.l10n.t(error.message));
}
this.send('refreshRoute');
this.set('isLoading', false);
let session = this.store.peekRecord('session', session_id, { backgroundReload: false });
session.set('isLocked', true);
this.set('isLoading', true);
session.save()
.then(() => {
this.notify.success(this.l10n.t('Session has been locked successfully.'));
this.refreshModel.bind(this)();
})
.catch(() => {
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
})
.finally(() => {
this.set('isLoading', false);
});
}

@action
async unlockSession(session_id) {
try {
let session = this.store.peekRecord('session', session_id, { backgroundReload: false });
session.set('isLocked', false);
this.set('isLoading', true);
await session.save();
this.notify.success(this.l10n.t('Session has been unlocked successfully.'));
} catch (error) {
this.notify.error(this.l10n.t(error.message));
}
this.send('refreshRoute');
this.set('isLoading', false);
let session = this.store.peekRecord('session', session_id, { backgroundReload: false });
session.set('isLocked', false);
this.set('isLoading', true);
session.save()
.then(() => {
this.notify.success(this.l10n.t('Session has been unlocked successfully.'));
this.refreshModel.bind(this)();
})
.catch(() => {
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
})
.finally(() => {
this.set('isLoading', false);
});
}

@action
async acceptProposal(session_id, sendEmail) {
try {
let session = this.store.peekRecord('session', session_id, { backgroundReload: false });
session.setProperties({
sendEmail,
'state' : 'accepted',
'isMailSent' : sendEmail
let session = this.store.peekRecord('session', session_id, { backgroundReload: false });
session.setProperties({
sendEmail,
'state' : 'accepted',
'isMailSent' : sendEmail
});
this.set('isLoading', true);
session.save()
.then(() => {
sendEmail ? this.notify.success(this.l10n.t('Session has been accepted and speaker has been notified via email.'))
: this.notify.success(this.l10n.t('Session has been accepted'));
this.refreshModel.bind(this)();
})
.catch(() => {
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
})
.finally(() => {
this.set('isLoading', false);
});
this.set('isLoading', true);
await session.save();
sendEmail ? this.notify.success(this.l10n.t('Session has been accepted and speaker has been notified via email.'))
: this.notify.success(this.l10n.t('Session has been accepted'));
} catch (error) {
this.notify.error(this.l10n.t(error.message));
}
this.send('refreshRoute');
this.set('isLoading', false);
}

@action
async confirmProposal(session_id, sendEmail) {
try {
let session = this.store.peekRecord('session', session_id, { backgroundReload: false });
session.setProperties({
sendEmail,
'state' : 'confirmed',
'isMailSent' : sendEmail
let session = this.store.peekRecord('session', session_id, { backgroundReload: false });
session.setProperties({
sendEmail,
'state' : 'confirmed',
'isMailSent' : sendEmail
});
this.set('isLoading', true);
session.save()
.then(() => {
sendEmail ? this.notify.success(this.l10n.t('Session has been confirmed and speaker has been notified via email.'))
: this.notify.success(this.l10n.t('Session has been confirmed'));
this.refreshModel.bind(this)();
})
.catch(() => {
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
})
.finally(() => {
this.set('isLoading', false);
});
this.set('isLoading', true);
await session.save();
sendEmail ? this.notify.success(this.l10n.t('Session has been confirmed and speaker has been notified via email.'))
: this.notify.success(this.l10n.t('Session has been confirmed'));
} catch (error) {
this.notify.error(this.l10n.t(error.message));
}
this.send('refreshRoute');
this.set('isLoading', false);
}

@action
async rejectProposal(session_id, sendEmail) {
try {
let session = this.store.peekRecord('session', session_id, { backgroundReload: false });
session.setProperties({
sendEmail,
'state' : 'rejected',
'isMailSent' : sendEmail
let session = this.store.peekRecord('session', session_id, { backgroundReload: false });
session.setProperties({
sendEmail,
'state' : 'rejected',
'isMailSent' : sendEmail
});
this.set('isLoading', true);
session.save()
.then(() => {
sendEmail ? this.notify.success(this.l10n.t('Session has been rejected and speaker has been notified via email.'))
: this.notify.success(this.l10n.t('Session has been rejected'));
this.refreshModel.bind(this)();
})
.catch(() => {
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
})
.finally(() => {
this.set('isLoading', false);
});
this.set('isLoading', true);
await session.save();
sendEmail ? this.notify.success(this.l10n.t('Session has been rejected and speaker has been notified via email.'))
: this.notify.success(this.l10n.t('Session has been rejected'));
} catch (error) {
this.notify.error(this.l10n.t(error.message));
}
this.send('refreshRoute');
this.set('isLoading', false);
}

@action
async updateRating(rating, feedback) {
try {
this.set('isLoading', true);
if (rating) {
feedback.set('rating', rating);
await feedback.save();
} else {
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.set('isLoading', true);
if (rating) {
feedback.set('rating', rating);
feedback.save()
.then(() => {
this.notify.success(this.l10n.t('Session feedback has been updated successfully.'));
this.refreshModel.bind(this)();
})
.catch(() => {
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
})
.finally(() => {
this.set('isLoading', false);
});
} else {
feedback.destroyRecord()
.then(() => {
this.notify.success(this.l10n.t('Session feedback has been updated successfully.'));
this.refreshModel.bind(this)();
})
.catch(() => {
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
})
.finally(() => {
this.set('isLoading', false);
});
}
this.send('refreshRoute');
this.set('isLoading', false);
}

@action
async addRating(rating, session_id) {
try {
let session = this.store.peekRecord('session', session_id, { backgroundReload: false });
this.set('isLoading', true);
let feedback = await this.store.createRecord('feedback', {
rating,
session,
comment : '',
user : this.authManager.currentUser
let session = this.store.peekRecord('session', session_id, { backgroundReload: false });
this.set('isLoading', true);
let feedback = await this.store.createRecord('feedback', {
rating,
session,
comment : '',
user : this.authManager.currentUser
});
feedback.save()
.then(() => {
this.notify.success(this.l10n.t('Session feedback has been created successfully.'));
this.refreshModel.bind(this)();
})
.catch(() => {
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
})
.finally(() => {
this.set('isLoading', false);
});
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));
}
this.send('refreshRoute');
this.set('isLoading', false);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{{record}}
<div class="hidden ui divider"></div>
<div class="ui horizontal compact basic buttons">
{{#ui-popup content=(t 'View Session') class="{{if device.isMobile 'medium' 'huge'}} ui icon button" click=(action props.actions.viewSession record) position='left center'}}
{{#ui-popup content=(t 'View Session') class="{{if device.isMobile 'medium' 'huge'}} ui icon button" click=(action props.actions.viewSession extraRecords.id) position='left center'}}
<i class="unhide icon"></i>
{{/ui-popup}}
{{#if (not extraRecords.isLocked)}}
{{#ui-popup content=(t 'Edit Session') class="{{if device.isMobile 'medium' 'huge'}} ui icon button" click=(action props.actions.editSession record extraRecords.event.id) position='left center'}}
{{#ui-popup content=(t 'Edit Session') class="{{if device.isMobile 'medium' 'huge'}} ui icon button" click=(action props.actions.editSession extraRecords.id extraRecords.event.id) position='left center'}}
<i class="edit icon"></i>
{{/ui-popup}}
{{/if}}
{{#ui-popup content=(t 'Delete Session') click=(action (confirm (t 'Are you sure you would like to delete this Session?') (action props.actions.deleteSession record))) class="{{if device.isMobile 'medium' 'huge'}} ui icon button" position='left center'}}
{{#ui-popup content=(t 'Delete Session') click=(action (confirm (t 'Are you sure you would like to delete this Session?') (action props.actions.deleteSession extraRecords.id))) class="{{if device.isMobile 'medium' 'huge'}} ui icon button" position='left center'}}
<i class="trash outline icon"></i>
{{/ui-popup}}
</div>

0 comments on commit 121a072

Please sign in to comment.