File

src/app/streams/stream/history/stream-history.component.ts

Description

Component that shows the history (versions) of a Stream Definition deployment. You can also perform a rollback to a version of the stream (stream rollback ...).

Implements

OnInit

Example

Metadata

selector app-stream-history
styleUrls .styles.scss
templateUrl stream-history.component.html

Index

Properties
Methods

Constructor

constructor(route: ActivatedRoute, router: Router, confirmService: ConfirmService, loggerService: LoggerService, notificationService: NotificationService, streamsService: StreamsService)

Constructor

Parameters :
Name Type Optional Description
route ActivatedRoute
router Router
confirmService ConfirmService
loggerService LoggerService
notificationService NotificationService
streamsService StreamsService

Methods

canRollback
canRollback(stream: StreamDefinition, history: StreamHistory)

Determine if the rollback action is allowed

Parameters :
Name Type Optional Description
stream StreamDefinition
history StreamHistory
Returns : boolean
ngOnInit
ngOnInit()

On Init

Returns : void
refresh
refresh()

Load the stream history

Returns : void
rollback
rollback(streamHistory: StreamHistory)

Rollback Action Ask a validation to the user (confirm) before performing a rollback.

Parameters :
Name Type Optional Description
streamHistory StreamHistory
Returns : void

Properties

stream$
stream$: Observable<any>
Type : Observable<any>

Observable of stream information Contains the stream definition, a list of the streams"s apps

import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { StreamDefinition } from '../../model/stream-definition';
import { map, mergeMap } from 'rxjs/operators';
import { StreamsService } from '../../streams.service';
import { ActivatedRoute, Router } from '@angular/router';
import { StreamHistory } from '../../model/stream-history';
import { ConfirmService } from '../../../shared/components/confirm/confirm.service';
import { LoggerService } from '../../../shared/services/logger.service';
import { NotificationService } from '../../../shared/services/notification.service';
import { AppError } from '../../../shared/model/error.model';

/**
 * Component that shows the history (versions) of a Stream Definition deployment. You can also perform a
 * rollback to a version of the stream (`stream rollback ...`).
 *
 * @author Damien Vitrac
 */
@Component({
  selector: 'app-stream-history',
  templateUrl: 'stream-history.component.html',
  styleUrls: ['../styles.scss'],
})
export class StreamHistoryComponent implements OnInit {

  /**
   * Observable of stream information
   * Contains the stream definition, a list of the streams"s apps
   */
  stream$: Observable<any>;

  /**
   * Constructor
   *
   * @param route
   * @param router
   * @param confirmService
   * @param loggerService
   * @param notificationService
   * @param streamsService
   */
  constructor(private route: ActivatedRoute,
              private router: Router,
              private confirmService: ConfirmService,
              private loggerService: LoggerService,
              private notificationService: NotificationService,
              private streamsService: StreamsService) {
  }

  /**
   * On Init
   */
  ngOnInit() {
    this.refresh();
  }

  /**
   * Load the stream history
   */
  refresh() {
    this.stream$ = this.route.parent.params
      .pipe(
        mergeMap(val => this.streamsService.getDefinition(val.id)),
        mergeMap(
          (streamDefinition: StreamDefinition) => this.streamsService.getHistory(streamDefinition.name)
            .pipe(map((streamHistory: StreamHistory[]) => {
              return {
                stream: streamDefinition,
                history: streamHistory
              };
            }))
        )
      );
  }

  /**
   * Rollback Action
   * Ask a validation to the user (confirm) before performing a rollback.
   * @param streamHistory
   */
  rollback(streamHistory: StreamHistory) {
    const title = `Confirm stream rollback`;
    const description = `This action will rollback the  ` +
      `<strong>stream ${streamHistory.stream} to the version ${streamHistory.version}</strong>. Are you sure?`;
    this.confirmService.open(title, description, { confirm: 'Rollback' }).subscribe(() => {
      this.loggerService.log('Rollback to ' + streamHistory);
      this.streamsService.historyRollback(streamHistory)
        .subscribe(data => {
            this.notificationService.success('Successful stream rollback to version "' + streamHistory.version + '"');
            this.refresh();
          }, error => {
            this.notificationService.error(AppError.is(error) ? error.getMessage() : error);
          }
        );
    });
  }

  /**
   * Determine if the rollback action is allowed
   * @param stream
   * @param history
   */
  canRollback(stream: StreamDefinition, history: StreamHistory): boolean {
    return stream.status.toLocaleLowerCase() === 'deployed' && history.statusCode.toLocaleLowerCase() !== 'deployed';
  }

}
<div dataflowLayoutType type="full" *ngIf="stream$ | async as stream; else loading">

  <div class="list-bar" *ngIf="stream.history.length > 0">
    <button name="refresh" class="btn btn-default btn-fa" (click)="refresh()" title="Refresh" type="button">
      <span class="fa fa-refresh"></span>
      Refresh
    </button>
  </div>

  <table class="table table-actions table-hover" id="table-history" *ngIf="stream.history.length > 0">
    <thead>
    <tr>
      <th>Version</th>
      <th>Date</th>
      <th>Stream Status</th>
      <th>Description</th>
      <th>platformName</th>
      <th [dataflowAppRoles]="['ROLE_MODIFY']">&nbsp;</th>
    </tr>
    </thead>
    <tbody>
    <tr *ngFor="let history of stream.history;let i=index" class="align-middle">
      <td>
        <strong>{{ history.version }}</strong>
      </td>
      <td>{{ history.firstDeployed | date: 'short'}}</td>
      <td>
        <app-stream-history-status [status]="history.statusCode"></app-stream-history-status>
      </td>
      <td>{{ history.description}}</td>
      <td>{{ history.platformName}}</td>
      <td class="table-actions" width="10px" nowrap="" [dataflowAppRoles]="['ROLE_MODIFY']">
        <div class="actions">
          <button name="stream_rollback{{ i }}" type="button" (click)="rollback(history)"
                  class="btn btn-default" [disabled]="!canRollback(stream.stream, history)"
                  style="padding: 0 8px;" title="Rollback">
            <span class="fa fa-undo"></span>
          </button>
        </div>
      </td>
    </tr>
    </tbody>
  </table>

  <div id="empty" *ngIf="stream.history.length == 0" class="dataflow-alert">
    <p>There is <strong>no history</strong>.</p>
    <p>
      You can <a (click)="refresh()">Refresh</a> the page.
    </p>
  </div>

</div>
<ng-template #loading>
  <app-loader></app-loader>
</ng-template>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""