Skip to content

Commit f40338a

Browse files
kushthedudeiamareebjamal
authored andcommitted
chore: Migrating event,speakers,session in controllers to ES6 (#3721)
* chore: Migrating event,speakers,session in controllers to ES6 * using object destructuring
1 parent 9bd3a2e commit f40338a

File tree

16 files changed

+598
-572
lines changed

16 files changed

+598
-572
lines changed

app/controllers/create.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import Controller from '@ember/controller';
22
import EventWizardMixin from 'open-event-frontend/mixins/event-wizard';
3+
import { action } from '@ember/object';
34

4-
export default Controller.extend(EventWizardMixin, {
5-
6-
actions: {
7-
save() {
8-
this.saveEventDataAndRedirectTo(
9-
'events.view.index',
10-
['tickets', 'socialLinks', 'copyright', 'tax', 'stripeAuthorization']
11-
);
12-
},
13-
move() {
14-
this.saveEventDataAndRedirectTo(
15-
'events.view.edit.attendee',
16-
['tickets', 'socialLinks', 'copyright', 'tax', 'stripeAuthorization']
17-
);
18-
}
5+
export default class extends Controller.extend(EventWizardMixin) {
6+
@action
7+
save() {
8+
this.saveEventDataAndRedirectTo(
9+
'events.view.index',
10+
['tickets', 'socialLinks', 'copyright', 'tax', 'stripeAuthorization']
11+
);
12+
}
13+
@action
14+
move() {
15+
this.saveEventDataAndRedirectTo(
16+
'events.view.edit.attendee',
17+
['tickets', 'socialLinks', 'copyright', 'tax', 'stripeAuthorization']
18+
);
1919
}
20-
});
20+
}
21+

app/controllers/events/import.js

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import Controller from '@ember/controller';
22
import { run } from '@ember/runloop';
3+
import { action } from '@ember/object';
4+
5+
export default class extends Controller {
6+
importStatus = '';
7+
importError = '';
8+
isImporting = false;
9+
file = false;
10+
fileName = '';
311

4-
export default Controller.extend({
5-
importStatus : '',
6-
importError : '',
7-
isImporting : false,
8-
file : false,
9-
fileName : '',
1012
importTask(taskUrl) {
1113
run.later(() => {
1214
this.loader
@@ -28,39 +30,38 @@ export default Controller.extend({
2830
});
2931
});
3032
}, 3000);
31-
},
32-
actions: {
33-
uploadFile(files) {
34-
let [file] = files;
35-
let data = new FormData();
36-
let endpoint = 'import/json';
37-
let ext = file.name.split('.');
38-
ext = ext[ext.length - 1].toLowerCase();
39-
if (ext === 'xml') {
40-
endpoint = 'import/pentabarf';
41-
} else if (ext === 'ics' || ext === 'ical') {
42-
endpoint = 'import/ical';
43-
} else if (ext === 'xcal') {
44-
endpoint = 'import/xcal';
45-
}
46-
data.append('file', file);
33+
}
34+
@action
35+
uploadFile(files) {
36+
let [file] = files;
37+
let data = new FormData();
38+
let endpoint = 'import/json';
39+
let ext = file.name.split('.');
40+
ext = ext[ext.length - 1].toLowerCase();
41+
if (ext === 'xml') {
42+
endpoint = 'import/pentabarf';
43+
} else if (ext === 'ics' || ext === 'ical') {
44+
endpoint = 'import/ical';
45+
} else if (ext === 'xcal') {
46+
endpoint = 'import/xcal';
47+
}
48+
data.append('file', file);
4749

48-
this.setProperties({
49-
'importStatus' : 'Uploading file.. Please don\'t close this window',
50-
'importError' : '',
51-
'isImporting' : true,
52-
'file' : true
53-
});
50+
this.setProperties({
51+
'importStatus' : 'Uploading file.. Please don\'t close this window',
52+
'importError' : '',
53+
'isImporting' : true,
54+
'file' : true
55+
});
5456

55-
this.loader.post(
56-
`/events/${endpoint}`,
57-
data,
58-
{ isFile: true }
59-
).then(data => {
60-
this.importTask(`tasks/${data.task_url.split('/')[3]}`);
61-
}).catch(e => {
62-
this.set('importError', e.message);
63-
});
64-
}
57+
this.loader.post(
58+
`/events/${endpoint}`,
59+
data,
60+
{ isFile: true }
61+
).then(data => {
62+
this.importTask(`tasks/${data.task_url.split('/')[3]}`);
63+
}).catch(e => {
64+
this.set('importError', e.message);
65+
});
6566
}
66-
});
67+
}

