@WidgetComponent

nm-documentation-list

File

src/app/shared/widgets/portal/documentationlist/documentationlist.component.ts

Metadata

providers WidgetframeService
selector nm-documentation-list
styleUrls documentationlist.component.scss
templateUrl ./documentationlist.component.html

Index

Widget inputs
Widget outputs
Properties
Methods

Constructor

constructor(translateService: TranslateService, currentLocaleService: CurrentLocaleService)
Parameters :
Name Type Optional
translateService TranslateService no
currentLocaleService CurrentLocaleService no

Methods

appendLanguageToLinks
appendLanguageToLinks(documentation: Documentation, selectedLocale: string)
Parameters :
Name Type Optional
documentation Documentation no
selectedLocale string no
Returns : Documentation
Protected configureWidget
configureWidget(configuration: WidgetConfig)
Decorators : WidgetConfigure
Parameters :
Name Type Optional
configuration WidgetConfig<DocumentationListWidgetConfiguration> no
Returns : void
Private externalizeLinks
externalizeLinks(config: Documentation[], links: any)
Parameters :
Name Type Optional
config Documentation[] no
links any no
Returns : void
getLinkWithAppendedLocale
getLinkWithAppendedLocale(parentElement: , selectedLocale: )
Parameters :
Name Optional
parentElement no
selectedLocale no
Returns : any
ngOnDestroy
ngOnDestroy()
Returns : void
sortChildrenLabels
sortChildrenLabels(children: )
Parameters :
Name Optional
children no
Returns : any

Properties

Public _id
_id:
Decorators : WidgetId
Public appendLanguage
appendLanguage: boolean
Type : boolean
Public configuration
configuration: WidgetConfig<DocumentationListWidgetConfiguration>
Type : WidgetConfig<DocumentationListWidgetConfiguration>
Decorators : WidgetConfiguration
Public documentations
documentations: Documentation[]
Type : Documentation[]
Public enableAlphabeticSort
enableAlphabeticSort: boolean
Type : boolean
Public translateService
translateService: TranslateService
Type : TranslateService
Private unsubscribe
unsubscribe:
Default value : NgUnsubscribe.create()
import { Component } from "@angular/core";
import { WidgetConfig } from "../../widget.configuration";
import {
  WidgetComponent,
  WidgetConfiguration,
  WidgetConfigure,
  WidgetId,
} from "../../widget.metadata";
import { WidgetframeService } from "../../widgetframe/widgetframe.service";
import { getOrDefault } from "../../widget.configuration";
import { TranslateService } from "@ngx-translate/core";
import { CurrentLocaleService } from "../../../components/i18n/currentLocale.service";
import { takeUntil, tap } from "rxjs/operators";
import { of as observableOf, zip } from "rxjs";
import { BaseConfiguration } from "../../widgetframe/widgetframe.component";
import { NgUnsubscribe } from "../../../ng-unsubscribe";
import * as uriTemplates_ from "uri-templates";
import { deepCopy } from "../../../components/util";
const uriTemplates = uriTemplates_;

declare var contextPath: string;

export interface Documentation {
  /**
   * Icon for the documentation entry.
   */
  icon: string;

  /**
   * Base link for the documented object.
   */
  baseLink: string;

  /**
   * link for the documented object.
   */
  link: string;

  /**
   * Label for the documented object.
   */
  label: string;

  /**
   * Translated label for the documented object.
   */
  translatedLabel: string;

  /**
   * Boolean to refer if the documentation is internal or external.
   */
  internal: boolean;

  /**
   * Used to add <mat-divider> after each entry @default(false)
   */
  module: boolean;

  /**
   * Children for the entry.
   */
  children: Documentation[];
}
export interface DocumentationListWidgetConfiguration
  extends BaseConfiguration {
  /**
   * Enables/Disables sorting by alphabet @default("false")
   */
  enableAlphabeticSort?: boolean;

  /**
   * Appends language to link @default("false")
   */
  appendLanguage?: boolean;

  /**
   * Documentations to be displayed
   */
  documentations: Documentation[];
}
@WidgetComponent("nm-documentation-list")
@Component({
  selector: "nm-documentation-list",
  templateUrl: "./documentationlist.component.html",
  styleUrls: ["./documentationlist.component.scss"],
  providers: [WidgetframeService],
})
export class DocumentationListWidgetComponent {
  public documentations: Documentation[];
  public enableAlphabeticSort: boolean;
  public appendLanguage: boolean;

  private unsubscribe = NgUnsubscribe.create();

  @WidgetConfiguration()
  public configuration: WidgetConfig<DocumentationListWidgetConfiguration>;

  @WidgetId()
  public _id;

  constructor(
    public translateService: TranslateService,
    private currentLocaleService: CurrentLocaleService
  ) {
    this.documentations = [];
  }

