|
|
@ -2,6 +2,7 @@ import marked from 'marked'; |
|
|
|
import {Vue, Component, Prop, Watch} from 'vue-property-decorator'; |
|
|
|
import {FileData} from '@/interfaces/FileData'; |
|
|
|
import { isServerError, getServerErrorMessage } from '@/SearchDisplace/helpers'; |
|
|
|
import { eventBus } from '@/app'; |
|
|
|
|
|
|
|
@Component |
|
|
|
export default class ProcessFile extends Vue { |
|
|
@ -70,7 +71,30 @@ export default class ProcessFile extends Vue { |
|
|
|
* |
|
|
|
*/ |
|
|
|
created() { |
|
|
|
let storedSearchers = localStorage.getItem('searchers'); |
|
|
|
if (storedSearchers !== null) { |
|
|
|
this.selectedSearchers = JSON.parse(storedSearchers); |
|
|
|
localStorage.removeItem('searchers'); |
|
|
|
|
|
|
|
let searchersOptions = localStorage.getItem('searchersOptions'); |
|
|
|
if (searchersOptions !== null) { |
|
|
|
this.searchersOptions = JSON.parse(searchersOptions); |
|
|
|
localStorage.removeItem('searchersOptions'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
this.intervalId = setInterval(this.waitForFile, 3000); |
|
|
|
|
|
|
|
window.addEventListener('beforeunload', async (event) => { |
|
|
|
// Cancel the event as stated by the standard.
|
|
|
|
event.preventDefault(); |
|
|
|
|
|
|
|
const response = await this.$api.discardFile(this.file.id); |
|
|
|
|
|
|
|
return event; |
|
|
|
}); |
|
|
|
|
|
|
|
eventBus.$on('changeRoute', this.changeRoute); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -94,6 +118,25 @@ export default class ProcessFile extends Vue { |
|
|
|
return marked(this.processedFileContentPreview); |
|
|
|
} |
|
|
|
|
|
|
|
public changeRoute(url: string) { |
|
|
|
const el = document.body; |
|
|
|
setTimeout(() => { |
|
|
|
el.classList.remove('p-overflow-hidden'); |
|
|
|
}, 10); |
|
|
|
this.$confirm.require({ |
|
|
|
message: 'You will lose any progress on the current uploaded document. Are you sure you want to proceed?', |
|
|
|
header: 'Confirmation', |
|
|
|
icon: 'pi pi-exclamation-triangle', |
|
|
|
blockScroll: false, |
|
|
|
accept: () => { |
|
|
|
window.location.href = url; |
|
|
|
}, |
|
|
|
reject: () => { |
|
|
|
// TODO: Show a message to the user that the action was cancelled.
|
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Toggle the sidebar containing the searchers |
|
|
|
*/ |
|
|
@ -136,7 +179,7 @@ export default class ProcessFile extends Vue { |
|
|
|
if (typeof newValue !== 'undefined') { |
|
|
|
this.uploadDialogVisible = newValue; |
|
|
|
} else { |
|
|
|
this.uploadDialogVisible = !this.searchersDialogVisible; |
|
|
|
this.uploadDialogVisible = !this.uploadDialogVisible; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -146,6 +189,8 @@ export default class ProcessFile extends Vue { |
|
|
|
* @param event The event containing the uploaded files information |
|
|
|
*/ |
|
|
|
public async uploadFile(event: any): Promise<void> { |
|
|
|
localStorage.setItem('searchers', JSON.stringify(this.selectedSearchers)); |
|
|
|
localStorage.setItem('searchersOptions', JSON.stringify(this.searchersOptions)); |
|
|
|
this.$confirm.require({ |
|
|
|
message: 'You will lose any progress on the current uploaded document. Are you sure you want to proceed?', |
|
|
|
header: 'Confirmation', |
|
|
@ -154,6 +199,7 @@ export default class ProcessFile extends Vue { |
|
|
|
this.fileContent = this.processedFileContent = ''; |
|
|
|
let file = event.files[0]; |
|
|
|
this.toggleUploadDialog(false); |
|
|
|
this.$api.discardFile(this.file.id); |
|
|
|
this.$emit('newFile', file); |
|
|
|
}, |
|
|
|
reject: () => { |
|
|
@ -248,7 +294,6 @@ export default class ProcessFile extends Vue { |
|
|
|
* Create the diff preview for the document |
|
|
|
*/ |
|
|
|
private createDiffPreview() { |
|
|
|
console.log('CREATING DIFF PREVIEW: ', this.processedFileContent); |
|
|
|
this.processedFileContentPreview = this.processedFileContent; |
|
|
|
|
|
|
|
let indexes: Array<{ start: number; end: number }> = []; |
|
|
@ -279,11 +324,43 @@ export default class ProcessFile extends Vue { |
|
|
|
* Download the document in ODT format |
|
|
|
*/ |
|
|
|
private async downloadOdt() { |
|
|
|
let response = await this.$api.convertFile(this.processedFileContent); |
|
|
|
let response = await this.$api.convertFile(this.processedFileContent, this.file.id); |
|
|
|
|
|
|
|
window.open(`${window.location.origin}/file/download/` + response.path); |
|
|
|
} |
|
|
|
|
|
|
|
private canRunSearchers(): boolean { |
|
|
|
if (this.fileContent == '' || Object.keys(this.selectedSearchers).length === 0) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
for (let key of Object.keys(this.selectedSearchers)) { |
|
|
|
const searcher = this.selectedSearchers[key]; |
|
|
|
if (!this.isValidParam(searcher.id, searcher.param)) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Check if a param is valid or not. |
|
|
|
* |
|
|
|
* @param {string} paramId |
|
|
|
* @param {string} paramType |
|
|
|
* @returns {boolean} |
|
|
|
*/ |
|
|
|
private isValidParam(paramId: string, paramType: string): boolean { |
|
|
|
if ( |
|
|
|
paramType === 'required' && |
|
|
|
(this.searchersOptions[paramId] === '' || this.searchersOptions[paramId] === undefined) |
|
|
|
) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Watch the `showDiffHighlight` property for changes |
|
|
|
* |
|
|
|