app/controllers/events/view.js

Lines changed: 82 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,91 @@
11
import Controller from '@ember/controller';
22
import { isEmpty } from '@ember/utils';
3+
import { action } from '@ember/object';
34

4-
export default Controller.extend({
5-
actions: {
6-
openDeleteEventModal() {
7-
this.set('isEventDeleteModalOpen', true);
8-
},
9-
togglePublishState() {
10-
if (isEmpty(this.get('model.locationName'))) {
11-
this.notify.error(this.l10n.t('Your event must have a location before it can be published.'),
12-
{
13-
id: 'event_location'
14-
});
15-
return;
16-
}
17-
this.set('isLoading', true);
18-
const state = this.get('model.state');
19-
this.set('model.state', state === 'draft' ? 'published' : 'draft');
20-
this.model.save()
21-
.then(() => {
22-
if (state === 'draft') {
23-
this.notify.success(this.l10n.t('Your event has been published successfully.'),
24-
{
25-
id: 'event_publish'
26-
});
27-
} else {
28-
this.notify.success(this.l10n.t('Your event has been unpublished.'),
29-
{
30-
id: 'event_unpublish'
31-
});
32-
}
33-
})
34-
.catch(() => {
35-
this.set('model.state', state);
36-
this.notify.error(this.l10n.t('An unexpected error has occurred.'),
37-
{
38-
id: 'event_publish_error'
39-
});
40-
})
41-
.finally(() => {
42-
this.set('isLoading', false);
43-
});
44-
},
45-
deleteEvent() {
46-
this.set('isLoading', true);
47-
this.model.destroyRecord()
48-
.then(() => {
49-
this.transitionToRoute('events');
50-
this.notify.success(this.l10n.t('Event has been deleted successfully.'),
51-
{
52-
id: 'event_deleted_succ'
53-
});
54-
})
55-
.catch(() => {
56-
this.notify.error(this.l10n.t('An unexpected error has occurred.'),
57-
{
58-
id: 'event_deleted_error'
59-
});
60-
})
61-
.finally(() => {
62-
this.set('isLoading', false);
5+
export default class extends Controller {
6+
@action
7+
openDeleteEventModal() {
8+
this.set('isEventDeleteModalOpen', true);
9+
}
10+
@action
11+
togglePublishState() {
12+
if (isEmpty(this.model.locationName)) {
13+
this.notify.error(this.l10n.t('Your event must have a location before it can be published.'),
14+
{
15+
id: 'event_location'
6316
});
64-
this.set('isEventDeleteModalOpen', false);
65-
},
66-
copyEvent() {
67-
this.set('isCopying', true);
68-
this.loader
69-
.post(`events/${this.get('model.id')}/copy`, {})
70-
.then(copiedEvent => {
71-
this.transitionToRoute('events.view.edit', copiedEvent.identifier);
72-
this.notify.success(this.l10n.t('Event copied successfully'),
17+
return;
18+
}
19+
this.set('isLoading', true);
20+
const { state } = this.model;
21+
this.set('model.state', state === 'draft' ? 'published' : 'draft');
22+
this.model.save()
23+
.then(() => {
24+
if (state === 'draft') {
25+
this.notify.success(this.l10n.t('Your event has been published successfully.'),
7326
{
74-
id: 'event_copy_succ'
27+
id: 'event_publish'
7528
});
76-
})
77-
.catch(() => {
78-
this.notify.error(this.l10n.t('Copying of event failed'),
29+
} else {
30+
this.notify.success(this.l10n.t('Your event has been unpublished.'),
7931
{
80-
id: 'event_copy_fail'
32+
id: 'event_unpublish'
8133
});
82-
})
83-
.finally(() => {
84-
this.set('isCopying', false);
85-
});
86-
}
34+
}
35+
})
36+
.catch(() => {
37+
this.set('model.state', state);
38+
this.notify.error(this.l10n.t('An unexpected error has occurred.'),
39+
{
40+
id: 'event_publish_error'
41+
});
42+
})
43+
.finally(() => {
44+
this.set('isLoading', false);
45+
});
46+
}
47+
@action
48+
deleteEvent() {
49+
this.set('isLoading', true);
50+
this.model.destroyRecord()
51+
.then(() => {
52+
this.transitionToRoute('events');
53+
this.notify.success(this.l10n.t('Event has been deleted successfully.'),
54+
{
55+
id: 'event_deleted_succ'
56+
});
57+
})
58+
.catch(() => {
59+
this.notify.error(this.l10n.t('An unexpected error has occurred.'),
60+
{
61+
id: 'event_deleted_error'
62+
});
63+
})
64+
.finally(() => {
65+
this.set('isLoading', false);
66+
});
67+
this.set('isEventDeleteModalOpen', false);
68+
}
69+
@action
70+
copyEvent() {
71+
this.set('isCopying', true);
72+
this.loader
73+
.post(`events/${this.model.id}/copy`, {})
74+
.then(copiedEvent => {
75+
this.transitionToRoute('events.view.edit', copiedEvent.identifier);
76+
this.notify.success(this.l10n.t('Event copied successfully'),
77+
{
78+
id: 'event_copy_succ'
79+
});
80+
})
81+
.catch(() => {
82+
this.notify.error(this.l10n.t('Copying of event failed'),
83+
{
84+
id: 'event_copy_fail'
85+
});
86+
})
87+
.finally(() => {
88+
this.set('isCopying', false);
89+
});
8790
}
88-
});
91+
}
Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,43 @@
11
import Controller from '@ember/controller';
2+
import { action } from '@ember/object';
23
import EventWizardMixin from 'open-event-frontend/mixins/event-wizard';
34

4-
export default Controller.extend(EventWizardMixin, {
5+
export default class extends Controller.extend(EventWizardMixin) {
6+
57
async saveForms(data) {
68
for (const customForm of data.customForms ? data.customForms.toArray() : []) {
79
await customForm.save();
810
}
911
return data;
10-
},
11-
actions: {
12-
async save(data) {
13-
try {
14-
await this.saveForms(data);
15-
this.saveEventDataAndRedirectTo(
16-
'events.view.index',
17-
['tickets']
18-
);
19-
} catch (error) {
20-
this.notify.error(this.l10n.t(error.message),
21-
{
22-
id: 'attendee_error_serv'
23-
});
24-
}
25-
},
26-
async move(direction, data) {
27-
try {
28-
await this.saveForms(data);
29-
this.saveEventDataAndRedirectTo(
30-
direction === 'forwards' ? 'events.view.edit.sponsors' : 'events.view.edit.basic-details',
31-
['tickets']
32-
);
33-
} catch (error) {
34-
this.notify.error(this.l10n.t(error.message),
35-
{
36-
id: 'attendee_move_error'
37-
});
38-
}
12+
}
13+
@action
14+
async save(data) {
15+
try {
16+
await this.saveForms(data);
17+
this.saveEventDataAndRedirectTo(
18+
'events.view.index',
19+
['tickets']
20+
);
21+
} catch (error) {
22+
this.notify.error(this.l10n.t(error.message),
23+
{
24+
id: 'attendee_error_serv'
25+
});
26+
}
27+
}
28+
@action
29+
async move(direction, data) {
30+
try {
31+
await this.saveForms(data);
32+
this.saveEventDataAndRedirectTo(
33+
direction === 'forwards' ? 'events.view.edit.sponsors' : 'events.view.edit.basic-details',
34+
['tickets']
35+
);
36+
} catch (error) {
37+
this.notify.error(this.l10n.t(error.message),
38+
{
39+
id: 'attendee_move_error'
40+
});
3941
}
4042
}
41-
});
43+
}

0 commit comments

Comments
 (0)