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.

149 lines
4.4 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
3 years ago
3 years ago
3 years ago
  1. import axios from 'axios';
  2. // import OverlayPanel from 'primevue/overlaypanel/OverlayPanel';
  3. import {Vue, Component, Prop, Watch} from 'vue-property-decorator';
  4. import {FileData} from '@/interfaces/FileData';
  5. @Component
  6. export default class ProcessFile extends Vue {
  7. /**
  8. * Props
  9. */
  10. // The data for the file we are processing
  11. @Prop({default: {id: -1, file: '', path: ''}})
  12. public readonly file!: FileData;
  13. // The list of available searchers
  14. @Prop({default: []})
  15. public readonly searchers!: [];
  16. /**
  17. * Class members
  18. */
  19. // The id of the interval used to query the file status
  20. private intervalId!: any;
  21. // The content of the file we are processing
  22. private fileContent: string = '';
  23. // The processed document content
  24. private processedFileContent: string = '';
  25. // Flag to determine whether the text is processing or not
  26. private processing: boolean = false;
  27. // Toggles the visibility of the selected searchers sidebar
  28. private searchersSidebarVisible: boolean = false;
  29. // Toggles the visibility of the available searchers dialog
  30. private searchersDialogVisible: boolean = false;
  31. // The list of filters/searchers in a format usable by the datatable
  32. // private searchersData: Array<{ id: string; name: string; type: string; }> = [];
  33. // The list of filters applied to the selected searchers
  34. private searchersFilters: any = [];
  35. // The list of selected filters/searchers
  36. private selectedSearchers: Array<{ id: string; name: string; }> = [];
  37. //The list of expanded rows in the selected filters/searchers table
  38. private expandedRows: Array<{ id: string; name: string; }> = [];
  39. // The list of options applied to the searchers (for the moment, only replace_with)
  40. private searchersOptions: { [key: string]: string } = {};
  41. /**
  42. *
  43. */
  44. created() {
  45. this.intervalId = setInterval(this.waitForFile, 3000);
  46. }
  47. /**
  48. * Toggle the sidebar containing the searchers
  49. */
  50. private toggleSearchersSidebar() {
  51. this.searchersSidebarVisible = !this.searchersSidebarVisible;
  52. }
  53. /**
  54. * Toggle the menu containing the list of available searchers
  55. *
  56. * @param {string} newValue The new value for the dialog visibility
  57. */
  58. private toggleSearchersDialog(newValue?: boolean) {
  59. if (typeof newValue !== 'undefined') {
  60. this.searchersDialogVisible = newValue;
  61. } else {
  62. this.searchersDialogVisible = !this.searchersDialogVisible;
  63. }
  64. }
  65. /**
  66. * Wait for the file to be processed in ingest
  67. */
  68. private async waitForFile() {
  69. const response = await this.$api.getFileData(this.file.id);
  70. if (response.content !== null) {
  71. if (response.ingest_status === 'fail') {
  72. this.$toast.add({
  73. severity: 'error',
  74. summary: 'File error',
  75. detail: 'THere was an error processing the file in ingest',
  76. life: 3000
  77. });
  78. } else {
  79. this.fileContent = response.content;
  80. this.$toast.add({
  81. severity: 'success',
  82. summary: 'File loaded',
  83. detail: 'The file has been processed by ingest.',
  84. life: 3000
  85. });
  86. clearInterval(this.intervalId);
  87. }
  88. }
  89. }
  90. private onSelectedSearchersReorder($event: any) {
  91. this.selectedSearchers = $event.value;
  92. }
  93. /**
  94. * Run the searchers
  95. */
  96. private async runSearchers() {
  97. this.processing = true;
  98. this.processedFileContent = '';
  99. let searchers: Array<{ key: string; replace_with: string; }> = [];
  100. this.selectedSearchers.forEach((searcher) => {
  101. searchers.push({
  102. 'key': searcher.id,
  103. 'replace_with': this.searchersOptions[searcher.id] || ''
  104. });
  105. });
  106. const response = await this.$api.filterDocument(this.fileContent, searchers);
  107. console.log(response);
  108. this.processedFileContent = response.content;
  109. this.processing = false;
  110. }
  111. private async downloadOdt() {
  112. let response = await this.$api.convertFile(this.processedFileContent);
  113. window.open(`${window.location.origin}/file/download/` + response.path);
  114. }
  115. }