File

app/sitesearch/shared/facet-list/facet-list.component.ts

Implements

OnInit OnDestroy

Metadata

changeDetection ChangeDetectionStrategy.OnPush
selector app-facet-list
styleUrls ./facet-list.component.scss
templateUrl ./facet-list.component.html

Index

Properties
Methods
Inputs

Constructor

constructor(loadingService: LoadingIndicatorService, constants: ConstantsService, filterToggleService: FilterToggleService, cdRef: ChangeDetectorRef)
Parameters :
Name Type Optional
loadingService LoadingIndicatorService No
constants ConstantsService No
filterToggleService FilterToggleService No
cdRef ChangeDetectorRef No

Inputs

facets
id
Type : string
stats
useHierarchy
Default value : true

Methods

Public close
close()

Hide filter section when clicking outside, only on small devices

Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
Public trackFacets
trackFacets(index, facet)

This is used to not re-render all facets when some facets are changed/removed/added. Only the ones that have actually changed will be re-rendered.

Parameters :
Name Optional
index No
facet No
Returns : any

Properties

Public loadingService
Type : LoadingIndicatorService
showFilters
Type : boolean
subscriptions
Type : []
Default value : []
import { Component, OnInit, Input, ChangeDetectionStrategy, Output, EventEmitter, ChangeDetectorRef, OnDestroy} from '@angular/core';
import { fromEvent } from 'rxjs';
import { map, debounceTime } from 'rxjs/operators';
import { LoadingIndicatorService } from 'src/app/core/services/loading-indicator.service';
import { ConstantsService } from 'src/app/shared/constants/constants.service';
import { FilterToggleService } from 'src/app/core/services/filter-toggler/filter-toggle.service';

@Component ({
		selector: 'app-facet-list',
		templateUrl: './facet-list.component.html',
		styleUrls: ['./facet-list.component.scss'],
		changeDetection: ChangeDetectionStrategy.OnPush
})
export class FacetListComponent implements OnInit, OnDestroy {

	@Input() facets;
	@Input() stats;
	@Input() useHierarchy = true;
	@Input() id: string;

	subscriptions = [];
	showFilters: boolean;

	constructor(
		public loadingService: LoadingIndicatorService,
		private constants: ConstantsService,
		private filterToggleService: FilterToggleService,
		private cdRef: ChangeDetectorRef
	) { }

	ngOnInit() {
		// Close filters when screen with is larger than 991px.
		const resizeEvent = fromEvent(window, 'resize');
		this.subscriptions.push(resizeEvent.pipe(map(() => {
			return document.documentElement.clientWidth;
		}), debounceTime(500)).subscribe(data => {
			if (data > this.constants.BOOTSTRAP_BREAKPOINTS.LG) { this.close(); }
		}));

		this.subscriptions.push(this.filterToggleService.filterState.subscribe(state => {
			this.showFilters = state[this.id];
			this.cdRef.detectChanges();
		}));
	}

	ngOnDestroy(): void {
		this.subscriptions.forEach(sub => {
			if (sub) { sub.unsubscribe(); }
		});
	}

	/** This is used to not re-render all facets when some facets are changed/removed/added.
		* Only the ones that have actually changed will be re-rendered.
	*/
	public trackFacets(index, facet) {
		return facet ? facet.displayName : {};
	}

	/** Hide filter section when clicking outside, only on small devices */
	public close() {
		this.filterToggleService.closeFilters(this.id);
	}
}
<ul class="facets list-unstyled" [ngClass]="{'show-filters': showFilters}">
    <div class="close-button"><i class="fas fa-times" aria-hidden="true" *ngIf="showFilters" (click)="close()"></i></div>
    <li *ngFor="let facet of facets; let i = index; trackBy: trackFacets">
        <range-facet *ngIf="facet.properties.renderingType == 'HISTOGRAM'" [facet]="facet"></range-facet>
        <checkbox-facet *ngIf="facet.properties.renderingType == 'TERMS'" [facet]="facet"></checkbox-facet>
        <hierarchy-facet *ngIf="facet.properties.renderingType == 'TREE' && useHierarchy" [facet]="facet" [stats]="stats"></hierarchy-facet>
        <designation-facet *ngIf="facet.properties.renderingType == 'DESIGNATION'" [facet]="facet"></designation-facet>
    </li>
</ul>

./facet-list.component.scss

@import "src/app/styles/helpers";

.facets{
    list-style-type: none;

    @include media-breakpoint-down(md) {
        position: fixed;
        top: -100vh;
        left: 0;
        height: 100vh;
        width: 100%;
        max-width: 100%;
        z-index: 999;
        padding: 20px;
        margin: 0;
        background-color: $cool-grey;
        border-right: 1px solid rgba(199, 191, 199, 0.7);
        overflow: auto;
        transition: all 0.5s ease-out;

        &.show-filters {
            top: 0
        }
    }

    .close-button {
        display: flex;
        justify-content: flex-end;
        color: white;
        padding: 0 calc-rem(20);

        @include media-breakpoint-up(lg) {
            display: none;
        }

        i { cursor: pointer; }
        
    }

}

Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""