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.

166 lines
3.5 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
3 years ago
3 years ago
5 years ago
5 years ago
  1. <template>
  2. <v-card>
  3. <v-card-title>
  4. <v-btn
  5. class="text-capitalize"
  6. color="primary"
  7. @click.stop="dialogCreate=true"
  8. >
  9. {{ $t('generic.add') }}
  10. </v-btn>
  11. <v-btn
  12. class="text-capitalize ms-2"
  13. :disabled="!canDelete"
  14. outlined
  15. @click.stop="dialogDelete=true"
  16. >
  17. {{ $t('generic.delete') }}
  18. </v-btn>
  19. <v-dialog v-model="dialogCreate">
  20. <form-create
  21. v-model="editedItem"
  22. :error-message="errorMessage"
  23. @cancel="close"
  24. @save="save"
  25. />
  26. </v-dialog>
  27. <v-dialog v-model="dialogDelete">
  28. <form-delete
  29. :selected="selected"
  30. @cancel="dialogDelete=false"
  31. @remove="remove"
  32. />
  33. </v-dialog>
  34. </v-card-title>
  35. <member-list
  36. v-model="selected"
  37. :items="items"
  38. :is-loading="isLoading"
  39. @edit="editItem"
  40. />
  41. </v-card>
  42. </template>
  43. <script lang="ts">
  44. import Vue from 'vue'
  45. import MemberList from '@/components/member/MemberList.vue'
  46. import FormDelete from '@/components/member/FormDelete.vue'
  47. import FormCreate from '~/components/member/FormCreate.vue'
  48. import { MemberDTO } from '~/services/application/member/memberData'
  49. export default Vue.extend({
  50. components: {
  51. MemberList,
  52. FormCreate,
  53. FormDelete
  54. },
  55. layout: 'project',
  56. validate({ params }) {
  57. return /^\d+$/.test(params.id)
  58. },
  59. data() {
  60. return {
  61. dialogCreate: false,
  62. dialogDelete: false,
  63. editedIndex: -1,
  64. editedItem: {
  65. user: -1,
  66. role: -1,
  67. username: '',
  68. rolename: ''
  69. } as MemberDTO,
  70. defaultItem: {
  71. user: -1,
  72. role: -1,
  73. username: '',
  74. rolename: ''
  75. } as MemberDTO,
  76. items: [] as MemberDTO[],
  77. selected: [] as MemberDTO[],
  78. isLoading: false,
  79. errorMessage: ''
  80. }
  81. },
  82. async fetch() {
  83. this.isLoading = true
  84. try {
  85. this.items = await this.$services.member.list(this.projectId)
  86. } catch(e) {
  87. this.$router.push(`/projects/${this.projectId}`)
  88. } finally {
  89. this.isLoading = false
  90. }
  91. },
  92. computed: {
  93. canDelete(): boolean {
  94. return this.selected.length > 0
  95. },
  96. projectId(): string {
  97. return this.$route.params.id
  98. }
  99. },
  100. methods: {
  101. async create() {
  102. try {
  103. await this.$services.member.create(this.projectId, this.editedItem)
  104. this.close()
  105. this.$fetch()
  106. } catch(e) {
  107. this.errorMessage = e.message
  108. }
  109. },
  110. async update() {
  111. try {
  112. await this.$services.member.update(this.projectId, this.editedItem)
  113. this.close()
  114. this.$fetch()
  115. } catch(e) {
  116. this.errorMessage = e.message
  117. }
  118. },
  119. save() {
  120. if (this.editedIndex > -1) {
  121. this.update()
  122. } else {
  123. this.create()
  124. }
  125. },
  126. close() {
  127. this.dialogCreate = false
  128. this.errorMessage = ''
  129. this.$nextTick(() => {
  130. this.editedItem = Object.assign({}, this.defaultItem)
  131. this.editedIndex = -1
  132. })
  133. },
  134. async remove() {
  135. await this.$services.member.bulkDelete(this.projectId, this.selected)
  136. this.$fetch()
  137. this.dialogDelete = false
  138. this.selected = []
  139. },
  140. editItem(item: MemberDTO) {
  141. this.editedIndex = this.items.indexOf(item)
  142. this.editedItem = Object.assign({}, item)
  143. this.dialogCreate = true
  144. }
  145. }
  146. })
  147. </script>
  148. <style scoped>
  149. ::v-deep .v-dialog {
  150. width: 800px;
  151. }
  152. </style>