[ADF-2045] Pagination is not working properly on Search Results Page (#2744)

This commit is contained in:
Eugenio Romano 2017-11-28 12:46:01 +00:00 committed by GitHub
parent ee901b6641
commit c763ba45e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 58 additions and 62 deletions

View File

@ -23,7 +23,7 @@ import { Component, Input } from '@angular/core';
export class OverlayViewerComponent { export class OverlayViewerComponent {
@Input() @Input()
showViewer: boolean = false; showViewer = false;
nodeId: string; nodeId: string;

View File

@ -1,7 +1,7 @@
<adf-search [searchTerm]="searchedWord" <adf-search [searchTerm]="searchedWord"
[maxResults]="maxItems" [maxResults]="maxItems"
[skipResults]="skipCount" [skipResults]="skipCount"
(resultLoaded)="showSearchResult($event)" (resultLoaded)="onSearchResultLoaded($event)"
#search> #search>
</adf-search> </adf-search>
@ -9,10 +9,11 @@
[currentFolderId]="null" [currentFolderId]="null"
[nodeResult]="resultNodePageList" [nodeResult]="resultNodePageList"
[disableDragArea]="true" [disableDragArea]="true"
(documentListReady)="refreshResults($event)" [pagination]="pagination"
(changedPageSize)="refreshPage($event)" (documentListReady)="onDocumentListReady($event)"
(changedPageNumber)="refreshPage($event)" (changedPageSize)="onRefreshPagination($event)"
(turnedNextPage)="refreshPage($event)" (changedPageNumber)="onRefreshPagination($event)"
(loadNext)="refreshPage($event)" (turnedNextPage)="onRefreshPagination($event)"
(turnedPreviousPage)="refreshPage($event)"> (loadNext)="onRefreshPagination($event)"
(turnedPreviousPage)="onRefreshPagination($event)">
</app-files-component> </app-files-component>

View File

@ -31,15 +31,12 @@ export class SearchResultComponent implements OnInit {
@ViewChild('search') @ViewChild('search')
search: SearchComponent; search: SearchComponent;
fileNodeId: string;
queryParamName = 'q'; queryParamName = 'q';
searchedWord = ''; searchedWord = '';
fileShowed = false;
navigationMode = 'dblclick';
resultNodePageList: NodePaging; resultNodePageList: NodePaging;
maxItems: number; maxItems: number;
skipCount = 0; skipCount = 0;
paging: Pagination; pagination: Pagination;
constructor(public router: Router, constructor(public router: Router,
private preferences: UserPreferencesService, private preferences: UserPreferencesService,
@ -56,17 +53,17 @@ export class SearchResultComponent implements OnInit {
this.maxItems = this.preferences.paginationSize; this.maxItems = this.preferences.paginationSize;
} }
showSearchResult(event: NodePaging) { onSearchResultLoaded(nodePaging: NodePaging) {
this.resultNodePageList = event; this.resultNodePageList = nodePaging;
this.paging = event.list.pagination; this.pagination = nodePaging.list.pagination;
} }
refreshResults(event: any) { onDocumentListReady() {
this.search.reload(); // this.search.reload();
} }
refreshPage(event: Pagination) { onRefreshPagination(pagination: Pagination) {
this.maxItems = event.maxItems; this.maxItems = pagination.maxItems;
this.skipCount = event.skipCount; this.skipCount = pagination.skipCount;
} }
} }

View File

@ -24,8 +24,6 @@ import { LogService } from '@alfresco/adf-core';
}) })
export class WebscriptComponent { export class WebscriptComponent {
currentPath = '/';
host = 'http://127.0.0.1:8080';
scriptPath = 'sample/folder/Company%20Home'; scriptPath = 'sample/folder/Company%20Home';
contextRoot = 'alfresco'; contextRoot = 'alfresco';
servicePath = 'service'; servicePath = 'service';

View File

@ -39,7 +39,7 @@ Displays a input text which shows find-as-you-type suggestions.
| expandable | boolean | true | Whether to use an expanding search control, if false then a regular input is used. | | expandable | boolean | true | Whether to use an expanding search control, if false then a regular input is used. |
| liveSearchEnabled | boolean | true | Whether find-as-you-type suggestions should be offered for matching content items. Set to false to disable. | | liveSearchEnabled | boolean | true | Whether find-as-you-type suggestions should be offered for matching content items. Set to false to disable. |
| liveSearchMaxResults | number | 5 | Maximum number of results to show in the live search. | | liveSearchMaxResults | number | 5 | Maximum number of results to show in the live search. |
| customSearchNode | [QueryBody](https://github.com/Alfresco/alfresco-js-api/blob/1.6.0/src/alfresco-search-rest-api/docs/QueryBody.md) | | object which allow you to perform more elaborated query from the search api | | customQueryBody | [QueryBody](https://github.com/Alfresco/alfresco-js-api/blob/1.6.0/src/alfresco-search-rest-api/docs/QueryBody.md) | | object which allow you to perform more elaborated query from the search api |
### Events ### Events

View File

@ -32,7 +32,7 @@
| maxResults | number | 20 | Maximum number of results to show in the search. | | maxResults | number | 20 | Maximum number of results to show in the search. |
| skipResults | number | 0 | Number of results to skip from the results pagination. | | skipResults | number | 0 | Number of results to skip from the results pagination. |
| displayWith | function | | Function that maps an option's value to its display value in the trigger | | displayWith | function | | Function that maps an option's value to its display value in the trigger |
| searchNode | [QueryBody](https://github.com/Alfresco/alfresco-js-api/blob/1.6.0/src/alfresco-search-rest-api/docs/QueryBody.md) | | object which allow you to perform more elaborated query from the search api | | queryBody| [QueryBody](https://github.com/Alfresco/alfresco-js-api/blob/1.6.0/src/alfresco-search-rest-api/docs/QueryBody.md) | | object which allow you to perform more elaborated query from the search api |
### Events ### Events

View File

@ -174,7 +174,6 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
noPermission: boolean = false; noPermission: boolean = false;
selection = new Array<MinimalNodeEntity>(); selection = new Array<MinimalNodeEntity>();
// PaginatedComponent implementation
pagination = new Subject<Pagination>(); pagination = new Subject<Pagination>();
private layoutPresets = {}; private layoutPresets = {};
@ -282,6 +281,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
if (changes.node && changes.node.currentValue) { if (changes.node && changes.node.currentValue) {
this.resetSelection(); this.resetSelection();
this.data.loadPage(changes.node.currentValue); this.data.loadPage(changes.node.currentValue);
this.pagination.next(changes.node.currentValue.list.pagination);
} else if (changes.rowFilter) { } else if (changes.rowFilter) {
this.data.setFilter(changes.rowFilter.currentValue); this.data.setFilter(changes.rowFilter.currentValue);
if (this.currentFolderId) { if (this.currentFolderId) {
@ -862,7 +862,6 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
} }
} }
// PaginatedComponent implementation
updatePagination(params: PaginationQueryParams) { updatePagination(params: PaginationQueryParams) {
const needsReload = this.maxItems !== params.maxItems || this.skipCount !== params.skipCount; const needsReload = this.maxItems !== params.maxItems || this.skipCount !== params.skipCount;
@ -874,7 +873,6 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
} }
} }
// PaginatedComponent implementation
get supportedPageSizes(): number[] { get supportedPageSizes(): number[] {
return this.appConfig.get('document-list.supportedPageSizes', [5, 10, 15, 25]); return this.appConfig.get('document-list.supportedPageSizes', [5, 10, 15, 25]);
} }

View File

@ -118,7 +118,7 @@ export let errorJson = {
@Component({ @Component({
template: ` template: `
<adf-search [searchTerm]="searchedWord" [searchNode]="searchNode" [maxResults]="maxResults" <adf-search [searchTerm]="searchedWord" [queryBody]="searchNode" [maxResults]="maxResults"
(error)="showSearchResult('ERROR')" (error)="showSearchResult('ERROR')"
(success)="showSearchResult('success')" #search> (success)="showSearchResult('success')" #search>
<ng-template let-data> <ng-template let-data>

View File

@ -28,7 +28,7 @@
<adf-search #auto="searchAutocomplete" <adf-search #auto="searchAutocomplete"
class="adf-search-result-autocomplete" class="adf-search-result-autocomplete"
[searchNode]="customSearchNode" [queryBody]="customSearchNode"
[maxResults]="liveSearchMaxResults"> [maxResults]="liveSearchMaxResults">
<ng-template let-data> <ng-template let-data>
<mat-list *ngIf="isSearchBarActive()" id="autocomplete-search-result-list"> <mat-list *ngIf="isSearchBarActive()" id="autocomplete-search-result-list">

View File

@ -64,7 +64,7 @@ export class SearchControlComponent implements OnInit, OnDestroy {
liveSearchMaxResults: number = 5; liveSearchMaxResults: number = 5;
@Input() @Input()
customSearchNode: QueryBody; customQueryBody: QueryBody;
@Output() @Output()
submit: EventEmitter<any> = new EventEmitter(); submit: EventEmitter<any> = new EventEmitter();

View File

@ -67,7 +67,7 @@ export class SearchComponent implements AfterContentInit, OnChanges {
searchTerm: string = ''; searchTerm: string = '';
@Input() @Input()
searchNode: QueryBody; queryBody: QueryBody;
@Input('class') @Input('class')
set classList(classList: string) { set classList(classList: string) {
@ -100,14 +100,13 @@ export class SearchComponent implements AfterContentInit, OnChanges {
_classList: { [key: string]: boolean } = {}; _classList: { [key: string]: boolean } = {};
constructor( constructor(private searchService: SearchService,
private searchService: SearchService, private changeDetectorRef: ChangeDetectorRef,
private changeDetectorRef: ChangeDetectorRef, private _elementRef: ElementRef) {
private _elementRef: ElementRef) {
this.keyPressedStream.asObservable() this.keyPressedStream.asObservable()
.debounceTime(200) .debounceTime(200)
.subscribe((searchedWord: string) => { .subscribe((searchedWord: string) => {
this.displaySearchResults(searchedWord); this.loadSearchResults(searchedWord);
}); });
} }
@ -117,11 +116,13 @@ export class SearchComponent implements AfterContentInit, OnChanges {
ngOnChanges(changes) { ngOnChanges(changes) {
this.resetResults(); this.resetResults();
if (changes.searchTerm && changes.searchTerm.currentValue) { if (changes.searchTerm && changes.searchTerm.currentValue) {
this.displaySearchResults(changes.searchTerm.currentValue); this.loadSearchResults(changes.searchTerm.currentValue);
} } else if (changes.queryBody && changes.queryBody.currentValue) {
if (changes.searchNode && changes.searchNode.currentValue) { this.loadSearchResults();
this.displaySearchResults(); } else {
this.loadSearchResults(this.searchTerm);
} }
} }
@ -131,7 +132,7 @@ export class SearchComponent implements AfterContentInit, OnChanges {
} }
reload() { reload() {
this.displaySearchResults(this.searchTerm); this.loadSearchResults(this.searchTerm);
} }
private cleanResults() { private cleanResults() {
@ -144,43 +145,43 @@ export class SearchComponent implements AfterContentInit, OnChanges {
return searchOpts && searchOpts.query && searchOpts.query.query; return searchOpts && searchOpts.query && searchOpts.query.query;
} }
private displaySearchResults(searchTerm?: string) { private loadSearchResults(searchTerm?: string) {
let searchOpts: QueryBody = this.getSearchNode(searchTerm); let searchOpts: QueryBody = this.getQueryBody(searchTerm);
if (this.hasValidSearchQuery(searchOpts)) { if (this.hasValidSearchQuery(searchOpts)) {
this.searchService this.searchService
.search(searchOpts) .search(searchOpts)
.subscribe( .subscribe(
results => { results => {
this.results = <NodePaging> results; this.results = <NodePaging> results;
this.resultLoaded.emit(this.results); this.resultLoaded.emit(this.results);
this.isOpen = true; this.isOpen = true;
this.setVisibility(); this.setVisibility();
}, },
error => { error => {
if (error.status !== 400) { if (error.status !== 400) {
this.results = null; this.results = null;
this.error.emit(error); this.error.emit(error);
} }
}); });
} else { } else {
this.cleanResults(); this.cleanResults();
} }
} }
private getSearchNode(searchTerm: string): QueryBody { private getQueryBody(searchTerm: string): QueryBody {
if (this.searchNode) { if (this.queryBody) {
if (!this.searchNode.query.query && searchTerm) { if (!this.queryBody.query.query && searchTerm) {
this.searchNode.query.query = searchTerm; this.queryBody.query.query = searchTerm;
} }
return this.searchNode; return this.queryBody;
} else { } else {
return this.generateDefaultSearchNode(searchTerm); return this.generateDefaultSearchNode(searchTerm);
} }
} }
private generateDefaultSearchNode(searchTerm: string): QueryBody { private generateDefaultSearchNode(searchTerm: string): QueryBody {
let defaultSearchNode: QueryBody = { let defaultQueryBody: QueryBody = {
query: { query: {
query: searchTerm ? `${searchTerm}* OR name:${searchTerm}*` : searchTerm query: searchTerm ? `${searchTerm}* OR name:${searchTerm}*` : searchTerm
}, },
@ -193,7 +194,8 @@ export class SearchComponent implements AfterContentInit, OnChanges {
{ query: "TYPE:'cm:folder' OR TYPE:'cm:content'" }, { query: "TYPE:'cm:folder' OR TYPE:'cm:content'" },
{ query: 'NOT cm:creator:System' }] { query: 'NOT cm:creator:System' }]
}; };
return defaultSearchNode;
return defaultQueryBody;
} }
hidePanel() { hidePanel() {