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.

61 lines
1.8 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. public error: string = '';
  15. /**
  16. * A method which uploads the files to the server for processing
  17. *
  18. * @param {any} event The event containing the uploaded files information
  19. */
  20. public async uploadFile(event: any): Promise<void> {
  21. let file = event.files[0];
  22. return this.uploadNewFile(file);
  23. }
  24. /**
  25. * A method which uploads the files to the server for processing
  26. *
  27. * @param {File} file The event containing the uploaded files information
  28. */
  29. public async uploadNewFile(file: File): Promise<void> {
  30. this.uploading = true;
  31. this.fileUploaded = false;
  32. this.$toast.add({severity: 'info', summary: 'Uploading...', detail: 'Uploading your file...', life: 3000});
  33. try {
  34. let response = await this.$api.uploadFile(file);
  35. this.fileUploaded = true;
  36. this.uploadResult = response;
  37. } catch (err) {
  38. console.log('Error uploading file: ', err);
  39. this.$toast.add({
  40. severity: 'error',
  41. summary: 'Error!',
  42. detail: 'There was an error uploading your file. Please try again later',
  43. life: 3000
  44. });
  45. this.uploading = false;
  46. this.fileUploaded = false;
  47. }
  48. }
  49. public onError(error: string) {
  50. this.error = error;
  51. }
  52. }