File

src/app/apps/app-details/app-details.component.ts

Description

Provides details for an App Registration

Implements

OnInit OnDestroy

Example

Metadata

selector app-details
styleUrls styles.scss
templateUrl ./app-details.component.html

Index

Properties
Methods

Constructor

constructor(appsService: AppsService, sharedAboutService: SharedAboutService, notificationService: NotificationService, route: ActivatedRoute, routingStateService: RoutingStateService, loggerService: LoggerService, modalService: BsModalService)

Constructor

Parameters :
Name Type Optional Description
appsService AppsService
sharedAboutService SharedAboutService
notificationService NotificationService
route ActivatedRoute
routingStateService RoutingStateService
loggerService LoggerService
modalService BsModalService

Methods

applySort
applySort(sort: SortParams)

Apply sort Triggered on column header click

Parameters :
Name Type Optional Description
sort SortParams
Returns : void
cancel
cancel()

Back action Navigate to the previous URL or /apps

Returns : void
loadProperties
loadProperties(version: string)

Used to load properties

Parameters :
Name Type Optional Description
version string

Optional version

Returns : void
loadVersions
loadVersions()

Used to load versions of an application

Returns : void
ngOnDestroy
ngOnDestroy()

Will cleanup any {@link Subscription}s to prevent memory leaks.

Returns : void
ngOnInit
ngOnInit()

Init

Returns : void
refresh
refresh()

Refresh page, load the current version informations

Returns : void
selectVersion
selectVersion(version: string)

Used to load properties form a selected version

Parameters :
Name Type Optional Description
version string

of the application

Returns : void
unregisterApp
unregisterApp()

Starts the unregistration process AppRegistrations by opening a confirmation modal dialog.

Returns : void
versions
versions(appRegistration: AppRegistration)

Open the version dialog of an application

Parameters :
Name Type Optional Description
appRegistration AppRegistration
Returns : void

Properties

application
application: AppRegistration
Type : AppRegistration

Application

defaultVersion
defaultVersion: any
Type : any

Current default version

detailedAppRegistration
detailedAppRegistration: DetailedAppRegistration
Type : DetailedAppRegistration

Properties

loaded
loaded:
Default value : false

Loaded properties

Private ngUnsubscribe$
ngUnsubscribe$: Subject<any>
Type : Subject<any>

Unsubscribe

showProperties
showProperties:
Default value : true

Display the properties

sort
sort: SortParams
Type : SortParams

Sort parameters use on the versions list

tooManyProperties
tooManyProperties:
Default value : false

State too Many properties

versionSelect
versionSelect: string
Type : string

State selected version (dropdown)

import { Component, OnInit, OnDestroy } from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
import { AppsService } from '../apps.service';
import { ApplicationType, AppVersion, DetailedAppRegistration } from '../../shared/model';
import { SharedAboutService } from '../../shared/services/shared-about.service';
import { AppRegistration } from '../../shared/model/app-registration.model';
import { AppVersionsComponent } from '../app-versions/app-versions.component';
import { BsModalService } from 'ngx-bootstrap';
import { SortParams } from '../../shared/components/shared.interface';
import { Subject, Subscription } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { RoutingStateService } from '../../shared/services/routing-state.service';
import { NotificationService } from '../../shared/services/notification.service';
import { LoggerService } from '../../shared/services/logger.service';
import { HttpAppError, AppError } from '../../shared/model/error.model';
import { AppsUnregisterComponent } from '../apps-unregister/apps-unregister.component';

/**
 * Provides details for an App Registration
 *
 * @author Gunnar Hillert
 * @author Damien Vitrac
 */
@Component({
  selector: 'app-details',
  styleUrls: ['./styles.scss'],
  templateUrl: './app-details.component.html'
})
export class AppDetailsComponent implements OnInit, OnDestroy {

  /**
   * Unsubscribe
   */
  private ngUnsubscribe$: Subject<any> = new Subject();

  /**
   * Properties
   */
  detailedAppRegistration: DetailedAppRegistration;

  /**
   * Application
   */
  application: AppRegistration;

  /**
   * Current default version
   */
  defaultVersion: any;

  /**
   * State selected version (dropdown)
   */
  versionSelect: string;

  /**
   * Sort parameters use on the versions list
   * @type {SortParams} Sort/Order params
   */
  sort: SortParams = {
    sort: '',
    order: ''
  };

  /**
   * Display the properties
   */
  showProperties = true;

  /**
   * State too Many properties
   */
  tooManyProperties = false;

  /**
   * Loaded properties
   */
  loaded = false;

