File

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

Implements

OnInit

Metadata

changeDetection ChangeDetectionStrategy.OnPush
selector div[slider-main]
styleUrls ./slider-main.component.scss
templateUrl ./slider-main.component.html

Index

Properties
Methods
Inputs
HostBindings

Constructor

constructor(util: UtilService, linkService: ComponentLinkService, doc: Document)
Parameters :
Name Type Optional
util UtilService No
linkService ComponentLinkService No
doc Document No

Inputs

entity

HostBindings

class

Methods

ngOnInit
ngOnInit()
Returns : void
Private parseJson
parseJson(data: any)
Parameters :
Name Type Optional
data any No
Returns : ISliderMain
Private resolveMediaType
resolveMediaType(jsonData: any)
Parameters :
Name Type Optional
jsonData any No
Returns : mediaType
Private resolveSliderItems
resolveSliderItems(sliderItem: any)
Parameters :
Name Type Optional
sliderItem any No
Returns : ISliderItem
setup
setup()
Returns : void

Properties

Public data
Type : ISliderMain
import { Component, OnInit, ChangeDetectionStrategy, Input, Inject, HostBinding } from '@angular/core';
import { UtilService } from 'src/app/core/services/util-service/util.service';
import { DOCUMENT } from '@angular/common';
import { ComponentLinkService } from 'src/app/core/services/component-link-service/component-link.service';
import { ComponentLink } from 'src/app/core/interfaces/interfaces.component';

type mediaType = 'image' | 'video' | 'missing';

interface ISliderMain {
	title: string;
	items: ISliderItem[];
}

interface ISliderItem {
	mediaType: mediaType;
	mediaUrl: string;
	mimeType: string;
	mediaAlt: string;
	link: ComponentLink;
}

@Component({
	selector: 'div[slider-main]',
	templateUrl: './slider-main.component.html',
	styleUrls: ['./slider-main.component.scss'],
	changeDetection: ChangeDetectionStrategy.OnPush
})
export class SliderMainComponent implements OnInit {

	@Input() entity;

	public data: ISliderMain;

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

	constructor(
		private util: UtilService,
		private linkService: ComponentLinkService,
		@Inject(DOCUMENT) private doc: Document
	) { }

	ngOnInit() {
		this.setup();
	}

	setup(): void {
		if (this.entity) {
			this.data = this.parseJson(this.entity);
			this.data.items = this.data.items.filter(item => item.mediaType === 'image');
		}
	}

	private parseJson(data: any): ISliderMain {
		const parsed: ISliderMain = {
			title: this.util.extract(data, 'Title'),
			items: (this.util.extract(data, 'SliderItems') || []).map(slider => this.resolveSliderItems(slider))
		};

		return parsed;
	}

	private resolveSliderItems(sliderItem: any): ISliderItem {
		return {
			mediaType: this.resolveMediaType(sliderItem),
			mediaUrl: this.util.extract(sliderItem, 'ImageVideo', 'Url'),
			mimeType: this.util.extract(sliderItem, 'ImageVideo', 'MimeType'),
			mediaAlt: this.util.extract(sliderItem, 'ImageVideo', 'Assetmetadata', 'Cmsdescription') || '',
			link: this.linkService.parseLink(this.util.extract(sliderItem, 'LinkTarget'))
		};
	}

	private resolveMediaType(jsonData: any): mediaType {
		const mimeType = this.util.extract(jsonData, 'ImageVideo', 'MimeType') || '';

		switch (mimeType.split('/')[0]) {
			case 'video': return 'video';
			case 'image': return 'image';
			default: return 'missing';
		}
	}
}
<ng-container *ngIf="data">
	<div slider [nrOfElements]="data.items.length" [columnSize]="'xl'" [btnClass]="'btn-extra-light-slate'">
		<h2 title>{{data.title}}</h2>
		<div slider-element class="col swiper-slide" *ngFor="let item of data.items">
			<a component-link [linkObject]="item.link.linkObject" class="card" *ngIf="item.link.url">
				<ng-container *ngTemplateOutlet="content"></ng-container>
			</a>
			<div *ngIf="!item.link.url" class="card">
				<ng-container *ngTemplateOutlet="content"></ng-container>
			</div>
			<ng-template #content>
				<div class="slider-image" *ngIf="item.mediaUrl">
					<img class="card-img-top" [src]="item.mediaUrl" [alt]="item.mediaAlt">
				</div>
				<div class="card-body">
					<div class="card-title">
						<span>{{item.link.title}}</span>
						<i class="icon-link-openNewWindow" *ngIf="item.link.newWindow"></i>
					</div>
				</div>
			</ng-template>
		</div>
	</div>
</ng-container>

./slider-main.component.scss

@import 'src/app/styles/helpers';
@import '~swiper/dist/css/swiper.min.css';

.card {
    display: flex;
    flex-direction: column;
    margin-left: auto;
    margin-right: auto;
    border: none;
    width: 90%;
    height: 100%;
    background-color: $light-blue;
    
    &:hover {
        img {
            opacity: 0.6;
        }
    }

    &[target=_blank]:after {
        content: none;
    }

    .slider-image {
        display: flex;
        position: relative;
        width: 100%;
        border-bottom: 1px solid $off-white;

        &:before {
            content: "";
            display: block;
            padding-top: 100%;  // Aspect ratio 1:1
        }

        .card-img-top {
            height: 100%;
            position: absolute;
            object-fit: cover;
        }
    }

    &-body {
        background-color: $white !important;
    }
}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""