From 43cc07f80bc0013a4705fc616a234ef822e210a2 Mon Sep 17 00:00:00 2001 From: Radu Liviu Carjan Date: Mon, 7 Jun 2021 17:12:33 +0300 Subject: [PATCH] Minor improvement for param check --- public/js/app.js | 37 ++++++++++++++----- resources/js/app.ts | 2 - .../js/components/ProcessFile/ProcessFile.ts | 25 +++++++++++-- .../js/components/ProcessFile/ProcessFile.vue | 4 +- 4 files changed, 52 insertions(+), 16 deletions(-) diff --git a/public/js/app.js b/public/js/app.js index 3c777a0..401f3a4 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -3948,7 +3948,6 @@ var ProcessFile = /*#__PURE__*/function (_Vue) { }, { key: "createDiffPreview", value: function createDiffPreview() { - // console.log('CREATING DIFF PREVIEW: ', this.processedFileContent); this.processedFileContentPreview = this.processedFileContent; var indexes = []; @@ -4002,11 +4001,35 @@ var ProcessFile = /*#__PURE__*/function (_Vue) { return downloadOdt; }() + }, { + key: "canRunSearchers", + value: function canRunSearchers() { + if (this.fileContent == '' || Object.keys(this.selectedSearchers).length === 0) { + return false; + } + + for (var _i = 0, _Object$keys = Object.keys(this.selectedSearchers); _i < _Object$keys.length; _i++) { + var key = _Object$keys[_i]; + var 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} + */ + }, { key: "isValidParam", value: function isValidParam(paramId, paramType) { - console.log('PARAM: ', paramId, this.searchersOptions[paramId]); - if (paramType === 'required' && (this.searchersOptions[paramId] === '' || this.searchersOptions[paramId] === undefined)) { return false; } @@ -29270,9 +29293,7 @@ var render = function() { attrs: { label: "Run filters", icon: "pi pi-play", - disabled: - _vm.fileContent == "" || - Object.keys(_vm.selectedSearchers).length === 0 + disabled: !_vm.canRunSearchers() }, on: { click: _vm.runSearchers } }) @@ -29622,9 +29643,7 @@ var render = function() { attrs: { label: "Run filters", icon: "pi pi-play", - disabled: - _vm.fileContent == "" || - Object.keys(_vm.selectedSearchers).length === 0 + disabled: !_vm.canRunSearchers() }, on: { click: function($event) { diff --git a/resources/js/app.ts b/resources/js/app.ts index 8aa990f..b78b1cd 100644 --- a/resources/js/app.ts +++ b/resources/js/app.ts @@ -92,9 +92,7 @@ Vue.component('app-footer', AppFooter); // Views Vue.component('home', Home); - Vue.component('regex-create', RegexCreate); - Vue.component('searchers-index', SearchersIndex); Vue.component('searchers-create', SearchersCreate); Vue.component('searchers-show', SearchersShow); diff --git a/resources/js/components/ProcessFile/ProcessFile.ts b/resources/js/components/ProcessFile/ProcessFile.ts index c61e1dc..569dff4 100644 --- a/resources/js/components/ProcessFile/ProcessFile.ts +++ b/resources/js/components/ProcessFile/ProcessFile.ts @@ -258,7 +258,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 }> = []; @@ -294,9 +293,29 @@ export default class ProcessFile extends Vue { window.open(`${window.location.origin}/file/download/` + response.path); } - private isValidParam(paramId: string, paramType: string): boolean { + private canRunSearchers(): boolean { + if (this.fileContent == '' || Object.keys(this.selectedSearchers).length === 0) { + return false; + } - console.log('PARAM: ', paramId, this.searchersOptions[paramId]); + 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) diff --git a/resources/js/components/ProcessFile/ProcessFile.vue b/resources/js/components/ProcessFile/ProcessFile.vue index 2e1df06..6ed94e3 100644 --- a/resources/js/components/ProcessFile/ProcessFile.vue +++ b/resources/js/components/ProcessFile/ProcessFile.vue @@ -69,7 +69,7 @@ label="Run filters" icon="pi pi-play" class="p-button-success p-button-outlined p-button-sm" - :disabled="fileContent == '' || Object.keys(selectedSearchers).length === 0" + :disabled="!canRunSearchers()" @click="runSearchers"/> @@ -226,7 +226,7 @@ label="Run filters" icon="pi pi-play" class="p-button-success p-button-sm" - :disabled="fileContent == '' || Object.keys(selectedSearchers).length === 0" + :disabled="!canRunSearchers()" @click="toggleSearchersSidebar(); runSearchers()"/>