app/dxa/dxa-entity/views/tools/tool-main/tool-main.component.ts
selector | div[tool-main] |
styleUrls | ./tool-main.component.scss |
templateUrl | ./tool-main.component.html |
Properties |
Methods |
Inputs |
HostBindings |
constructor(util: UtilService, labelService: LabelService, keycloakService: KeycloakService, linkService: ComponentLinkService)
|
|||||||||||||||
Parameters :
|
entity | |
class |
isLoginRequired |
isLoginRequired(json: any, openOrRestricted: string)
|
Returns :
void
|
ngOnInit |
ngOnInit()
|
Returns :
void
|
parseIcon | ||||
parseIcon(json)
|
||||
Parameters :
Returns :
Icon
|
parseJson | ||||||
parseJson(json: any)
|
||||||
Parameters :
Returns :
Tool
|
parseRole | ||||||
parseRole(role: string)
|
||||||
Parameters :
Returns :
String
|
Readonly appStoreIconName |
Type : string
|
Default value : 'icon-app-store-apple'
|
autoButtonLabel |
Type : string
|
buttonDisabled |
Type : boolean
|
buttonTitle |
Type : string
|
data |
Type : Tool
|
devicesLabel |
Type : string
|
downloadToolLabel |
Type : string
|
Readonly googlePlayIconName |
Type : string
|
Default value : 'icon-app-store-google'
|
industriesLabel |
Type : string
|
isDownload |
Type : boolean
|
isLoggedIn |
Type : any
|
languagesLabel |
Type : string
|
loginRequired |
Type : boolean
|
productPlatformLabel |
Type : string
|
servicesLabel |
Type : string
|
toolButtonLabel |
Type : string
|
toolLabel |
Type : string
|
urlOrDownloadObj |
Type : any
|
userRoles |
Type : String[]
|
Default value : []
|
import { Component, OnInit, Input, HostBinding } from '@angular/core';
import { UtilService } from 'src/app/core/services/util-service/util.service';
import { LabelService } from 'src/app/core/services/label-service/label-service.service';
import { ComponentLinkService } from 'src/app/core/services/component-link-service/component-link.service';
import { KeycloakService } from 'keycloak-angular';
interface Tool {
imageUrl: string;
altText: string;
toolUrl: any;
toolFile: string;
buttonTitle: string;
description: string;
industries: any;
services: any;
products: any;
devices: any;
languages: any;
icons: Icon[];
presentingTool: string;
toolFileName: string;
}
interface Icon {
name: string;
type: iconType;
url: string;
}
type iconType = 'icon' | 'apple-app-store' | 'google-play';
@Component({
selector: 'div[tool-main]',
templateUrl: './tool-main.component.html',
styleUrls: ['./tool-main.component.scss']
})
export class ToolMainComponent implements OnInit {
@Input() entity;
isLoggedIn: any;
userRoles: String[] = [];
data: Tool;
loginRequired: boolean;
buttonDisabled: boolean;
// Labels
industriesLabel: string;
productPlatformLabel: string;
servicesLabel: string;
devicesLabel: string;
languagesLabel: string;
toolButtonLabel: string;
buttonTitle: string;
autoButtonLabel: string;
downloadToolLabel: string;
urlOrDownloadObj: any;
isDownload: boolean;
toolLabel: string;
readonly appStoreIconName = 'icon-app-store-apple';
readonly googlePlayIconName = 'icon-app-store-google';
@HostBinding('class') get class() { return 'space-between--slider-no-bottom'; }
constructor(
private util: UtilService,
private labelService: LabelService,
private keycloakService: KeycloakService,
private linkService: ComponentLinkService
) { }
ngOnInit() {
this.keycloakService.isLoggedIn().then(res => {
this.isLoggedIn = res;
if (this.isLoggedIn) {
this.keycloakService.getUserRoles(true).map(role => this.userRoles.push(this.parseRole(role.toString())));
}
this.isLoginRequired(this.entity, this.util.extract(this.entity, 'OpenOrRestrictedTool'));
setTimeout(() => {
this.data = this.parseJson(this.entity);
this.isDownload = (this.data.presentingTool.toLowerCase() === 'download tool') ? true : false;
if (this.isDownload) {
this.urlOrDownloadObj = this.data.toolFile;
this.urlOrDownloadObj['toolFileName'] = this.data.toolFileName;
} else {
this.urlOrDownloadObj = this.data.toolUrl;
}
this.toolLabel = (this.isDownload) ? this.downloadToolLabel : this.toolButtonLabel;
}, 100);
});
this.labelService.getLabel('industries').then(x => this.industriesLabel = x);
this.labelService.getLabel('productPlatform').then(x => this.productPlatformLabel = x);
this.labelService.getLabel('services').then(x => this.servicesLabel = x);
this.labelService.getLabel('devices').then(x => this.devicesLabel = x);
this.labelService.getLabel('languages').then(x => this.languagesLabel = x);
this.labelService.getLabel('autoButtonTitle').then(x => this.autoButtonLabel = x);
}
parseJson(json: any): Tool {
return {
imageUrl: this.util.extract(json, 'Image', 'Url'),
altText: this.util.extract('Image', 'Assetmetadata', 'Titlemm'),
industries: this.util.extract(json, 'Industries') || [],
services: this.util.extract(json, 'Services') || [],
products: this.util.extract(json, 'ProductsPlatform') || [],
devices: this.util.extract(json, 'Devices') || [],
languages: this.util.extract(json, 'Language') || [],
icons: (this.util.extract(json, 'SocialMedia') || []).map(e => this.parseIcon(e)),
buttonTitle: this.buttonTitle,
description: this.util.extract(json, 'Description'),
toolUrl: this.util.extract(json, 'UrlToTool'),
toolFile: this.util.extract(json, 'ToolFile'),
presentingTool: this.util.extract(json, 'PresentingTool'),
toolFileName: this.util.extract(json, 'ToolFileName')
};
}
parseIcon(json): Icon {
const iconName = this.util.extract(json, 'Icon');
const link = this.util.extract(json, 'Link');
const url = this.linkService.getUrl(link);
let type: iconType = 'icon';
if (this.appStoreIconName === iconName) {
type = 'apple-app-store';
} else if (this.googlePlayIconName === iconName) {
type = 'google-play';
}
return {
name: iconName,
type: type,
url: url
};
}
parseRole(role: string): String {
if (role.includes('[')) {
role = role.slice(0, role.indexOf('['));
}
return role.trim();
}
isLoginRequired(json: any, openOrRestricted: string) {
this.loginRequired = false;
this.buttonDisabled = false;
this.labelService.getLabel('openTool').then(x => this.toolButtonLabel = x);
this.labelService.getLabel('downloadTool').then(x => this.downloadToolLabel = x);
this.buttonTitle = this.util.extract(json, 'ButtonTitle');
if ((openOrRestricted.startsWith('Login') || openOrRestricted.startsWith('Role')) && !this.isLoggedIn) {
this.loginRequired = true;
this.labelService.getLabel('loginRequired').then(x => this.toolButtonLabel = x);
this.labelService.getLabel('loginPrompt').then(x => this.buttonTitle = x);
} else if (openOrRestricted.startsWith('Role')) {
const requiredRoles = this.util.extract(json, 'Roles') || [];
this.labelService.getLabel('roleBased').then(x => this.toolButtonLabel = x);
this.buttonDisabled = true;
requiredRoles.forEach(requiredRole => {
if (this.userRoles.includes(requiredRole)) {
this.labelService.getLabel('openTool').then(x => this.toolButtonLabel = x);
this.labelService.getLabel('downloadTool').then(x => this.downloadToolLabel = x);
this.buttonDisabled = false;
}
});
}
}
}
<div class="container">
<div class="row" *ngIf="data">
<div class="col-lg-4 col-sm-12">
<img class="tool-img" [src]="data.imageUrl" [alt]="data.altText">
</div>
<div class="col-lg-8 col-sm-12">
<div class="card-group">
<div class="card">
<div class="card-body" *ngIf="data.industries.length > 0">
<div class="card-title">{{industriesLabel}}</div>
<div class="card-text" *ngFor="let industry of data.industries">
{{industry}}
</div>
</div>
<div class="card-body" *ngIf="data.services.length > 0">
<div class="card-title">{{servicesLabel}}</div>
<div class="card-text" *ngFor="let service of data.services">
{{service}}
</div>
</div>
<div class="card-body" *ngIf="data.products.length > 0">
<div class="card-title">{{productPlatformLabel}}</div>
<div class="card-text" *ngFor="let product of data.products">
{{product}}
</div>
</div>
</div>
<div class="card" *ngIf="data.devices.length > 0">
<div class="card-body">
<div class="card-title">{{devicesLabel}}</div>
<div class="card-text" *ngFor="let device of data.devices">
{{device}}
</div>
</div>
</div>
<div class="card" *ngIf="data.languages.length > 0">
<div class="card-body">
<div class="card-title">{{languagesLabel}}</div>
<div class="card-text" *ngFor="let language of data.languages">
{{language}}
</div>
</div>
</div>
</div>
<ul class="list-group list-group-horizontal">
<ng-container *ngIf="data.icons.length > 0">
<li *ngFor="let icon of data.icons" class="list-group-item">
<a class="apple-app-store" *ngIf="icon.type === 'apple-app-store'" target="_blank"
[href]="icon.url">
<img src="v2/assets/img/App-store-black.svg">
</a>
<a class="google-play" *ngIf="icon.type === 'google-play'" target="_blank"
[href]="icon.url">
<img alt='Get it on Google Play' src='v2/assets/img/google-play-badge.png' />
</a>
</li>
</ng-container>
<li class="list-group-item custom-app-link" *ngIf="data.toolUrl?.ExternalLink">
<a [href]="data.toolUrl.ExternalLink" target="_blank">
<i class="fas fa-globe"></i> <span>{{autoButtonLabel}}</span>
</a>
</li>
</ul>
</div>
</div>
</div>
<div class="action-panel" *ngIf="data?.toolUrl || data?.toolFile" action-panel [buttonText]="data.buttonTitle" [openOrDownloadUrl]="urlOrDownloadObj"
[newWindow]="!loginRequired" [loginRequired]="loginRequired" [disabled]="buttonDisabled" [isDownload]=isDownload>
<span action-text class="action-label">{{toolLabel}}</span>
</div>
./tool-main.component.scss
@import "src/app/styles/helpers";
.container {
padding-bottom: calc-rem(40);
@include media-breakpoint-up(md) {
padding-bottom: calc-rem(80);
}
}
.tool-img {
width: 100%;
margin-bottom: calc-rem(20);
@include media-breakpoint-up(lg) {
margin-bottom: 0;
}
}
.card {
background-color: $off-white;
padding: calc-rem(20) 0;
border: none;
margin: 0;
@include media-breakpoint-up(sm) {
padding: calc-rem(35) 0;
}
&-body {
padding: calc-rem(15) calc-rem(35);
@include media-breakpoint-up(sm){
border-right: 1px solid $slate;
}
&:first-child {
padding-top: 0;
}
&:last-child {
padding-bottom: 0;
}
}
&-title {
@include font-scale(18, medium);
//font-weight: 600;
color: $cool-grey;
margin-bottom: calc-rem(5);
}
&-text {
color: $cool-grey;
@include font-scale(16, light);
}
&:last-child {
.card-body {
border-right: none;
}
}
}
.list-group {
flex-wrap: wrap;
align-items: center;
margin-top: calc-rem(5);
@include media-breakpoint-up(md) {
justify-content: flex-start;
}
a[target=_blank]:after {
content: none;
}
&-item {
padding: 0 calc-rem(10);
border: none;
background-color: transparent;
}
.apple-app-store {
img {
height: calc-rem(40);
}
}
.google-play {
img {
height: calc-rem(58);
@include media-breakpoint-down(xs) {
margin-left: calc-rem(-10);
}
}
}
.custom-app-link {
background-color: black;
border-radius: calc-rem(6);
padding: calc-rem(7.5) calc-rem(8);
margin-left: calc-rem(10);
a {
color: $off-white;
&:hover {
text-decoration: none;
}
i {
margin-right: calc-rem(10);
}
}
}
}
.action-panel {
.action-label {
@include font-scale(24, light);
}
}