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

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="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. components: {
  50. FormCreate,
  51. FormDelete,
  52. ProjectList,
  53. },
  54. layout: 'projects',
  55. middleware: ['check-auth', 'auth'],
  56. data() {
  57. return {
  58. dialogCreate: false,
  59. dialogDelete: false,
  60. editedItem: {
  61. name: '',
  62. description: '',
  63. projectType: 'DocumentClassification',
  64. enableRandomOrder: false,
  65. enableShareAnnotation: false,
  66. singleClassClassification: false,
  67. allowOverlapping: false,
  68. graphemeMode: false
  69. } as ProjectWriteDTO,
  70. defaultItem: {
  71. name: '',
  72. description: '',
  73. projectType: 'DocumentClassification',
  74. enableRandomOrder: false,
  75. enableShareAnnotation: false,
  76. singleClassClassification: false,
  77. allowOverlapping: false,
  78. graphemeMode: false
  79. } as ProjectWriteDTO,
  80. items: [] as ProjectDTO[],
  81. selected: [] as ProjectDTO[],
  82. isLoading: false
  83. }
  84. },
  85. async fetch() {
  86. this.isLoading = true
  87. this.items = await this.$services.project.list()
  88. this.isLoading = false
  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>