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.

160 lines
4.6 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!: { [keys: string]: string; }
  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; }> = [];
  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. for(let index in this.searchers) {
  46. let searcherData = {
  47. id: index,
  48. name: this.searchers[index]
  49. };
  50. this.searchersData.push(searcherData);
  51. }
  52. this.intervalId = setInterval(this.waitForFile, 3000);
  53. }
  54. /**
  55. * Toggle the sidebar containing the searchers
  56. */
  57. private toggleSearchersSidebar() {
  58. this.searchersSidebarVisible = !this.searchersSidebarVisible;
  59. }
  60. /**
  61. * Toggle the menu containing the list of available searchers
  62. *
  63. * @param {string} newValue The new value for the dialog visibility
  64. */
  65. private toggleSearchersDialog(newValue?: boolean) {
  66. if (typeof newValue !== 'undefined') {
  67. this.searchersDialogVisible = newValue;
  68. } else {
  69. this.searchersDialogVisible = !this.searchersDialogVisible;
  70. }
  71. }
  72. /**
  73. * Wait for the file to be processed in ingest
  74. */
  75. private async waitForFile() {
  76. const response = await this.$api.getFileData(this.file.id);
  77. if (response.content !== null) {
  78. if (response.ingest_status === 'fail') {
  79. this.$toast.add({
  80. severity: 'error',
  81. summary: 'File error',
  82. detail: 'THere was an error processing the file in ingest',
  83. life: 3000
  84. });
  85. } else {
  86. this.fileContent = response.content;
  87. this.$toast.add({
  88. severity:'success',
  89. summary: 'File loaded',
  90. detail: 'The file has been processed by ingest.',
  91. life: 3000
  92. });
  93. clearInterval(this.intervalId);
  94. }
  95. }
  96. }
  97. private onSelectedSearchersReorder($event: any)
  98. {
  99. this.selectedSearchers = $event.value;
  100. }
  101. /**
  102. * Run the searchers
  103. */
  104. private async runSearchers() {
  105. this.processing = true;
  106. this.processedFileContent = '';
  107. let searchers: Array<{ key: string; replace_with: string; }> = [];
  108. this.selectedSearchers.forEach( (searcher) => {
  109. searchers.push({
  110. 'key': searcher.id,
  111. 'replace_with': this.searchersOptions[searcher.id] || ''
  112. });
  113. });
  114. const response = await this.$api.filterDocument(this.fileContent, searchers);
  115. console.log(response);
  116. this.processedFileContent = response.content;
  117. this.processing = false;
  118. }
  119. private async downloadOdt()
  120. {
  121. let response = await this.$api.convertFile(this.processedFileContent);
  122. window.open('http://core.sandd/file/download/' + response.path);
  123. }
  124. }