  /**
   * Constructor
   *
   * @param {AppsService} appsService
   * @param {SharedAboutService} sharedAboutService
   * @param {NotificationService} notificationService
   * @param {ActivatedRoute} route
   * @param {RoutingStateService} routingStateService
   * @param {LoggerService} loggerService
   * @param {BsModalService} modalService
   */
  constructor(private appsService: AppsService,
              private sharedAboutService: SharedAboutService,
              private notificationService: NotificationService,
              private route: ActivatedRoute,
              private routingStateService: RoutingStateService,
              private loggerService: LoggerService,
              private modalService: BsModalService) {
  }

  /**
   * Init
   */
  ngOnInit() {
    this.loggerService.log('App Service Details');
    this.route.params
      .pipe(takeUntil(this.ngUnsubscribe$))
      .subscribe((params: Params) => {
        this.application = new AppRegistration(params['appName'], params['appType'] as ApplicationType);
        this.refresh();
      });
  }

  /**
   * Will cleanup any {@link Subscription}s to prevent
   * memory leaks.
   */
  ngOnDestroy() {
    this.ngUnsubscribe$.next();
    this.ngUnsubscribe$.complete();
  }

  /**
   * Refresh page, load the current version informations
   */
  refresh() {
    this.loadVersions();
  }

  /**
   * Used to load properties
   *
   * @param {string} version Optional version
   */
  loadProperties(version: string = '') {
    this.loggerService.log('Retrieving properties application for ' + this.application.name + ' (' +
    this.application.type + ', version ' + version ? version : '/' + ').');
    this.versionSelect = version;
    this.appsService.getAppInfo(this.application.type, this.application.name, version)
      .pipe(takeUntil(this.ngUnsubscribe$))
      .subscribe((detailed: DetailedAppRegistration) => {
          this.tooManyProperties = (detailed.options.length > 50);
          this.showProperties = !this.tooManyProperties;
          this.detailedAppRegistration = detailed;
        },
        error => {
          if (HttpAppError.is404(error)) {
            this.cancel();
          }
          this.notificationService.error(AppError.is(error) ? error.getMessage() : error);
        }, () => {
          this.loaded = true;
        });
  }

  /**
   * Used to load versions of an application
   */
  loadVersions() {
    this.loggerService.log(`Retrieving versions application for ${this.application.name} (${this.application.type}).`);
    this.appsService
      .getAppVersions(ApplicationType[this.application.type.toString()], this.application.name)
      .pipe(takeUntil(this.ngUnsubscribe$))
      .subscribe((appVersions: AppVersion[]) => {
          this.application.versions = appVersions;
          this.defaultVersion = this.application.versions.find((a) => a.defaultVersion);
          if (this.defaultVersion) {
            this.application.version = this.defaultVersion.version;
            this.application.uri = this.defaultVersion.uri;
            this.selectVersion(this.defaultVersion.version);
          } else {
            this.selectVersion(this.application.versions[0].version);
          }
        },
        error => {
          this.notificationService.error(AppError.is(error) ? error.getMessage() : error);
        });
  }

  /**
   * Apply sort
   * Triggered on column header click
   *
   * @param {SortParams} sort
   */
  applySort(sort: SortParams) {
    this.sort.sort = sort.sort;
    this.sort.order = sort.order;
  }

  /**
   * Open the version dialog of an application
   *
   * @param {AppRegistration} appRegistration
   */
  versions(appRegistration: AppRegistration) {
    this.loggerService.log(`Manage versions ${appRegistration.name} app.`, appRegistration);
    const modal = this.modalService.show(AppVersionsComponent, { class: 'modal-xl' });
    modal.content.open(appRegistration)
      .pipe(takeUntil(this.ngUnsubscribe$))
      .subscribe(() => {
        this.loadVersions();
      });
  }

  /**
   * Starts the unregistration process {@link AppRegistration}s
   * by opening a confirmation modal dialog.
   */
  unregisterApp() {
    const modal = this.modalService.show(AppsUnregisterComponent);
    modal.content.open([this.application])
      .pipe(takeUntil(this.ngUnsubscribe$))
      .subscribe(() => {
        this.refresh();
      });
  }


  /**
   * Used to load properties form a selected version
   *
   * @param {string} version of the application
   */
  selectVersion(version: string) {
    if (this.versionSelect === version) {
      return;
    }
    this.loaded = false;
    this.loadProperties(version);
  }

