File

app/dxa/dxa-entity/views/page-detail-views/page-profile-info-header/page-profile-info-header.component.ts

Implements

OnInit

Metadata

selector app-page-profile-info-header
styleUrls ./page-profile-info-header.component.scss
templateUrl ./page-profile-info-header.component.html

Index

Properties
Methods
Inputs

Constructor

constructor(keycloakService: KeycloakService, constants: ConstantsService, resize: ResizeContentService, idGenerator: IdGeneratorService, util: UtilService, doc)
Parameters :
Name Type Optional
keycloakService KeycloakService No
constants ConstantsService No
resize ResizeContentService No
idGenerator IdGeneratorService No
util UtilService No
doc No

Inputs

entity

Methods

inDesktopView
inDesktopView(width: number)
Parameters :
Name Type Optional
width number No
Returns : boolean
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
onResize
onResize()
Returns : void
Public setUpFields
setUpFields()
Returns : void

Properties

attributes
Type : userAttributes[]
Default value : []
Private componentId
Type : string
Default value : this.idGenerator.getId()
Public constants
Type : ConstantsService
inDesktop
Type : boolean
Public isLoggedIn
Type : boolean
Public resize
Type : ResizeContentService
Public util
Type : UtilService
welcomeText
Type : string
import { Component, OnInit, Input, Inject } from '@angular/core';
import { KeycloakService } from 'keycloak-angular';
import { ConstantsService } from 'src/app/shared/constants/constants.service';
import { ResizeContentService } from 'src/app/core/services/resize-service/resize-content.service';
import { UtilService } from 'src/app/core/services/util-service/util.service';
import { IdGeneratorService } from 'src/app/core/services/id-generator.service';
import { DOCUMENT } from '@angular/common';

interface userAttributes {
  firstName: string;
  userType: string;
  companyName: string,
  city: string;
  country: string;
  cityAndCountry : string;
}

@Component({
  selector: 'app-page-profile-info-header',
  templateUrl: './page-profile-info-header.component.html',
  styleUrls: ['./page-profile-info-header.component.scss']
})
export class PageDetailsProfileComponent implements OnInit {

  @Input() entity;
  attributes: userAttributes[] = [];
  inDesktop: boolean;
  welcomeText: string;
  public isLoggedIn: boolean;
  private componentId: string = this.idGenerator.getId();
  
  constructor(
    private keycloakService: KeycloakService,
    public constants: ConstantsService,
    public resize: ResizeContentService,
    private idGenerator: IdGeneratorService,
    public util: UtilService,
    @Inject(DOCUMENT) private doc
  ) { }

  ngOnInit() {

    // Handle responsiveness (mobile/desktop)
    const width = (window.innerWidth || this.doc.documentElement.clientWidth);
    this.inDesktop = this.inDesktopView(width);
    this.resize.registerCallback(this.componentId, () => this.onResize());

    // Get values from SSO
    this.keycloakService.isLoggedIn().then(res => {
      this.isLoggedIn = res;
      if (this.isLoggedIn) {
        this.keycloakService.loadUserProfile(false).then(data => {
          // Push values to list, if undefined place empty strings
          this.attributes.push({
            firstName: data.firstName ? data.firstName : "",
            userType: data['attributes'].user_type ? data['attributes'].user_type.toString().split(' [')[0] : "",
            companyName: data['attributes'].companyName ? data['attributes'].companyName.toString(): "",
            city: data['attributes'].city ? data['attributes'].city.toString() : "",
            country: data['attributes'].country_iso ? data['attributes'].country_iso.toString().split(' [')[0] : "",
            cityAndCountry: data['attributes'].city && data['attributes'].country_iso ?
                            data['attributes'].city.toString() + ", " + data['attributes'].country_iso.toString().split(' [')[0] : "",
          });
        });
      }
    });
    this.setUpFields();
  }

  ngOnDestroy(): void {
    this.resize.destroyCallback(this.componentId);
  }


  onResize() {
    const currentWidth = window.innerWidth;
    this.inDesktop = currentWidth >= this.constants.BOOTSTRAP_BREAKPOINTS.MD;
  }

  // Used for setting fields, currently minimal functionality but might include more later on
  public setUpFields() {
    this.welcomeText = this.util.extract(this.entity, 'H1Title') || '';
  }

  inDesktopView(width: number): boolean {
    return width > this.constants.BOOTSTRAP_BREAKPOINTS.LG;
  }
}
<div class="page-profile-info-header">
  <div class="container d-flex" *ngIf="isLoggedIn">
      <div class="logo">
      </div>
      <div class="header-container">
          <div class="header-title">
              <h5>{{welcomeText}}</h5>
            </div>
            <ul class="header-list">
              <ng-container *ngFor="let userAttribute of attributes">
                <li *ngIf="userAttribute.firstName"> {{userAttribute.firstName | uppercase}}</li>
                <li *ngIf="userAttribute.userType"> {{userAttribute.userType | uppercase}}</li>
                <li *ngIf="userAttribute.companyName"> {{userAttribute.companyName | uppercase}}</li>
                <li *ngIf="userAttribute.cityAndCountry"> {{userAttribute.cityAndCountry | uppercase}}</li>
                <ng-container *ngIf="!userAttribute.cityAndCountry">
                  <li *ngIf="userAttribute.city"> {{userAttribute.city | uppercase}}</li>
                  <li *ngIf="userAttribute.country"> {{userAttribute.country | uppercase}}</li>
                </ng-container>
              </ng-container>
            </ul>
      </div>
  </div>
</div>

./page-profile-info-header.component.scss

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

  .page-profile-info-header {
    background-color: $blue;

    .container {
      display: flex;
      padding-top: calc-rem(30);
      padding-bottom: calc-rem(30);

      @include media-breakpoint-down(md) {
        flex-direction: column;
        align-items: center;
      }
    }

    .logo {
      display: inline-block;
      margin-right: 2%;
      margin-bottom: 2%;
      width: calc-rem(123);
      height: calc-rem(123);
      background-image: linear-gradient(135deg, #3023ae, #c86dd7);
      -moz-border-radius: 100%;
      -webkit-border-radius: 100%;
      border-radius: 100%;

      @include media-breakpoint-down(md) {
        margin-right: 0;
      }
    }

    li {
      display: inline-block;
      color: $white;
      @include font-size(24);
      padding-right: calc-rem(10);
    }

    li:after {
      content: " |";
    }
    li:last-child:after {
      content: "";
    }

    .header-list {
      list-style-type: none;
      padding: 0;
      text-align: center;
    }

    .header-title {
      color: $white;
      margin-top: 8%;

      @include media-breakpoint-down(md) {
        margin-top: 3%;
      }
    }

    .logo img {
      width: 80px;
    }

    .header-container {
      display: flex;
      flex-direction: column;
      margin-top: -2%;

      @include media-breakpoint-down(md) {
        align-items: center;
        margin-right: 0;
      }
    }
  }

Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""