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.

149 lines
3.4 KiB

3 years ago
3 years ago
3 years ago
3 years ago
  1. <template>
  2. <v-card>
  3. <v-card-title v-if="isStaff">
  4. <v-btn
  5. class="text-capitalize"
  6. color="primary"
  7. @click.stop="dialogCreate=true"
  8. >
  9. {{ $t('generic.create') }}
  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-bind.sync="editedItem"
  22. @cancel="close"
  23. @save="create"
  24. />
  25. </v-dialog>
  26. <v-dialog v-model="dialogDelete">
  27. <form-delete
  28. :selected="selected"
  29. @cancel="dialogDelete=false"
  30. @remove="remove"
  31. />
  32. </v-dialog>
  33. </v-card-title>
  34. <project-list
  35. v-model="selected"
  36. :items="projects.items"
  37. :is-loading="isLoading"
  38. :total="projects.count"
  39. @update:query="updateQuery"
  40. />
  41. </v-card>
  42. </template>
  43. <script lang="ts">
  44. import _ from 'lodash'
  45. import Vue from 'vue'
  46. import { mapGetters } from 'vuex'
  47. import ProjectList from '@/components/project/ProjectList.vue'
  48. import { ProjectDTO, ProjectWriteDTO, ProjectListDTO } from '~/services/application/project/projectData'
  49. import FormDelete from '~/components/project/FormDelete.vue'
  50. import FormCreate from '~/components/project/FormCreate.vue'
  51. export default Vue.extend({
  52. components: {
  53. FormCreate,
  54. FormDelete,
  55. ProjectList,
  56. },
  57. layout: 'projects',
  58. middleware: ['check-auth', 'auth'],
  59. data() {
  60. return {
  61. dialogCreate: false,
  62. dialogDelete: false,
  63. editedItem: {
  64. name: '',
  65. description: '',
  66. projectType: 'DocumentClassification',
  67. enableRandomOrder: false,
  68. enableShareAnnotation: false,
  69. singleClassClassification: false,
  70. allowOverlapping: false,
  71. graphemeMode: false,
  72. useRelation: false,
  73. } as ProjectWriteDTO,
  74. defaultItem: {
  75. name: '',
  76. description: '',
  77. projectType: 'DocumentClassification',
  78. enableRandomOrder: false,
  79. enableShareAnnotation: false,
  80. singleClassClassification: false,
  81. allowOverlapping: false,
  82. graphemeMode: false,
  83. useRelation: false,
  84. } as ProjectWriteDTO,
  85. projects: {} as ProjectListDTO,
  86. selected: [] as ProjectDTO[],
  87. isLoading: false
  88. }
  89. },
  90. async fetch() {
  91. this.isLoading = true
  92. this.projects = await this.$services.project.list(this.$route.query)
  93. this.isLoading = false
  94. },
  95. computed: {
  96. ...mapGetters('auth', ['isStaff']),
  97. canDelete(): boolean {
  98. return this.selected.length > 0
  99. },
  100. },
  101. watch: {
  102. '$route.query': _.debounce(function() {
  103. // @ts-ignore
  104. this.$fetch()
  105. }, 1000
  106. ),
  107. },
  108. methods: {
  109. async create() {
  110. const project = await this.$services.project.create(this.editedItem)
  111. this.$router.push(`/projects/${project.id}`)
  112. this.close()
  113. },
  114. close() {
  115. this.dialogCreate = false
  116. this.$nextTick(() => {
  117. this.editedItem = Object.assign({}, this.defaultItem)
  118. })
  119. },
  120. async remove() {
  121. await this.$services.project.bulkDelete(this.selected)
  122. this.$fetch()
  123. this.dialogDelete = false
  124. this.selected = []
  125. },
  126. updateQuery(query: object) {
  127. this.$router.push(query)
  128. }
  129. }
  130. })
  131. </script>
  132. <style scoped>
  133. ::v-deep .v-dialog {
  134. width: 800px;
  135. }
  136. </style>