@WidgetComponent

nm-login

File

src/app/shared/widgets/login/login.component.ts

Metadata

selector nm-login
styleUrls login.component.scss
templateUrl ./login.component.html

Index

Widget inputs
Widget outputs
Properties
Methods

Constructor

constructor(authService: AuthService, _appdata: AppdataStore, router: Router, formBuilder: FormBuilder, localStorageService: LocalStorageService, sanitizer: DomSanitizer, configService: ConfigService)
Parameters :
Name Type Optional
authService AuthService no
_appdata AppdataStore no
router Router no
formBuilder FormBuilder no
localStorageService LocalStorageService no
sanitizer DomSanitizer no
configService ConfigService no

Methods

clientChanged
clientChanged(value: )
Parameters :
Name Optional
value no
Returns : void
Protected configureWidget
configureWidget(configuration: WidgetConfig)
Decorators : WidgetConfigure
Parameters :
Name Type Optional
configuration WidgetConfig no
Returns : void
getBackgroundImage
getBackgroundImage()
Returns : SafeStyle
keyPressEvent
keyPressEvent(event: )
Parameters :
Name Optional
event no
Returns : void
login
login()
Returns : void
ngOnInit
ngOnInit()
Returns : void

Properties

Public backgroundImage
backgroundImage: string
Type : string
Public clients
clients: Client[]
Type : Client[]
Public configuration
configuration: WidgetConfig
Type : WidgetConfig
Decorators : WidgetConfiguration
Public errorHeadline
errorHeadline: string
Type : string
Default value : ""
Public errorMsg
errorMsg: string
Type : string
Default value : ""
Private loggedIn
loggedIn:
Default value : new Subject<any>()
Decorators : WidgetOutput
Public loginform
loginform: FormGroup
Type : FormGroup
Public publicappdata
publicappdata: AppdataModules
Type : AppdataModules
Public response
response:
Public routerNavigate
routerNavigate: string
Type : string
Public selectedClientId
selectedClientId: string
Type : string
Private selectedClientIdEntry
selectedClientIdEntry: LocalStorageEntry
Type : LocalStorageEntry
Public showClientSelection
showClientSelection:
Default value : true
Public testNeeded
testNeeded:
Default value : true
Public themes
themes:
Public user
user:
Default value : new User("", "")
Public welcomeText
welcomeText: string
Type : string
Public widgetId
widgetId: string
Type : string
Decorators : WidgetId
import { map, mergeMap } from "rxjs/operators";
import { Component } from "@angular/core";
import { DomSanitizer, SafeStyle } from "@angular/platform-browser";
import { Router } from "@angular/router";
import { AuthService, Client } from "../../components/auth/auth.service";
import {
  AppdataModules,
  AppdataStore,
} from "../../components/appdata/appdata.store";
import { FormBuilder, FormGroup } from "@angular/forms";
import { WidgetConfig } from "../widget.configuration";
import {
  WidgetComponent,
  WidgetConfiguration,
  WidgetConfigure,
  WidgetId,
  WidgetOutput,
} from "../widget.metadata";
import { Subject } from "rxjs";
import { User } from "../../components/auth/user";
import {
  LocalStorageEntry,
  LocalStorageService,
} from "../../components/local-storage/local-storage.service";
import {
  DeletionMode,
  Scope,
} from "../../components/local-storage/local-storage-constants";
import { ConfigService, themeLocalStorageConfig } from "../portal/config";

declare var contextPath: string;
declare var $;

@WidgetComponent("nm-login")
@Component({
  selector: "nm-login",
  templateUrl: "./login.component.html",
  styleUrls: ["./login.component.scss"],
})
export class LoginComponent {
  public user = new User("", "");
  public errorMsg = "";
  public errorHeadline = "";
  public response;
  public clients: Client[];
  public selectedClientId: string;
  public publicappdata: AppdataModules;
  public loginform: FormGroup;
  public backgroundImage: string;
  public welcomeText: string;
  public routerNavigate: string;
  public testNeeded = true;
  public showClientSelection = true;
  public themes;

  private selectedClientIdEntry: LocalStorageEntry;
  @WidgetConfiguration()
  public configuration: WidgetConfig;

  @WidgetId()
  public widgetId: string;

  @WidgetOutput("loggedIn")
  private loggedIn = new Subject<any>();

  constructor(
    private authService: AuthService,
    private _appdata: AppdataStore,
    private router: Router,
    private formBuilder: FormBuilder,
    private localStorageService: LocalStorageService,
    private sanitizer: DomSanitizer,
    private configService: ConfigService
  ) {
    this.clients = [];

    const themeEntry: LocalStorageEntry = this.localStorageService.getLocalStorageEntryByConfig(
      themeLocalStorageConfig
    );

    let currentTheme;
    this.configService.getThemes().subscribe((data) => {
      this.themes = data;
      if (
        themeEntry.exists() &&
        this.themes.map((entry) => entry.identifier).includes(themeEntry.value)
      ) {
        currentTheme = themeEntry.value;
      } else {
        let defaultheme = this.themes.find((entry) => entry.default);
        currentTheme = defaultheme.identifier;
      }
      window.setTimeout(() => {
        for (let entry of this.themes) {
          <any>$("body").removeClass(entry.identifer);
        }
        <any>$("body").addClass(currentTheme);
      }, 1);
    });
  }

