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.

122 lines
2.3 KiB

  1. <template>
  2. <base-card
  3. :disabled="!valid"
  4. @agree="create"
  5. @cancel="cancel"
  6. title="Upload Label"
  7. agree-text="Upload"
  8. cancel-text="Cancel"
  9. >
  10. <template #content>
  11. <v-form
  12. ref="form"
  13. v-model="valid"
  14. >
  15. <v-alert
  16. v-show="showError"
  17. v-model="showError"
  18. type="error"
  19. dismissible
  20. >
  21. The file could not be uploaded. Maybe invalid format.
  22. Please check available formats carefully.
  23. </v-alert>
  24. <h2>Example format</h2>
  25. <code class="mb-10 pa-5 highlight">
  26. <span>{{ exampleFormat }}</span>
  27. </code>
  28. <h2>Select a file</h2>
  29. <v-file-input
  30. v-model="file"
  31. :rules="uploadFileRules"
  32. accept=".json"
  33. label="File input"
  34. />
  35. </v-form>
  36. </template>
  37. </base-card>
  38. </template>
  39. <script>
  40. import BaseCard from '@/components/molecules/BaseCard'
  41. import { uploadFileRules } from '@/rules/index'
  42. export default {
  43. components: {
  44. BaseCard
  45. },
  46. props: {
  47. uploadLabel: {
  48. type: Function,
  49. default: () => {},
  50. required: true
  51. }
  52. },
  53. data() {
  54. return {
  55. valid: false,
  56. file: null,
  57. uploadFileRules,
  58. showError: false
  59. }
  60. },
  61. computed: {
  62. exampleFormat() {
  63. const data = [
  64. {
  65. text: 'Dog',
  66. suffix_key: 'a',
  67. background_color: '#FF0000',
  68. text_color: '#ffffff'
  69. },
  70. {
  71. text: 'Cat',
  72. suffix_key: 'c',
  73. background_color: '#FF0000',
  74. text_color: '#ffffff'
  75. }
  76. ]
  77. console.log(JSON.stringify(data, null, 4))
  78. return JSON.stringify(data, null, 4)
  79. }
  80. },
  81. methods: {
  82. cancel() {
  83. this.$emit('close')
  84. },
  85. validate() {
  86. return this.$refs.form.validate()
  87. },
  88. reset() {
  89. this.$refs.form.reset()
  90. },
  91. create() {
  92. if (this.validate()) {
  93. this.uploadLabel({
  94. projectId: this.$route.params.id,
  95. file: this.file
  96. })
  97. .then((response) => {
  98. this.reset()
  99. this.cancel()
  100. })
  101. .catch(() => {
  102. this.showError = true
  103. })
  104. }
  105. }
  106. }
  107. }
  108. </script>
  109. <style scoped>
  110. .highlight {
  111. font-size: 100%;
  112. width: 100%;
  113. }
  114. .highlight:before {
  115. content: ''
  116. }
  117. </style>