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.

98 lines
2.8 KiB

3 years ago
4 years ago
4 years ago
3 years ago
4 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 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. import { Searcher } from '@/interfaces/Searcher';
  5. import { eventBus } from '@/app';
  6. @Component
  7. export default class Home extends Vue {
  8. private availableSearchers: Array<Searcher> = [];
  9. public uiBlocked = false;
  10. public uploading = false;
  11. public fileUploaded: boolean = false;
  12. public document: File | null = null;
  13. public uploadResult: FileUploadResponse = {
  14. id: '',
  15. file_name: '',
  16. };
  17. public error: string = '';
  18. @Prop({default: []})
  19. public searchers!: Searcher[];
  20. public mounted()
  21. {
  22. eventBus.$on('changeRoute', this.changeRoute);
  23. this.availableSearchers = this.searchers;
  24. }
  25. /**
  26. * A method which uploads the files to the server for processing
  27. *
  28. * @param {any} event The event containing the uploaded files information
  29. */
  30. public async uploadFile(event: any): Promise<void> {
  31. let file = event.files[0];
  32. return this.uploadNewFile(file);
  33. }
  34. /**
  35. * A method which uploads the files to the server for processing
  36. *
  37. * @param {File} file The event containing the uploaded files information
  38. */
  39. public async uploadNewFile(file: File): Promise<void> {
  40. this.uploading = true;
  41. this.fileUploaded = false;
  42. this.$toast.add({severity: 'info', summary: 'Uploading...', detail: 'Uploading your file...', life: 3000});
  43. try {
  44. let response = await this.$api.uploadFile(file);
  45. this.fileUploaded = true;
  46. this.uploadResult = response;
  47. this.document = file;
  48. } catch (e) {
  49. this.uploading = false;
  50. this.fileUploaded = false;
  51. if (isServerError(e)) {
  52. if (e.response.data.hasOwnProperty('errors')) {
  53. const errors = e.response.data.errors;
  54. if (errors.hasOwnProperty('file')) {
  55. this.error = errors.file[0];
  56. return;
  57. }
  58. }
  59. if (e.response.data.hasOwnProperty('message')) {
  60. this.error = e.response.data.message;
  61. return;
  62. }
  63. }
  64. this.error = 'There was an error uploading your file. Please try again later.';
  65. }
  66. }
  67. private onNewSearcher(searcher: Searcher): void {
  68. this.availableSearchers.unshift(searcher);
  69. }
  70. public onError(error: string) {
  71. this.error = error;
  72. }
  73. public changeRoute(url: string) {
  74. if (!this.fileUploaded) {
  75. window.location.href = url;
  76. }
  77. }
  78. }