  @WidgetConfigure()
  protected configureWidget(
    configuration: WidgetConfig<DocumentationListWidgetConfiguration>
  ) {
    this.documentations = configuration.configuration.documentations;
    this.enableAlphabeticSort = getOrDefault(
      configuration.configuration.enableAlphabeticSort,
      false
    );
    this.appendLanguage = getOrDefault(
      configuration.configuration.appendLanguage,
      false
    );
    this.documentations.forEach((doc: Documentation, index) => {
      if (doc.icon) {
        doc.icon = contextPath + doc.icon;
      }
      if (this.appendLanguage) {
        doc.baseLink = doc.link;
        doc.children.forEach((child) => {
          child.baseLink = child.link;
        });
      }
    });

    if (configuration._links) {
      this.externalizeLinks(this.documentations, configuration._links);
    }

    this.currentLocaleService
      .getCurrentLocale()
      .pipe(takeUntil(this.unsubscribe))
      .subscribe((selectedLocale) => {
        this.documentations.forEach((documentation) => {
          if(documentation.children){
          const observableArray = documentation.children.map((child) =>
            this.translateService
              .get(child.label)
              .pipe(tap((translation) => (child.translatedLabel = translation)))
          );
          const zipped = zip(...observableArray);
          if (this.appendLanguage) {
            documentation = this.appendLanguageToLinks(
              documentation,
              selectedLocale.substring(0, 2)
            );
          }
          zipped.subscribe(() => {
            if (this.enableAlphabeticSort) {
              documentation.children = this.sortChildrenLabels(
                documentation.children
              );
            }
          });
          return;
        }});
      });
  }

  private externalizeLinks(config: Documentation[], links: any) {
    config.forEach((conf) => {
      if (conf.link && !conf.link.startsWith("/") && !conf.internal) {
        conf.link = links[conf.link].href;
      } else if (conf.link && conf.internal) {
        conf.link = contextPath + conf.link;
      }

      if (conf.children) {
        this.externalizeLinks(conf.children, links);
      }
    });
  }

  sortChildrenLabels(children) {
    return children.sort(function (a, b) {
      return a.translatedLabel.localeCompare(b.translatedLabel);
    });
  }

  appendLanguageToLinks(documentation: Documentation, selectedLocale: string) {
    documentation.link = this.getLinkWithAppendedLocale(
      documentation,
      selectedLocale
    );
    documentation.children.forEach((child) => {
      child.link = this.getLinkWithAppendedLocale(child, selectedLocale);
    });
    return documentation;
  }

  getLinkWithAppendedLocale(parentElement, selectedLocale) {
    if (parentElement.link) {
      return uriTemplates(parentElement.baseLink).fill({
        language: selectedLocale,
      });
    }
  }

  ngOnDestroy() {
    this.unsubscribe.destroy();
  }
}
<nm-widgetframe
  [header]="configuration.configuration.header"
  style="max-width: 50%; min-width: 200px"
  [infoTitle]="configuration.configuration.infoTitle"
  [infoText]="configuration.configuration.infoText"
  infoPlacement="bottom"
  [wikiLink]="configuration.configuration.wikiLink"
  [configuration]="configuration"
  widgetId="{{ _id }}"
>
  <div slot="title" class="nm-widgetframe__title">
    {{ configuration.configuration.title | translate }}
  </div>
  <div slot="content" class="nm-widgetframe__content">
    <mat-list>
      <mat-divider></mat-divider>
      <div *ngFor="let documentation of documentations">
        <div class="docu-image {{ documentation.cssClass }}">
          <img
            *ngIf="documentation.icon"
            style="text-decoration: none"
            src="{{ documentation.icon }}"
            height="auto"
          />
        </div>

        <a
          mat-menu-item
          style="text-decoration: none"
          [href]="documentation.link | doculink"
          target="_blank"
        >
          <div mat-line>
            <span style="margin-left: 15px">{{
              documentation.label | translate
            }}</span>
          </div>
        </a>
        <mat-list class="nm-sublist" *ngIf="documentation.children">
          <div *ngFor="let child of documentation.children">
            <a
              style="text-decoration: none; margin-left: 50px"
              [href]="child.internal ? child.link : (child.link | doculink)"
              target="_blank"
              mat-menu-item
              [ngClass]="{ 'disabled-link': child.link == null }"
            >
              <div mat-line>
                <span style="margin-left: 15px">{{
                  child.translatedLabel
                }}</span>
              </div>
            </a>
            <mat-list class="nm-sublist" *ngIf="child.children != undefined">
              <a
                style="text-decoration: none"
                [href]="child.internal ? child.link : (child.link | doculink)"
                target="_blank"
                mat-menu-item
                *ngFor="let child of child.children"
              >
                <div mat-line>
                  <span style="margin-left: 15px">{{
                    child.label | translate
                  }}</span>
                </div>
              </a>
            </mat-list>
          </div>
        </mat-list>
        <mat-divider *ngIf="documentation.module"></mat-divider>
      </div>
    </mat-list>
  </div>
</nm-widgetframe>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""