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.

131 lines
3.0 KiB

  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="items"
  37. :is-loading="isLoading"
  38. />
  39. </v-card>
  40. </template>
  41. <script lang="ts">
  42. import Vue from 'vue'
  43. import { mapGetters } from 'vuex'
  44. import ProjectList from '@/components/project/ProjectList.vue'
  45. import { ProjectDTO, ProjectWriteDTO } from '~/services/application/project/projectData'
  46. import FormDelete from '~/components/project/FormDelete.vue'
  47. import FormCreate from '~/components/project/FormCreate.vue'
  48. export default Vue.extend({
  49. layout: 'projects',
  50. middleware: ['check-auth', 'auth'],
  51. components: {
  52. FormCreate,
  53. FormDelete,
  54. ProjectList,
  55. },
  56. async fetch() {
  57. this.isLoading = true
  58. this.items = await this.$services.project.list()
  59. this.isLoading = false
  60. },
  61. data() {
  62. return {
  63. dialogCreate: false,
  64. dialogDelete: false,
  65. editedItem: {
  66. name: '',
  67. description: '',
  68. projectType: 'DocumentClassification',
  69. enableRandomOrder: false,
  70. enableShareAnnotation: false,
  71. singleClassClassification: false,
  72. allowOverlapping: false,
  73. graphemeMode: false
  74. } as ProjectWriteDTO,
  75. defaultItem: {
  76. name: '',
  77. description: '',
  78. projectType: 'DocumentClassification',
  79. enableRandomOrder: false,
  80. enableShareAnnotation: false,
  81. singleClassClassification: false,
  82. allowOverlapping: false,
  83. graphemeMode: false
  84. } as ProjectWriteDTO,
  85. items: [] as ProjectDTO[],
  86. selected: [] as ProjectDTO[],
  87. isLoading: false
  88. }
  89. },
  90. computed: {
  91. ...mapGetters('auth', ['isStaff']),
  92. canDelete(): boolean {
  93. return this.selected.length > 0
  94. },
  95. },
  96. methods: {
  97. async create() {
  98. const project = await this.$services.project.create(this.editedItem)
  99. this.$router.push(`/projects/${project.id}`)
  100. this.close()
  101. },
  102. close() {
  103. this.dialogCreate = false
  104. this.$nextTick(() => {
  105. this.editedItem = Object.assign({}, this.defaultItem)
  106. })
  107. },
  108. async remove() {
  109. await this.$services.project.bulkDelete(this.selected)
  110. this.$fetch()
  111. this.dialogDelete = false
  112. this.selected = []
  113. },
  114. }
  115. })
  116. </script>
  117. <style scoped>
  118. ::v-deep .v-dialog {
  119. width: 800px;
  120. }
  121. </style>