Restore navigation to search page in demo-shell

- Remove deprecated router component
- searchChanges and new searchSubmit component outputs work as you would expect
- Update tests

Refs #737
This commit is contained in:
Will Abson
2016-09-23 18:07:40 +01:00
parent 79fc3085c0
commit 147af98bda
6 changed files with 85 additions and 24 deletions

View File

@@ -15,8 +15,8 @@
* limitations under the License.
*/
import { Component, EventEmitter, Input, Output, OnChanges, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Component, EventEmitter, Input, Output, Optional, OnChanges, SimpleChanges, OnInit } from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
import { AlfrescoSearchService } from './../services/alfresco-search.service';
import { AlfrescoThumbnailService } from './../services/alfresco-thumbnail.service';
import { AlfrescoTranslationService } from 'ng2-alfresco-core';
@@ -46,12 +46,12 @@ export class AlfrescoSearchComponent implements OnChanges, OnInit {
errorMessage;
route: any[] = [];
queryParamName = 'q';
constructor(private alfrescoSearchService: AlfrescoSearchService,
private translate: AlfrescoTranslationService,
private _alfrescoThumbnailService: AlfrescoThumbnailService,
private activatedRoute: ActivatedRoute) {
@Optional() private route: ActivatedRoute) {
if (translate !== null) {
translate.addTranslationFolder('node_modules/ng2-alfresco-search/dist/src');
@@ -61,15 +61,19 @@ export class AlfrescoSearchComponent implements OnChanges, OnInit {
}
ngOnInit(): void {
this.activatedRoute.params.subscribe(params => {
this.searchTerm = params['q'];
if (this.route) {
this.route.params.forEach((params: Params) => {
this.searchTerm = params.hasOwnProperty(this.queryParamName) ? params[this.queryParamName] : null;
this.displaySearchResults(this.searchTerm);
});
} else {
this.displaySearchResults(this.searchTerm);
});
}
}
ngOnChanges(changes): void {
if (changes.searchTerm) {
this.displaySearchResults(changes.searchTerm.currentValue);
ngOnChanges(changes: SimpleChanges): void {
if (changes['searchTerm']) {
this.displaySearchResults(changes['searchTerm'].currentValue);
}
}