Skip to content

Commit e568a3b

Browse files
shreyanshdwivedikushthedude
authored andcommitted
fix: view/edit/delete sometimes pass unexpected values in session table (#3448)
1 parent f1fcb70 commit e568a3b

File tree

2 files changed

+149
-115
lines changed

2 files changed

+149
-115
lines changed

app/controllers/events/view/sessions/list.js

Lines changed: 146 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default class extends Controller.extend(EmberTableControllerMixin) {
1919
{
2020
name : 'Title',
2121
valuePath : 'title',
22-
extraValuePaths : ['event', 'isLocked'],
22+
extraValuePaths : ['id', 'event', 'isLocked'],
2323
isSortable : true,
2424
headerComponent : 'tables/headers/sort',
2525
cellComponent : 'ui-table/cell/events/view/sessions/cell-session-title',
@@ -114,15 +114,18 @@ export default class extends Controller.extend(EmberTableControllerMixin) {
114114
@action
115115
async deleteSession(session_id) {
116116
this.set('isLoading', true);
117-
try {
118-
let session = this.store.peekRecord('session', session_id, { backgroundReload: false });
119-
await session.destroyRecord();
120-
this.notify.success(this.l10n.t('Session has been deleted successfully.'));
121-
} catch (e) {
122-
console.warn(e);
123-
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
124-
}
125-
this.set('isLoading', false);
117+
let session = this.store.peekRecord('session', session_id, { backgroundReload: false });
118+
session.destroyRecord()
119+
.then(() => {
120+
this.notify.success(this.l10n.t('Session has been deleted successfully.'));
121+
this.refreshModel.bind(this)();
122+
})
123+
.catch(() => {
124+
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
125+
})
126+
.finally(() => {
127+
this.set('isLoading', false);
128+
});
126129
}
127130

128131
@action
@@ -136,130 +139,161 @@ export default class extends Controller.extend(EmberTableControllerMixin) {
136139
}
137140

138141
@action
139-
async lockSession(session_id) {
140-
try {
141-
let session = this.store.peekRecord('session', session_id, { backgroundReload: false });
142-
session.set('isLocked', true);
143-
this.set('isLoading', true);
144-
await session.save();
145-
this.notify.success(this.l10n.t('Session has been locked successfully.'));
146-
} catch (error) {
147-
this.notify.error(this.l10n.t(error.message));
148-
}
149-
this.send('refreshRoute');
150-
this.set('isLoading', false);
142+
lockSession(session_id) {
143+
let session = this.store.peekRecord('session', session_id, { backgroundReload: false });
144+
session.set('isLocked', true);
145+
this.set('isLoading', true);
146+
session.save()
147+
.then(() => {
148+
this.notify.success(this.l10n.t('Session has been locked successfully.'));
149+
this.refreshModel.bind(this)();
150+
})
151+
.catch(() => {
152+
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
153+
})
154+
.finally(() => {
155+
this.set('isLoading', false);
156+
});
151157
}
152158

153159
@action
154-
async unlockSession(session_id) {
155-
try {
156-
let session = this.store.peekRecord('session', session_id, { backgroundReload: false });
157-
session.set('isLocked', false);
158-
this.set('isLoading', true);
159-
await session.save();
160-
this.notify.success(this.l10n.t('Session has been unlocked successfully.'));
161-
} catch (error) {
162-
this.notify.error(this.l10n.t(error.message));
163-
}
164-
this.send('refreshRoute');
165-
this.set('isLoading', false);
160+
unlockSession(session_id) {
161+
let session = this.store.peekRecord('session', session_id, { backgroundReload: false });
162+
session.set('isLocked', false);
163+
this.set('isLoading', true);
164+
session.save()
165+
.then(() => {
166+
this.notify.success(this.l10n.t('Session has been unlocked successfully.'));
167+
this.refreshModel.bind(this)();
168+
})
169+
.catch(() => {
170+
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
171+
})
172+
.finally(() => {
173+
this.set('isLoading', false);
174+
});
166175
}
167176

168177
@action
169-
async acceptProposal(session_id, sendEmail) {
170-
try {
171-
let session = this.store.peekRecord('session', session_id, { backgroundReload: false });
172-
session.setProperties({
173-
sendEmail,
174-
'state' : 'accepted',
175-
'isMailSent' : sendEmail
178+
acceptProposal(session_id, sendEmail) {
179+
let session = this.store.peekRecord('session', session_id, { backgroundReload: false });
180+
session.setProperties({
181+
sendEmail,
182+
'state' : 'accepted',
183+
'isMailSent' : sendEmail
184+
});
185+
this.set('isLoading', true);
186+
session.save()
187+
.then(() => {
188+
sendEmail ? this.notify.success(this.l10n.t('Session has been accepted and speaker has been notified via email.'))
189+
: this.notify.success(this.l10n.t('Session has been accepted'));
190+
this.refreshModel.bind(this)();
191+
})
192+
.catch(() => {
193+
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
194+
})
195+
.finally(() => {
196+
this.set('isLoading', false);
176197
});
177-
this.set('isLoading', true);
178-
await session.save();
179-
sendEmail ? this.notify.success(this.l10n.t('Session has been accepted and speaker has been notified via email.'))
180-
: this.notify.success(this.l10n.t('Session has been accepted'));
181-
} catch (error) {
182-
this.notify.error(this.l10n.t(error.message));
183-
}
184-
this.send('refreshRoute');
185-
this.set('isLoading', false);
186198
}
187199

188200
@action
189-
async confirmProposal(session_id, sendEmail) {
190-
try {
191-
let session = this.store.peekRecord('session', session_id, { backgroundReload: false });
192-
session.setProperties({
193-
sendEmail,
194-
'state' : 'confirmed',
195-
'isMailSent' : sendEmail
201+
confirmProposal(session_id, sendEmail) {
202+
let session = this.store.peekRecord('session', session_id, { backgroundReload: false });
203+
session.setProperties({
204+
sendEmail,
205+
'state' : 'confirmed',
206+
'isMailSent' : sendEmail
207+
});
208+
this.set('isLoading', true);
209+
session.save()
210+
.then(() => {
211+
sendEmail ? this.notify.success(this.l10n.t('Session has been confirmed and speaker has been notified via email.'))
212+
: this.notify.success(this.l10n.t('Session has been confirmed'));
213+
this.refreshModel.bind(this)();
214+
})
215+
.catch(() => {
216+
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
217+
})
218+
.finally(() => {
219+
this.set('isLoading', false);
196220
});
197-
this.set('isLoading', true);
198-
await session.save();
199-
sendEmail ? this.notify.success(this.l10n.t('Session has been confirmed and speaker has been notified via email.'))
200-
: this.notify.success(this.l10n.t('Session has been confirmed'));
201-
} catch (error) {
202-
this.notify.error(this.l10n.t(error.message));
203-
}
204-
this.send('refreshRoute');
205-
this.set('isLoading', false);
206221
}
207222

208223
@action
209-
async rejectProposal(session_id, sendEmail) {
210-
try {
211-
let session = this.store.peekRecord('session', session_id, { backgroundReload: false });
212-
session.setProperties({
213-
sendEmail,
214-
'state' : 'rejected',
215-
'isMailSent' : sendEmail
224+
rejectProposal(session_id, sendEmail) {
225+
let session = this.store.peekRecord('session', session_id, { backgroundReload: false });
226+
session.setProperties({
227+
sendEmail,
228+
'state' : 'rejected',
229+
'isMailSent' : sendEmail
230+
});
231+
this.set('isLoading', true);
232+
session.save()
233+
.then(() => {
234+
sendEmail ? this.notify.success(this.l10n.t('Session has been rejected and speaker has been notified via email.'))
235+
: this.notify.success(this.l10n.t('Session has been rejected'));
236+
this.refreshModel.bind(this)();
237+
})
238+
.catch(() => {
239+
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
240+
})
241+
.finally(() => {
242+
this.set('isLoading', false);
216243
});
217-
this.set('isLoading', true);
218-
await session.save();
219-
sendEmail ? this.notify.success(this.l10n.t('Session has been rejected and speaker has been notified via email.'))
220-
: this.notify.success(this.l10n.t('Session has been rejected'));
221-
} catch (error) {
222-
this.notify.error(this.l10n.t(error.message));
223-
}
224-
this.send('refreshRoute');
225-
this.set('isLoading', false);
226244
}
227245

228246
@action
229-
async updateRating(rating, feedback) {
230-
try {
231-
this.set('isLoading', true);
232-
if (rating) {
233-
feedback.set('rating', rating);
234-
await feedback.save();
235-
} else {
236-
await feedback.destroyRecord();
237-
}
238-
this.notify.success(this.l10n.t('Session feedback has been updated successfully.'));
239-
} catch (error) {
240-
this.notify.error(this.l10n.t(error.message));
247+
updateRating(rating, feedback) {
248+
this.set('isLoading', true);
249+
if (rating) {
250+
feedback.set('rating', rating);
251+
feedback.save()
252+
.then(() => {
253+
this.notify.success(this.l10n.t('Session feedback has been updated successfully.'));
254+
this.refreshModel.bind(this)();
255+
})
256+
.catch(() => {
257+
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
258+
})
259+
.finally(() => {
260+
this.set('isLoading', false);
261+
});
262+
} else {
263+
feedback.destroyRecord()
264+
.then(() => {
265+
this.notify.success(this.l10n.t('Session feedback has been updated successfully.'));
266+
this.refreshModel.bind(this)();
267+
})
268+
.catch(() => {
269+
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
270+
})
271+
.finally(() => {
272+
this.set('isLoading', false);
273+
});
241274
}
242-
this.send('refreshRoute');
243-
this.set('isLoading', false);
244275
}
245276

246277
@action
247-
async addRating(rating, session_id) {
248-
try {
249-
let session = this.store.peekRecord('session', session_id, { backgroundReload: false });
250-
this.set('isLoading', true);
251-
let feedback = await this.store.createRecord('feedback', {
252-
rating,
253-
session,
254-
comment : '',
255-
user : this.authManager.currentUser
278+
addRating(rating, session_id) {
279+
let session = this.store.peekRecord('session', session_id, { backgroundReload: false });
280+
this.set('isLoading', true);
281+
let feedback = this.store.createRecord('feedback', {
282+
rating,
283+
session,
284+
comment : '',
285+
user : this.authManager.currentUser
286+
});
287+
feedback.save()
288+
.then(() => {
289+
this.notify.success(this.l10n.t('Session feedback has been created successfully.'));
290+
this.refreshModel.bind(this)();
291+
})
292+
.catch(() => {
293+
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
294+
})
295+
.finally(() => {
296+
this.set('isLoading', false);
256297
});
257-
await feedback.save();
258-
this.notify.success(this.l10n.t('Session feedback has been created successfully.'));
259-
} catch (error) {
260-
this.notify.error(this.l10n.t(error.message));
261-
}
262-
this.send('refreshRoute');
263-
this.set('isLoading', false);
264298
}
265299
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{{record}}
22
<div class="hidden ui divider"></div>
33
<div class="ui horizontal compact basic buttons">
4-
{{#ui-popup content=(t 'View Session') class="{{if device.isMobile 'medium' 'huge'}} ui icon button" click=(action props.actions.viewSession record) position='left center'}}
4+
{{#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'}}
55
<i class="unhide icon"></i>
66
{{/ui-popup}}
77
{{#if (not extraRecords.isLocked)}}
8-
{{#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'}}
8+
{{#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'}}
99
<i class="edit icon"></i>
1010
{{/ui-popup}}
1111
{{/if}}
12-
{{#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'}}
12+
{{#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'}}
1313
<i class="trash outline icon"></i>
1414
{{/ui-popup}}
1515
</div>

0 commit comments

Comments
 (0)