src/app/modules/workspace/components/collaboration-content-filter/collaboration-content-filter.component.ts
selector | app-collaboration-content-filter |
styles |
>>> .ui.dropdown:not(.button)>.default.text {
display: none;
}
.ui.inline.dropdown.search-dropdown {
margin-left: 5px;
box-sizing: border-box;
}
.popup-content{
width: 850px !important;
}
|
templateUrl | collaboration-content-filter.component.html |
constructor(resourceService: any, config: any, activatedRoute: ActivatedRoute, route: Router)
|
Constructor to create injected service(s) object
Parameters :
|
Public handleSearch |
handleSearch()
|
Returns:
void
|
keyup |
keyup(event: any)
|
Returns:
void
|
applySorting |
applySorting(sortByOption: any)
|
Returns:
void
|
removeFilterSelection |
removeFilterSelection(filterType: any, value: any)
|
Returns:
void
|
Private activatedRoute |
activatedRoute: |
To send activatedRoute.snapshot to router navigation |
Public config |
config: |
To get url, app configs |
filterIntractEdata |
filterIntractEdata: |
Telemetry filterIntractEdata |
Public filterType |
filterType: |
type of filter |
label |
label: |
label for filter selected |
modelChanged |
modelChanged: |
position |
position: |
position for the popup |
query |
query: |
value typed |
queryParams |
queryParams: |
queryParams |
Public resourceService |
resourceService: |
To call resource service which helps to use language constant |
route |
route: |
To navigate to other pages |
sortByOption |
sortByOption: |
sortIcon |
sortIcon: |
Default value: true
|
To show / hide sortIcon |
sortingOptions |
sortingOptions: |
SortingOptions |
import { Component, OnInit, EventEmitter, Output } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { ResourceService, ConfigService } from '@sunbird/shared';
import { ISelectFilter } from '../../interfaces/selectfilter';
import * as _ from 'lodash-es';
import { Subject , Observable, of} from 'rxjs';
import { debounceTime, distinctUntilChanged, delay, flatMap } from 'rxjs/operators';
import { IInteractEventEdata } from '@sunbird/telemetry';
@Component({
selector: 'app-collaboration-content-filter',
templateUrl: './collaboration-content-filter.component.html',
styles: [`
>>> .ui.dropdown:not(.button)>.default.text {
display: none;
}
.ui.inline.dropdown.search-dropdown {
margin-left: 5px;
box-sizing: border-box;
}
.popup-content{
width: 850px !important;
}
`]
})
export class CollaborationContentFilterComponent 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 collaboration 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>;
/**
* queryParams
*/
queryParams: any;
/**
* Telemetry filterIntractEdata
*/
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,
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.collaboratingOnSortingOptions;
}
ngOnInit() {
this.filterType = this.config.appConfig.collaboration.filterType;
this.activatedRoute.queryParams
.subscribe(params => {
this.queryParams = { ...params };
this.query = this.queryParams['query'];
this.sortByOption = 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: 'collaboration-content-page'
};
}
public handleSearch() {
if (this.query.length > 0) {
this.queryParams['query'] = this.query;
} else {
delete this.queryParams['query'];
}
this.route.navigate(['workspace/content/collaborating-on', 1], { 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(['workspace/content/collaborating-on', 1], { 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(['workspace/content/collaborating-on', 1], { queryParams: this.queryParams });
}
}