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.

104 lines
2.1 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="$router.push('projects/create')"
  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="dialogDelete">
  20. <form-delete
  21. :selected="selected"
  22. @cancel="dialogDelete=false"
  23. @remove="remove"
  24. />
  25. </v-dialog>
  26. </v-card-title>
  27. <project-list
  28. v-model="selected"
  29. :items="projects.items"
  30. :is-loading="isLoading"
  31. :total="projects.count"
  32. @update:query="updateQuery"
  33. />
  34. </v-card>
  35. </template>
  36. <script lang="ts">
  37. import _ from 'lodash'
  38. import Vue from 'vue'
  39. import { mapGetters } from 'vuex'
  40. import ProjectList from '@/components/project/ProjectList.vue'
  41. import { ProjectDTO, ProjectListDTO } from '~/services/application/project/projectData'
  42. import FormDelete from '~/components/project/FormDelete.vue'
  43. export default Vue.extend({
  44. components: {
  45. FormDelete,
  46. ProjectList,
  47. },
  48. layout: 'projects',
  49. middleware: ['check-auth', 'auth'],
  50. data() {
  51. return {
  52. dialogDelete: false,
  53. projects: {} as ProjectListDTO,
  54. selected: [] as ProjectDTO[],
  55. isLoading: false
  56. }
  57. },
  58. async fetch() {
  59. this.isLoading = true
  60. this.projects = await this.$services.project.list(this.$route.query)
  61. this.isLoading = false
  62. },
  63. computed: {
  64. ...mapGetters('auth', ['isStaff']),
  65. canDelete(): boolean {
  66. return this.selected.length > 0
  67. },
  68. },
  69. watch: {
  70. '$route.query': _.debounce(function() {
  71. // @ts-ignore
  72. this.$fetch()
  73. }, 1000
  74. ),
  75. },
  76. methods: {
  77. async remove() {
  78. await this.$services.project.bulkDelete(this.selected)
  79. this.$fetch()
  80. this.dialogDelete = false
  81. this.selected = []
  82. },
  83. updateQuery(query: object) {
  84. this.$router.push(query)
  85. }
  86. }
  87. })
  88. </script>
  89. <style scoped>
  90. ::v-deep .v-dialog {
  91. width: 800px;
  92. }
  93. </style>