  /**
   * Back action
   * Navigate to the previous URL or /apps
   */
  cancel() {
    this.routingStateService.back('/apps', /^(\/apps\/)/);
  }

}
<app-page *ngIf="application" id="app-details">

  <app-page-head>
    <app-page-head-back [defaultUrl]="'/apps'" [isNotRegex]="'^(\/apps\/)'"></app-page-head-back>
    <app-page-head-title>Application <strong>{{ application.name }}</strong></app-page-head-title>
    <app-page-head-subtitle>
      <app-type [application]="application"></app-type>
      <span *ngIf="defaultVersion" class="label label-default" style="margin-left: 5px;">
        {{ defaultVersion.version }}
      </span>
    </app-page-head-subtitle>
    <app-page-head-actions>
      <button type="button" class="btn btn-danger btn-fa" (click)="unregisterApp()"
              [dataflowAppRoles]="['ROLE_DESTROY']">
        <span class="fa fa-trash"></span>
        Remove
      </button>
    </app-page-head-actions>
  </app-page-head>

  <div dataflowLayoutType type="large">

    <div id="no-default-version" *ngIf="application.versions.length > 0 && !defaultVersion">
      <div class="alert alert-danger" style="display: inline-block;padding:1rem 2rem;">
        <strong>Application unavailable.</strong><br>
        You have to set a default version for this application.
        <div style="padding-top:1rem;">
          <a (click)="versions(application)" class="btn btn-danger">Manage versions</a>
        </div>
      </div>
    </div>

    <div *ngIf="detailedAppRegistration">
      <div *ngIf="application.versions.length > 1" style="padding: 1rem 0;">
        <div id="version-dropdown" class="dropdown" dropdown>
          <button dropdownToggle type="button" class="btn btn-dropdown btn-primary">
            Version: {{ versionSelect }}
            <span *ngIf="versionSelect == defaultVersion?.version">
          <span placement="bottom" tooltip="Default version"
                class="ico-current-version fa fa-star"></span>
        </span>
            <span class="caret"></span>
          </button>
          <ul *dropdownMenu class="dropdown-menu">
            <li *ngFor="let version of application.versions" [class.active]="versionSelect == version.version">
              <a style="cursor: pointer" (click)="selectVersion(version.version)">
                {{ version.version }}
                <span *ngIf="version.defaultVersion">
              <span placement="bottom" tooltip="Default version"
                    class="ico-current-version fa fa-star"></span>
            </span>
              </a>
            </li>
          </ul>
        </div>
      </div>

      <div *ngIf="loaded">

        <div class="app-details-info" style="padding: 0.5rem 0 1.5rem;">
          <div><strong>Uri</strong>: {{ detailedAppRegistration.uri }}</div>
          <div *ngIf="application.versions.length == 1">
            <strong>Version</strong>: {{ detailedAppRegistration.version }}
          </div>
        </div>

        <div *ngIf="tooManyProperties && !showProperties" class="dataflow-alert dataflow-alert-info">
          <p style="padding-bottom: 5px;">
            There are <strong>more than 50 properties</strong> to display, the UI can be slow.<br>Do you want to
            <strong>display all the properties</strong> ?
          </p>
          <button class="btn btn-primary" (click)="showProperties = true">Show all the properties</button>
        </div>
        <div *ngIf="showProperties">
          <div *ngIf="detailedAppRegistration?.options && detailedAppRegistration?.options.length > 0">
            <table id="table-properties" class="table table-hover" *ngIf="detailedAppRegistration?.options">
              <thead>
              <tr>
                <th>
                  <app-sort id="sort-name" [indeterminate]="true" (change)="applySort($event)" [value]="'name'"
                            [sort]="sort">
                    Property
                  </app-sort>
                </th>
                <th>Description</th>
              </tr>
              </thead>
              <tbody>
              <tr *ngFor="let property of detailedAppRegistration.options | orderby:sort.sort:sort.order">
                <td>
                  <strong>{{ property.name }}</strong>
                  <div *ngIf="property.isDeprecated">
                    <span class="label label-warning">Deprecation level: {{ property.deprecation.level }}</span>
                  </div>
                </td>
                <td>
                  <p>{{ property.description ? property.description : '(No Description Available)' }}</p>
                  <p class="type-block"><code>{{ property.type }}</code> <span
                    *ngIf="property.defaultValue">(Default value: <code>{{ property.defaultValue }}</code>)</span></p>
                </td>
              </tr>
              </tbody>
            </table>
          </div>
        </div>

      </div>

      <div *ngIf="!loaded" style="padding:1rem;">
        <app-loader></app-loader>
      </div>

      <div *ngIf="!(detailedAppRegistration?.options && detailedAppRegistration?.options.length > 0)"
           class="dataflow-alert">
        No properties available.
      </div>

    </div>
    <div *ngIf="!detailedAppRegistration">
      <app-loader></app-loader>
    </div>
  </div>
</app-page>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""