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.
|
|
import axios from 'axios'; // import OverlayPanel from 'primevue/overlaypanel/OverlayPanel';
import {Vue, Component, Prop, Watch} from 'vue-property-decorator'; import {FileData} from '@/interfaces/FileData';
@Component export default class ProcessFile extends Vue {
/** * Props */ // The data for the file we are processing
@Prop({default: {id: -1, file: '', path: ''}}) public readonly file!: FileData;
// The list of available searchers
@Prop({default: []}) public readonly searchers!: [];
/** * Class members */ // The id of the interval used to query the file status
private intervalId!: any;
// The content of the file we are processing
private fileContent: string = '';
// The processed document content
private processedFileContent: string = '';
// Flag to determine whether the text is processing or not
private processing: boolean = false;
// Toggles the visibility of the selected searchers sidebar
private searchersSidebarVisible: boolean = false;
// Toggles the visibility of the available searchers dialog
private searchersDialogVisible: boolean = false;
// The list of filters/searchers in a format usable by the datatable
// private searchersData: Array<{ id: string; name: string; type: string; }> = [];
// The list of filters applied to the selected searchers
private searchersFilters: any = [];
// The list of selected filters/searchers
private selectedSearchers: Array<{ id: string; name: string; }> = [];
//The list of expanded rows in the selected filters/searchers table
private expandedRows: Array<{ id: string; name: string; }> = [];
// The list of options applied to the searchers (for the moment, only replace_with)
private searchersOptions: { [key: string]: string } = {};
/** * */ created() { this.intervalId = setInterval(this.waitForFile, 3000); }
/** * Toggle the sidebar containing the searchers */ private toggleSearchersSidebar() { this.searchersSidebarVisible = !this.searchersSidebarVisible; }
/** * Toggle the menu containing the list of available searchers * * @param {string} newValue The new value for the dialog visibility */ private toggleSearchersDialog(newValue?: boolean) {
if (typeof newValue !== 'undefined') { this.searchersDialogVisible = newValue; } else { this.searchersDialogVisible = !this.searchersDialogVisible; } }
/** * Wait for the file to be processed in ingest */ private async waitForFile() {
const response = await this.$api.getFileData(this.file.id);
if (response.content !== null) {
if (response.ingest_status === 'fail') { this.$toast.add({ severity: 'error', summary: 'File error', detail: 'THere was an error processing the file in ingest', life: 3000 }); } else { this.fileContent = response.content;
this.$toast.add({ severity: 'success', summary: 'File loaded', detail: 'The file has been processed by ingest.', life: 3000 });
clearInterval(this.intervalId); } } }
private onSelectedSearchersReorder($event: any) { this.selectedSearchers = $event.value; }
/** * Run the searchers */ private async runSearchers() { this.processing = true; this.processedFileContent = '';
let searchers: Array<{ key: string; replace_with: string; }> = []; this.selectedSearchers.forEach((searcher) => { searchers.push({ 'key': searcher.id, 'replace_with': this.searchersOptions[searcher.id] || '' }); });
const response = await this.$api.filterDocument(this.fileContent, searchers);
console.log(response);
this.processedFileContent = response.content; this.processing = false; }
private async downloadOdt() { let response = await this.$api.convertFile(this.processedFileContent);
window.open(`${window.location.origin}/file/download/` + response.path); } }
|