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: access-code & discount-code ember tables #3422

Merged
merged 1 commit into from
Aug 15, 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
139 changes: 78 additions & 61 deletions app/controllers/events/view/tickets/access-codes/list.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,85 @@
import Controller from '@ember/controller';
import { computed, action } from '@ember/object';
import EmberTableControllerMixin from 'open-event-frontend/mixins/ember-table-controller';

export default Controller.extend({
columns: [
{
propertyName : 'code',
title : 'Access Code'
},
{
propertyName : 'accessUrl',
title : 'Access Code URL',
template : 'components/ui-table/cell/events/view/tickets/access-codes/cell-url',
disableSorting : true
},
{
propertyName : 'valid-till',
title : 'Validity',
template : 'components/ui-table/cell/cell-validity'
},
{
propertyName : 'is-active',
title : 'Status',
template : 'components/ui-table/cell/cell-label'
},
{
title : 'Actions',
template : 'components/ui-table/cell/events/view/tickets/access-codes/cell-actions',
disableSorting : true,
disableFiltering : true
}
],

actions: {
deleteAccessCode(accessCode) {
this.set('isLoading', true);
accessCode.destroyRecord()
.then(() => {
this.model.reload();
this.notify.success(this.l10n.t('Access Code has been deleted successfully.'));
})
.catch(() => {
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
})
.finally(() => {
this.set('isLoading', false);
});
},
toggleStatus(accessCode) {
this.set('isLoading', true);
accessCode.toggleProperty('isActive');
accessCode.save()
.then(() => {
this.notify.success(this.l10n.t('Access Code has been updated successfully.'));
this.send('refreshRoute');
})
.catch(() => {
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
})
.finally(() => {
this.set('isLoading', false);
});
},
export default class extends Controller.extend(EmberTableControllerMixin) {
@computed()
get columns() {
return [
{
name : 'Access Code',
valuePath : 'code'
},
{
name : 'Access Code URL',
valuePath : 'accessUrl',
cellComponent : 'ui-table/cell/events/view/tickets/access-codes/cell-url',
disableSorting : true
},
{
name : 'Validity',
valuePath : 'validFrom',
extraValuePaths : ['validTill'],
cellComponent : 'ui-table/cell/cell-validity'
},
{
name : 'Status',
valuePath : 'isActive',
extraValuePaths : ['isExpired'],
cellComponent : 'ui-table/cell/cell-label'
},
{
name : 'Actions',
cellComponent : 'ui-table/cell/events/view/tickets/access-codes/cell-actions',
valuePath : 'id',
extraValuePaths : ['isActive', 'isExpired'],
actions : {
deleteAccessCode : this.deleteAccessCode.bind(this),
toggleStatus : this.toggleStatus.bind(this),
editAccessCode : this.editAccessCode.bind(this)
}
}
];
}

@action
deleteAccessCode(access_id) {
this.set('isLoading', true);
let accessCode = this.store.peekRecord('accessCode', access_id, { backgroundReload: false });
accessCode.destroyRecord()
.then(() => {
this.notify.success(this.l10n.t('Access Code has been deleted successfully.'));
this.refreshModel.bind(this)();
})
.catch(() => {
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
})
.finally(() => {
this.set('isLoading', false);
});
}
@action
toggleStatus(access_id) {
this.set('isLoading', true);
let accessCode = this.store.peekRecord('accessCode', access_id, { backgroundReload: false });
accessCode.toggleProperty('isActive');
accessCode.save()
.then(() => {
this.notify.success(this.l10n.t('Access Code has been updated successfully.'));
this.refreshModel.bind(this)();
})
.catch(() => {
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
})
.finally(() => {
this.set('isLoading', false);
});
}
@action
editAccessCode(id) {
this.transitionToRoute('events.view.tickets.access-codes.edit', id);
}
}

});

}
158 changes: 89 additions & 69 deletions app/controllers/events/view/tickets/discount-codes/list.js
Original file line number Diff line number Diff line change
@@ -1,73 +1,93 @@
import Controller from '@ember/controller';
export default Controller.extend({
columns: [
{
propertyName : 'code',
title : 'Discount code'
},
{
propertyName : 'discount-url',
template : 'components/ui-table/cell/events/view/tickets/discount-codes/cell-url',
title : 'Discount code URL',
disableSorting : true
},
{
propertyName : 'value',
template : 'components/ui-table/cell/events/view/tickets/discount-codes/cell-value',
title : 'Discount Per Ticket'
},
{
propertyName : 'valid-till',
template : 'components/ui-table/cell/events/view/tickets/discount-codes/cell-validity',
title : 'Validity'
},
{
propertyName : 'is-active',
template : 'components/ui-table/cell/events/view/tickets/discount-codes/cell-status',
title : 'Status',
disableSorting : true
},
{
title : 'Actions',
template : 'components/ui-table/cell/events/view/tickets/discount-codes/cell-actions',
disableSorting : true
}
],
import { computed, action } from '@ember/object';
import EmberTableControllerMixin from 'open-event-frontend/mixins/ember-table-controller';

actions: {
deleteDiscountCode(discountCode) {
this.set('isLoading', true);
discountCode.destroyRecord()
.then(() => {
this.model.reload();
this.notify.success(this.l10n.t('Discount Code has been deleted successfully.'));
})
.catch(() => {
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
})
.finally(() => {
this.set('isLoading', false);
});
},
toggleStatus(discountCode) {
this.set('isLoading', true);
discountCode.toggleProperty('isActive');
discountCode.save()
.then(() => {
this.notify.success(this.l10n.t('Discount Code has been updated successfully.'));
this.send('refreshRoute');
})
.catch(() => {
discountCode.toggleProperty('isActive');
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
})
.finally(() => {
this.set('isLoading', false);
});
},
editDiscountCode(id) {
this.transitionToRoute('events.view.tickets.discount-codes.edit', id);
}

export default class extends Controller.extend(EmberTableControllerMixin) {
@computed()
get columns() {
return [
{
name : 'Discount code',
valuePath : 'code'
},
{
name : 'Discount code URL',
valuePath : 'discountUrl',
cellComponent : 'ui-table/cell/events/view/tickets/discount-codes/cell-url'
},
{
name : 'Discount Per Ticket',
valuePath : 'value',
extraValuePaths : ['type', 'event'],
cellComponent : 'ui-table/cell/events/view/tickets/discount-codes/cell-value'
},
{
name : 'Validity',
valuePath : 'validTill',
cellComponent : 'ui-table/cell/events/view/tickets/discount-codes/cell-validity'
},
{
name : 'Status',
valuePath : 'isActive',
extraValuePaths : ['isExpired'],
cellComponent : 'ui-table/cell/events/view/tickets/discount-codes/cell-status'
},
{
name : 'Actions',
valuePath : 'id',
extraValuePaths : ['isActive', 'isExpired'],
cellComponent : 'ui-table/cell/events/view/tickets/discount-codes/cell-actions',
actions : {
deleteDiscountCode : this.deleteDiscountCode.bind(this),
toggleStatus : this.toggleStatus.bind(this),
editDiscountCode : this.editDiscountCode.bind(this)
}
}
];
}

});

@action
deleteDiscountCode(discount_id) {
this.set('isLoading', true);
let discountCode = this.store.peekRecord('discountCode', discount_id, { backgroundReload: false });
discountCode.destroyRecord()
.then(() => {
this.notify.success(this.l10n.t('Discount Code has been deleted successfully.'));
this.refreshModel.bind(this)();
})
.catch(() => {
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
})
.finally(() => {
this.set('isLoading', false);
});
}

@action
toggleStatus(discount_id) {
this.set('isLoading', true);
let discountCode = this.store.peekRecord('discountCode', discount_id, { backgroundReload: false });
discountCode.toggleProperty('isActive');
discountCode.save()
.then(() => {
this.notify.success(this.l10n.t('Discount Code has been updated successfully.'));
this.refreshModel.bind(this)();
})
.catch(e => {
console.warn(e);
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
})
.finally(() => {
this.set('isLoading', false);
});
}

@action
editDiscountCode(id) {
this.transitionToRoute('events.view.tickets.discount-codes.edit', id);
}


}
34 changes: 13 additions & 21 deletions app/routes/events/view/tickets/access-codes/list.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Route from '@ember/routing/route';
import EmberTableRouteMixin from 'open-event-frontend/mixins/ember-table-route';
import moment from 'moment';

export default Route.extend({
export default class extends Route.extend(EmberTableRouteMixin) {
titleToken() {
switch (this.get('params.access_status')) {
case 'active':
Expand All @@ -11,9 +12,11 @@ export default Route.extend({
case 'expired':
return this.l10n.t('Expired');
}
},
}

async model(params) {
let filterOptions = [];
const searchField = 'code';
if (params.access_status === 'active') {
filterOptions = [
{
Expand Down Expand Up @@ -60,26 +63,15 @@ export default Route.extend({
filterOptions = [];
}

let queryObject = {
filter : filterOptions,
'page[size]' : 10
filterOptions = this.applySearchFilters(filterOptions, params, searchField);
let queryString = {
filter : filterOptions,
'page[size]' : params.per_page || 10,
'page[number]' : params.page || 1
};

let store = this.modelFor('events.view');

let data = await store.query('accessCodes', queryObject);
queryString = this.applySortFilters(queryString, params);

return {
data,
store,
query : queryObject,
objectType : 'accessCodes'
};
},

actions: {
refreshRoute() {
this.refresh();
}
return this.asArray(this.modelFor('events.view').query('accessCodes', queryString));
}
});
}
Loading