@WidgetComponent

nm-app-root

File

src/app/shared/widgets/configuration/app.root.component.ts

Implements

OnChanges OnDestroy

Metadata

host {
}
providers { : , : , : [, , ], }
selector nm-app-root
styleUrls app.root.component.scss
templateUrl ./app.root.component.html

Index

Widget inputs
Widget outputs
Properties
Methods
Inputs

Constructor

constructor(service: AppService, scrollService: ScrollService, changeDetectorRef: ChangeDetectorRef)
Parameters :
Name Type Optional
service AppService no
scrollService ScrollService no
changeDetectorRef ChangeDetectorRef no

Inputs

href

Type: string

is-attached

Type: boolean

Default value: true

overlayScrollbarActive

Type: boolean

param

Type: any

Methods

ngOnChanges
ngOnChanges(changes: SimpleChanges)
Parameters :
Name Type Optional
changes SimpleChanges no
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
onComponentInitialized
onComponentInitialized(id: string)
Parameters :
Name Type Optional
id string no
Returns : void

Properties

Public configuration
configuration:
Default value : new Subject<{ id: string; pageTitle?: string; infoTitle?: string; infoText?: string; infoWidth?: string; infoHeight?: string; infoToolTip?: string; wikiLink?: string; overlayScrollbarActive?: boolean; config: WidgetConfig; }>()
import {
  Component,
  OnChanges,
  OnDestroy,
  Input,
  ChangeDetectorRef,
  Injector,
  SimpleChanges,
  SimpleChange,
  ChangeDetectionStrategy,
  NgModule,
} from "@angular/core";
import { Subject } from "rxjs";
import { WidgetConfig } from "../widget.configuration";
import { AppService, appServiceFactory } from "./app.service";
import { AppGlobalChannelsService } from "./app.global-channels.service";
import { AppParams } from "./app.controller";
import { HttpClient } from "@angular/common/http";
import {
  OverlayScrollbarsComponent,
  OverlayscrollbarsModule,
} from "overlayscrollbars-ngx";
import { CommonModule } from "@angular/common";
import { ContainerModule } from "../container/container.component";
import { TranslateModule } from "@ngx-translate/core";
import { CoreComponentsModule } from "../../components/core-components.module";
import { ScrollService } from "../../components/scroll";
import {
  animate,
  keyframes,
  style,
  transition,
  trigger,
} from "@angular/animations";

@Component({
  selector: "nm-app-root",
  templateUrl: "./app.root.component.html",
  styleUrls: ["./app.root.component.scss"],
  host: {
    "[attr.data-layout]":
      "overlayScrollbarActive ? 'scrollbar': 'no-scrollbar'",
  },
  providers: [
    {
      provide: AppService,
      useFactory: appServiceFactory,
      deps: [HttpClient, AppGlobalChannelsService, Injector],
    },
  ],
  animations: [
    trigger("fadeTrigger", [
      transition(":enter", [
        style({ opacity: 0 }),
        animate(
          "0.3s 0.7s",
          keyframes([
            style({ opacity: 0, transform: "translateZ(0)" }),
            style({ opacity: 1, transform: "translateZ(50px)" }),
          ])
        ),
      ]),
      transition(":leave", [animate("200ms ease-out", style({ opacity: 0 }))]),
    ]),
  ],
  // can't be activated, until PIMWEB-1219 is completed
  // changeDetection: ChangeDetectionStrategy.OnPush
})
export class AppRootComponent implements OnChanges, OnDestroy {
  @Input("href")
  public href: string;

  @Input("param")
  public param: any;

  @Input("is-attached")
  public attached: boolean = true;

  @Input("overlayScrollbarActive")
  public overlayScrollbarActive: boolean;

  public configuration = new Subject<{
    id: string;
    pageTitle?: string;
    infoTitle?: string;
    infoText?: string;
    infoWidth?: string;
    infoHeight?: string;
    infoToolTip?: string;
    wikiLink?: string;
    overlayScrollbarActive?: boolean;
    config: WidgetConfig;
  }>();

