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.

87 lines
1.6 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>Select a file</h2>
  25. <v-file-input
  26. v-model="file"
  27. :rules="uploadFileRules"
  28. accept=".json"
  29. label="File input"
  30. />
  31. </v-form>
  32. </template>
  33. </base-card>
  34. </template>
  35. <script>
  36. import BaseCard from '@/components/molecules/BaseCard'
  37. import { uploadFileRules } from '@/rules/index'
  38. export default {
  39. components: {
  40. BaseCard
  41. },
  42. props: {
  43. importLabel: {
  44. type: Function,
  45. default: () => {},
  46. required: true
  47. }
  48. },
  49. data() {
  50. return {
  51. valid: false,
  52. file: null,
  53. uploadFileRules,
  54. showError: false
  55. }
  56. },
  57. methods: {
  58. cancel() {
  59. this.$emit('close')
  60. },
  61. validate() {
  62. return this.$refs.form.validate()
  63. },
  64. reset() {
  65. this.$refs.form.reset()
  66. },
  67. create() {
  68. if (this.validate()) {
  69. this.importLabel({
  70. projectId: this.$route.params.id,
  71. file: this.file
  72. })
  73. .then((response) => {
  74. this.reset()
  75. this.cancel()
  76. })
  77. .catch(() => {
  78. this.showError = true
  79. })
  80. }
  81. }
  82. }
  83. }
  84. </script>