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.

162 lines
3.6 KiB

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