File

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

Description

Provides versions for an App Registration

Example

Metadata

selector app-versions
templateUrl ./app-versions.component.html

Index

Properties
Methods

Constructor

constructor(appsService: AppsService, confirmService: ConfirmService, modalRef: BsModalRef, notificationService: NotificationService, loggerService: LoggerService)

Constructor

Parameters :
Name Type Optional Description
appsService AppsService
confirmService ConfirmService
modalRef BsModalRef
notificationService NotificationService
loggerService LoggerService

Methods

applySort
applySort(sort: SortParams)

Apply sort Triggered on column header click

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

Close the modal

Returns : void
isVersionOnError
isVersionOnError(versions: AppVersion[])
Parameters :
Name Type Optional Description
versions AppVersion[]
Returns : boolean
makeDefaultVersion
makeDefaultVersion(versions: AppVersion[], version: AppVersion)

Used to update the current version

Parameters :
Name Type Optional Description
versions AppVersion[]
version AppVersion
Returns : void
open
open(application: AppRegistration)

Init the component

Parameters :
Name Type Optional Description
application AppRegistration
Returns : any
refresh
refresh()

Used to load versions of an application

Returns : void
unregisterVersion
unregisterVersion(version: AppVersion)

Used to unregister a version of an application Confirm is required for this action

Parameters :
Name Type Optional Description
version AppVersion

to unregister

Returns : void

Properties

application
application: AppRegistration
Type : AppRegistration

Application

event
event: EventEmitter<boolean>
Type : EventEmitter<boolean>

Emit at every success change makeDefaultVersion and unregisterVersion

isRunning
isRunning:
Default value : false

State is running (make default or unregister)

sort
sort: SortParams
Type : SortParams

Sort parameters use on the versions list Initialize for a sort by version name

versions$
versions$: Observable<[]>
Type : Observable<[]>

Observable of AppVersion[]

import { Component, EventEmitter } from '@angular/core';
import { AppRegistration } from '../../shared/model/app-registration.model';
import { AppsService } from '../apps.service';
import { ConfirmService } from '../../shared/components/confirm/confirm.service';
import { BsModalRef } from 'ngx-bootstrap';
import { AppVersion } from '../../shared/model/app-version';
import { SortParams, OrderParams } from '../../shared/components/shared.interface';
import { ApplicationType } from '../../shared/model/application-type';
import { NotificationService } from '../../shared/services/notification.service';
import { LoggerService } from '../../shared/services/logger.service';
import { AppError } from '../../shared/model/error.model';
import { Observable } from 'rxjs';

/**
 * Provides versions for an App Registration
 *
 * @author Damien Vitrac
 */
@Component({
  selector: 'app-versions',
  templateUrl: './app-versions.component.html'
})
export class AppVersionsComponent {

  /**
   * Application
   */
  application: AppRegistration;

  /**
   * Observable of AppVersion[]
   */
  versions$: Observable<AppVersion[]>;

  /**
   * Emit at every success change
   * makeDefaultVersion and unregisterVersion
   *
   * @type {EventEmitter<boolean>}
   */
  event: EventEmitter<boolean> = new EventEmitter();

  /**
   * Sort parameters use on the versions list
   * Initialize for a sort by version name
   * @type {SortParams} Sort/Order params
   */
  sort: SortParams = {
    sort: 'version',
    order: OrderParams.ASC
  };

  /**
   * State is running (make default or unregister)
   * @type {boolean}
   */
  isRunning = false;

  /**
   * Constructor
   *
   * @param {AppsService} appsService
   * @param {ConfirmService} confirmService
   * @param {BsModalRef} modalRef
   * @param {NotificationService} notificationService
   * @param {LoggerService} loggerService
   */
  constructor(private appsService: AppsService,
              private confirmService: ConfirmService,
              private modalRef: BsModalRef,
              private notificationService: NotificationService,
              private loggerService: LoggerService) {

  }

  /**
   * Init the component
   *
   * @param {AppRegistration} application
   * @returns {EventEmitter<boolean>}
   */
  open(application: AppRegistration) {
    this.application = new AppRegistration(application.name, application.type);
    this.refresh();
    return this.event;
  }

  /**
   * Used to load versions of an application
   */
  refresh() {
    this.loggerService.log(`Retrieving versions application for ${this.application.name} (${this.application.type}).`);
    this.versions$ = this.appsService
      .getAppVersions(ApplicationType[this.application.type.toString()], this.application.name);
  }

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

  /**
   * Used to update the current version
   *
   * @param {AppVersion[]} versions
   * @param {AppVersion} version
   */
  makeDefaultVersion(versions: AppVersion[], version: AppVersion) {
    const run = () => {
      this.isRunning = true;
      this.appsService.setAppDefaultVersion(this.application.type, this.application.name, version.version)
        .subscribe(() => {
            this.notificationService.success(`The version <strong>${version.version}</strong> is now the default ` +
              `version of the application <strong>${this.application.name}</strong> (${this.application.type}).`);
            this.refresh();
            this.event.emit(true);
          },
          error => {
            this.notificationService.error(error);
          }, () => {
            this.isRunning = false;
          });
    };

    if (this.isVersionOnError(versions)) {
      run();
    } else {
      const title = `Confirm make default version`;
      const description = `This action will make the version <strong>${version.version}</strong> as the default ` +
        ` version for the application <strong>${this.application.name}</strong> (${this.application.type}). ` +
        `Are you sure?`;
      this.confirmService.open(title, description).subscribe(() => {
        this.loggerService.log(`Set default version application "${version}" for ${this.application.name} (${this.application.type}).`);
        run();
      });
    }
  }

