Skip to content

Commit 7a47254

Browse files
authored
feat: access-code & discount-code ember tables (#3422)
1 parent b0bcbf2 commit 7a47254

File tree

16 files changed

+250
-229
lines changed

16 files changed

+250
-229
lines changed
Lines changed: 78 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,85 @@
11
import Controller from '@ember/controller';
2+
import { computed, action } from '@ember/object';
3+
import EmberTableControllerMixin from 'open-event-frontend/mixins/ember-table-controller';
24

3-
export default Controller.extend({
4-
columns: [
5-
{
6-
propertyName : 'code',
7-
title : 'Access Code'
8-
},
9-
{
10-
propertyName : 'accessUrl',
11-
title : 'Access Code URL',
12-
template : 'components/ui-table/cell/events/view/tickets/access-codes/cell-url',
13-
disableSorting : true
14-
},
15-
{
16-
propertyName : 'valid-till',
17-
title : 'Validity',
18-
template : 'components/ui-table/cell/cell-validity'
19-
},
20-
{
21-
propertyName : 'is-active',
22-
title : 'Status',
23-
template : 'components/ui-table/cell/cell-label'
24-
},
25-
{
26-
title : 'Actions',
27-
template : 'components/ui-table/cell/events/view/tickets/access-codes/cell-actions',
28-
disableSorting : true,
29-
disableFiltering : true
30-
}
31-
],
325

33-
actions: {
34-
deleteAccessCode(accessCode) {
35-
this.set('isLoading', true);
36-
accessCode.destroyRecord()
37-
.then(() => {
38-
this.model.reload();
39-
this.notify.success(this.l10n.t('Access Code has been deleted successfully.'));
40-
})
41-
.catch(() => {
42-
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
43-
})
44-
.finally(() => {
45-
this.set('isLoading', false);
46-
});
47-
},
48-
toggleStatus(accessCode) {
49-
this.set('isLoading', true);
50-
accessCode.toggleProperty('isActive');
51-
accessCode.save()
52-
.then(() => {
53-
this.notify.success(this.l10n.t('Access Code has been updated successfully.'));
54-
this.send('refreshRoute');
55-
})
56-
.catch(() => {
57-
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
58-
})
59-
.finally(() => {
60-
this.set('isLoading', false);
61-
});
62-
},
6+
export default class extends Controller.extend(EmberTableControllerMixin) {
7+
@computed()
8+
get columns() {
9+
return [
10+
{
11+
name : 'Access Code',
12+
valuePath : 'code'
13+
},
14+
{
15+
name : 'Access Code URL',
16+
valuePath : 'accessUrl',
17+
cellComponent : 'ui-table/cell/events/view/tickets/access-codes/cell-url',
18+
disableSorting : true
19+
},
20+
{
21+
name : 'Validity',
22+
valuePath : 'validFrom',
23+
extraValuePaths : ['validTill'],
24+
cellComponent : 'ui-table/cell/cell-validity'
25+
},
26+
{
27+
name : 'Status',
28+
valuePath : 'isActive',
29+
extraValuePaths : ['isExpired'],
30+
cellComponent : 'ui-table/cell/cell-label'
31+
},
32+
{
33+
name : 'Actions',
34+
cellComponent : 'ui-table/cell/events/view/tickets/access-codes/cell-actions',
35+
valuePath : 'id',
36+
extraValuePaths : ['isActive', 'isExpired'],
37+
actions : {
38+
deleteAccessCode : this.deleteAccessCode.bind(this),
39+
toggleStatus : this.toggleStatus.bind(this),
40+
editAccessCode : this.editAccessCode.bind(this)
41+
}
42+
}
43+
];
44+
}
45+
46+
@action
47+
deleteAccessCode(access_id) {
48+
this.set('isLoading', true);
49+
let accessCode = this.store.peekRecord('accessCode', access_id, { backgroundReload: false });
50+
accessCode.destroyRecord()
51+
.then(() => {
52+
this.notify.success(this.l10n.t('Access Code has been deleted successfully.'));
53+
this.refreshModel.bind(this)();
54+
})
55+
.catch(() => {
56+
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
57+
})
58+
.finally(() => {
59+
this.set('isLoading', false);
60+
});
61+
}
62+
@action
63+
toggleStatus(access_id) {
64+
this.set('isLoading', true);
65+
let accessCode = this.store.peekRecord('accessCode', access_id, { backgroundReload: false });
66+
accessCode.toggleProperty('isActive');
67+
accessCode.save()
68+
.then(() => {
69+
this.notify.success(this.l10n.t('Access Code has been updated successfully.'));
70+
this.refreshModel.bind(this)();
71+
})
72+
.catch(() => {
73+
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
74+
})
75+
.finally(() => {
76+
this.set('isLoading', false);
77+
});
78+
}
79+
@action
6380
editAccessCode(id) {
6481
this.transitionToRoute('events.view.tickets.access-codes.edit', id);
6582
}
66-
}
6783

68-
});
84+
85+
}
Lines changed: 89 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,93 @@
11
import Controller from '@ember/controller';
2-
export default Controller.extend({
3-
columns: [
4-
{
5-
propertyName : 'code',
6-
title : 'Discount code'
7-
},
8-
{
9-
propertyName : 'discount-url',
10-
template : 'components/ui-table/cell/events/view/tickets/discount-codes/cell-url',
11-
title : 'Discount code URL',
12-
disableSorting : true
13-
},
14-
{
15-
propertyName : 'value',
16-
template : 'components/ui-table/cell/events/view/tickets/discount-codes/cell-value',
17-
title : 'Discount Per Ticket'
18-
},
19-
{
20-
propertyName : 'valid-till',
21-
template : 'components/ui-table/cell/events/view/tickets/discount-codes/cell-validity',
22-
title : 'Validity'
23-
},
24-
{
25-
propertyName : 'is-active',
26-
template : 'components/ui-table/cell/events/view/tickets/discount-codes/cell-status',
27-
title : 'Status',
28-
disableSorting : true
29-
},
30-
{
31-
title : 'Actions',
32-
template : 'components/ui-table/cell/events/view/tickets/discount-codes/cell-actions',
33-
disableSorting : true
34-
}
35-
],
2+
import { computed, action } from '@ember/object';
3+
import EmberTableControllerMixin from 'open-event-frontend/mixins/ember-table-controller';
364

37-
actions: {
38-
deleteDiscountCode(discountCode) {
39-
this.set('isLoading', true);
40-
discountCode.destroyRecord()
41-
.then(() => {
42-
this.model.reload();
43-
this.notify.success(this.l10n.t('Discount Code has been deleted successfully.'));
44-
})
45-
.catch(() => {
46-
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
47-
})
48-
.finally(() => {
49-
this.set('isLoading', false);
50-
});
51-
},
52-
toggleStatus(discountCode) {
53-
this.set('isLoading', true);
54-
discountCode.toggleProperty('isActive');
55-
discountCode.save()
56-
.then(() => {
57-
this.notify.success(this.l10n.t('Discount Code has been updated successfully.'));
58-
this.send('refreshRoute');
59-
})
60-
.catch(() => {
61-
discountCode.toggleProperty('isActive');
62-
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
63-
})
64-
.finally(() => {
65-
this.set('isLoading', false);
66-
});
67-
},
68-
editDiscountCode(id) {
69-
this.transitionToRoute('events.view.tickets.discount-codes.edit', id);
70-
}
5+
6+
export default class extends Controller.extend(EmberTableControllerMixin) {
7+
@computed()
8+
get columns() {
9+
return [
10+
{
11+
name : 'Discount code',
12+
valuePath : 'code'
13+
},
14+
{
15+
name : 'Discount code URL',
16+
valuePath : 'discountUrl',
17+
cellComponent : 'ui-table/cell/events/view/tickets/discount-codes/cell-url'
18+
},
19+
{
20+
name : 'Discount Per Ticket',
21+
valuePath : 'value',
22+
extraValuePaths : ['type', 'event'],
23+
cellComponent : 'ui-table/cell/events/view/tickets/discount-codes/cell-value'
24+
},
25+
{
26+
name : 'Validity',
27+
valuePath : 'validTill',
28+
cellComponent : 'ui-table/cell/events/view/tickets/discount-codes/cell-validity'
29+
},
30+
{
31+
name : 'Status',
32+
valuePath : 'isActive',
33+
extraValuePaths : ['isExpired'],
34+
cellComponent : 'ui-table/cell/events/view/tickets/discount-codes/cell-status'
35+
},
36+
{
37+
name : 'Actions',
38+
valuePath : 'id',
39+
extraValuePaths : ['isActive', 'isExpired'],
40+
cellComponent : 'ui-table/cell/events/view/tickets/discount-codes/cell-actions',
41+
actions : {
42+
deleteDiscountCode : this.deleteDiscountCode.bind(this),
43+
toggleStatus : this.toggleStatus.bind(this),
44+
editDiscountCode : this.editDiscountCode.bind(this)
45+
}
46+
}
47+
];
7148
}
7249

73-
});
50+
51+
@action
52+
deleteDiscountCode(discount_id) {
53+
this.set('isLoading', true);
54+
let discountCode = this.store.peekRecord('discountCode', discount_id, { backgroundReload: false });
55+
discountCode.destroyRecord()
56+
.then(() => {
57+
this.notify.success(this.l10n.t('Discount Code has been deleted successfully.'));
58+
this.refreshModel.bind(this)();
59+
})
60+
.catch(() => {
61+
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
62+
})
63+
.finally(() => {
64+
this.set('isLoading', false);
65+
});
66+
}
67+
68+
@action
69+
toggleStatus(discount_id) {
70+
this.set('isLoading', true);
71+
let discountCode = this.store.peekRecord('discountCode', discount_id, { backgroundReload: false });
72+
discountCode.toggleProperty('isActive');
73+
discountCode.save()
74+
.then(() => {
75+
this.notify.success(this.l10n.t('Discount Code has been updated successfully.'));
76+
this.refreshModel.bind(this)();
77+
})
78+
.catch(e => {
79+
console.warn(e);
80+
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
81+
})
82+
.finally(() => {
83+
this.set('isLoading', false);
84+
});
85+
}
86+
87+
@action
88+
editDiscountCode(id) {
89+
this.transitionToRoute('events.view.tickets.discount-codes.edit', id);
90+
}
91+
92+
93+
}

app/routes/events/view/tickets/access-codes/list.js

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import Route from '@ember/routing/route';
2+
import EmberTableRouteMixin from 'open-event-frontend/mixins/ember-table-route';
23
import moment from 'moment';
34

4-
export default Route.extend({
5+
export default class extends Route.extend(EmberTableRouteMixin) {
56
titleToken() {
67
switch (this.get('params.access_status')) {
78
case 'active':
@@ -11,9 +12,11 @@ export default Route.extend({
1112
case 'expired':
1213
return this.l10n.t('Expired');
1314
}
14-
},
15+
}
16+
1517
async model(params) {
1618
let filterOptions = [];
19+
const searchField = 'code';
1720
if (params.access_status === 'active') {
1821
filterOptions = [
1922
{
@@ -60,26 +63,15 @@ export default Route.extend({
6063
filterOptions = [];
6164
}
6265

63-
let queryObject = {
64-
filter : filterOptions,
65-
'page[size]' : 10
66+
filterOptions = this.applySearchFilters(filterOptions, params, searchField);
67+
let queryString = {
68+
filter : filterOptions,
69+
'page[size]' : params.per_page || 10,
70+
'page[number]' : params.page || 1
6671
};
6772

68-
let store = this.modelFor('events.view');
69-
70-
let data = await store.query('accessCodes', queryObject);
73+
queryString = this.applySortFilters(queryString, params);
7174

72-
return {
73-
data,
74-
store,
75-
query : queryObject,
76-
objectType : 'accessCodes'
77-
};
78-
},
79-
80-
actions: {
81-
refreshRoute() {
82-
this.refresh();
83-
}
75+
return this.asArray(this.modelFor('events.view').query('accessCodes', queryString));
8476
}
85-
});
77+
}

0 commit comments

Comments
 (0)