From 9771b172508192124bb75258d038ed40c4ffdfbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tamara=20M=C3=BCller?= Date: Fri, 1 Dec 2017 15:14:49 +0100 Subject: [PATCH] Add the functionality to show all comments of a PDF file #3. --- .../reference/components/pdf/pdf.component.ts | 31 +++++++++++-- .../reference/components/pdf/pdf.html | 15 ++++-- .../src/app/theme/pipes/search/search.pipe.ts | 46 ++++++++++--------- 3 files changed, 64 insertions(+), 28 deletions(-) diff --git a/frontend/src/app/pages/references/components/reference/components/pdf/pdf.component.ts b/frontend/src/app/pages/references/components/reference/components/pdf/pdf.component.ts index 0e99ecc5..d6ce7196 100644 --- a/frontend/src/app/pages/references/components/reference/components/pdf/pdf.component.ts +++ b/frontend/src/app/pages/references/components/reference/components/pdf/pdf.component.ts @@ -64,15 +64,40 @@ export class PdfViewComponent implements AfterViewInit, OnDestroy { searchableList = ['author', 'content']; sort: string = 'pageNumber'; - private queryString: string = ''; + private queryString: string = null; private lastPageNumberLabel: number; private searchInputValue: string; + private showAll: boolean = false; + private disableShowAll: boolean = false; + + private triggerShowAll() { + // toggle + this.showAll = !this.showAll; + + if (this.showAll) { + // show all comments + this.queryString = ''; + } else { + // reset show all + this.queryString = null; + } + } private searchComments() { // check if search input changed if (this.queryString !== this.searchInputValue) { - // change search string - this.queryString = this.searchInputValue; + + if (this.searchInputValue != null && this.searchInputValue !== '') { + // change search string + this.queryString = this.searchInputValue; + this.showAll = true; + this.disableShowAll = true; + } else { + // reset search + this.queryString = null; + this.showAll = false; + this.disableShowAll = false; + } // check if a comment is selected if (this.selectedComment != null) { diff --git a/frontend/src/app/pages/references/components/reference/components/pdf/pdf.html b/frontend/src/app/pages/references/components/reference/components/pdf/pdf.html index 971e7bc5..18a6db88 100644 --- a/frontend/src/app/pages/references/components/reference/components/pdf/pdf.html +++ b/frontend/src/app/pages/references/components/reference/components/pdf/pdf.html @@ -26,6 +26,15 @@ + +
+ +
@@ -45,7 +54,7 @@ [@anim]="comment"> Edited on
{{comment.alterationDate}}
-
Page {{comment.pageNumber}} @@ -54,7 +63,7 @@
@@ -81,7 +90,7 @@
diff --git a/frontend/src/app/theme/pipes/search/search.pipe.ts b/frontend/src/app/theme/pipes/search/search.pipe.ts index 6bfc7d35..ea1dacd4 100644 --- a/frontend/src/app/theme/pipes/search/search.pipe.ts +++ b/frontend/src/app/theme/pipes/search/search.pipe.ts @@ -19,30 +19,32 @@ export class SearchPipe implements PipeTransform { transform(list: any, input: string, searchableList: any, sort: string) { let result = list; - if (input) { - input = input.toLowerCase(); - result = result.filter(function (el: any) { - let isTrue = false; - for (let k in searchableList) { - if (el[searchableList[k]].toLowerCase().indexOf(input) > -1) { - isTrue = true; + if (input != null) { + if (input) { + input = input.toLowerCase(); + result = result.filter(function (el: any) { + let isTrue = false; + for (let k in searchableList) { + if (el[searchableList[k]].toLowerCase().indexOf(input) > -1) { + isTrue = true; + } + if (isTrue) { + return el; + } } - if (isTrue) { - return el; - } - } - }); + }); - // sort result - result = result.sort((obj1, obj2) => { - if (obj1[sort] > obj2[sort]) { - return 1; - } - if (obj1[sort] < obj2[sort]) { - return -1; - } - return 0; - }); + // sort result + result = result.sort((obj1, obj2) => { + if (obj1[sort] > obj2[sort]) { + return 1; + } + if (obj1[sort] < obj2[sort]) { + return -1; + } + return 0; + }); + } } return result; }