Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add more session states #4638

Merged
merged 3 commits into from
Jul 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
import classic from 'ember-classic-decorator';
import Component from '@ember/component';
import { stateColorMap } from 'open-event-frontend/utils/dictionary/sessions';
import { computed } from '@ember/object';

@classic
export default class CellButtons extends Component {}
export default class CellButtons extends Component {

@computed('extraRecords.status')
get states() {
return Object.keys(this.props.options.sessionStateMap.organizer[this.extraRecords.status])
.map(state => ({ name: state, color: stateColorMap[state] }));
}

@computed('extraRecords.status')
get color() {
return stateColorMap[this.extraRecords.status];
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import classic from 'ember-classic-decorator';
import Component from '@ember/component';
import { computed } from '@ember/object';
import { stateColorMap } from 'open-event-frontend/utils/dictionary/sessions';

@classic
export default class CellSessionState extends Component {}
export default class CellSessionState extends Component {

@computed('record')
get color() {
return stateColorMap[this.record] || 'yellow';
}

}
5 changes: 5 additions & 0 deletions app/controllers/events/view/sessions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Controller from '@ember/controller';
import { computed, action } from '@ember/object';
import { run } from '@ember/runloop';
import { SESSION_STATES } from 'open-event-frontend/utils/dictionary/sessions';

export default class extends Controller {

Expand All @@ -12,6 +13,10 @@ export default class extends Controller {
return currentRouteName !== 'events.view.sessions.create' && currentRouteName !== 'events.view.sessions.edit';
}

get sessionStates() {
return SESSION_STATES;
}

@action
export() {
this.set('isLoading', true);
Expand Down
101 changes: 15 additions & 86 deletions app/controllers/events/view/sessions/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,6 @@ export default class extends Controller.extend(EmberTableControllerMixin) {
addRating : this.addRating.bind(this)
}
},
{
name : 'Avg Rating',
valuePath : 'averageRating'
},
{
name : 'No. of ratings',
valuePath : 'feedbacks.length'
},
{
name : 'Track',
valuePath : 'track.name'
Expand Down Expand Up @@ -87,14 +79,15 @@ export default class extends Controller.extend(EmberTableControllerMixin) {
cellComponent : 'ui-table/cell/events/view/sessions/cell-is-mail-sent'
},
{
name : 'Actions',
name : 'Change State',
cellComponent : 'ui-table/cell/events/view/sessions/cell-buttons',
valuePath : 'id',
extraValuePaths : ['status'],
actions : {
acceptProposal : this.acceptProposal.bind(this),
confirmProposal : this.confirmProposal.bind(this),
rejectProposal : this.rejectProposal.bind(this)
options : {
sessionStateMap: this.model.sessionStateMap
},
actions: {
changeState: this.changeState.bind(this)
}
},
{
Expand Down Expand Up @@ -192,94 +185,30 @@ export default class extends Controller.extend(EmberTableControllerMixin) {
}

@action
acceptProposal(session_id, 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.'),
{
id: 'session_accep_email'
})
: this.notify.success(this.l10n.t('Session has been accepted'),
{
id: 'session_accep'
});
this.refreshModel.bind(this)();
})
.catch(() => {
this.notify.error(this.l10n.t('An unexpected error has occurred.'),
{
id: 'session_unex_error'
});
})
.finally(() => {
this.set('isLoading', false);
});
}

@action
confirmProposal(session_id, 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.'),
{
id: 'session_confirm_email'
})
: this.notify.success(this.l10n.t('Session has been confirmed'),
{
id: 'session_confirm'
});
this.refreshModel.bind(this)();
})
.catch(() => {
this.notify.error(this.l10n.t('An unexpected error has occurred.'),
{
id: 'session_confirm_unexpected'
});
})
.finally(() => {
this.set('isLoading', false);
});
}

