#1014 use document list to display search results (#1548)

* #1014 use document list to diplay search results

* #1014 refactor pagination

* #1014 documentation and scripts update

* fix random erros on tests executrion

* #1014 fix travis scripts and raise timeout jasmine

* #1014 fix appveyor script

* #1014 type nodeId
This commit is contained in:
Mario Romano
2017-01-27 12:22:25 +00:00
committed by Denys Vuika
parent 9e00b1d4f1
commit b05247dade
52 changed files with 917 additions and 414 deletions

View File

@@ -18,9 +18,8 @@
import { Component, EventEmitter, Input, Output, Optional, OnChanges, SimpleChanges, OnInit } from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
import { AlfrescoSearchService, SearchOptions } from './../services/alfresco-search.service';
import { AlfrescoThumbnailService } from './../services/alfresco-thumbnail.service';
import { AlfrescoTranslationService } from 'ng2-alfresco-core';
import { MinimalNodeEntity } from 'alfresco-js-api';
import { NodePaging, Pagination } from 'alfresco-js-api';
@Component({
moduleId: module.id,
@@ -51,23 +50,28 @@ export class AlfrescoSearchComponent implements OnChanges, OnInit {
@Input()
navigationMode: string = AlfrescoSearchComponent.DOUBLE_CLICK_NAVIGATION; // click|dblclick
@Output()
navigate: EventEmitter<MinimalNodeEntity> = new EventEmitter<MinimalNodeEntity>();
@Output()
resultsLoad = new EventEmitter();
@Output()
preview: EventEmitter<any> = new EventEmitter<any>();
results: any = null;
pagination: Pagination;
errorMessage;
queryParamName = 'q';
skipCount: number = 0;
nodeResults: NodePaging;
baseComponentPath: string = module.id.replace('/components/alfresco-search.component.js', '');
constructor(private searchService: AlfrescoSearchService,
private translateService: AlfrescoTranslationService,
private thumbnailService: AlfrescoThumbnailService,
@Optional() private route: ActivatedRoute) {
}
@@ -75,6 +79,7 @@ export class AlfrescoSearchComponent implements OnChanges, OnInit {
if (this.translateService !== null) {
this.translateService.addTranslationFolder('ng2-alfresco-search', 'node_modules/ng2-alfresco-search/src');
}
if (this.route) {
this.route.params.forEach((params: Params) => {
this.searchTerm = params.hasOwnProperty(this.queryParamName) ? params[this.queryParamName] : null;
@@ -88,38 +93,16 @@ export class AlfrescoSearchComponent implements OnChanges, OnInit {
ngOnChanges(changes: SimpleChanges) {
if (changes['searchTerm']) {
this.searchTerm = changes['searchTerm'].currentValue;
this.skipCount = 0;
this.displaySearchResults(this.searchTerm);
}
}
/**
* Gets thumbnail URL for the given document node.
* @param node Node to get URL for.
* @returns {string} URL address.
*/
getMimeTypeIcon(node: any): string {
if (node.entry.content && node.entry.content.mimeType) {
let icon = this.thumbnailService.getMimeTypeIcon(node.entry.content.mimeType);
return this.resolveIconPath(icon);
} else if (node.entry.isFolder) {
return `${this.baseComponentPath}/../assets/images/ft_ic_folder.svg`;
}
}
private resolveIconPath(icon: string): string {
return `${this.baseComponentPath}/../assets/images/${icon}`;
}
/**
* Gets thumbnail message key for the given document node, which can be used to look up alt text
* @param node Node to get URL for.
* @returns {string} URL address.
*/
getMimeTypeKey(node: any): string {
if (node.entry.content && node.entry.content.mimeType) {
return 'SEARCH.ICONS.' + this.thumbnailService.getMimeTypeKey(node.entry.content.mimeType);
} else {
return '';
onPreviewFile(event: any) {
if (event.value) {
this.preview.emit({
value: event.value
});
}
}
@@ -131,6 +114,7 @@ export class AlfrescoSearchComponent implements OnChanges, OnInit {
if (searchTerm && this.searchService) {
let searchOpts: SearchOptions = {
include: ['path'],
skipCount: this.skipCount,
rootNodeId: this.rootNodeId,
nodeType: this.resultType,
maxItems: this.maxResults,
@@ -140,33 +124,35 @@ export class AlfrescoSearchComponent implements OnChanges, OnInit {
.getNodeQueryResults(searchTerm, searchOpts)
.subscribe(
results => {
this.nodeResults = results;
this.results = results.list.entries;
this.pagination = results.list.pagination;
this.resultsLoad.emit(this.results);
this.errorMessage = null;
},
error => {
this.results = null;
this.errorMessage = <any>error;
this.resultsLoad.error(error);
if (error.status !== 400) {
this.results = null;
this.errorMessage = <any>error;
this.resultsLoad.error(error);
}
}
);
}
}
onItemClick(node, event?: Event) {
if (this.navigate && this.navigationMode === AlfrescoSearchComponent.SINGLE_CLICK_NAVIGATION) {
if (node && node.entry) {
this.navigate.emit(node);
}
}
public onChangePageSize(event: Pagination): void {
this.maxResults = event.maxItems;
this.displaySearchResults(this.searchTerm);
}
onItemDblClick(node: MinimalNodeEntity) {
if (this.navigate && this.navigationMode === AlfrescoSearchComponent.DOUBLE_CLICK_NAVIGATION) {
if (node && node.entry) {
this.navigate.emit(node);
}
}
public onNextPage(event: Pagination): void {
this.skipCount = event.skipCount;
this.displaySearchResults(this.searchTerm);
}
public onPrevPage(event: Pagination): void {
this.skipCount = event.skipCount;
this.displaySearchResults(this.searchTerm);
}
}