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

chore: Migrating event,speakers,session in controllers to ES6 #3721

Merged
merged 4 commits into from
Dec 25, 2019
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
33 changes: 17 additions & 16 deletions app/controllers/create.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import Controller from '@ember/controller';
import EventWizardMixin from 'open-event-frontend/mixins/event-wizard';
import { action } from '@ember/object';

export default Controller.extend(EventWizardMixin, {

actions: {
save() {
this.saveEventDataAndRedirectTo(
'events.view.index',
['tickets', 'socialLinks', 'copyright', 'tax', 'stripeAuthorization']
);
},
move() {
this.saveEventDataAndRedirectTo(
'events.view.edit.attendee',
['tickets', 'socialLinks', 'copyright', 'tax', 'stripeAuthorization']
);
}
export default class extends Controller.extend(EventWizardMixin) {
@action
save() {
this.saveEventDataAndRedirectTo(
'events.view.index',
['tickets', 'socialLinks', 'copyright', 'tax', 'stripeAuthorization']
);
}
@action
move() {
this.saveEventDataAndRedirectTo(
'events.view.edit.attendee',
['tickets', 'socialLinks', 'copyright', 'tax', 'stripeAuthorization']
);
}
});
}

79 changes: 40 additions & 39 deletions app/controllers/events/import.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import Controller from '@ember/controller';
import { run } from '@ember/runloop';
import { action } from '@ember/object';

export default class extends Controller {
importStatus = '';
importError = '';
isImporting = false;
file = false;
fileName = '';

export default Controller.extend({
importStatus : '',
importError : '',
isImporting : false,
file : false,
fileName : '',
importTask(taskUrl) {
run.later(() => {
this.loader
Expand All @@ -28,39 +30,38 @@ export default Controller.extend({
});
});
}, 3000);
},
actions: {
uploadFile(files) {
let [file] = files;
let data = new FormData();
let endpoint = 'import/json';
let ext = file.name.split('.');
ext = ext[ext.length - 1].toLowerCase();
if (ext === 'xml') {
endpoint = 'import/pentabarf';
} else if (ext === 'ics' || ext === 'ical') {
endpoint = 'import/ical';
} else if (ext === 'xcal') {
endpoint = 'import/xcal';
}
data.append('file', file);
}
@action
uploadFile(files) {
let [file] = files;
let data = new FormData();
let endpoint = 'import/json';
let ext = file.name.split('.');
ext = ext[ext.length - 1].toLowerCase();
if (ext === 'xml') {
endpoint = 'import/pentabarf';
} else if (ext === 'ics' || ext === 'ical') {
endpoint = 'import/ical';
} else if (ext === 'xcal') {
endpoint = 'import/xcal';
}
data.append('file', file);

this.setProperties({
'importStatus' : 'Uploading file.. Please don\'t close this window',
'importError' : '',
'isImporting' : true,
'file' : true
});
this.setProperties({
'importStatus' : 'Uploading file.. Please don\'t close this window',
'importError' : '',
'isImporting' : true,
'file' : true
});

this.loader.post(
`/events/${endpoint}`,
data,
{ isFile: true }
).then(data => {
this.importTask(`tasks/${data.task_url.split('/')[3]}`);
}).catch(e => {
this.set('importError', e.message);
});
}
this.loader.post(
`/events/${endpoint}`,
data,
{ isFile: true }
).then(data => {
this.importTask(`tasks/${data.task_url.split('/')[3]}`);
}).catch(e => {
this.set('importError', e.message);
});
}
});
}
161 changes: 82 additions & 79 deletions app/controllers/events/view.js
Original file line number Diff line number Diff line change
@@ -1,88 +1,91 @@
import Controller from '@ember/controller';
import { isEmpty } from '@ember/utils';
import { action } from '@ember/object';