  constructor(
    private service: AppService,
    private scrollService: ScrollService,
    private changeDetectorRef: ChangeDetectorRef
  ) {
    document.addEventListener(
      "scroll",
      (e) => {
        this.scrollService.setOnScroll(e);
      },
      true
    );
  }

  ngOnChanges(changes: SimpleChanges): void {
    if (changes.param) {
      this.service.activeContext = changes.param.currentValue;
    }

    if (changes.attached) {
      if (changes.attached.currentValue === true) {
        this.service.attach();
      } else {
        this.service.detach();
      }
    }

    if (changes.href && changes.href.currentValue) {
      let appData: AppParams = {
        href: changes.href.currentValue,
      };

      this.configuration.next({ id: "empty", config: null });
      this.changeDetectorRef.detectChanges();

      this.service.reset();
      this.service.loadPage(appData).subscribe((pageConfiguration) => {
        let rootWidget = pageConfiguration["root-widget"];
        let widgetConfig = this.service.toWidgetConfig(rootWidget);

        let configuration = {
          id: rootWidget,
          pageTitle: pageConfiguration.pageTitle,
          infoTitle: pageConfiguration.infoTitle,
          infoText: pageConfiguration.infoText,
          infoWidth: pageConfiguration.infoWidth,
          infoHeight: pageConfiguration.infoHeight,
          infoToolTip: pageConfiguration.infoToolTip,
          wikiLink: pageConfiguration.wikiLink,
          overlayScrollbarActive:
            pageConfiguration.overlayScrollbarActive !== null
              ? pageConfiguration.overlayScrollbarActive
              : true,
          config: widgetConfig,
        };

        this.overlayScrollbarActive = !(
          this.overlayScrollbarActive === null ||
          this.overlayScrollbarActive === undefined
        )
          ? this.overlayScrollbarActive
          : configuration.overlayScrollbarActive;

        this.configuration.next(configuration);
      });
    }
  }

  onComponentInitialized(id: string) {
    this.service.initialized();
  }

  ngOnDestroy() {
    this.service.dispose();
  }
}

@NgModule({
  imports: [
    CommonModule,
    ContainerModule,
    TranslateModule,
    OverlayscrollbarsModule,
    CoreComponentsModule,
  ],
  declarations: [AppRootComponent],
  exports: [AppRootComponent],
})
export class AppRootModule {}
<ng-container *ngIf="configuration | async as config">
  <ng-container *ngIf="overlayScrollbarActive; else noScrollbar">
    <overlay-scrollbars style="height: 100%">
      <ng-container
        *ngTemplateOutlet="pageContent; context: { config: config }"
      >
      </ng-container>
    </overlay-scrollbars>
  </ng-container>

  <ng-template #noScrollbar>
    <ng-container *ngTemplateOutlet="pageContent; context: { config: config }">
    </ng-container>
  </ng-template>
</ng-container>

<ng-template #pageContent let-config="config">
  <div class="nm-appRoot__header">
    <div [@fadeTrigger] class="nm-appRoot__pageTitle" *ngIf="config.pageTitle">
      <div class="nm-appRoot__rectangle"></div>
      <h1 class="mat-h1">
        {{ config.pageTitle | translate | uppercase }}
      </h1>
    </div>

    <nm-help-icon
      *ngIf="config.infoText"
      [info-title]="config.infoTitle"
      [info-width]="config.infoWidth"
      [info-height]="config.infoHeight"
      [info-tooltip]="config.infoToolTip"
      [info-text]="config.infoText"
      [wiki-link]="config.wikiLink"
    >
    </nm-help-icon>
  </div>

  <nm-container
    [configuration]="config.config"
    [parent]="null"
    [id]="config.id"
    (component-initialized)="onComponentInitialized($event)"
  >
  </nm-container>
  <nm-scrollToTop></nm-scrollToTop>
</ng-template>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""