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.

161 lines
4.3 KiB

2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. <template>
  2. <v-stepper v-model="step.count">
  3. <v-overlay :value="isLoading">
  4. <v-progress-circular indeterminate size="64" />
  5. </v-overlay>
  6. <config-header :step="step.count" />
  7. <config-template-name v-model="fields" @next="step.next()" />
  8. <config-parameters
  9. v-if="fields.modelAttrs !== undefined"
  10. v-model="fields.modelAttrs"
  11. :is-passed="passTesting.parameter"
  12. :error-messages="errors"
  13. :response="response.parameter"
  14. @prev="step.prev()"
  15. @next="step.next()"
  16. @onTest="testParameters"
  17. />
  18. <config-template
  19. v-model="fields.template"
  20. :is-passed="passTesting.template"
  21. :error-messages="errors"
  22. :response="response.parameter"
  23. :result="response.template"
  24. @prev="step.prev()"
  25. @next="step.next()"
  26. @onTest="testTemplate"
  27. />
  28. <config-label-mapping
  29. v-model="fields.labelMapping"
  30. :is-passed="passTesting.mapping"
  31. :error-messages="errors"
  32. :response="response.template"
  33. :result="response.mapping"
  34. @prev="step.prev()"
  35. @next="saveConfig"
  36. @onTest="testMapping"
  37. />
  38. </v-stepper>
  39. </template>
  40. <script lang="ts">
  41. import Vue from 'vue'
  42. import ConfigHeader from './form/ConfigHeader.vue'
  43. import ConfigLabelMapping from './form/ConfigLabelMapping.vue'
  44. import ConfigParameters from './form/ConfigParameters.vue'
  45. import ConfigTemplate from './form/ConfigTemplate.vue'
  46. import ConfigTemplateName from './form/ConfigTemplateName.vue'
  47. import { StepCounter } from '@/domain/models/utils/stepper'
  48. import { ConfigItem, Fields } from '@/domain/models/autoLabeling/config'
  49. export default Vue.extend({
  50. components: {
  51. ConfigHeader,
  52. ConfigLabelMapping,
  53. ConfigParameters,
  54. ConfigTemplate,
  55. ConfigTemplateName
  56. },
  57. data() {
  58. return {
  59. config: {} as ConfigItem,
  60. errors: [] as string[],
  61. fields: {} as Fields,
  62. isLoading: false,
  63. step: new StepCounter(),
  64. passTesting: {
  65. parameter: false,
  66. template: false,
  67. mapping: false
  68. },
  69. response: {
  70. parameter: [],
  71. template: [],
  72. mapping: []
  73. }
  74. }
  75. },
  76. watch: {
  77. 'fields.modelName'() {
  78. this.passTesting = { parameter: false, template: false, mapping: false }
  79. },
  80. 'fields.modelAttrs': {
  81. handler() {
  82. this.passTesting = {
  83. parameter: false,
  84. template: false,
  85. mapping: false
  86. }
  87. },
  88. deep: true
  89. },
  90. 'fields.template'() {
  91. this.passTesting = { parameter: true, template: false, mapping: false }
  92. },
  93. 'fields.labelMapping': {
  94. handler() {
  95. this.passTesting = { parameter: true, template: true, mapping: false }
  96. },
  97. deep: true
  98. }
  99. },
  100. methods: {
  101. testConfig(promise: Promise<any>, key: 'parameter' | 'template' | 'mapping') {
  102. this.isLoading = true
  103. promise
  104. .then((value) => {
  105. this.response[key] = value
  106. this.passTesting[key] = true
  107. this.errors = []
  108. })
  109. .catch((error) => {
  110. this.errors = [error.response.data]
  111. })
  112. .finally(() => {
  113. this.isLoading = false
  114. })
  115. },
  116. testParameters(text: string) {
  117. const projectId = this.$route.params.id
  118. const item = ConfigItem.parseFromUI(this.fields)
  119. const promise = this.$repositories.config.testParameters(projectId, item, text)
  120. this.testConfig(promise, 'parameter')
  121. },
  122. testTemplate() {
  123. const projectId = this.$route.params.id
  124. const item = ConfigItem.parseFromUI(this.fields)
  125. const promise = this.$repositories.config.testTemplate(
  126. projectId,
  127. this.response.parameter,
  128. item
  129. )
  130. this.testConfig(promise, 'template')
  131. },
  132. testMapping() {
  133. const projectId = this.$route.params.id
  134. const item = ConfigItem.parseFromUI(this.fields)
  135. const promise = this.$repositories.config.testMapping(projectId, item, this.response.template)
  136. this.testConfig(promise, 'mapping')
  137. },
  138. saveConfig() {
  139. const projectId = this.$route.params.id
  140. const item = ConfigItem.parseFromUI(this.fields)
  141. this.isLoading = true
  142. this.$repositories.config
  143. .create(projectId, item)
  144. .then(() => {
  145. this.step.first()
  146. this.$emit('onCreate')
  147. })
  148. .finally(() => {
  149. this.isLoading = false
  150. })
  151. }
  152. }
  153. })
  154. </script>