From 5816a202395d8b41dc3c49b93615f0e09a7c11f6 Mon Sep 17 00:00:00 2001 From: Charan Girijala <82193104+charangirijala@users.noreply.github.com> Date: Mon, 23 Dec 2024 14:30:48 +0530 Subject: [PATCH 1/2] =?UTF-8?q?Search=20implementation=20done=F0=9F=94=8D?= =?UTF-8?q?=E2=9C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/main/logViewer/logViewer.css | 8 ++ src/modules/main/logViewer/logViewer.html | 7 +- src/modules/main/logViewer/logViewer.js | 133 +++++++++++++--------- src/modules/ui/search/search.js | 57 +++++++--- 4 files changed, 136 insertions(+), 69 deletions(-) diff --git a/src/modules/main/logViewer/logViewer.css b/src/modules/main/logViewer/logViewer.css index 8cf777d..7e94af7 100644 --- a/src/modules/main/logViewer/logViewer.css +++ b/src/modules/main/logViewer/logViewer.css @@ -8,6 +8,14 @@ a { overflow: visible; z-index: 10; } + +.search-res { + background-color: rgb(250, 255, 189); +} + +.search-res-focus { + background-color: yellow; +} :host { --dxp-s-form-element-text-font-size: 0.75rem; --dxp-s-button-font-size: 0.8125rem; diff --git a/src/modules/main/logViewer/logViewer.html b/src/modules/main/logViewer/logViewer.html index 6b0cca1..5bb818b 100644 --- a/src/modules/main/logViewer/logViewer.html +++ b/src/modules/main/logViewer/logViewer.html @@ -645,8 +645,9 @@

@@ -733,6 +734,8 @@

> 0; } - // subscribeToMessageChannel() { - // console.log("Subscribe called"); - // if (!this.logChannelSub) { - // this.logChannelSub = subscribe( - // this.messageContext, - // STATE, - // (message) => { - // this.setFileData(message); - // }, - // { scope: APPLICATION_SCOPE } - // ); - // this.logChannelSub = true; - // } - // } - - // setFileData(message) { - // if (message !== null && message !== undefined) { - // // console.log("[LogPreviewer.js] setFileData called", message); - // if (message.fileData !== undefined && message.fileData !== null) { - // this.fileData = message.fileData; - // this.pageNumber = 1; - // this.noOfPages = Math.ceil( - // this.fileData.length / this.linesPerPage - // ); - // this.calculations(); - // } - // if ( - // message.fileMetadata !== undefined && - // message.fileMetadata !== null - // ) { - // this.fileMetadata = message.fileMetadata; - // } - // if ( - // message.eventsPicklistValues !== undefined && - // message.eventsPicklistValues !== null - // ) { - // if (Array.isArray(message.eventsPicklistValues)) { - // this.filterPickListMaster = - // message.eventsPicklistValues.map((str) => ({ - // value: str, - // label: str - // })); - // } - // } - // } - // } onLinesPerPageChange(event) { // console.log("Page Change: ", event.target.value); let input = parseInt(event.target.value, 10); @@ -508,15 +493,59 @@ export default class logViewer extends LightningElement { handleSearch() { this.isSearching = !this.isSearching; - // const payload = this.fileData; - // publish('searchChannel', payload); + if (this.isSearching === false) { + this.processNoSearchRes(); + } + } + + processSearchRes(event) { + const lineNumbers = event.detail; + this.LineNumMap = new Map(); + console.log(lineNumbers); + if (Array.isArray(lineNumbers)) { + lineNumbers.forEach((l) => { + if (this.linesPerPage !== 0) { + const pNum = Math.ceil(l / this.linesPerPage); + if (this.LineNumMap.has(pNum)) { + this.LineNumMap.get(pNum).push(l); + } else { + this.LineNumMap.set(pNum, [l]); + } + } + }); + } + // console.log('Map: ', this.LineNumMap); + } + + goToMatch(event) { + const lineNumber = event.detail; + // console.log('lineNumber: ', lineNumber); + this.goToPage(lineNumber); } - goToNxtMatch(event) { - console.log(event.detail); + goToPage(lineNumber) { + //calculate the pagenumber + if (this.linesPerPage <= 0 || lineNumber <= 0) return; + this.LineNumFocus = lineNumber; + this.pageNumber = Math.ceil(lineNumber / this.linesPerPage); + this.calculations(); } - goToPrevMatch(event) { - console.log(event.detail); + processNoSearchRes() { + this.LineNumFocus = null; + if (this.LineNumMap.size > 0) { + if (this.LineNumMap.has(this.pageNumber)) { + const highEle = this.LineNumMap.get(this.pageNumber); + highEle.forEach((ele) => { + const element = this.template.querySelector( + `[data-logid="${ele}"]` + ); + if (element) { + element.style.backgroundColor = 'rgba(0, 0, 0, 0)'; + } + }); + } + } + this.LineNumMap = new Map(); } } diff --git a/src/modules/ui/search/search.js b/src/modules/ui/search/search.js index 0d93f94..26ec3e4 100644 --- a/src/modules/ui/search/search.js +++ b/src/modules/ui/search/search.js @@ -5,7 +5,7 @@ export default class Search extends LightningElement { onRes = 0; totRes = 0; nextDisabled = false; - prevDisabled = true; + prevDisabled = false; matchedLines = []; @api logtobeFiltered = []; @@ -24,32 +24,52 @@ export default class Search extends LightningElement { this.timeoutId = setTimeout(() => { this.searchLog(input); }, 500); - console.log('input: ', event.target.value); + // console.log('input: ', event.target.value); } gotoNext() { + let idx = this.onRes - 1; if (this.onRes < this.totRes) { + this.onRes++; this.dispatchEvent( - new CustomEvent('nextmatch', { - detail: this.matchedLines[this.onRes++] + new CustomEvent('matchchange', { + detail: this.matchedLines[++idx] }) ); + } else if (this.onRes === this.totRes) { + if (this.totRes !== 0) { + this.onRes = 1; + this.dispatchEvent( + new CustomEvent('matchchange', { + detail: this.matchedLines[0] + }) + ); + } } - this.nextDisabled = this.onRes === this.totRes ? true : false; - this.prevDisabled = this.onRes === 0 ? true : false; + // this.nextDisabled = this.onRes === this.totRes ? true : false; + // this.prevDisabled = this.onRes === 0 ? true : false; } goBack() { - if (this.onRes > 0) { + let idx = this.onRes - 1; + if (idx > 0) { + this.onRes--; this.dispatchEvent( - new CustomEvent('prevmatch', { - detail: this.matchedLines[this.onRes--] + new CustomEvent('matchchange', { + detail: this.matchedLines[--idx] + }) + ); + } else if (idx === 0) { + this.onRes = this.totRes; + this.dispatchEvent( + new CustomEvent('matchchange', { + detail: this.matchedLines[this.onRes - 1] }) ); } - this.nextDisabled = this.onRes === this.totRes ? true : false; - this.prevDisabled = this.onRes === 0 ? true : false; + // this.nextDisabled = this.onRes === this.totRes ? true : false; + // this.prevDisabled = this.onRes === 0 ? true : false; } searchLog(searchTerm) { @@ -57,7 +77,7 @@ export default class Search extends LightningElement { this.onRes = this.totRes = 0; return; } - if (searchTerm.length !== 0 && searchTerm !== undefined) { + if (searchTerm.length > 2 && searchTerm !== undefined) { const results = this.logtobeFiltered.filter((log) => log.line.includes(searchTerm) ); @@ -66,20 +86,27 @@ export default class Search extends LightningElement { // console.log('Found logs:', results); this.matchedLines = results.map((log) => log.lineNumber); this.totRes = this.matchedLines.length; - + this.onRes = 1; + this.dispatchEvent( + new CustomEvent('searchres', { + detail: this.matchedLines + }) + ); this.dispatchEvent( - new CustomEvent('nextmatch', { - detail: this.matchedLines[this.onRes++] + new CustomEvent('matchchange', { + detail: this.matchedLines[this.onRes - 1] }) ); // console.log('Line numbers:', lineNumbers); } else if (results.length === 0) { this.onRes = 0; this.totRes = 0; + this.dispatchEvent(new CustomEvent('nores')); } } else { this.onRes = 0; this.totRes = 0; + this.dispatchEvent(new CustomEvent('nores')); } } } From 3a035bc3af2c1e40c23e86834533346ae713d53e Mon Sep 17 00:00:00 2001 From: Charan Girijala <82193104+charangirijala@users.noreply.github.com> Date: Mon, 23 Dec 2024 21:05:11 +0530 Subject: [PATCH 2/2] GoTo functionality implemented --- src/modules/main/logViewer/logViewer.html | 35 +++++++---------------- src/modules/main/logViewer/logViewer.js | 14 +++++++-- src/modules/ui/input/input.html | 31 ++++++++++++++------ src/modules/ui/input/input.js | 15 +++++++++- src/modules/ui/search/search.js | 3 +- 5 files changed, 59 insertions(+), 39 deletions(-) diff --git a/src/modules/main/logViewer/logViewer.html b/src/modules/main/logViewer/logViewer.html index 5bb818b..ec66434 100644 --- a/src/modules/main/logViewer/logViewer.html +++ b/src/modules/main/logViewer/logViewer.html @@ -49,28 +49,11 @@

-
- -
+
line-height: 1; " > -
+
-
@@ -139,7 +124,7 @@

>Add Chart -

+
-->
{ if (this.linesPerPage !== 0) { @@ -548,4 +550,10 @@ export default class logViewer extends LightningElement { } this.LineNumMap = new Map(); } + + goToLine(event) { + // console.log('linenumber', event.detail); + const lNum = event.detail; + this.goToPage(lNum); + } } diff --git a/src/modules/ui/input/input.html b/src/modules/ui/input/input.html index a4ecf33..dec1478 100644 --- a/src/modules/ui/input/input.html +++ b/src/modules/ui/input/input.html @@ -1,15 +1,28 @@