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.

99 lines
2.3 KiB

2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
  1. <template>
  2. <form-create v-slot="slotProps" v-bind.sync="editedItem" :items="items">
  3. <v-btn :disabled="!slotProps.valid" color="primary" class="text-capitalize" @click="save">
  4. Save
  5. </v-btn>
  6. <v-btn
  7. :disabled="!slotProps.valid"
  8. color="primary"
  9. style="text-transform: none"
  10. outlined
  11. @click="saveAndAnother"
  12. >
  13. Save and add another
  14. </v-btn>
  15. </form-create>
  16. </template>
  17. <script lang="ts">
  18. import Vue from 'vue'
  19. import FormCreate from '~/components/label/FormCreate.vue'
  20. import { Project } from '~/domain/models/project/project'
  21. import { LabelDTO } from '~/services/application/label/labelData'
  22. export default Vue.extend({
  23. components: {
  24. FormCreate
  25. },
  26. layout: 'project',
  27. middleware: ['check-auth', 'auth', 'setCurrentProject'],
  28. validate({ params, query, store }) {
  29. if (!['category', 'span', 'relation'].includes(query.type as string)) {
  30. return false
  31. }
  32. if (/^\d+$/.test(params.id)) {
  33. const project = store.getters['projects/project'] as Project
  34. return project.canDefineLabel
  35. }
  36. return false
  37. },
  38. data() {
  39. return {
  40. editedItem: {
  41. text: '',
  42. prefixKey: null,
  43. suffixKey: null,
  44. backgroundColor: '#73D8FF',
  45. textColor: '#ffffff'
  46. } as LabelDTO,
  47. defaultItem: {
  48. text: '',
  49. prefixKey: null,
  50. suffixKey: null,
  51. backgroundColor: '#73D8FF',
  52. textColor: '#ffffff'
  53. } as LabelDTO,
  54. items: [] as LabelDTO[]
  55. }
  56. },
  57. computed: {
  58. projectId(): string {
  59. return this.$route.params.id
  60. },
  61. service(): any {
  62. const type = this.$route.query.type
  63. if (type === 'category') {
  64. return this.$services.categoryType
  65. } else if (type === 'span') {
  66. return this.$services.spanType
  67. } else {
  68. return this.$services.relationType
  69. }
  70. }
  71. },
  72. async created() {
  73. this.items = await this.service.list(this.projectId)
  74. },
  75. methods: {
  76. async save() {
  77. await this.service.create(this.projectId, this.editedItem)
  78. this.$router.push(`/projects/${this.projectId}/labels`)
  79. },
  80. async saveAndAnother() {
  81. await this.service.create(this.projectId, this.editedItem)
  82. this.editedItem = Object.assign({}, this.defaultItem)
  83. this.items = await this.service.list(this.projectId)
  84. }
  85. }
  86. })
  87. </script>