All files / about si-about.component.ts

100% Statements 42/42
100% Branches 8/8
100% Functions 7/7
100% Lines 42/42

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145                                                                            1x 9x 9x         9x       9x       9x       9x       9x       9x       9x       9x       9x       9x       9x           9x       9x   9x 9x 9x         9x 9x     9x 9x 5x 5x 5x 4x 4x 4x             8x 8x 1x 1x 1x     8x 8x       2x 2x 2x 1x 1x 1x          
/**
 * Copyright (c) Siemens 2016 - 2025
 * SPDX-License-Identifier: MIT
 */
import { NgTemplateOutlet } from '@angular/common';
import { HttpClient } from '@angular/common/http';
import {
  ChangeDetectionStrategy,
  Component,
  computed,
  inject,
  input,
  OnInit,
  signal
} from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
import { SiCollapsiblePanelComponent } from '@siemens/element-ng/accordion';
import { CopyrightDetails, SiCopyrightNoticeComponent } from '@siemens/element-ng/copyright-notice';
import { addIcons, elementDocument, SiIconComponent } from '@siemens/element-ng/icon';
import { Link, SiLinkDirective } from '@siemens/element-ng/link';
import { SiTranslatePipe } from '@siemens/element-translate-ng/translate';
 
import { ApiInfo, LicenseInfo } from './si-about-data.model';
 
@Component({
  selector: 'si-about',
  imports: [
    NgTemplateOutlet,
    SiCollapsiblePanelComponent,
    SiCopyrightNoticeComponent,
    SiIconComponent,
    SiLinkDirective,
    SiTranslatePipe
  ],
  templateUrl: './si-about.component.html',
  styleUrl: './si-about.component.scss',
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class SiAboutComponent implements OnInit {
  private http = inject(HttpClient);
  private sanitizer = inject(DomSanitizer);
 
  /**
   * Title shown above the about information.
   */
  readonly aboutTitle = input.required<string>();
  /**
   * Define mode to display the licenses. See {@link LicenseInfo}
   */
  readonly licenseInfo = input.required<LicenseInfo>();
  /**
   * Path to the application logo. Use for image
   */
  readonly icon = input<string>();
  /**
   * Name of element icon. Use as alternative to image
   */
  readonly iconName = input<string>();
  /**
   * Title of this application.
   */
  readonly appName = input.required<string>();
  /**
   * Sub titles of the application. Shown as a list below the application name. (Optional)
   */
  readonly subheading = input<string[]>();
  /**
   * Link to `Acceptable Use Policy`.
   */
  readonly acceptableUsePolicyLink = input<Link>();
  /**
   * Link to `Corporate Information`.
   */
  readonly imprintLink = input<Link>();
  /**
   * Link to `Privacy Notice`.
   */
  readonly privacyLink = input<Link>();
  /**
   * Link to `Cookie Notice`.
   */
  readonly cookieNoticeLink = input<Link>();
  /**
   * Link to `Terms of Use`.
   */
  readonly termsLink = input<Link>();
  /**
   * Additional links listed in the about section.
   *
   * @defaultValue []
   */
  readonly links = input<Link[]>([]);
  /**
   * Copyright information to be displayed. Alternatively, you can use the {@link SI_COPYRIGHT_DETAILS} global inject.
   */
  readonly copyrightDetails = input<CopyrightDetails>();
 
  protected readonly sanitizedUrl = computed(() => {
    const licenseInfo = this.licenseInfo();
    return licenseInfo.iframe != null
      ? this.sanitizer.bypassSecurityTrustResourceUrl(licenseInfo.iframe)
      : undefined;
  });
 
  protected readonly licenseApi = signal<ApiInfo[]>([]);
  protected readonly icons = addIcons({ elementDocument });
 
  ngOnInit(): void {
    const licenseInfo = this.licenseInfo();
    if (licenseInfo.api) {
      this.http.get<ApiInfo[]>(licenseInfo.api, { responseType: 'json' }).subscribe(data => {
        this.licenseApi.set(data);
        if (this.licenseApi().length === 1) {
          data[0].isOpen = false;
          this.licenseApi.set([...data]);
          this.toggleLoadLicenseApi(this.licenseApi()[0]);
        }
      });
    }
  }
 
  protected toggleLoadLicenseApi(apiInfo: ApiInfo): void {
    const licenseApi = this.licenseApi();
    if (!apiInfo.isOpen && !apiInfo.files) {
      this.http.get<ApiInfo[]>(apiInfo.href, { responseType: 'json' }).subscribe(files => {
        apiInfo.files = files;
        this.licenseApi.set([...licenseApi]);
      });
    }
    apiInfo.isOpen = !apiInfo.isOpen;
    this.licenseApi.set([...licenseApi]);
  }
 
  protected toggleLoadLicenseContent(apiInfo: ApiInfo): void {
    const licenseApi = this.licenseApi();
    apiInfo.isOpen = !apiInfo.isOpen;
    if (!apiInfo.content) {
      this.http.get(apiInfo.href, { responseType: 'text' }).subscribe((content: string) => {
        apiInfo.content = content;
        this.licenseApi.set([...licenseApi]);
      });
    }
  }
}