export default Controller.extend({
actions: {
openDeleteEventModal() {
this.set('isEventDeleteModalOpen', true);
},
togglePublishState() {
if (isEmpty(this.get('model.locationName'))) {
this.notify.error(this.l10n.t('Your event must have a location before it can be published.'),
{
id: 'event_location'
});
return;
}
this.set('isLoading', true);
const state = this.get('model.state');
this.set('model.state', state === 'draft' ? 'published' : 'draft');
this.model.save()
.then(() => {
if (state === 'draft') {
this.notify.success(this.l10n.t('Your event has been published successfully.'),
{
id: 'event_publish'
});
} else {
this.notify.success(this.l10n.t('Your event has been unpublished.'),
{
id: 'event_unpublish'
});
}
})
.catch(() => {
this.set('model.state', state);
this.notify.error(this.l10n.t('An unexpected error has occurred.'),
{
id: 'event_publish_error'
});
})
.finally(() => {
this.set('isLoading', false);
});
},
deleteEvent() {
this.set('isLoading', true);
this.model.destroyRecord()
.then(() => {
this.transitionToRoute('events');
this.notify.success(this.l10n.t('Event has been deleted successfully.'),
{
id: 'event_deleted_succ'
});
})
.catch(() => {
this.notify.error(this.l10n.t('An unexpected error has occurred.'),
{
id: 'event_deleted_error'
});
})
.finally(() => {
this.set('isLoading', false);
export default class extends Controller {
@action
openDeleteEventModal() {
this.set('isEventDeleteModalOpen', true);
}
@action
togglePublishState() {
if (isEmpty(this.model.locationName)) {
this.notify.error(this.l10n.t('Your event must have a location before it can be published.'),
{
id: 'event_location'
});
this.set('isEventDeleteModalOpen', false);
},
copyEvent() {
this.set('isCopying', true);
this.loader
.post(`events/${this.get('model.id')}/copy`, {})
.then(copiedEvent => {
this.transitionToRoute('events.view.edit', copiedEvent.identifier);
this.notify.success(this.l10n.t('Event copied successfully'),
return;
}
this.set('isLoading', true);
const { state } = this.model;
this.set('model.state', state === 'draft' ? 'published' : 'draft');
this.model.save()
.then(() => {
if (state === 'draft') {
this.notify.success(this.l10n.t('Your event has been published successfully.'),
{
id: 'event_copy_succ'
id: 'event_publish'
});
})
.catch(() => {
this.notify.error(this.l10n.t('Copying of event failed'),
} else {
this.notify.success(this.l10n.t('Your event has been unpublished.'),
{
id: 'event_copy_fail'
id: 'event_unpublish'
});
})
.finally(() => {
this.set('isCopying', false);
});
}
}
})
.catch(() => {
this.set('model.state', state);
this.notify.error(this.l10n.t('An unexpected error has occurred.'),
{
id: 'event_publish_error'
});
})
.finally(() => {
this.set('isLoading', false);
});
}
@action
deleteEvent() {
this.set('isLoading', true);
this.model.destroyRecord()
.then(() => {
this.transitionToRoute('events');
this.notify.success(this.l10n.t('Event has been deleted successfully.'),
{
id: 'event_deleted_succ'
});
})
.catch(() => {
this.notify.error(this.l10n.t('An unexpected error has occurred.'),
{
id: 'event_deleted_error'
});
})
.finally(() => {
this.set('isLoading', false);
});
this.set('isEventDeleteModalOpen', false);
}
@action
copyEvent() {
this.set('isCopying', true);
this.loader
.post(`events/${this.model.id}/copy`, {})
.then(copiedEvent => {
this.transitionToRoute('events.view.edit', copiedEvent.identifier);
this.notify.success(this.l10n.t('Event copied successfully'),
{
id: 'event_copy_succ'
});
})
.catch(() => {
this.notify.error(this.l10n.t('Copying of event failed'),
{
id: 'event_copy_fail'
});
})
.finally(() => {
this.set('isCopying', false);
});
}
});
}
64 changes: 33 additions & 31 deletions app/controllers/events/view/edit/attendee.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
import Controller from '@ember/controller';
import { action } from '@ember/object';
import EventWizardMixin from 'open-event-frontend/mixins/event-wizard';

export default Controller.extend(EventWizardMixin, {
export default class extends Controller.extend(EventWizardMixin) {

async saveForms(data) {
for (const customForm of data.customForms ? data.customForms.toArray() : []) {
await customForm.save();
}
return data;
},
actions: {
async save(data) {
try {
await this.saveForms(data);
this.saveEventDataAndRedirectTo(
'events.view.index',
['tickets']
);
} catch (error) {
this.notify.error(this.l10n.t(error.message),
{
id: 'attendee_error_serv'
});
}
},
async move(direction, data) {
try {
await this.saveForms(data);
this.saveEventDataAndRedirectTo(
direction === 'forwards' ? 'events.view.edit.sponsors' : 'events.view.edit.basic-details',
['tickets']
);
} catch (error) {
this.notify.error(this.l10n.t(error.message),
{
id: 'attendee_move_error'
});
}
}
@action
async save(data) {
try {
await this.saveForms(data);
this.saveEventDataAndRedirectTo(
'events.view.index',
['tickets']
);
} catch (error) {
this.notify.error(this.l10n.t(error.message),
{
id: 'attendee_error_serv'
});
}
}
@action
async move(direction, data) {
try {
await this.saveForms(data);
this.saveEventDataAndRedirectTo(
direction === 'forwards' ? 'events.view.edit.sponsors' : 'events.view.edit.basic-details',
['tickets']
);
} catch (error) {
this.notify.error(this.l10n.t(error.message),
{
id: 'attendee_move_error'
});
}
}
});
}
Loading