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.

218 lines
5.4 KiB

  1. <template>
  2. <v-content>
  3. <v-container
  4. fluid
  5. fill-height
  6. >
  7. <v-layout
  8. justify-center
  9. >
  10. <v-flex>
  11. <v-card>
  12. <v-card-title>
  13. <v-btn
  14. class="mb-2 text-capitalize"
  15. color="primary"
  16. @click="openAddModal"
  17. >
  18. Add User
  19. </v-btn>
  20. <Modal
  21. ref="childDialogue"
  22. :title="addModal.title"
  23. :button="addModal.button"
  24. >
  25. <v-autocomplete
  26. v-model="selectedUser"
  27. :items="items"
  28. :loading="isLoading"
  29. :search-input.sync="username"
  30. color="white"
  31. hide-no-data
  32. hide-selected
  33. item-text="username"
  34. label="User Search APIs"
  35. placeholder="Start typing to Search"
  36. prepend-icon="mdi-account"
  37. return-object
  38. />
  39. <v-select
  40. :items="roles"
  41. label="Role"
  42. prepend-icon="mdi-account-card-details-outline"
  43. />
  44. </Modal>
  45. <v-btn
  46. class="mb-2 ml-2 text-capitalize"
  47. outlined
  48. :disabled="selected.length === 0"
  49. @click="openRemoveModal"
  50. >
  51. Remove
  52. </v-btn>
  53. <Modal
  54. ref="removeDialogue"
  55. :title="removeModal.title"
  56. :button="removeModal.button"
  57. >
  58. Are you sure you want to remove these users from this project?
  59. <v-list dense>
  60. <v-list-item v-for="(user, i) in selected" :key="i">
  61. <v-list-item-content>
  62. <v-list-item-title>{{ user.name }}</v-list-item-title>
  63. </v-list-item-content>
  64. </v-list-item>
  65. </v-list>
  66. </Modal>
  67. </v-card-title>
  68. <v-data-table
  69. v-model="selected"
  70. :headers="headers"
  71. :items="users"
  72. item-key="name"
  73. :search="search"
  74. show-select
  75. >
  76. <template v-slot:top>
  77. <v-text-field
  78. v-model="search"
  79. prepend-inner-icon="search"
  80. label="Search"
  81. single-line
  82. hide-details
  83. filled
  84. />
  85. </template>
  86. <template v-slot:item.role="props">
  87. <v-edit-dialog
  88. :return-value.sync="props.item.role"
  89. large
  90. persistent
  91. @save="save"
  92. >
  93. <div>{{ props.item.role }}</div>
  94. <template v-slot:input>
  95. <div class="mt-4 title">
  96. Update Role
  97. </div>
  98. </template>
  99. <template v-slot:input>
  100. <v-select
  101. v-model="props.item.role"
  102. :items="roles"
  103. label="Role"
  104. />
  105. </template>
  106. </v-edit-dialog>
  107. </template>
  108. </v-data-table>
  109. </v-card>
  110. </v-flex>
  111. </v-layout>
  112. </v-container>
  113. </v-content>
  114. </template>
  115. <script>
  116. import Modal from '~/components/Modal'
  117. export default {
  118. layout: 'project',
  119. components: {
  120. Modal
  121. },
  122. data: () => ({
  123. search: '',
  124. username: '',
  125. isLoading: false,
  126. selected: [],
  127. selectedUser: null,
  128. roles: ['Admin', 'Member'],
  129. addModal: {
  130. title: 'Add User',
  131. button: 'Add User'
  132. },
  133. removeModal: {
  134. title: 'Remove User',
  135. button: 'Yes, remove'
  136. },
  137. headers: [
  138. {
  139. text: 'Name',
  140. align: 'left',
  141. sortable: false,
  142. value: 'name'
  143. },
  144. { text: 'Role', value: 'role' }
  145. ],
  146. users: [
  147. {
  148. name: 'Hiroki Nakayama',
  149. role: 'Admin'
  150. },
  151. {
  152. name: 'Takahiro Kubo',
  153. role: 'Member'
  154. },
  155. {
  156. name: 'Junya Kamura',
  157. role: 'Member'
  158. },
  159. {
  160. name: 'Yasufumi Taniguchi',
  161. role: 'Member'
  162. },
  163. {
  164. name: 'Ryo Sho',
  165. role: 'Member'
  166. }
  167. ],
  168. items: [
  169. {
  170. id: 1,
  171. username: 'Donald Trump',
  172. Description: 'Daily cat facts'
  173. },
  174. {
  175. id: 2,
  176. username: 'Barack Obama',
  177. Description: 'Pictures of cats from Tumblr'
  178. }
  179. ]
  180. }),
  181. watch: {
  182. username(val) {
  183. // Items have already been requested
  184. if (this.isLoading) return
  185. this.isLoading = true
  186. // Lazily load input items
  187. // GET /users endpoint
  188. // fetch('https://api.publicapis.org/entries')
  189. // .then(res => res.json())
  190. // .then((res) => {
  191. // this.items.push({ username: 'Bush', id: this.items.length + 1 })
  192. // })
  193. // .catch((err) => {
  194. // alert(err)
  195. // })
  196. // .finally(() => (this.isLoading = false))
  197. }
  198. },
  199. methods: {
  200. save() {
  201. // send server
  202. },
  203. openAddModal() {
  204. this.$refs.childDialogue.open()
  205. },
  206. openRemoveModal() {
  207. this.$refs.removeDialogue.open()
  208. }
  209. }
  210. }
  211. </script>