mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-2045] Pagination is not working properly on Search Results Page (#2744)
This commit is contained in:
@@ -174,7 +174,6 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
noPermission: boolean = false;
|
||||
selection = new Array<MinimalNodeEntity>();
|
||||
|
||||
// PaginatedComponent implementation
|
||||
pagination = new Subject<Pagination>();
|
||||
|
||||
private layoutPresets = {};
|
||||
@@ -282,6 +281,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
if (changes.node && changes.node.currentValue) {
|
||||
this.resetSelection();
|
||||
this.data.loadPage(changes.node.currentValue);
|
||||
this.pagination.next(changes.node.currentValue.list.pagination);
|
||||
} else if (changes.rowFilter) {
|
||||
this.data.setFilter(changes.rowFilter.currentValue);
|
||||
if (this.currentFolderId) {
|
||||
@@ -862,7 +862,6 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
}
|
||||
}
|
||||
|
||||
// PaginatedComponent implementation
|
||||
updatePagination(params: PaginationQueryParams) {
|
||||
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[] {
|
||||
return this.appConfig.get('document-list.supportedPageSizes', [5, 10, 15, 25]);
|
||||
}
|
||||
|
@@ -118,7 +118,7 @@ export let errorJson = {
|
||||
|
||||
@Component({
|
||||
template: `
|
||||
<adf-search [searchTerm]="searchedWord" [searchNode]="searchNode" [maxResults]="maxResults"
|
||||
<adf-search [searchTerm]="searchedWord" [queryBody]="searchNode" [maxResults]="maxResults"
|
||||
(error)="showSearchResult('ERROR')"
|
||||
(success)="showSearchResult('success')" #search>
|
||||
<ng-template let-data>
|
||||
|
@@ -28,7 +28,7 @@
|
||||
|
||||
<adf-search #auto="searchAutocomplete"
|
||||
class="adf-search-result-autocomplete"
|
||||
[searchNode]="customSearchNode"
|
||||
[queryBody]="customSearchNode"
|
||||
[maxResults]="liveSearchMaxResults">
|
||||
<ng-template let-data>
|
||||
<mat-list *ngIf="isSearchBarActive()" id="autocomplete-search-result-list">
|
||||
|
@@ -64,7 +64,7 @@ export class SearchControlComponent implements OnInit, OnDestroy {
|
||||
liveSearchMaxResults: number = 5;
|
||||
|
||||
@Input()
|
||||
customSearchNode: QueryBody;
|
||||
customQueryBody: QueryBody;
|
||||
|
||||
@Output()
|
||||
submit: EventEmitter<any> = new EventEmitter();
|
||||
|
@@ -67,7 +67,7 @@ export class SearchComponent implements AfterContentInit, OnChanges {
|
||||
searchTerm: string = '';
|
||||
|
||||
@Input()
|
||||
searchNode: QueryBody;
|
||||
queryBody: QueryBody;
|
||||
|
||||
@Input('class')
|
||||
set classList(classList: string) {
|
||||
@@ -100,14 +100,13 @@ export class SearchComponent implements AfterContentInit, OnChanges {
|
||||
|
||||
_classList: { [key: string]: boolean } = {};
|
||||
|
||||
constructor(
|
||||
private searchService: SearchService,
|
||||
private changeDetectorRef: ChangeDetectorRef,
|
||||
private _elementRef: ElementRef) {
|
||||
constructor(private searchService: SearchService,
|
||||
private changeDetectorRef: ChangeDetectorRef,
|
||||
private _elementRef: ElementRef) {
|
||||
this.keyPressedStream.asObservable()
|
||||
.debounceTime(200)
|
||||
.subscribe((searchedWord: string) => {
|
||||
this.displaySearchResults(searchedWord);
|
||||
this.loadSearchResults(searchedWord);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -117,11 +116,13 @@ export class SearchComponent implements AfterContentInit, OnChanges {
|
||||
|
||||
ngOnChanges(changes) {
|
||||
this.resetResults();
|
||||
|
||||
if (changes.searchTerm && changes.searchTerm.currentValue) {
|
||||
this.displaySearchResults(changes.searchTerm.currentValue);
|
||||
}
|
||||
if (changes.searchNode && changes.searchNode.currentValue) {
|
||||
this.displaySearchResults();
|
||||
this.loadSearchResults(changes.searchTerm.currentValue);
|
||||
} else if (changes.queryBody && changes.queryBody.currentValue) {
|
||||
this.loadSearchResults();
|
||||
} else {
|
||||
this.loadSearchResults(this.searchTerm);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,7 +132,7 @@ export class SearchComponent implements AfterContentInit, OnChanges {
|
||||
}
|
||||
|
||||
reload() {
|
||||
this.displaySearchResults(this.searchTerm);
|
||||
this.loadSearchResults(this.searchTerm);
|
||||
}
|
||||
|
||||
private cleanResults() {
|
||||
@@ -144,43 +145,43 @@ export class SearchComponent implements AfterContentInit, OnChanges {
|
||||
return searchOpts && searchOpts.query && searchOpts.query.query;
|
||||
}
|
||||
|
||||
private displaySearchResults(searchTerm?: string) {
|
||||
let searchOpts: QueryBody = this.getSearchNode(searchTerm);
|
||||
private loadSearchResults(searchTerm?: string) {
|
||||
let searchOpts: QueryBody = this.getQueryBody(searchTerm);
|
||||
|
||||
if (this.hasValidSearchQuery(searchOpts)) {
|
||||
this.searchService
|
||||
.search(searchOpts)
|
||||
.subscribe(
|
||||
results => {
|
||||
this.results = <NodePaging> results;
|
||||
this.resultLoaded.emit(this.results);
|
||||
this.isOpen = true;
|
||||
this.setVisibility();
|
||||
},
|
||||
error => {
|
||||
if (error.status !== 400) {
|
||||
this.results = null;
|
||||
this.error.emit(error);
|
||||
}
|
||||
});
|
||||
results => {
|
||||
this.results = <NodePaging> results;
|
||||
this.resultLoaded.emit(this.results);
|
||||
this.isOpen = true;
|
||||
this.setVisibility();
|
||||
},
|
||||
error => {
|
||||
if (error.status !== 400) {
|
||||
this.results = null;
|
||||
this.error.emit(error);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.cleanResults();
|
||||
}
|
||||
}
|
||||
|
||||
private getSearchNode(searchTerm: string): QueryBody {
|
||||
if (this.searchNode) {
|
||||
if (!this.searchNode.query.query && searchTerm) {
|
||||
this.searchNode.query.query = searchTerm;
|
||||
private getQueryBody(searchTerm: string): QueryBody {
|
||||
if (this.queryBody) {
|
||||
if (!this.queryBody.query.query && searchTerm) {
|
||||
this.queryBody.query.query = searchTerm;
|
||||
}
|
||||
return this.searchNode;
|
||||
return this.queryBody;
|
||||
} else {
|
||||
return this.generateDefaultSearchNode(searchTerm);
|
||||
}
|
||||
}
|
||||
|
||||
private generateDefaultSearchNode(searchTerm: string): QueryBody {
|
||||
let defaultSearchNode: QueryBody = {
|
||||
let defaultQueryBody: QueryBody = {
|
||||
query: {
|
||||
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: 'NOT cm:creator:System' }]
|
||||
};
|
||||
return defaultSearchNode;
|
||||
|
||||
return defaultQueryBody;
|
||||
}
|
||||
|
||||
hidePanel() {
|
||||
|
Reference in New Issue
Block a user