  /**
   * Used to unregister a version of an application
   * Confirm is required for this action
   *
   * @param {AppVersion} version to unregister
   */
  unregisterVersion(version: AppVersion) {
    const title = `Confirm unregister version`;
    let description = `This action will unregister the <strong>version ${version.version}</strong> ` +
      `of the application <strong>${this.application.name}</strong> (${this.application.type}). Are you sure?`;

    if (version.defaultVersion) {
      description = `This action will unregister the <strong>version ${version.version}</strong>` +
        `of the application <strong>${this.application.name}</strong> (${this.application.type}). This version ` +
        ` is the <strong>default version</strong>. Are you sure?`;
    }
    this.confirmService.open(title, description, { confirm: 'Unregister version' }).subscribe(() => {
      this.isRunning = true;
      this.appsService.unregisterAppVersion(this.application, version.version).subscribe(() => {
          this.notificationService.success(`The version <strong>${version.version}</strong> of the application ` +
            `<strong>${this.application.name}</strong> (${this.application.type}) has been unregister.`);

          if (this.application.versions.length === 1) {
            this.close();
          } else {
            this.refresh();
          }
          this.event.emit(true);
        },
        error => {
          this.notificationService.error(AppError.is(error) ? error.getMessage() : error);
        }, () => {
          this.isRunning = false;
        });
    });
  }

  isVersionOnError(versions: AppVersion[]) {
    for (let i = 0; i < versions.length; i++) {
      if (versions[i].defaultVersion) {
        return false;
      }
    }
    return true;
  }

  /**
   * Close the modal
   */
  close() {
    this.modalRef.hide();
  }
}
<div *ngIf="application" id="app-versions">

  <div *ngIf="versions$ | async as versions; else loading">

    <div class="modal-header">
      <h4 class="modal-title pull-left">
        Manage versions of the application
        <strong>{{ application.name }}
          <app-type [application]="application"></app-type>
        </strong>
      </h4>
      <button type="button" class="close pull-right" aria-label="Close" (click)="close()">
        <span aria-hidden="true">&times;</span>
      </button>
    </div>

    <div class="modal-body" *ngIf="!isRunning">

      <p>
        This section lists all the <strong>versions available for an application</strong>.
        You can <strong>unregister</strong> an app or <strong>switch the default version</strong> of the application.
      </p>

      <div style="text-align: center" *ngIf="isVersionOnError(versions)">
        <div class="alert alert-danger" style="display: inline-block">
          <strong>Application unavailable.</strong><br>
          You have to set a default version for this application.
        </div>
      </div>

      <table id="table-versions" class="table table-checkbox" *ngIf="application.versions">
        <thead>
        <tr>
          <th width="10px">&nbsp;</th>
          <th>
            <app-sort id="sort-version" [indeterminate]="false" (change)="applySort($event)" [value]="'version'"
                      [sort]="sort">
              Version
            </app-sort>
          <th>
            <app-sort id="sort-uri" [indeterminate]="false" (change)="applySort($event)" [value]="'uri'" [sort]="sort">
              Uri
            </app-sort>
          </th>
          <th [dataflowAppRoles]="['ROLE_DESTROY', 'ROLE_MODIFY']">&nbsp;</th>
        </tr>
        </thead>
        <tbody>
        <tr *ngFor="let version of versions | orderby:sort.sort:sort.order" [class.activeVersion]="version.defaultVersion">
          <td>
            <strong *ngIf="version.defaultVersion">
            <span placement="bottom" tooltip="Default version"
                  class="ico-current-version glyphicon glyphicon-star"></span>
            </strong>
          </td>
          <td nowrap="">
            <app-version-label [version]="version"></app-version-label>
          </td>
          <td>
            <code>{{ version?.uri }}</code>
          </td>
          <td class="table-actions" width="10px" nowrap="" [dataflowAppRoles]="['ROLE_DESTROY', 'ROLE_MODIFY']">
            <div class="actions-btn" role="group">
              <button type="button" (click)="makeDefaultVersion(versions, version)"
                      [dataflowAppRoles]="['ROLE_MODIFY']"
                      [disabled]="version.defaultVersion"
                      class="btn btn-default" title="Make default version">
                <span style="margin-top: 2px" class="fa fa-star"></span>
              </button>
              <button type="button" (click)="unregisterVersion(version)"
                      [dataflowAppRoles]="['ROLE_DESTROY']"
                      class="btn btn-default" title="Unregister">
                <span style="margin-top: 2px" class="fa fa-trash"></span>
              </button>
            </div>
          </td>
        </tr>
        </tbody>
      </table>
    </div>

    <div style="padding: 2rem;" *ngIf="isRunning">
      <app-loader></app-loader>
    </div>

    <div class="modal-footer">
      <button type="button" class="btn btn-default" (click)="close()">Cancel</button>
    </div>
  </div>

  <ng-template #loading>
    <div style="padding: 2rem;">
      <app-loader></app-loader>
    </div>
  </ng-template>

</div>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""