[ACA-1449][ACA-1448] Show searched term on the extended search input (#411)

* [ACA-1449][ACA-1448] Show searched term on the extended search input

* [ACA-1449][ACA-1448] fix test
This commit is contained in:
Suzana Dirla 2018-06-14 16:26:25 +03:00 committed by Denys Vuika
parent f8fe664f1f
commit 981b59095c
4 changed files with 82 additions and 14 deletions

View File

@ -1,8 +1,17 @@
<adf-search-control
[highlight]="true"
(optionClicked)="onItemClicked($event)"
[expandable]="!onSearchResults"
[liveSearchEnabled]="!onSearchResults"
(submit)="onSearchSubmit($event)"
(searchChange)="onSearchChange($event)">
</adf-search-control>
<div class="adf-search-control-wrapper">
<button mat-icon-button
*ngIf="onSearchResults"
id="adf-search-button"
class="adf-search-button"
[title]="'SEARCH.BUTTON.TOOLTIP' | translate">
<mat-icon [attr.aria-label]="'SEARCH.BUTTON.ARIA-LABEL' | translate">search</mat-icon>
</button>
<adf-search-control #searchControl
[highlight]="true"
(optionClicked)="onItemClicked($event)"
[expandable]="!onSearchResults"
[liveSearchEnabled]="!onSearchResults"
(submit)="onSearchSubmit($event)"
(searchChange)="onSearchChange($event)">
</adf-search-control>
</div>

View File

@ -8,3 +8,21 @@
adf-search-control {
color: $alfresco-white;
}
.adf-search-control-wrapper {
display: flex;
box-sizing: border-box;
padding: 0;
width: 100%;
flex-direction: row;
align-items: center;
white-space: nowrap;
.adf-search-button {
left: -15px;
margin-left: 13px;
align-items: flex-start;
font: 400 11px system-ui;
color: #fff;
}
}

View File

@ -29,6 +29,7 @@ import { Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { SearchInputComponent } from './search-input.component';
import { TranslateModule } from '@ngx-translate/core';
describe('SearchInputComponent', () => {
let fixture;
@ -38,7 +39,8 @@ describe('SearchInputComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule
RouterTestingModule,
TranslateModule.forRoot()
],
declarations: [
SearchInputComponent

View File

@ -23,23 +23,62 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { Component, OnInit, ViewChild } from '@angular/core';
import {
NavigationEnd, PRIMARY_OUTLET, Router, RouterEvent, UrlSegment, UrlSegmentGroup,
UrlTree
} from '@angular/router';
import { MinimalNodeEntity } from 'alfresco-js-api';
import { SearchControlComponent } from '@alfresco/adf-content-services';
@Component({
selector: 'app-search-input',
templateUrl: 'search-input.component.html',
styleUrls: ['search-input.component.scss']
})
export class SearchInputComponent {
export class SearchInputComponent implements OnInit {
hasOneChange = false;
hasNewChange = false;
navigationTimer: any;
constructor(
private router: Router) {
@ViewChild('searchControl')
searchControl: SearchControlComponent;
constructor(private router: Router) {
this.router.events.filter(e => e instanceof RouterEvent).subscribe(event => {
if (event instanceof NavigationEnd) {
this.showInputValue();
}
});
}
ngOnInit() {
this.showInputValue();
}
showInputValue() {
if (this.onSearchResults) {
let searchedWord = null;
const urlTree: UrlTree = this.router.parseUrl(this.router.url);
const urlSegmentGroup: UrlSegmentGroup = urlTree.root.children[PRIMARY_OUTLET];
if (urlSegmentGroup) {
const urlSegments: UrlSegment[] = urlSegmentGroup.segments;
searchedWord = urlSegments[0].parameters['q'];
}
this.searchControl.searchTerm = searchedWord;
this.searchControl.subscriptAnimationState = 'no-animation';
} else {
if (this.searchControl.subscriptAnimationState === 'no-animation') {
this.searchControl.subscriptAnimationState = 'active';
this.searchControl.searchTerm = '';
this.searchControl.toggleSearchBar();
}
}
}
onItemClicked(node: MinimalNodeEntity) {