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.

72 lines
1.5 KiB

  1. <template>
  2. <form-import
  3. :error-message="errorMessage"
  4. @clear="clearErrorMessage"
  5. @upload="upload"
  6. />
  7. </template>
  8. <script lang="ts">
  9. import Vue from 'vue'
  10. import { ProjectDTO } from '~/services/application/project/projectData'
  11. import FormImport from '~/components/label/FormImport.vue'
  12. export default Vue.extend({
  13. components: {
  14. FormImport,
  15. },
  16. layout: 'project',
  17. validate({ params, query, app }) {
  18. if (!['category', 'span', 'relation'].includes((query.type as string))) {
  19. return false
  20. }
  21. if (/^\d+$/.test(params.id)) {
  22. return app.$services.project.findById(params.id)
  23. .then((res:ProjectDTO) => {
  24. return res.canDefineLabel
  25. })
  26. }
  27. return false
  28. },
  29. data() {
  30. return {
  31. errorMessage: '',
  32. }
  33. },
  34. computed: {
  35. projectId(): string {
  36. return this.$route.params.id
  37. },
  38. service(): any {
  39. const type = this.$route.query.type
  40. if (type === 'category') {
  41. return this.$services.categoryType
  42. } else if (type === 'span') {
  43. return this.$services.spanType
  44. } else {
  45. return this.$services.relationType
  46. }
  47. },
  48. },
  49. methods: {
  50. async upload(file: File) {
  51. try {
  52. await this.service.upload(this.projectId, file)
  53. this.$router.push(`/projects/${this.projectId}/labels`)
  54. } catch(e) {
  55. this.errorMessage = e.message
  56. }
  57. },
  58. clearErrorMessage() {
  59. this.errorMessage = ''
  60. }
  61. },
  62. })
  63. </script>