diff --git a/app/controllers/events/view/tickets/orders/list.js b/app/controllers/events/view/tickets/orders/list.js index 33eca59a2ff..bd5b2b5a12f 100644 --- a/app/controllers/events/view/tickets/orders/list.js +++ b/app/controllers/events/view/tickets/orders/list.js @@ -1,99 +1,136 @@ 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 : 'user', - template : 'components/ui-table/cell/events/view/tickets/orders/cell-order', - title : 'Order', - disableSorting : true - }, - { - propertyName : 'completedAt', - template : 'components/ui-table/cell/events/view/tickets/orders/cell-date', - dateFormat : 'MMMM DD, YYYY - HH:mm A', - title : 'Date And Time' - }, - { - propertyName : 'amount', - template : 'components/ui-table/cell/events/view/tickets/orders/cell-amount', - title : 'Total Amount' - }, - { - propertyName : 'attendees.length', - title : 'Quantity' - }, - { - propertyName : 'user.email', - title : 'Buyer/Registration Contact', - disableSorting : true - } - ], - actions: { - completeOrder(order) { - this.set('isLoading', true); - order.set('status', 'completed'); - order.save() - .then(() => { - this.send('refreshRoute'); - this.notify.success(this.l10n.t('Order has been marked completed successfully.')); - }) - .catch(() => { - this.notify.error(this.l10n.t('An unexpected error has occurred.')); - }) - .finally(() => { - this.set('isLoading', false); - }); - }, - deleteOrder(order) { - this.set('isLoading', true); - order.destroyRecord() - .then(() => { - this.send('refreshRoute'); - this.notify.success(this.l10n.t('Order has been deleted successfully.')); - }) - .catch(() => { - this.notify.error(this.l10n.t('An unexpected error has occurred.')); - }) - .finally(() => { - this.set('isLoading', false); - }); - }, - cancelOrder(order) { - this.set('isLoading', true); - order.set('status', 'cancelled'); - order.save() - .then(() => { - this.send('refreshRoute'); - this.notify.success(this.l10n.t('Order has been cancelled successfully.')); - }) - .catch(() => { - this.notify.error(this.l10n.t('An unexpected error has occurred.')); - }) - .finally(() => { - this.set('isLoading', false); - }); - }, - async resendConfirmation(order) { - try { - const payload = { - 'data': { - 'order' : order.identifier, - 'user' : this.authManager.currentUser.email - } - }; - await this.loader.post('orders/resend-email', payload); - this.notify.success(this.l10n.t('Email confirmation has been sent to attendees successfully')); - } catch (error) { - if (error.status && error.status === 429) { - this.notify.error(this.l10n.t('Only 5 resend actions are allowed in a minute')); - } else if (error.status && error.status === 422) { - this.notify.error(this.l10n.tVar(error.response.errors[0].detail)); - } else { - this.notify.error(this.l10n.t('An unexpected error has occurred.')); +export default class extends Controller.extend(EmberTableControllerMixin) { + @computed() + get columns() { + return [ + { + name : 'Order', + valuePath : 'identifier', + extraValuePaths : ['user', 'status', 'paidVia', 'completedAt', 'createdAt'], + cellComponent : 'ui-table/cell/events/view/tickets/orders/cell-order', + width : 200, + actions : { + completeOrder : this.completeOrder.bind(this), + deleteOrder : this.deleteOrder.bind(this), + cancelOrder : this.cancelOrder.bind(this), + resendConfirmation : this.resendConfirmation.bind(this) + } + }, + { + name : 'Date And Time', + valuePath : 'completedAt', + extraValuePaths : ['createdAt'], + cellComponent : 'ui-table/cell/events/view/tickets/orders/cell-date', + headerComponent : 'tables/headers/sort', + width : 100, + dateFormat : 'MMMM DD, YYYY - HH:mm A', + isSortable : true + }, + { + name : 'Total Amount', + valuePath : 'amount', + extraValuePaths : ['discountCode', 'event'], + cellComponent : 'ui-table/cell/events/view/tickets/orders/cell-amount', + headerComponent : 'tables/headers/sort', + width : 100, + isSortable : true + }, + { + name : 'Quantity', + valuePath : 'attendees.length', + width : 50 + }, + { + name : 'Buyer/Registration Contact', + valuePath : 'user.email', + width : 140 + + } + ]; + } + + @computed('model.data.@each') + get rows() { + return this.model.data; + } + + @action + completeOrder(order_id) { + this.set('isLoading', true); + const order = this.store.peekRecord('order', order_id, { backgroundReload: false }); + order.set('status', 'completed'); + order.save() + .then(() => { + this.notify.success(this.l10n.t('Order has been marked completed successfully.')); + this.refreshModel.bind(this)(); + }) + .catch(() => { + this.notify.error(this.l10n.t('An unexpected error has occurred.')); + }) + .finally(() => { + this.set('isLoading', false); + }); + } + @action + deleteOrder(order_id) { + this.set('isLoading', true); + const order = this.store.peekRecord('order', order_id, { backgroundReload: false }); + order.destroyRecord() + .then(() => { + this.notify.success(this.l10n.t('Order has been deleted 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 + cancelOrder(order_id) { + this.set('isLoading', true); + const order = this.store.peekRecord('order', order_id, { backgroundReload: false }); + order.set('status', 'cancelled'); + order.save() + .then(() => { + this.notify.success(this.l10n.t('Order has been cancelled successfully.')); + this.refreshModel.bind(this)(); + }) + .catch(() => { + this.notify.error(this.l10n.t('An unexpected error has occurred.')); + }) + .finally(() => { + this.set('isLoading', false); + }); + } + + @action + async resendConfirmation(order_id) { + try { + const order = this.store.peekRecord('order', order_id, { backgroundReload: false }); + const payload = { + 'data': { + 'order' : order.identifier, + 'user' : this.authManager.currentUser.email } + }; + await this.loader.post('orders/resend-email', payload); + this.notify.success(this.l10n.t('Email confirmation has been sent to attendees successfully')); + } catch (error) { + if (error.status && error.status === 429) { + this.notify.error(this.l10n.t('Only 5 resend actions are allowed in a minute')); + } else if (error.status && error.status === 422) { + this.notify.error(this.l10n.tVar(error.response.errors[0].detail)); + } else { + this.notify.error(this.l10n.t('An unexpected error has occurred.')); } } } -}); +} diff --git a/app/routes/events/view/tickets/orders/list.js b/app/routes/events/view/tickets/orders/list.js index f68d6a28904..ba8c63219cf 100644 --- a/app/routes/events/view/tickets/orders/list.js +++ b/app/routes/events/view/tickets/orders/list.js @@ -1,6 +1,7 @@ import Route from '@ember/routing/route'; +import EmberTableRouteMixin from 'open-event-frontend/mixins/ember-table-route'; -export default Route.extend({ +export default class extends Route.extend(EmberTableRouteMixin) { titleToken() { switch (this.get('params.orders_status')) { case 'placed': @@ -14,10 +15,11 @@ export default Route.extend({ case 'all': return this.l10n.t('All'); } - }, + } async model(params) { this.set('params', params); + const searchField = 'identifier'; let filterOptions = []; if (params.orders_status !== 'all') { filterOptions = [ @@ -28,27 +30,17 @@ export default Route.extend({ } ]; } + filterOptions = this.applySearchFilters(filterOptions, params, searchField); - let queryObject = { - include : 'tickets,user', - filter : filterOptions, - 'page[size]' : 10 + let queryString = { + include : 'tickets,user', + filter : filterOptions, + 'page[size]' : params.per_page || 10, + 'page[number]' : params.page || 1 }; - let store = this.modelFor('events.view'); - - let data = await store.query('orders', queryObject); + queryString = this.applySortFilters(queryString, params); - return { - data, - store, - query : queryObject, - objectType : 'orders' - }; - }, - actions: { - refreshRoute() { - this.refresh(); - } + return this.asArray(this.modelFor('events.view').query('orders', queryString)); } -}); +} diff --git a/app/templates/components/ui-table/cell/events/view/tickets/orders/cell-amount.hbs b/app/templates/components/ui-table/cell/events/view/tickets/orders/cell-amount.hbs index 29ddcf2bc09..c55b42d7409 100644 --- a/app/templates/components/ui-table/cell/events/view/tickets/orders/cell-amount.hbs +++ b/app/templates/components/ui-table/cell/events/view/tickets/orders/cell-amount.hbs @@ -1,8 +1,8 @@