Repo for the search and displace core module including the interface to select files and search and displace operations to run on them. https://searchanddisplace.com
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.

74 lines
2.2 KiB

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
  1. import {Vue, Component, Prop} from 'vue-property-decorator';
  2. import FileUploadResponse from '@/interfaces/responses/FileUploadResponse';
  3. import {isServerError} from "@/SearchDisplace/helpers";
  4. @Component
  5. export default class Home extends Vue {
  6. @Prop({default: []})
  7. public readonly searchers!: { [key: string]: string; }
  8. public uiBlocked = false;
  9. public uploading = false;
  10. public fileUploaded: boolean = false;
  11. public uploadResult: FileUploadResponse = {
  12. id: '',
  13. file_name: '',
  14. };
  15. public error: string = '';
  16. /**
  17. * A method which uploads the files to the server for processing
  18. *
  19. * @param {any} event The event containing the uploaded files information
  20. */
  21. public async uploadFile(event: any): Promise<void> {
  22. let file = event.files[0];
  23. return this.uploadNewFile(file);
  24. }
  25. /**
  26. * A method which uploads the files to the server for processing
  27. *
  28. * @param {File} file The event containing the uploaded files information
  29. */
  30. public async uploadNewFile(file: File): Promise<void> {
  31. this.uploading = true;
  32. this.fileUploaded = false;
  33. this.$toast.add({severity: 'info', summary: 'Uploading...', detail: 'Uploading your file...', life: 3000});
  34. try {
  35. let response = await this.$api.uploadFile(file);
  36. this.fileUploaded = true;
  37. this.uploadResult = response;
  38. } catch (e) {
  39. this.uploading = false;
  40. this.fileUploaded = false;
  41. if (isServerError(e)) {
  42. if (e.response.data.hasOwnProperty('errors')) {
  43. const errors = e.response.data.errors;
  44. if (errors.hasOwnProperty('file')) {
  45. this.error = errors.file[0];
  46. return;
  47. }
  48. }
  49. if (e.response.data.hasOwnProperty('message')) {
  50. this.error = e.response.data.message;
  51. return;
  52. }
  53. }
  54. this.error = 'There was an error uploading your file. Please try again later.';
  55. }
  56. }
  57. public onError(error: string) {
  58. this.error = error;
  59. }
  60. }