You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

289 lines
9.5 KiB

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