mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
[ADF-2045] Pagination is not working properly on Search Results Page (#2744)
This commit is contained in:
parent
ee901b6641
commit
c763ba45e0
@ -23,7 +23,7 @@ import { Component, Input } from '@angular/core';
|
||||
export class OverlayViewerComponent {
|
||||
|
||||
@Input()
|
||||
showViewer: boolean = false;
|
||||
showViewer = false;
|
||||
|
||||
nodeId: string;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
<adf-search [searchTerm]="searchedWord"
|
||||
[maxResults]="maxItems"
|
||||
[skipResults]="skipCount"
|
||||
(resultLoaded)="showSearchResult($event)"
|
||||
(resultLoaded)="onSearchResultLoaded($event)"
|
||||
#search>
|
||||
</adf-search>
|
||||
|
||||
@ -9,10 +9,11 @@
|
||||
[currentFolderId]="null"
|
||||
[nodeResult]="resultNodePageList"
|
||||
[disableDragArea]="true"
|
||||
(documentListReady)="refreshResults($event)"
|
||||
(changedPageSize)="refreshPage($event)"
|
||||
(changedPageNumber)="refreshPage($event)"
|
||||
(turnedNextPage)="refreshPage($event)"
|
||||
(loadNext)="refreshPage($event)"
|
||||
(turnedPreviousPage)="refreshPage($event)">
|
||||
[pagination]="pagination"
|
||||
(documentListReady)="onDocumentListReady($event)"
|
||||
(changedPageSize)="onRefreshPagination($event)"
|
||||
(changedPageNumber)="onRefreshPagination($event)"
|
||||
(turnedNextPage)="onRefreshPagination($event)"
|
||||
(loadNext)="onRefreshPagination($event)"
|
||||
(turnedPreviousPage)="onRefreshPagination($event)">
|
||||
</app-files-component>
|
||||
|
@ -31,15 +31,12 @@ export class SearchResultComponent implements OnInit {
|
||||
@ViewChild('search')
|
||||
search: SearchComponent;
|
||||
|
||||
fileNodeId: string;
|
||||
queryParamName = 'q';
|
||||
searchedWord = '';
|
||||
fileShowed = false;
|
||||
navigationMode = 'dblclick';
|
||||
resultNodePageList: NodePaging;
|
||||
maxItems: number;
|
||||
skipCount = 0;
|
||||
paging: Pagination;
|
||||
pagination: Pagination;
|
||||
|
||||
constructor(public router: Router,
|
||||
private preferences: UserPreferencesService,
|
||||
@ -56,17 +53,17 @@ export class SearchResultComponent implements OnInit {
|
||||
this.maxItems = this.preferences.paginationSize;
|
||||
}
|
||||
|
||||
showSearchResult(event: NodePaging) {
|
||||
this.resultNodePageList = event;
|
||||
this.paging = event.list.pagination;
|
||||
onSearchResultLoaded(nodePaging: NodePaging) {
|
||||
this.resultNodePageList = nodePaging;
|
||||
this.pagination = nodePaging.list.pagination;
|
||||
}
|
||||
|
||||
refreshResults(event: any) {
|
||||
this.search.reload();
|
||||
onDocumentListReady() {
|
||||
// this.search.reload();
|
||||
}
|
||||
|
||||
refreshPage(event: Pagination) {
|
||||
this.maxItems = event.maxItems;
|
||||
this.skipCount = event.skipCount;
|
||||
onRefreshPagination(pagination: Pagination) {
|
||||
this.maxItems = pagination.maxItems;
|
||||
this.skipCount = pagination.skipCount;
|
||||
}
|
||||
}
|
||||
|
@ -24,8 +24,6 @@ import { LogService } from '@alfresco/adf-core';
|
||||
})
|
||||
export class WebscriptComponent {
|
||||
|
||||
currentPath = '/';
|
||||
host = 'http://127.0.0.1:8080';
|
||||
scriptPath = 'sample/folder/Company%20Home';
|
||||
contextRoot = 'alfresco';
|
||||
servicePath = 'service';
|
||||
|
@ -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. |
|
||||
| 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. |
|
||||
| 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
|
||||
|
||||
|
@ -32,7 +32,7 @@
|
||||
| maxResults | number | 20 | Maximum number of results to show in the search. |
|
||||
| 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 |
|
||||
| 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
|
||||
|
||||
|
@ -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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user