  @WidgetConfigure()
  protected configureWidget(configuration: WidgetConfig) {
    this.backgroundImage =
      contextPath + this.configuration.configuration["backgroundImage"];
    this.welcomeText = this.configuration.configuration["welcomeText"];
    this.routerNavigate = this.configuration.configuration["routerNavigate"];
    this.showClientSelection =
      this.configuration.configuration["showClientSelection"] !== undefined
        ? this.configuration.configuration["showClientSelection"]
        : true;
  }

  getBackgroundImage(): SafeStyle {
    // sanitize the style expression
    return this.sanitizer.bypassSecurityTrustStyle(
      `url(${this.backgroundImage}`
    );
  }

  keyPressEvent(event) {
    if (event.keyCode === 13) {
      this.login();
    }
  }

  ngOnInit() {
    this.selectedClientIdEntry = this.localStorageService.getLocalStorageEntry(
      "selectedClientId",
      Scope.GLOBAL,
      DeletionMode.NEVER
    );
    this.loginform = this.formBuilder.group({
      name: "",
      password: "",
      clientselect: null,
    });

    if (this.showClientSelection) {
      this._appdata
        .getAppdata()
        .pipe(
          map((data) => data["ipim"]._links["clients"].href),
          mergeMap((data) => this.authService.getClients(data))
        )
        .subscribe(
          (data) => {
            this.clients = data._embedded.clients;
            if (this.selectedClientIdEntry.exists()) {
              window.setTimeout(() => {
                this.loginform.patchValue({
                  clientselect: Number(this.selectedClientIdEntry.value),
                });
              }, 1);
            } else if (this.clients && this.clients.length !== 0) {
              this.loginform.patchValue({
                clientselect: this.clients[0].clientId,
              });
            }
          },
          (err) => console.error(err)
        );
    }

    this._appdata.getPublicAppdata().subscribe(
      (data) => {
        this.publicappdata = data;
      },
      (err) => console.error(err)
    );
  }

  clientChanged(value) {
    this.selectedClientId = value;
    this.selectedClientIdEntry.value = value;
  }

  login() {
    this.user.name = this.loginform["value"].name;
    this.user.password = this.loginform["value"].password;
    this.selectedClientId = this.loginform["value"].clientselect;
    this.selectedClientIdEntry.value = this.selectedClientId;

    this.authService
      .doLogin(
        this.publicappdata._links["login"].href,
        this.user,
        this.selectedClientId,
        false
      )
      .subscribe(
        (response) => {
          this.authService.userLoggedIn(true, this.routerNavigate);
        },
        (error) => {
          this.errorHeadline = error.error.error;
          this.errorMsg = error.error.message;
        }
      );
  }
}
<mat-card-content
  class="mat-padding nm-login"
  [style.background-image]="getBackgroundImage()"
  layout="row"
  layout-wrap
  layout-align="center center"
  (keypress)="keyPressEvent($event)"
>
  <div class="login-container visible" style="overflow: visible">
    <section class="login" id="login">
      <header>
        <h3 class="headline-popup">{{ welcomeText | translate }}</h3>
      </header>

      <div class="skewed-border-container">
        <div class="skewed-border skewed-border-top"></div>
        <div class="skewed-border skewed-border-bottom"></div>
      </div>

      <form
        style="display: flex; flex-direction: column"
        class="login-form"
        [formGroup]="loginform"
      >
        <mat-form-field>
          <mat-label>{{ "login.placeholder.username" | translate }}</mat-label>
          <input
            matInput
            required
            style="width: 100%"
            formControlName="name"
            name="name"
            id="name"
            assetType="text"
            autocomplete="on"
            class="validate"
          />
        </mat-form-field>
        <mat-form-field>
          <mat-label>{{ "login.placeholder.password" | translate }}</mat-label>
          <input
            matInput
            required
            style="width: 100%"
            formControlName="password"
            name="password"
            id="password"
            type="password"
            autocomplete="on"
            assetType="password"
            class="validate"
          />
        </mat-form-field>
        <mat-form-field style="margin-top: 20px" *ngIf="showClientSelection">
          <mat-label>{{ "login.placeholder.client" | translate }}</mat-label>
          <mat-select
            style="width: 100%"
            formControlName="clientselect"
            [required]="true"
          >
            <mat-option
              *ngFor="let client of clients"
              [value]="client.clientId"
            >
              {{ client.description }}
            </mat-option>
          </mat-select>
        </mat-form-field>
        <div class>
          <div class="nm-error-login-headline">{{ errorHeadline }}</div>
          <div class="nm-error-login-text">{{ errorMsg }}</div>
        </div>

        <div class="submit-container">
          <button
            mat-raised-button
            color="primary"
            (click)="login()"
            class="btn nm-button-login"
            type="submit"
            name="action"
          >
            Login
          </button>
        </div>
      </form>
    </section>
  </div>

  <nm-container
    class="footer"
    *ngIf="configuration && configuration.footer"
    [configuration]="configuration.footer | widgetFor: configuration"
    [parent]="widgetId"
    id="footer"
  ></nm-container>
</mat-card-content>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""