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.

123 lines
2.7 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.service'
  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. enableRandomizeDocOrder: false,
  69. enableShareAnnotation: false
  70. } as ProjectWriteDTO,
  71. defaultItem: {
  72. name: '',
  73. description: '',
  74. projectType: 'DocumentClassification',
  75. enableRandomizeDocOrder: false,
  76. enableShareAnnotation: false
  77. } as ProjectWriteDTO,
  78. items: [] as ProjectDTO[],
  79. selected: [] as ProjectDTO[],
  80. isLoading: false
  81. }
  82. },
  83. computed: {
  84. canDelete(): boolean {
  85. return this.selected.length > 0
  86. },
  87. },
  88. methods: {
  89. async create() {
  90. const project = await this.$services.project.create(this.editedItem)
  91. this.$router.push(`/projects/${project.id}`)
  92. this.close()
  93. },
  94. close() {
  95. this.dialogCreate = false
  96. this.$nextTick(() => {
  97. this.editedItem = Object.assign({}, this.defaultItem)
  98. })
  99. },
  100. async remove() {
  101. await this.$services.project.bulkDelete(this.selected)
  102. this.$fetch()
  103. this.dialogDelete = false
  104. this.selected = []
  105. },
  106. }
  107. })
  108. </script>
  109. <style scoped>
  110. ::v-deep .v-dialog {
  111. width: 800px;
  112. }
  113. </style>