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.

57 lines
1.7 KiB

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. @Component
  4. export default class Home extends Vue {
  5. @Prop({default: []})
  6. public readonly searchers!: { [key: string]: string; }
  7. public uiBlocked = false;
  8. public uploading = false;
  9. public fileUploaded: boolean = false;
  10. public uploadResult: FileUploadResponse = {
  11. id: '',
  12. file_name: '',
  13. };
  14. /**
  15. * A method which uploads the files to the server for processing
  16. *
  17. * @param {any} event The event containing the uploaded files information
  18. */
  19. public async uploadFile(event: any): Promise<void> {
  20. let file = event.files[0];
  21. return this.uploadNewFile(file);
  22. }
  23. /**
  24. * A method which uploads the files to the server for processing
  25. *
  26. * @param {File} file The event containing the uploaded files information
  27. */
  28. public async uploadNewFile(file: File): Promise<void> {
  29. this.uploading = true;
  30. this.fileUploaded = false;
  31. this.$toast.add({severity: 'info', summary: 'Uploading...', detail: 'Uploading your file...', life: 3000});
  32. try {
  33. let response = await this.$api.uploadFile(file);
  34. this.fileUploaded = true;
  35. this.uploadResult = response;
  36. } catch (err) {
  37. console.log('Error uploading file: ', err);
  38. this.$toast.add({
  39. severity: 'error',
  40. summary: 'Error!',
  41. detail: 'There was an error uploading your file. Please try again later',
  42. life: 3000
  43. });
  44. this.uploading = false;
  45. this.fileUploaded = false;
  46. }
  47. }
  48. }