File
Implements
Constructor
constructor(resourceService: ResourceService, config: ConfigService, activatedRoute: ActivatedRoute, navigationHelperService: NavigationHelperService, route: Router)
|
|
Constructor to create injected service(s) object
Default method of Draft Component class
Parameters :
Name |
Type |
Optional |
Description |
resourceService |
ResourceService
|
No
|
|
config |
ConfigService
|
No
|
Reference of ConfigService
|
activatedRoute |
ActivatedRoute
|
No
|
Reference of ActivatedRoute
|
navigationHelperService |
NavigationHelperService
|
No
|
|
route |
Router
|
No
|
Reference of Router
|
|
Methods
applySorting
|
applySorting(sortByOption)
|
|
Parameters :
Name |
Optional |
sortByOption |
No
|
|
Public
handleSearch
|
handleSearch()
|
|
|
removeFilterSelection
|
removeFilterSelection(filterType, value)
|
|
Parameters :
Name |
Optional |
filterType |
No
|
value |
No
|
|
setFilterTypeAndRedirectURL
|
setFilterTypeAndRedirectURL()
|
|
|
Private
activatedRoute
|
Type : ActivatedRoute
|
|
To send activatedRoute.snapshot to router navigation
service for redirection to draft component
|
Public
filterType
|
Type : any
|
|
|
label
|
Type : Array<string>
|
|
label for filter selected
|
modelChanged
|
Type : Subject<string>
|
Default value : new Subject<string>()
|
|
Public
redirectUrl
|
Type : string
|
|
|
Public
resourceService
|
Type : ResourceService
|
|
To call resource service which helps to use language constant
|
route
|
Type : Router
|
|
To navigate to other pages
|
sortIcon
|
Default value : true
|
|
|
sortingOptions
|
Type : Array<string>
|
|
|
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { ResourceService, ConfigService, NavigationHelperService } from '@sunbird/shared';
import * as _ from 'lodash-es';
import { Subject, of} from 'rxjs';
import { debounceTime, distinctUntilChanged, delay, flatMap } from 'rxjs/operators';
import { IInteractEventEdata } from '@sunbird/telemetry';
@Component({
selector: 'app-workspace-content-filter',
templateUrl: './workspace-content-filter.component.html',
styleUrls: ['./workspace-content-filter.component.scss']
})
export class WorkspaceContentFilterComponent implements OnInit {
modelChanged: Subject<string> = new Subject<string>();
/**
* To navigate to other pages
*/
route: Router;
/**
* To send activatedRoute.snapshot to router navigation
* service for redirection to draft component
*/
private activatedRoute: ActivatedRoute;
/**
* value typed
*/
query: string;
/**
* SortingOptions
*/
sortingOptions: Array<string>;
/**
* To show / hide sortIcon
*/
sortIcon = true;
/**
* position for the popup
*/
position: string;
/**
* To call resource service which helps to use language constant
*/
public resourceService: ResourceService;
/**
* To get url, app configs
*/
public config: ConfigService;
sortByOption: string;
/**
* type of filter
*/
public filterType: any;
/**
* label for filter selected
*/
label: Array<string>;
/**
* redirect url
*/
public redirectUrl: string;
queryParams: any;
filterIntractEdata: IInteractEventEdata;
/**
* Constructor to create injected service(s) object
Default method of Draft Component class
* @param {SearchService} SearchService Reference of SearchService
* @param {UserService} UserService Reference of UserService
* @param {Router} route Reference of Router
* @param {PaginationService} paginationService Reference of PaginationService
* @param {ActivatedRoute} activatedRoute Reference of ActivatedRoute
* @param {ConfigService} config Reference of ConfigService
*/
constructor(resourceService: ResourceService, config: ConfigService,
activatedRoute: ActivatedRoute,
public navigationHelperService: NavigationHelperService,
route: Router) {
this.route = route;
this.activatedRoute = activatedRoute;
this.resourceService = resourceService;
this.config = config;
this.position = 'bottom right';
this.route.onSameUrlNavigation = 'reload';
this.label = this.config.dropDownConfig.FILTER.WORKSPACE.label;
this.sortingOptions = this.config.dropDownConfig.FILTER.RESOURCES.sortingOptions;
}
ngOnInit() {
this.setFilterTypeAndRedirectURL();
this.activatedRoute.queryParams
.subscribe(params => {
this.queryParams = { ...params };
this.query = this.queryParams['query'];
this.sortByOption = _.isArray(this.queryParams['sort_by']) ? this.queryParams['sort_by'][0] : this.queryParams['sort_by'];
_.forIn(params, (value, key) => {
if (typeof value === 'string' && key !== 'query') {
this.queryParams[key] = [value];
}
});
});
this.modelChanged.pipe(debounceTime(1000),
distinctUntilChanged(),
flatMap(search => of(search).pipe(delay(500)))
).
subscribe(query => {
this.query = query;
this.handleSearch();
});
this.filterIntractEdata = {
id: 'filter',
type: 'click',
pageid: 'all-my-content-page'
};
}
setFilterTypeAndRedirectURL() {
if (_.includes(this.route.url, 'published')) {
this.filterType = this.config.appConfig.published.filterType;
this.redirectUrl = this.config.appConfig.published.inPageredirectUrl;
} else if (_.includes(this.route.url, 'draft')) {
this.filterType = this.config.appConfig.draft.filterType;
this.redirectUrl = this.config.appConfig.draft.inPageredirectUrl;
} else if (_.includes(this.route.url, 'alltextbooks')) {
this.filterType = this.config.appConfig.alltextbooks.filterType;
this.redirectUrl = this.config.appConfig.alltextbooks.inPageredirectUrl;
} else {
this.filterType = this.config.appConfig.allmycontent.filterType;
this.redirectUrl = this.config.appConfig.allmycontent.inPageredirectUrl;
}
}
public handleSearch() {
if (!_.isEmpty(this.query)) {
this.queryParams['query'] = this.query;
} else {
delete this.queryParams['query'];
}
this.route.navigate([this.redirectUrl], { queryParams: this.queryParams});
}
keyup(event) {
this.query = event;
this.modelChanged.next(this.query);
}
applySorting(sortByOption) {
this.sortIcon = !this.sortIcon;
this.queryParams['sortType'] = this.sortIcon ? 'desc' : 'asc';
this.queryParams['sort_by'] = sortByOption;
this.route.navigate([this.redirectUrl], { queryParams: this.queryParams});
}
removeFilterSelection(filterType, value) {
const itemIndex = this.queryParams[filterType].indexOf(value);
if (itemIndex !== -1) {
this.queryParams[filterType].splice(itemIndex, 1);
}
this.route.navigate([this.redirectUrl], { queryParams: this.queryParams});
}
}
<div class="sbt-page-gap">
<div class="ui grid padded">
<div class="seven wide column pt-0 pl-0">
<div class="ui fluid icon input left action" id="search-input-container">
<div class="searchfilterinput ui search">
<div class="searchicon ui icon input ">
<input class="upForReviewSearchBox" type="text" name="filter_search"
[(ngModel)]="query" (keyup)="keyup(query)"
placeholder="{{resourceService?.frmelmnts?.prmpt?.searchContent}}"
title="Search" autocomplete="off" spellcheck="false" dir="auto" />
<i class="circular search link icon"></i>
</div>
</div>
</div>
</div>
<div class="two wide column pt-10" id="showFilterButton">
<span class="browse item cursor-pointer" suiPopup [popupPlacement]="position" [popupTemplate]="popupTemplate" popupTrigger="outsideClick">
{{resourceService?.frmelmnts?.lbl?.showFilters}}
<i class="dropdown icon" appTelemetryInteract [telemetryInteractEdata]="filterIntractEdata"></i>
</span>
</div>
<div class="three wide column pt-5">
<div class="twelve wide column">
<div class="field">
<div class="content dropdown-content">
<span class="ShowFilterSubTitle">{{resourceService?.frmelmnts?.lbl?.sortby}}: </span>
<div class="ui inline dropdown search-dropdown content-filter-sort" id="sortByDropDown">
<sui-select class="inline" (selectedOptionChange)= "applySorting($event)" [(ngModel)]="sortByOption" [options]="sortingOptions"
valueField="field"
labelField="name" #selectSort>
<sui-select-option *ngFor="let option of selectSort.filteredOptions" [value]="option" >
</sui-select-option>
</sui-select>
</div>
<i *ngIf="sortByOption && sortByOption.length > 0" [ngClass]=" sortIcon === false ? 'sort content ascending icon' : 'sort content descending icon' "
class="link" tabindex="0" (click)="applySorting(sortByOption)">
</i>
</div>
</div>
</div>
</div>
</div>
<ng-template let-popup #popupTemplate>
<div class="popup-content">
<app-data-driven-filter [pageId]="'all-my-content-page'" [ignoreQuery]="['key','sortType','sort_by','query']" *ngIf="filterType" [filterEnv]="filterType"
[accordionDefaultOpen]=true [isShowFilterLabel]=false [showSearchedParam]=false></app-data-driven-filter>
</div>
</ng-template>
<div class="ui grid">
<div class="twelve wide column content" *ngIf='queryParams != undefined'>
<span *ngFor="let value of label">
<span class="padded chip pr-5" *ngIf='queryParams[value.id] && queryParams[value.id].length > 0'>
{{value.name}}:
<span *ngFor="let item of queryParams[value.id] ">
<a class="ui label mt-5 mr-5">
{{item}}
<i class="delete icon" tabindex="0" (click)="removeFilterSelection(value.id,item)"></i>
</a>
</span>
</span>
</span>
</div>
</div>
</div>
@use "@project-sunbird/sb-styles/assets/mixins/mixins" as *;
>>>.ui.dropdown:not(.button)>.default.text {
display: none;
}
.ui.inline.dropdown.search-dropdown {
margin-left: calculateRem(5px);
box-sizing: border-box;
}
.popup-content{
width: calculateRem(850px) !important;
}
Legend
Html element with directive