File

app/dxa/dxa-entity/views/news-slider/news-slider.component.ts

Implements

OnInit

Metadata

selector div[news-slider]
styleUrls ./news-slider.component.scss
templateUrl ./news-slider.component.html

Index

Properties
Methods
Inputs
HostBindings

Constructor

constructor(searchFactory: SearchFactory, idGenerator: IdGeneratorService, pubService: PublicationService, util: UtilService)
Parameters :
Name Type Optional
searchFactory SearchFactory No
idGenerator IdGeneratorService No
pubService PublicationService No
util UtilService No

Inputs

entity

HostBindings

class

Methods

getCategoryTcmId
getCategoryTcmId(id)

Builds a category tcm-id based on a given id

Parameters :
Name Optional
id No
Returns : any
ngOnInit
ngOnInit()
Returns : void

Properties

documents
Type : []
Default value : []
search
Type : SearchService
title
Type : string
import { Component, OnInit, Input, HostBinding } from '@angular/core';
import { SearchFactory, SearchService, SimpleSearchResult, HttpParams } from 'skf-search-angular-service';
import { IdGeneratorService } from 'src/app/core/services/id-generator.service';
import { UtilService } from 'src/app/core/services/util-service/util.service';
import { PublicationService } from 'src/app/core/services/publication-service/publication.service';
import { AppConfig } from '../../../../app.config';

@Component({
	selector: 'div[news-slider]',
	templateUrl: './news-slider.component.html',
	styleUrls: ['./news-slider.component.scss'],
})
export class NewsSliderComponent implements OnInit {

	@Input() entity;

	search: SearchService;
	documents = [];
	title: string;

	@HostBinding('class') get class() { return 'space-between--slider bg-off-white'; }

	constructor(
		private searchFactory: SearchFactory,
		private idGenerator: IdGeneratorService,
		private pubService: PublicationService,
		private util: UtilService
	) {
		const searchId = this.idGenerator.getId();	// ID for search service instance
		this.search = this.searchFactory.get(`news-slider-${searchId}`, `news-slider-${AppConfig.settings.searchEnvironment.name}`);
	}

	ngOnInit(): void {
		this.search.result.subscribe(res => {
			const results = res as SimpleSearchResult;
			this.documents = this.util.extract(results, 'documentList', 'documents') || [];
		});

		this.title = this.util.extract(this.entity, 'Title');
		const newsCategory = this.util.extract(this.entity, 'NewsCategory') || [];
		const newsTopics = this.util.extract(this.entity, 'NewsTopics') || [];
		const products = this.util.extract(this.entity, 'Products') || [];
		const services = this.util.extract(this.entity, 'Services') || [];
		const industries = this.util.extract(this.entity, 'Industries') || [];
		const language = this.pubService.getLanguage();
		const pubId = this.pubService.getPublicationId();

		const categories = [newsCategory, newsTopics, products, industries, services].filter(category => category.length > 0);

		let query = `site=${pubId}&language=${language}`;

		/**	Loop through categories and build query.
		 *	Format: [category tcm-id]=[keyword name]&[category tcm-id]=[keyword name]&...
		*/
		categories.forEach(category => {
			const catId = this.getCategoryTcmId(this.util.extract(category[0], 'TaxonomyId'));
			if (catId) {
				category.forEach(keyword => {
					query += `&${catId}=${keyword.Title}`;
				});
			}
		});

		const searchParams = new HttpParams({fromString: query});
		this.search.doSearchWithParameters({params: searchParams});
	}

	/** Builds a category tcm-id based on a given id */
	getCategoryTcmId(id) {
		let taxonomyId;

		if (id) {
			const pubId = this.pubService.getPublicationId();
			taxonomyId = `tcm:${pubId}-${id}-512`;	// 512 is id for category type
		}
		return taxonomyId;
	}
}
<div slider [nrOfElements]="documents.length" [columnSize]="'lg'" *ngIf="documents.length > 0" [btnClass]="'btn-extra-light-slate'">
    <h2 title *ngIf="title">{{title}}</h2>
    <div slider-element class="col swiper-slide" *ngFor="let document of documents">
        <div news-document [newsDocument]="document" [type]="'GRID'" [theme]="'light'"></div>
    </div>
</div>

./news-slider.component.scss

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

.swiper-slide {
	height: 100%;
	margin-left: calc-rem(15);
	margin-right: calc-rem(15)
}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""