|
1 | 1 | import Controller from '@ember/controller';
|
2 |
| -import { computed } from '@ember/object'; |
3 |
| - |
4 |
| -export default Controller.extend({ |
5 |
| - hasRestorePrivileges: computed('authManager.currentUser.isAdmin', function() { |
6 |
| - return this.get('authManager.currentUser.isSuperAdmin') || this.get('authManager.currentUser.isAdmin'); |
7 |
| - }), |
8 |
| - columns: [ |
9 |
| - { |
10 |
| - propertyName : 'first-name', |
11 |
| - title : 'Name', |
12 |
| - template : 'components/ui-table/cell/admin/users/cell-first-name', |
13 |
| - disableSorting : true, |
14 |
| - disableFiltering : true |
15 |
| - }, |
16 |
| - { |
17 |
| - propertyName : 'email', |
18 |
| - title : 'Email', |
19 |
| - disableSorting : true, |
20 |
| - disableFiltering : true |
21 |
| - }, |
22 |
| - { |
23 |
| - propertyName : 'status', |
24 |
| - title : 'Status', |
25 |
| - template : 'components/ui-table/cell/admin/users/cell-status', |
26 |
| - disableSorting : true, |
27 |
| - disableFiltering : true |
28 |
| - }, |
29 |
| - { |
30 |
| - propertyName : 'system-roles', |
31 |
| - title : 'System Roles', |
32 |
| - template : 'components/ui-table/cell/admin/users/cell-system-roles', |
33 |
| - disableSorting : true, |
34 |
| - disableFiltering : true |
35 |
| - }, |
36 |
| - { |
37 |
| - propertyName : 'event-roles', |
38 |
| - title : 'Event Roles', |
39 |
| - template : 'components/ui-table/cell/admin/users/cell-event-roles', |
40 |
| - disableSorting : true, |
41 |
| - disableFiltering : true |
42 |
| - }, |
43 |
| - { |
44 |
| - propertyName : 'user-links', |
45 |
| - title : 'User Links', |
46 |
| - template : 'components/ui-table/cell/admin/users/cell-user-links', |
47 |
| - disableSorting : true, |
48 |
| - disableFiltering : true |
49 |
| - }, |
50 |
| - { |
51 |
| - propertyName : 'created-at', |
52 |
| - title : 'Member Since', |
53 |
| - template : 'components/ui-table/cell/admin/users/cell-created-at' |
54 |
| - }, |
55 |
| - { |
56 |
| - propertyName : 'lastAccessedAt', |
57 |
| - title : 'Last Accessed', |
58 |
| - template : 'components/ui-table/cell/cell-simple-date', |
59 |
| - dateFormat : 'MMMM DD, YYYY - hh:mm A', |
60 |
| - disableSorting : true, |
61 |
| - disableFiltering : true |
62 |
| - }, |
63 |
| - { |
64 |
| - template : 'components/ui-table/cell/admin/users/cell-actions', |
65 |
| - title : 'Actions', |
66 |
| - disableSorting : true, |
67 |
| - disableFiltering : true |
| 2 | +import { computed, action } from '@ember/object'; |
| 3 | +import { or } from '@ember/object/computed'; |
| 4 | +import EmberTableControllerMixin from 'open-event-frontend/mixins/ember-table-controller'; |
| 5 | + |
| 6 | + |
| 7 | +export default class extends Controller.extend(EmberTableControllerMixin) { |
| 8 | + @or('authManager.currentUser.isSuperAdmin', 'authManager.currentUser.isAdmin') hasRestorePrivileges; |
| 9 | + |
| 10 | + @computed() |
| 11 | + get columns() { |
| 12 | + return [ |
| 13 | + { |
| 14 | + name : 'Name', |
| 15 | + valuePath : 'id', |
| 16 | + extraValuePaths : ['firstName', 'deletedAt'], |
| 17 | + cellComponent : 'ui-table/cell/admin/users/cell-first-name', |
| 18 | + options : { |
| 19 | + hasRestorePrivileges: this.hasRestorePrivileges |
| 20 | + }, |
| 21 | + actions: { |
| 22 | + moveToUserDetails : this.moveToUserDetails.bind(this), |
| 23 | + deleteUser : this.deleteUser.bind(this), |
| 24 | + openEditModal : this.openEditModal.bind(this), |
| 25 | + restoreUser : this.restoreUser.bind(this) |
| 26 | + } |
| 27 | + |
| 28 | + }, |
| 29 | + { |
| 30 | + name : 'Email', |
| 31 | + valuePath : 'email' |
| 32 | + |
| 33 | + |
| 34 | + }, |
| 35 | + { |
| 36 | + name : 'Status', |
| 37 | + valuePath : 'status', |
| 38 | + cellComponent : 'ui-table/cell/admin/users/cell-status' |
| 39 | + |
| 40 | + |
| 41 | + }, |
| 42 | + { |
| 43 | + name : 'System Roles', |
| 44 | + valuePath : 'isSuperAdmin', |
| 45 | + extraValuePaths : ['isAdmin', 'isVerified'], |
| 46 | + cellComponent : 'ui-table/cell/admin/users/cell-system-roles' |
| 47 | + |
| 48 | + |
| 49 | + }, |
| 50 | + { |
| 51 | + name : 'Event Roles', |
| 52 | + valuePath : 'isSuperAdmin', |
| 53 | + extraValuePaths : ['isAdmin', 'isUserOwner', 'ownerEvents', |
| 54 | + 'isUserOrganizer', 'organizerEvents', 'isUserCoorganizer', 'coorganizerEvents', |
| 55 | + 'isUserTrackOrganizer', 'trackOrganizerEvents', 'isUserRegistrar', 'registrarEvents', |
| 56 | + 'isUserModerator', 'moderatorEvents', 'isMarketer', 'marketerEvents', 'isSalesAdmin', |
| 57 | + 'salesAdminEvents'], |
| 58 | + cellComponent: 'ui-table/cell/admin/users/cell-event-roles' |
| 59 | + |
| 60 | + |
| 61 | + }, |
| 62 | + { |
| 63 | + name : 'User Links', |
| 64 | + valuePath : 'id', |
| 65 | + cellComponent : 'ui-table/cell/admin/users/cell-user-links' |
| 66 | + |
| 67 | + |
| 68 | + }, |
| 69 | + { |
| 70 | + name : 'Member Since', |
| 71 | + valuePath : 'createdAt', |
| 72 | + cellComponent : 'ui-table/cell/admin/users/cell-created-at' |
| 73 | + }, |
| 74 | + { |
| 75 | + name : 'Last Accessed', |
| 76 | + valuePath : 'lastAccessedAt', |
| 77 | + cellComponent : 'ui-table/cell/cell-simple-date', |
| 78 | + options : { |
| 79 | + dateFormat: 'MMMM DD, YYYY - hh:mm A' |
| 80 | + } |
| 81 | + } |
| 82 | + ]; |
| 83 | + } |
| 84 | + |
| 85 | + @action |
| 86 | + moveToUserDetails(id) { |
| 87 | + this.transitionToRoute('admin.users.view', id); |
| 88 | + } |
| 89 | + @action |
| 90 | + async deleteUser(user_id) { |
| 91 | + this.set('isLoading', true); |
| 92 | + try { |
| 93 | + let user = this.store.peekRecord('user', user_id, { backgroundReload: false }); |
| 94 | + await user.destroyRecord(); |
| 95 | + this.notify.success(this.l10n.t('User has been deleted successfully.')); |
| 96 | + |
| 97 | + } catch (e) { |
| 98 | + this.notify.error(this.l10n.t('An unexpected error has occurred.')); |
68 | 99 | }
|
69 |
| - ], |
70 |
| - actions: { |
71 |
| - moveToUserDetails(id) { |
72 |
| - this.transitionToRoute('admin.users.view', id); |
73 |
| - }, |
74 |
| - deleteUser(user) { |
75 |
| - this.set('isLoading', true); |
76 |
| - user.destroyRecord() |
77 |
| - .then(() => { |
78 |
| - this.notify.success(this.l10n.t('User has been deleted successfully.')); |
79 |
| - }) |
80 |
| - .catch(() => { |
81 |
| - this.notify.error(this.l10n.t('An unexpected error has occurred.')); |
82 |
| - }) |
83 |
| - .finally(() => { |
84 |
| - this.set('isLoading', false); |
85 |
| - }); |
86 |
| - }, |
87 |
| - openEditModal(user) { |
88 |
| - this.set('isEditUserModalOpen', true); |
89 |
| - this.set('data', user); |
90 |
| - }, |
91 |
| - restoreUser(user) { |
92 |
| - this.set('isLoading', true); |
| 100 | + this.set('isLoading', false); |
| 101 | + } |
| 102 | + |
| 103 | + @action |
| 104 | + openEditModal(user_id) { |
| 105 | + let user = this.store.peekRecord('user', user_id, { backgroundReload: false }); |
| 106 | + this.setProperties({ |
| 107 | + isEditUserModalOpen : true, |
| 108 | + data : user |
| 109 | + }); |
| 110 | + } |
| 111 | + |
| 112 | + @action |
| 113 | + async restoreUser(user_id) { |
| 114 | + this.set('isLoading', true); |
| 115 | + try { |
| 116 | + let user = this.store.peekRecord('user', user_id, { backgroundReload: false }); |
93 | 117 | user.set('deletedAt', null);
|
94 |
| - user.save({ adapterOptions: { getTrashed: true } }) |
95 |
| - .then(() => { |
96 |
| - this.notify.success(this.l10n.t('User has been restored successfully.')); |
97 |
| - this.send('refreshRoute'); |
98 |
| - }) |
99 |
| - .catch(e => { |
100 |
| - this.notify.error(this.l10n.t('An unexpected error has occurred.')); |
101 |
| - console.warn(e); |
102 |
| - }) |
103 |
| - .finally(() => { |
104 |
| - this.set('isLoading', false); |
105 |
| - }); |
| 118 | + user.save({ adapterOptions: { getTrashed: true } }); |
| 119 | + this.notify.success(this.l10n.t('User has been restored successfully.')); |
| 120 | + } catch (e) { |
| 121 | + this.notify.error(this.l10n.t('An unexpected error has occurred.')); |
| 122 | + console.warn(e); |
106 | 123 | }
|
| 124 | + this.set('isLoading', false); |
107 | 125 | }
|
108 |
| -}); |
| 126 | +} |
0 commit comments