admin-groups-edit.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <template lang='pug'>
  2. v-container(fluid, grid-list-lg)
  3. v-layout(row wrap)
  4. v-flex(xs12)
  5. .admin-header
  6. v-icon(size='80', color='grey lighten-2') people
  7. .admin-header-title
  8. .headline.blue--text.text--darken-2 Edit Group
  9. .subheading.grey--text {{name}}
  10. v-btn(color='primary', fab, absolute, bottom, right, small, to='/groups'): v-icon arrow_upward
  11. v-tabs(v-model='tab', :color='$vuetify.dark ? "primary" : "grey lighten-4"', fixed-tabs, :slider-color='$vuetify.dark ? "white" : "primary"', show-arrows)
  12. v-tab(key='properties') Properties
  13. v-tab(key='rights') Permissions
  14. v-tab(key='users') Users
  15. v-tab-item(key='properties', :transition='false', :reverse-transition='false')
  16. v-card
  17. v-card-text
  18. v-text-field(v-model='name', label='Group Name', counter='255', prepend-icon='people')
  19. v-card-actions.pa-3
  20. v-btn(color='primary', @click='updateGroup')
  21. v-icon(left) check
  22. | Save Changes
  23. .caption.ml-4.grey--text ID: {{group.id}}
  24. v-spacer
  25. v-dialog(v-model='deleteGroupDialog', max-width='500')
  26. v-btn(color='red', flat, @click='', slot='activator')
  27. v-icon(left) delete
  28. | Delete Group
  29. v-card
  30. .dialog-header.is-red Delete Group?
  31. v-card-text Are you sure you want to delete group #[strong {{ name }}]? All users will be unassigned from this group.
  32. v-card-actions
  33. v-spacer
  34. v-btn(flat, @click='deleteGroupDialog = false') Cancel
  35. v-btn(color='red', dark, @click='deleteGroup') Delete
  36. v-tab-item(key='rights', :transition='false', :reverse-transition='false')
  37. v-card
  38. v-card-title.pb-0
  39. v-subheader
  40. v-icon.mr-2 border_color
  41. .subheading Read and Write
  42. v-spacer
  43. v-btn(flat, outline)
  44. v-icon(left) arrow_drop_down
  45. | Load Preset
  46. v-btn(flat, outline)
  47. v-icon(left) vertical_align_bottom
  48. | Import Rules
  49. .pa-3.pl-4
  50. criterias
  51. v-divider.my-0
  52. v-card-title.pb-0
  53. v-subheader
  54. v-icon.mr-2 pageview
  55. .subheading Read Only
  56. v-spacer
  57. v-btn(flat, outline)
  58. v-icon(left) arrow_drop_down
  59. | Load Preset
  60. v-btn(flat, outline)
  61. v-icon(left) vertical_align_bottom
  62. | Import Rules
  63. .pa-3.pl-4
  64. criterias
  65. v-divider.my-0
  66. v-card-title.pb-0
  67. v-subheader Legend
  68. .px-4.pb-4
  69. .body-1.px-1.py-2 Any number of rules can be used at the same time. However, some rules requires more processing time than others. Rule types are color-coded as followed:
  70. .caption
  71. v-icon(color='blue') stop
  72. span Fast rules. None or insignificant latency introduced to all page loads.
  73. .caption
  74. v-icon(color='orange') stop
  75. span Medium rules. Some latency added to all page loads.
  76. .caption
  77. v-icon(color='red') stop
  78. span Slow rules. May adds noticeable latency to all page loads. Avoid using in multiple rules.
  79. v-tab-item(key='users', :transition='false', :reverse-transition='false')
  80. v-card
  81. v-card-title.pb-0
  82. v-btn(color='primary', @click='searchUserDialog = true')
  83. v-icon(left) assignment_ind
  84. | Assign User
  85. v-data-table(
  86. :items='group.users',
  87. :headers='headers',
  88. :search='search',
  89. :pagination.sync='pagination',
  90. :rows-per-page-items='[15]'
  91. hide-actions
  92. )
  93. template(slot='items', slot-scope='props')
  94. tr(:active='props.selected')
  95. td.text-xs-right {{ props.item.id }}
  96. td {{ props.item.name }}
  97. td {{ props.item.email }}
  98. td
  99. v-menu(bottom, right, min-width='200')
  100. v-btn(icon, slot='activator'): v-icon.grey--text.text--darken-1 more_horiz
  101. v-list
  102. v-list-tile(@click='unassignUser(props.item.id)')
  103. v-list-tile-action: v-icon(color='orange') highlight_off
  104. v-list-tile-content
  105. v-list-tile-title Unassign
  106. template(slot='no-data')
  107. v-alert.ma-3(icon='warning', :value='true', outline) No users to display.
  108. .text-xs-center.py-2(v-if='users.length > 15')
  109. v-pagination(v-model='pagination.page', :length='pages')
  110. user-search(v-model='searchUserDialog', @select='assignUser')
  111. </template>
  112. <script>
  113. import Criterias from '../common/criterias.vue'
  114. import UserSearch from '../common/user-search.vue'
  115. import groupQuery from 'gql/admin/groups/groups-query-single.gql'
  116. import assignUserMutation from 'gql/admin/groups/groups-mutation-assign.gql'
  117. import deleteGroupMutation from 'gql/admin/groups/groups-mutation-delete.gql'
  118. import unassignUserMutation from 'gql/admin/groups/groups-mutation-unassign.gql'
  119. import updateGroupMutation from 'gql/admin/groups/groups-mutation-update.gql'
  120. export default {
  121. components: {
  122. Criterias,
  123. UserSearch
  124. },
  125. data() {
  126. return {
  127. group: {
  128. id: 0,
  129. name: '',
  130. users: []
  131. },
  132. name: '',
  133. deleteGroupDialog: false,
  134. searchUserDialog: false,
  135. pagination: {},
  136. users: [],
  137. headers: [
  138. { text: 'ID', value: 'id', width: 50, align: 'right' },
  139. { text: 'Name', value: 'name' },
  140. { text: 'Email', value: 'email' },
  141. { text: '', value: 'actions', sortable: false, width: 50 }
  142. ],
  143. search: '',
  144. tab: '1'
  145. }
  146. },
  147. computed: {
  148. pages () {
  149. if (this.pagination.rowsPerPage == null || this.pagination.totalItems == null) {
  150. return 0
  151. }
  152. return Math.ceil(this.pagination.totalItems / this.pagination.rowsPerPage)
  153. }
  154. },
  155. watch: {
  156. group(newValue, oldValue) {
  157. this.name = newValue.name
  158. }
  159. },
  160. methods: {
  161. async updateGroup() {
  162. try {
  163. await this.$apollo.mutate({
  164. mutation: updateGroupMutation,
  165. variables: {
  166. id: this.group.id,
  167. name: this.name
  168. },
  169. watchLoading (isLoading) {
  170. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-groups-update')
  171. }
  172. })
  173. this.$store.commit('showNotification', {
  174. style: 'success',
  175. message: `Group changes have been saved.`,
  176. icon: 'check'
  177. })
  178. } catch (err) {
  179. this.$store.commit('showNotification', {
  180. style: 'red',
  181. message: err.message,
  182. icon: 'warning'
  183. })
  184. }
  185. },
  186. async deleteGroup() {
  187. this.deleteGroupDialog = false
  188. try {
  189. await this.$apollo.mutate({
  190. mutation: deleteGroupMutation,
  191. variables: {
  192. id: this.group.id
  193. },
  194. watchLoading (isLoading) {
  195. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-groups-delete')
  196. }
  197. })
  198. this.$store.commit('showNotification', {
  199. style: 'success',
  200. message: `Group ${this.group.name} has been deleted.`,
  201. icon: 'delete'
  202. })
  203. this.$router.replace('/groups')
  204. } catch (err) {
  205. this.$store.commit('showNotification', {
  206. style: 'red',
  207. message: err.message,
  208. icon: 'warning'
  209. })
  210. }
  211. },
  212. async assignUser(id) {
  213. try {
  214. await this.$apollo.mutate({
  215. mutation: assignUserMutation,
  216. variables: {
  217. groupId: this.group.id,
  218. userId: id
  219. },
  220. watchLoading (isLoading) {
  221. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-groups-assign')
  222. }
  223. })
  224. this.$store.commit('showNotification', {
  225. style: 'success',
  226. message: `User has been assigned to ${this.group.name}.`,
  227. icon: 'assignment_ind'
  228. })
  229. this.$apollo.queries.group.refetch()
  230. } catch (err) {
  231. this.$store.commit('showNotification', {
  232. style: 'red',
  233. message: err.message,
  234. icon: 'warning'
  235. })
  236. }
  237. },
  238. async unassignUser(id) {
  239. try {
  240. await this.$apollo.mutate({
  241. mutation: unassignUserMutation,
  242. variables: {
  243. groupId: this.group.id,
  244. userId: id
  245. },
  246. watchLoading (isLoading) {
  247. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-groups-unassign')
  248. }
  249. })
  250. this.$store.commit('showNotification', {
  251. style: 'success',
  252. message: `User has been unassigned from ${this.group.name}.`,
  253. icon: 'assignment_ind'
  254. })
  255. this.$apollo.queries.group.refetch()
  256. } catch (err) {
  257. this.$store.commit('showNotification', {
  258. style: 'red',
  259. message: err.message,
  260. icon: 'warning'
  261. })
  262. }
  263. }
  264. },
  265. apollo: {
  266. group: {
  267. query: groupQuery,
  268. variables() {
  269. return {
  270. id: this.$route.params.id
  271. }
  272. },
  273. fetchPolicy: 'network-only',
  274. update: (data) => data.groups.single,
  275. watchLoading (isLoading) {
  276. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-groups-refresh')
  277. }
  278. }
  279. }
  280. }
  281. </script>
  282. <style lang='scss'>
  283. </style>