import { AppComponentBase } from '@shared/common/app-component-base' ; import { Component , Injector , OnInit } from '@angular/core' ; import { AppAuthService } from '@app/shared/common/auth/app-auth.service' ; import { ChangePasswordModalComponent } from '@app/shared/layout/profile/change-password-modal.component' ; import { LoginAttemptsModalComponent } from '@app/shared/layout/login-attempts-modal.component' ; import { MySettingsModalComponent } from '@app/shared/layout/profile/my-settings-modal.component' ; import { ChangeProfilePictureModalComponent } from '@app/shared/layout/profile/change-profile-picture-modal.component' ; import { AppConsts } from '@shared/AppConsts' ; import { ProfileServiceProxy , TenantLoginInfoDto } from '@shared/service-proxies/service-proxies' ; @ Component ( { selector : 'header-user' , template : `
    <div nz-dropdown class="alain-default__nav-item d-flex align-items-center px-sm" nzPlacement="bottomRight" [nzDropdownMenu]="userMenuTpl">
        <div class="mr-sm">
            <strong>{{shownLoginName}}</strong>
        </div>
        <nz-avatar [nzSrc]="profilePicture" nzSize="small" class="mr-sm"></nz-avatar>
    </div>
    <nz-dropdown-menu #userMenuTpl="nzDropdownMenu">
        <ul nz-menu>
            <li nz-menu-item (click)="changePassword()">
                <i nz-icon nzType="ellipsis" class="mr-sm"></i>
                {{"ChangePassword" | localize}}
            </li>
            <li nz-menu-item (click)="showLoginAttempts()">
                <i nz-icon nzType="bars" class="mr-sm"></i>
                {{"LoginAttempts" | localize}}
            </li>
            <li nz-menu-item (click)="changeProfilePicture()">
                <i nz-icon nzType="picture" class="mr-sm"></i>
                {{"ChangeProfilePicture" | localize}}
            </li>
            <li nz-menu-item (click)="changeMySettings()">
                <i nz-icon nzType="setting" class="mr-sm"></i>
                {{"MySettings" | localize}}
            </li>
            <li nz-menu-divider></li>
            <li nz-menu-item (click)="logout()">
                <i nz-icon nzType="logout" class="mr-sm"></i>
                {{'Logout' | localize}}
            </li>
        </ul>
    </nz-dropdown-menu>
  ` , } ) export class HeaderUserComponent extends AppComponentBase implements OnInit { shownLoginNameTitle = '' ; shownLoginName = '' ; tenancyName = '' ; userName = '' ; profilePicture = AppConsts . appBaseUrl + '/assets/common/images/default-profile-picture.png' ; tenant : TenantLoginInfoDto = new TenantLoginInfoDto ( ) ; constructor ( injector , private authService , private _profileServiceProxy ) { super ( injector ) ; } ngOnInit ( ) { this . setCurrentLoginInformations ( ) ; this . getProfilePicture ( ) ; this . registerToEvents ( ) ; } changePassword ( ) { this . modalHelper . createStatic ( ChangePasswordModalComponent ) . subscribe ( result => { if ( result ) { this . logout ( ) ; } } ) ; } registerToEvents ( ) { abp . event . on ( 'profilePictureChanged' , ( ) => { this . getProfilePicture ( ) ; } ) ; } setCurrentLoginInformations ( ) { this . shownLoginName = this . appSession . getShownLoginName ( ) ; this . tenancyName = this . appSession . tenancyName ; this . userName = this . appSession . user . userName ; this . tenant = this . appSession . tenant ; } getProfilePicture ( ) { this . _profileServiceProxy . getProfilePicture ( ) . subscribe ( result => { if ( result && result . profilePicture ) { this . profilePicture = 'data:image/jpeg;base64,' + result . profilePicture ; } } ) ; } showLoginAttempts ( ) { this . modalHelper . create ( LoginAttemptsModalComponent ) . subscribe ( result => { } ) ; } changeMySettings ( ) { this . modalHelper . createStatic ( MySettingsModalComponent ) . subscribe ( result => { } ) ; } changeProfilePicture ( ) { this . modalHelper . createStatic ( ChangeProfilePictureModalComponent ) . subscribe ( _ => { } ) ; } logout ( ) { this . authService . logout ( ) ; } }