File
Description
Main menu component
Implements
Index
Properties
|
|
Methods
|
|
Inputs
|
|
layoutConfiguration
|
Type : any
|
|
To send activatedRoute.snapshot to router navigation
service for redirection to parent component
|
Methods
getInteractEdata
|
getInteractEdata(key)
|
|
|
isLayoutAvailable
|
isLayoutAvailable()
|
|
|
ngOnDestroy
|
ngOnDestroy()
|
|
|
onChange
|
onChange()
|
|
on changing dropdown option
it navigate
|
onEnter
|
onEnter(key)
|
|
on entering keyword
it navigate
|
setDropdownSelectedOption
|
setDropdownSelectedOption(value)
|
|
|
setSearchPlaceHolderValue
|
setSearchPlaceHolderValue()
|
|
search input box placeholder value
|
Private
activatedRoute
|
Type : ActivatedRoute
|
|
isConnected
|
Default value : true
|
|
isDesktopApp
|
Default value : false
|
|
queryParam
|
Type : any
|
Default value : {}
|
|
resourceDataSubscription
|
Type : Subscription
|
|
Private
route
|
Type : Router
|
|
To navigate to other pages
|
search
|
Type : object
|
|
input keyword depending on url
|
searchDisplayValueMappers
|
Type : object
|
|
searchDropdownValues
|
Type : Array<string>
|
Default value : ['All', 'Courses', 'Library']
|
|
searchPlaceHolderValue
|
Type : string
|
|
selectedOption
|
Type : string
|
|
option selected on dropdown
|
showSuiSelectDropdown
|
Type : boolean
|
|
Public
userService
|
Type : UserService
|
|
reference of UserService service.
|
import { filter } from 'rxjs/operators';
import { Component, OnInit, ChangeDetectorRef, OnDestroy, Input } from '@angular/core';
import { ActivatedRoute, Router, NavigationEnd } from '@angular/router';
import { UserService } from './../../services';
import { ResourceService, ConfigService, IUserProfile, LayoutService, UtilService, ConnectionService } from '@sunbird/shared';
import { Subscription } from 'rxjs';
import * as _ from 'lodash-es';
/**
* Main menu component
*/
@Component({
selector: 'app-search',
templateUrl: './search.component.html',
styleUrls: ['./search.component.scss']
})
export class SearchComponent implements OnInit, OnDestroy {
/**
* Sui dropdown initiator
*/
isOpen: boolean;
showSuiSelectDropdown: boolean;
/**
*
*/
queryParam: any = {};
/**
* value of current url
*/
value: any;
/**
* key enter for search
*/
key: string;
resourceService: ResourceService;
resourceDataSubscription: Subscription;
/**
* option selected on dropdown
*/
selectedOption: string;
/**
* show input field
*/
showInput: boolean;
/**
* input keyword depending on url
*/
search: object;
/**
* url
*/
searchUrl: object;
config: ConfigService;
userProfile: IUserProfile;
searchDropdownValues: Array<string> = ['All', 'Courses', 'Library'];
searchPlaceHolderValue: string;
searchDisplayValueMappers: object;
isDesktopApp = false;
isConnected = true;
/**
* reference of UserService service.
*/
public userService: UserService;
/**
* To navigate to other pages
*/
private route: Router;
/**
* To send activatedRoute.snapshot to router navigation
* service for redirection to parent component
*/
@Input() layoutConfiguration: any;
private activatedRoute: ActivatedRoute;
/**
* Constructor to create injected service(s) object
* Default method of Draft Component class
* @param {Router} route Reference of Router
* @param {ActivatedRoute} activatedRoute Reference of ActivatedRoute
*/
constructor(route: Router, activatedRoute: ActivatedRoute, userService: UserService,
resourceService: ResourceService, config: ConfigService, public utilService: UtilService,
private cdr: ChangeDetectorRef, public layoutService: LayoutService, public connectionService: ConnectionService) {
this.route = route;
this.activatedRoute = activatedRoute;
this.resourceService = resourceService;
this.config = config;
this.userService = userService;
this.searchDisplayValueMappers = {
'Users': 'users'
};
}
ngOnInit() {
this.isDesktopApp = this.utilService.isDesktopApp;
this.showInput = true;
this.activatedRoute.queryParams.subscribe(queryParams => {
this.queryParam = { ...queryParams };
this.key = this.queryParam['key'];
});
this.userService.userData$.subscribe(userdata => {
if (userdata && !userdata.err) {
this.userProfile = userdata.userProfile;
if (this.userProfile.rootOrgAdmin) {
this.searchDropdownValues.push('Users');
}
}
this.setFilters();
this.route.events.pipe(
filter(e => e instanceof NavigationEnd)).subscribe((params: any) => {
this.setFilters();
});
});
this.showSuiSelectDropdown = true;
this.resourceDataSubscription = this.resourceService.languageSelected$
.subscribe(item => {
this.setSearchPlaceHolderValue();
}
);
this.connectionService.monitor().subscribe(isConnected => {
this.isConnected = isConnected;
});
}
/**
* on changing dropdown option
* it navigate
*/
onChange() {
this.route.navigate([this.search[this.selectedOption], 1]);
}
ngOnDestroy() {
if (this.resourceDataSubscription) {
this.resourceDataSubscription.unsubscribe();
}
}
/**
* search input box placeholder value
*/
setSearchPlaceHolderValue () {
const keyName = this.searchDisplayValueMappers[this.selectedOption];
if (keyName) {
this.searchPlaceHolderValue = this.selectedOption;
}
}
/**
* on entering keyword
* it navigate
*/
onEnter(key) {
this.key = key;
this.queryParam = {};
this.queryParam['key'] = this.key;
if (this.key && this.key.length > 0) {
this.queryParam['key'] = this.key;
} else {
delete this.queryParam['key'];
}
const url = this.route.url.split('?')[0];
let redirectUrl;
if (this.selectedOption) {
redirectUrl = this.search[this.selectedOption];
} else {
redirectUrl = url.substring(0, url.indexOf('explore')) + 'explore';
}
if (!_.includes(['Users', 'profile'], this.selectedOption)) {
this.queryParam['selectedTab'] = this.isDesktopApp && !this.isConnected ? 'mydownloads' : 'all';
}
if (this.isDesktopApp && !this.isConnected) {
this.route.navigate(['mydownloads'], { queryParams: this.queryParam });
} else {
this.route.navigate([redirectUrl, 1], { queryParams: this.queryParam });
}
}
setFilters() {
this.search = this.config.dropDownConfig.FILTER.SEARCH.search;
this.searchUrl = this.config.dropDownConfig.FILTER.SEARCH.searchUrl;
const currUrl = this.route.url.split('?');
this.value = currUrl[0].split('/', 3);
const searchEnabledStates = this.config.dropDownConfig.FILTER.SEARCH.searchEnabled;
if (this.searchUrl[this.value[1]] && searchEnabledStates.includes(this.value[1])) {
this.setDropdownSelectedOption(this.searchUrl[this.value[1]]);
} else if (this.value[1] === 'search' && searchEnabledStates.includes(this.value[1])) {
this.setDropdownSelectedOption(this.value[2]);
} else if (this.value[1] === 'observation') {
this.showInput = true;
} else {
this.selectedOption = 'All';
this.setSearchPlaceHolderValue();
this.showInput = false;
}
}
setDropdownSelectedOption (value) {
if ( value === 'Users' ) {
if ( !this.userProfile.rootOrgAdmin ) {
this.selectedOption = 'All';
} else {
this.selectedOption = value;
this.showSuiSelectDropdown = false;
this.cdr.detectChanges();
this.showSuiSelectDropdown = true;
}
} else {
this.selectedOption = value;
}
this.setSearchPlaceHolderValue();
this.showInput = true;
}
getInteractEdata(key) {
const searchInteractEdata = {
id: `search-${_.lowerCase(this.searchPlaceHolderValue)}-button`,
type: 'click',
pageid: this.route.url.split('/')[1]
};
if (key) {
searchInteractEdata['extra'] = {
query: key
};
}
return searchInteractEdata;
}
isLayoutAvailable() {
return this.layoutService.isLayoutAvailable(this.layoutConfiguration);
}
}
<ng-container *ngIf="!isLayoutAvailable()">
<div class="input-div relative" id="search-input-container">
<img src="assets/images/search-icon.svg" class="search icon" alt="Search Icon">
<!-- Updated input tag -->
<input type="text" id="keyword" name="filter_search" tabindex="0" class="sb-search-input" title="{{resourceService.frmelmnts?.lbl?.SearchIn | interpolate:'{searchContentType}':searchPlaceHolderValue}}"
placeholder="{{!searchPlaceHolderValue ? resourceService.frmelmnts?.lbl?.searchOrQr : resourceService.frmelmnts?.lbl?.SearchIn | interpolate:'{searchContentType}':searchPlaceHolderValue}}" [(ngModel)]="key"
(keyup.enter)="onEnter(key)" [disabled]="!showInput"
[ngClass]="{'disabled': !showInput }" />
</div>
<button class="sb-btn sb-btn-normal" tabindex="0" appTelemetryInteract [telemetryInteractEdata]="getInteractEdata(key)" [ngClass]="{'disabled': !showInput }" (click)="onEnter(key)" title="{{resourceService.frmelmnts?.lbl?.SearchIn | interpolate:'{searchContentType}':searchPlaceHolderValue}}">{{resourceService.frmelmnts?.lbl?.search}}</button>
</ng-container>
<ng-container *ngIf="isLayoutAvailable()">
<div class="input-div relative" id="search-input-container">
<svg class="search icon" width="16px" height="16px" viewBox="0 0 16 16" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g transform="translate(-444.000000, -104.000000)" class="search-fill">
<g id="Group-4" transform="translate(436.000000, 96.000000)">
<g id="Group-17">
<path d="M23.70654,22.3704831 L19.3259278,17.9881566 C20.1111588,16.9171794 20.531804,15.6223935 20.525939,14.294408 C20.5109564,10.8279251 17.7071951,8.02008526 14.2407377,8.00006368 C12.5818424,7.99255813 10.9888461,8.64882008 9.81662335,9.82265292 C8.64440056,10.9964858 7.99032571,12.5903813 8.00010817,14.2492647 C8.01509084,17.7160631 10.819108,20.5241588 14.2858809,20.5441804 C15.6192764,20.5499595 16.9187929,20.1244044 17.9904868,19.3310263 L17.9950583,19.3275977 L22.3716705,23.7064955 C22.6083,23.9547418 22.960894,24.0552261 23.2928389,23.9690154 C23.6247839,23.8828047 23.8839215,23.6234452 23.9698481,23.2914266 C24.0557747,22.959408 23.9549887,22.6069001 23.70654,22.3704831 L23.70654,22.3704831 Z M14.2813095,19.2893116 C11.5080426,19.2733583 9.26486537,17.0271222 9.25269126,14.2538362 C9.24520615,12.9269013 9.76850908,11.652041 10.7061107,10.7130441 C11.6437124,9.77404715 12.9177932,9.2488491 14.2447377,9.25436106 C17.0180046,9.27031434 19.2611818,11.5165504 19.2733559,14.2898365 C19.280841,15.6167713 18.7575381,16.8916317 17.8199364,17.8306286 C16.8823348,18.7696255 15.608254,19.2948235 14.2813095,19.2893116 Z" id="Search"></path>
</g>
</g>
</g>
</g>
</svg>
<!-- <img src="assets/images/search-icon.svg" class="search icon" alt="Search Icon"> -->
<!-- Updated input tag -->
<input type="text" id="keyword" tabindex="0" name="filter_search" class="sb-search-input" title="{{resourceService.frmelmnts?.lbl?.searchOrQr}}"
placeholder="{{resourceService.frmelmnts?.lbl?.searchOrQr}}" [(ngModel)]="key"
(keyup.enter)="onEnter(key)" [disabled]="!showInput"
[ngClass]="{'disabled': !showInput }" />
<button class="sb-btn sb-btn-md" tabindex="0" appTelemetryInteract [telemetryInteractEdata]="getInteractEdata(key)" [ngClass]="{'disabled': !showInput }" (click)="onEnter(key)" title="{{resourceService.frmelmnts?.lbl?.SearchIn | interpolate:'{searchContentType}':searchPlaceHolderValue}}">{{resourceService.frmelmnts?.lbl?.search}}</button>
</div>
</ng-container>
.ui.button.disabled,
.disabled {
pointer-events: none !important;
opacity: 0.95 !important;
}
.search-fill {
fill: var(--primary-color);
}
Legend
Html element with directive