From 83d8284d5af0ee64ef195069e370f28238291ecd Mon Sep 17 00:00:00 2001 From: kushthedude Date: Wed, 31 Jul 2019 23:24:45 +0530 Subject: [PATCH 1/5] Introducing Ember Tables in Admin/Messages --- app/controllers/admin/messages/list.js | 86 +++++++++++-------- app/routes/admin/messages/list.js | 33 ++++++- app/templates/admin/messages/list.hbs | 17 +++- .../ui-table/cell/cell-title-message.hbs | 6 +- 4 files changed, 97 insertions(+), 45 deletions(-) diff --git a/app/controllers/admin/messages/list.js b/app/controllers/admin/messages/list.js index 12d8f955494..684768a2370 100644 --- a/app/controllers/admin/messages/list.js +++ b/app/controllers/admin/messages/list.js @@ -1,36 +1,54 @@ import Controller from '@ember/controller'; +import { computed } from '@ember/object'; +import EmberTableControllerMixin from 'open-event-frontend/mixins/ember-table-controller'; -export default Controller.extend({ - columns: [ - { - propertyName : 'recipient', - title : 'Recipients' - }, - { - propertyName : 'action', - title : 'Trigger' - }, - { - subject : 'emailSubject', - message : 'emailMessage', - title : 'Email Message', - template : 'components/ui-table/cell/cell-title-message' - }, - { - subject : 'notificationTitle', - message : 'notificationMessage', - title : 'Notification Message', - template : 'components/ui-table/cell/cell-title-message' - }, - { - title : 'Options', - template : 'components/ui-table/cell/admin/messages/cell-options' - }, - { - propertyName : 'sentAt', - title : 'Time/Date sent out', - template : 'components/ui-table/cell/cell-simple-date', - dateFormat : 'MMMM DD, YYYY - HH:mm A' - } - ] -}); +export default class extends Controller.extend(EmberTableControllerMixin) { + @computed() + get columns() { + return [ + { + name : 'Recipients', + valuePath : 'recipient' + }, + { + name : 'Trigger', + valuePath : 'action' + }, + { + name : 'Email Message', + valuePath : 'emailMessage', + + cellComponent : 'ui-table/cell/cell-title-message', + options : { + subject : 'emailSubject', + message : 'emailMessage' + } + }, + { + name : 'Notification Message', + valuePath : 'notificationMessage', + cellComponent : 'ui-table/cell/cell-title-message', + options : { + subject : 'notificationSubject', + message : 'notificationMessage' + } + }, + { + name : 'Options', + valuePath : 'option', + cellComponent : 'ui-table/cell/admin/messages/cell-options' + }, + { + name : 'Time/Date Sent Out', + valuePath : 'sentAt', + cellComponent : 'ui-table/cell/cell-simple-date', + options : { + dateFormat: 'MMMM DD, YYYY - HH:mm A' + } + } + + ]; + } +} + + \ No newline at end of file diff --git a/app/routes/admin/messages/list.js b/app/routes/admin/messages/list.js index 401c13c1696..8318ca85160 100644 --- a/app/routes/admin/messages/list.js +++ b/app/routes/admin/messages/list.js @@ -1,7 +1,32 @@ import Route from '@ember/routing/route'; +import EmberTableRouteMixin from 'open-event-frontend/mixins/ember-table-route'; -export default Route.extend({ - model() { - return this.modelFor('admin.messages'); +export default class extends Route.extend(EmberTableRouteMixin) { + + async model(params) { + return this.asArray(this.modelFor('admin.messages')); } -}); + +} +// } +// import Route from '@ember/routing/route'; +// import EmberTableRouteMixin from 'open-event-frontend/mixins/ember-table-route'; + +// export default class extends Route.extend(EmberTableRouteMixin) { +// titleToken() { +// return this.l10n.t('Mail Logs'); +// } + +// async model(params) { +// const searchField = 'recipient'; +// let filterOptions = this.applySearchFilters([], params, searchField); + +// let queryString = { +// filter : filterOptions, +// 'page[size]' : params.per_page || 100, +// 'page[number]' : params.page || 1 +// }; +// queryString = this.applySortFilters(queryString, params); +// return this.asArray(this.store.query('mail', queryString)); +// } +// } \ No newline at end of file diff --git a/app/templates/admin/messages/list.hbs b/app/templates/admin/messages/list.hbs index e0334e28997..6f1177d80a7 100644 --- a/app/templates/admin/messages/list.hbs +++ b/app/templates/admin/messages/list.hbs @@ -1,7 +1,16 @@
- {{events/events-table columns=columns data=model - useNumericPagination=true - showGlobalFilter=true - showPageSize=true + {{tables/default columns=columns + rows=model.data + currentPage=page + pageSize=per_page + searchQuery=search + sortBy=sort_by + sortDir=sort_dir + metaData=model.meta + filterOptions=filterOptions + widthConstraint="eq-container" + resizeMode="fluid" + fillMode="equal-column" + }}
diff --git a/app/templates/components/ui-table/cell/cell-title-message.hbs b/app/templates/components/ui-table/cell/cell-title-message.hbs index ce84b5ae78f..f7051adc391 100644 --- a/app/templates/components/ui-table/cell/cell-title-message.hbs +++ b/app/templates/components/ui-table/cell/cell-title-message.hbs @@ -1,5 +1,5 @@
- {{#if (eq column.subject 'emailSubject')}} + {{#if (eq props.options.subject 'emailSubject')}} {{sanitize record.emailSubject}} {{else}} {{#if record.notificationTitle}} @@ -7,9 +7,9 @@ {{/if}} {{/if}}
- {{#if (eq column.message 'emailMessage')}} + {{#if (eq props.options.message 'emailMessage')}}

{{sanitize record.emailMessage}}

- {{else if (eq column.message 'notificationMessage')}} + {{else if (eq props.options.message 'notificationMessage')}} {{#if record.notificationMessage}}

{{sanitize record.notificationMessage}}

{{/if}} From 4cc28905c2910fcdc6ad3a63d41e0e346f267eff Mon Sep 17 00:00:00 2001 From: kushthedude Date: Fri, 2 Aug 2019 18:09:37 +0530 Subject: [PATCH 2/5] Final Changes --- app/controllers/admin/messages/list.js | 103 ++++++++++-------- app/routes/admin/messages/list.js | 32 ++---- .../ui-table/cell/cell-title-message.hbs | 16 +-- 3 files changed, 74 insertions(+), 77 deletions(-) diff --git a/app/controllers/admin/messages/list.js b/app/controllers/admin/messages/list.js index 684768a2370..fcf71f2f200 100644 --- a/app/controllers/admin/messages/list.js +++ b/app/controllers/admin/messages/list.js @@ -3,52 +3,63 @@ import { computed } from '@ember/object'; import EmberTableControllerMixin from 'open-event-frontend/mixins/ember-table-controller'; export default class extends Controller.extend(EmberTableControllerMixin) { - @computed() - get columns() { - return [ - { - name : 'Recipients', - valuePath : 'recipient' - }, - { - name : 'Trigger', - valuePath : 'action' - }, - { - name : 'Email Message', - valuePath : 'emailMessage', - - cellComponent : 'ui-table/cell/cell-title-message', - options : { - subject : 'emailSubject', - message : 'emailMessage' - } - }, - { - name : 'Notification Message', - valuePath : 'notificationMessage', - cellComponent : 'ui-table/cell/cell-title-message', - options : { - subject : 'notificationSubject', - message : 'notificationMessage' +per_page = 100; + +sort_by = 'time'; + +sort_dir = 'ASC'; + +@computed() +get columns() { + return [ + { + name : 'Recipients', + valuePath : 'recipient', + headerComponent : 'tables/headers/sort', + isSortable : true + }, + { + name : 'Trigger', + valuePath : 'action' + }, + { + name : 'Email Message', + valuePath : 'emailMessage', + + cellComponent : 'ui-table/cell/cell-title-message', + extraValuePaths : ['emailSubject', 'emailMessage'], + options : { + subject : 'emailSubject', + message : 'emailMessage' } - }, - { - name : 'Options', - valuePath : 'option', - cellComponent : 'ui-table/cell/admin/messages/cell-options' - }, - { - name : 'Time/Date Sent Out', - valuePath : 'sentAt', - cellComponent : 'ui-table/cell/cell-simple-date', - options : { - dateFormat: 'MMMM DD, YYYY - HH:mm A' - } - } + }, + { + name : 'Notification Message', + valuePath : 'notificationMessage', + cellComponent : 'ui-table/cell/cell-title-message', + extraValuePaths : ['notificationTitle', 'notificationMessage'], + options : { + subject : 'notificationTitle', + message : 'notificationMessage' + } + }, + { + name : 'Options', + valuePath : 'option', + cellComponent : 'ui-table/cell/admin/messages/cell-options' + }, + { + name : 'Time/Date Sent Out', + valuePath : 'sentAt', + headerComponent : 'tables/headers/sort', + isSortable : true, + cellComponent : 'ui-table/cell/cell-simple-date', + options : { + dateFormat: 'MMMM DD, YYYY - HH:mm A' + } + } - ]; - } + ]; } - - \ No newline at end of file +} + diff --git a/app/routes/admin/messages/list.js b/app/routes/admin/messages/list.js index 8318ca85160..acf83bc58cd 100644 --- a/app/routes/admin/messages/list.js +++ b/app/routes/admin/messages/list.js @@ -4,29 +4,15 @@ import EmberTableRouteMixin from 'open-event-frontend/mixins/ember-table-route'; export default class extends Route.extend(EmberTableRouteMixin) { async model(params) { - return this.asArray(this.modelFor('admin.messages')); + const searchField = 'recipient'; + let filterOptions = this.applySearchFilters([], params, searchField); + let queryString = { + filter : filterOptions, + 'page[size]' : params.per_page || 100, + 'page[number' : params.page || 1 + }; + queryString = this.applySortFilters(queryString, params); + return this.asArray(this.modelFor('admin.messages', queryString)); } } -// } -// import Route from '@ember/routing/route'; -// import EmberTableRouteMixin from 'open-event-frontend/mixins/ember-table-route'; - -// export default class extends Route.extend(EmberTableRouteMixin) { -// titleToken() { -// return this.l10n.t('Mail Logs'); -// } - -// async model(params) { -// const searchField = 'recipient'; -// let filterOptions = this.applySearchFilters([], params, searchField); - -// let queryString = { -// filter : filterOptions, -// 'page[size]' : params.per_page || 100, -// 'page[number]' : params.page || 1 -// }; -// queryString = this.applySortFilters(queryString, params); -// return this.asArray(this.store.query('mail', queryString)); -// } -// } \ No newline at end of file diff --git a/app/templates/components/ui-table/cell/cell-title-message.hbs b/app/templates/components/ui-table/cell/cell-title-message.hbs index f7051adc391..43e6dd655ef 100644 --- a/app/templates/components/ui-table/cell/cell-title-message.hbs +++ b/app/templates/components/ui-table/cell/cell-title-message.hbs @@ -1,17 +1,17 @@
{{#if (eq props.options.subject 'emailSubject')}} - {{sanitize record.emailSubject}} - {{else}} - {{#if record.notificationTitle}} - {{sanitize record.notificationTitle}} - {{/if}} + {{sanitize extraRecords.emailSubject}} + {{else if (eq props.options.subject 'notificationTitle')}} + {{#if extraRecords.notificationTitle}} + {{sanitize extraRecords.notificationTitle}} + {{/if}} {{/if}}
{{#if (eq props.options.message 'emailMessage')}} -

{{sanitize record.emailMessage}}

+

{{sanitize extraRecords.emailMessage}}

{{else if (eq props.options.message 'notificationMessage')}} - {{#if record.notificationMessage}} -

{{sanitize record.notificationMessage}}

+ {{#if extraRecords.notificationMessage}} +

{{sanitize extraRecords.notificationMessage}}

{{/if}} {{/if}}
From b58c1669fd2fe24f7ced5d439e082dc242005ada Mon Sep 17 00:00:00 2001 From: kushthedude Date: Fri, 2 Aug 2019 18:29:24 +0530 Subject: [PATCH 3/5] Making cell options correct --- app/controllers/admin/messages/list.js | 7 ++++--- .../ui-table/cell/admin/messages/cell-options.hbs | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/controllers/admin/messages/list.js b/app/controllers/admin/messages/list.js index fcf71f2f200..bf99a42c879 100644 --- a/app/controllers/admin/messages/list.js +++ b/app/controllers/admin/messages/list.js @@ -44,9 +44,10 @@ get columns() { } }, { - name : 'Options', - valuePath : 'option', - cellComponent : 'ui-table/cell/admin/messages/cell-options' + name : 'Options', + valuePath : 'option', + extraValuePaths : ['mailStatus', 'notificationStatus', 'userControlStatus'], + cellComponent : 'ui-table/cell/admin/messages/cell-options' }, { name : 'Time/Date Sent Out', diff --git a/app/templates/components/ui-table/cell/admin/messages/cell-options.hbs b/app/templates/components/ui-table/cell/admin/messages/cell-options.hbs index 0c86dcb14cd..3572189a1c8 100644 --- a/app/templates/components/ui-table/cell/admin/messages/cell-options.hbs +++ b/app/templates/components/ui-table/cell/admin/messages/cell-options.hbs @@ -1,12 +1,12 @@
- {{input type='checkbox' name='mail_status' checked=record.mailStatus}} + {{input type='checkbox' name='mail_status' checked=extraRecords.mailStatus}}
- {{input type='checkbox' name='notification_status' checked=record.notificationStatus}} + {{input type='checkbox' name='notification_status' checked=extraRecords.notificationStatus}}
- {{input type='checkbox' name='user_control_status' checked=record.userControlStatus}} + {{input type='checkbox' name='user_control_status' checked=extraRecords.userControlStatus}}
From 628831dfc725c7bcc967ca2d9546294ba92038c7 Mon Sep 17 00:00:00 2001 From: kushthedude Date: Sat, 10 Aug 2019 18:14:46 +0530 Subject: [PATCH 4/5] Removing one extraValue --- app/controllers/admin/messages/list.js | 4 ++-- app/templates/components/ui-table/cell/cell-title-message.hbs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/messages/list.js b/app/controllers/admin/messages/list.js index bf99a42c879..5a0261b3b2e 100644 --- a/app/controllers/admin/messages/list.js +++ b/app/controllers/admin/messages/list.js @@ -27,7 +27,7 @@ get columns() { valuePath : 'emailMessage', cellComponent : 'ui-table/cell/cell-title-message', - extraValuePaths : ['emailSubject', 'emailMessage'], + extraValuePaths : ['emailSubject'], options : { subject : 'emailSubject', message : 'emailMessage' @@ -37,7 +37,7 @@ get columns() { name : 'Notification Message', valuePath : 'notificationMessage', cellComponent : 'ui-table/cell/cell-title-message', - extraValuePaths : ['notificationTitle', 'notificationMessage'], + extraValuePaths : ['notificationTitle'], options : { subject : 'notificationTitle', message : 'notificationMessage' diff --git a/app/templates/components/ui-table/cell/cell-title-message.hbs b/app/templates/components/ui-table/cell/cell-title-message.hbs index 43e6dd655ef..cb51c4940be 100644 --- a/app/templates/components/ui-table/cell/cell-title-message.hbs +++ b/app/templates/components/ui-table/cell/cell-title-message.hbs @@ -8,10 +8,10 @@ {{/if}}
{{#if (eq props.options.message 'emailMessage')}} -

{{sanitize extraRecords.emailMessage}}

+

{{sanitize record}}

{{else if (eq props.options.message 'notificationMessage')}} {{#if extraRecords.notificationMessage}} -

{{sanitize extraRecords.notificationMessage}}

+

{{sanitize record}}

{{/if}} {{/if}}
From c734708e0c4da64a959c72810b1b305d77927b6f Mon Sep 17 00:00:00 2001 From: kushthedude Date: Sat, 10 Aug 2019 18:15:44 +0530 Subject: [PATCH 5/5] Removing one extraValue --- app/templates/components/ui-table/cell/cell-title-message.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/templates/components/ui-table/cell/cell-title-message.hbs b/app/templates/components/ui-table/cell/cell-title-message.hbs index cb51c4940be..0126bb89d93 100644 --- a/app/templates/components/ui-table/cell/cell-title-message.hbs +++ b/app/templates/components/ui-table/cell/cell-title-message.hbs @@ -10,7 +10,7 @@ {{#if (eq props.options.message 'emailMessage')}}

{{sanitize record}}

{{else if (eq props.options.message 'notificationMessage')}} - {{#if extraRecords.notificationMessage}} + {{#if record}}

{{sanitize record}}

{{/if}} {{/if}}