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.

125 lines
2.8 KiB

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