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.

106 lines
2.3 KiB

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