@action
rejectProposal(session_id, sendEmail) {
let session = this.store.peekRecord('session', session_id, { backgroundReload: false });
changeState(session_id, state, sendEmail) {
const session = this.store.peekRecord('session', session_id, { backgroundReload: false });
session.setProperties({
sendEmail,
'state' : 'rejected',
'isMailSent' : sendEmail
state,
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.'),
sendEmail ? this.notify.success(this.l10n.t(`Session has been ${state} and speaker has been notified via email.`),
{
id: 'session_reject_email'
id: 'session_state_email'
})
: this.notify.success(this.l10n.t('Session has been rejected'),
: this.notify.success(this.l10n.t(`Session has been ${state}`),
{
id: 'session_rejected'
id: 'session_state'
});
this.refreshModel.bind(this)();
})
.catch(() => {
this.notify.error(this.l10n.t('An unexpected error has occurred.'),
{
id: 'session_reject_error'
id: 'session_state_unexpected'
});
})
.finally(() => {
Expand Down
7 changes: 7 additions & 0 deletions app/routes/admin/sessions.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import classic from 'ember-classic-decorator';
import Route from '@ember/routing/route';
import { SESSION_STATES } from 'open-event-frontend/utils/dictionary/sessions';

@classic
export default class SessionsRoute extends Route {
titleToken() {
return this.l10n.t('Sessions');
}

model() {
return {
sessionStates: SESSION_STATES
};
}
}
126 changes: 18 additions & 108 deletions app/routes/admin/sessions/list.js
Original file line number Diff line number Diff line change
@@ -1,110 +1,32 @@
import Route from '@ember/routing/route';
import EmberTableRouteMixin from 'open-event-frontend/mixins/ember-table-route';
import { capitalize } from 'lodash-es';
import { SESSION_STATES } from 'open-event-frontend/utils/dictionary/sessions';

export default class extends Route.extend(EmberTableRouteMixin) {
titleToken() {
switch (this.params.sessions_state) {
case 'confirmed':
return this.l10n.t('Confirmed');
case 'pending':
return this.l10n.t('Pending');
case 'accepted':
return this.l10n.t('Accepted');
case 'rejected':
return this.l10n.t('Rejected');
case 'deleted':
return this.l10n.t('Deleted');
default:
return this.l10n.t('Session');
if ([...SESSION_STATES, 'deleted'].includes(this.params.sessions_state)) {
return this.l10n.t(capitalize(this.params.sessions_state));
} else {
return this.l10n.t('Session');
}
}

async model(params) {
this.set('params', params);
const searchField = 'title';
let filterOptions = [];
if (params.sessions_state === 'pending') {
filterOptions = [
{
and:
[
{
name : 'event',
op : 'has',
val : {
name : 'deleted-at',
op : 'eq',
val : null
}
},
{
name : 'deleted-at',
op : 'eq',
val : null
},
{
name : 'state',
op : 'eq',
val : 'pending'
}
]
}
];
} else if (params.sessions_state === 'confirmed') {
filterOptions = [
{
and:
[
{
name : 'event',
op : 'has',
val : {
name : 'deleted-at',
op : 'eq',
val : null
}
},
{
name : 'deleted-at',
op : 'eq',
val : null
},
{
name : 'state',
op : 'eq',
val : 'confirmed'
}
]
}
];
} else if (params.sessions_state === 'accepted') {
filterOptions = [
{
and:
[
{
name : 'event',
op : 'has',
val : {
name : 'deleted-at',
op : 'eq',
val : null
}
},
{
name : 'deleted-at',
op : 'eq',
val : null
},
{
name : 'state',
op : 'eq',
val : 'accepted'
}
]
let filterOptions = [
{
name : 'event',
op : 'has',
val : {
name : 'deleted-at',
op : 'eq',
val : null
}
];
} else if (params.sessions_state === 'rejected') {
}
];
if (SESSION_STATES.includes(params.sessions_state)) {
filterOptions = [
{
and:
Expand All @@ -126,7 +48,7 @@ export default class extends Route.extend(EmberTableRouteMixin) {
{
name : 'state',
op : 'eq',
val : 'rejected'
val : params.sessions_state
}
]
}
Expand All @@ -153,18 +75,6 @@ export default class extends Route.extend(EmberTableRouteMixin) {
]
}
];
} else {
filterOptions = [
{
name : 'event',
op : 'has',
val : {
name : 'deleted-at',
op : 'eq',
val : null
}
}
];
}
filterOptions = this.applySearchFilters(filterOptions, params, searchField);
let queryString = {
Expand Down
Loading