File

src/app/streams/streams-destroy/streams-destroy.component.ts

Extends

Modal

Implements

OnDestroy

Metadata

selector app-stream-destroy
templateUrl ./streams-destroy.component.html

Index

Properties
Methods

Constructor

constructor(modalRef: BsModalRef, streamsService: StreamsService, loggerService: LoggerService, blockerService: BlockerService, notificationService: NotificationService)

Initialize component

Parameters :
Name Type Optional Description
modalRef BsModalRef

used to control the current modal

streamsService StreamsService
loggerService LoggerService
blockerService BlockerService
notificationService NotificationService

Methods

destroy
destroy()

Submit destroy stream(s)

Returns : void
ngOnDestroy
ngOnDestroy()

On Destroy operations

Returns : void
open
open(args: literal type)

Initialize

Parameters :
Name Type Optional Description
args literal type
Returns : Observable<any>

Properties

confirm
confirm: EventEmitter<string>
Type : EventEmitter<string>

Emit after undeploy success

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

Unsubscribe

streamDefinitions
streamDefinitions: StreamDefinition[]
Type : StreamDefinition[]

Stream Definitions

import { Component, EventEmitter, OnDestroy } from '@angular/core';
import { BsModalRef } from 'ngx-bootstrap';
import { StreamDefinition } from '../model/stream-definition';
import { StreamsService } from '../streams.service';
import { Modal } from '../../shared/components/modal/modal-abstract';
import { Observable, Subject } from 'rxjs';
import { finalize, takeUntil } from 'rxjs/operators';
import { NotificationService } from '../../shared/services/notification.service';
import { LoggerService } from '../../shared/services/logger.service';
import { BlockerService } from '../../shared/components/blocker/blocker.service';

@Component({
  selector: 'app-stream-destroy',
  templateUrl: './streams-destroy.component.html'
})
export class StreamsDestroyComponent extends Modal implements OnDestroy {

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

  /**
   * Stream Definitions
   */
  streamDefinitions: StreamDefinition[];

  /**
   * Emit after undeploy success
   */
  confirm: EventEmitter<string> = new EventEmitter();

  /**
   * Initialize component
   *
   * @param {BsModalRef} modalRef used to control the current modal
   * @param {StreamsService} streamsService
   * @param {BlockerService} blockerService
   * @param {NotificationService} notificationService
   * @param {LoggerService} loggerService
   */
  constructor(private modalRef: BsModalRef,
              private streamsService: StreamsService,
              private loggerService: LoggerService,
              private blockerService: BlockerService,
              private notificationService: NotificationService) {
    super(modalRef);
  }

  /**
   * Initialize
   */
  open(args: { streamDefinitions: StreamDefinition[] }): Observable<any> {
    this.streamDefinitions = args.streamDefinitions;
    return this.confirm;
  }

  /**
   * Submit destroy stream(s)
   */
  destroy() {
    this.loggerService.log(`Proceeding to destroy ${this.streamDefinitions.length} stream definition(s).`, this.streamDefinitions);
    this.blockerService.lock();
    this.streamsService.destroyMultipleStreamDefinitions(this.streamDefinitions)
      .pipe(takeUntil(this.ngUnsubscribe$), finalize(() => this.blockerService.unlock()))
      .subscribe((data) => {
        let successMessgage: string;
        if (data.length > 1) {
          successMessgage = `${data.length} stream definitions were destroyed.`;
        } else {
          successMessgage = `${data.length} stream definition was destroyed.`;
        }

        this.notificationService.success(successMessgage);
        this.confirm.emit('done');
        this.cancel();
      }, () => {
        this.notificationService.error('An error occurred while bulk deleting Streams. ' +
          'Please check the server logs for more details.');
        this.confirm.emit('done');
        this.cancel();
      });
  }

  /**
   * On Destroy operations
   */
  ngOnDestroy() {
    this.ngUnsubscribe$.next();
    this.ngUnsubscribe$.complete();
  }

}
<div *ngIf="streamDefinitions">
  <div class="modal-header">
    <h4 class="modal-title pull-left">Confirm Destroy Stream Definitions</h4>
    <button type="button" class="close pull-right" aria-label="Close" (click)="cancel()">
      <span aria-hidden="true">&times;</span>
    </button>
  </div>
  <div class="modal-body" *ngIf="streamDefinitions.length == 1">
    <p>This action will destroy and delete the stream <strong>{{ streamDefinitions[0].name }}</strong>.
      Are you sure?</p>
  </div>
  <div class="modal-body" *ngIf="streamDefinitions.length > 1">
    <p>
      This action will destroy the <strong>{{ streamDefinitions.length }} stream definitions</strong> listed below.
      Are you sure?
    </p>
    <br/>
    <table id="table-streams" class="table table-striped">
      <thead>
      <tr>
        <th>Name</th>
        <th>Definition</th>
      </tr>
      </thead>
      <tbody>
      <tr *ngFor="let item of streamDefinitions">
        <td>{{ item.name }}</td>
        <td>
          <app-stream-dsl>{{ item.dslText | truncate: 95 }}</app-stream-dsl>
        </td>
      </tr>
      </tbody>
    </table>
  </div>
  <div class="modal-footer" style="text-align:center">
    <button id="btn-cancel" type="button" class="btn btn-default" (click)="cancel()">No</button>
    <button id="btn-destroy" type="button" class="btn btn-primary" (click)="destroy(streamDefinitions)">
      Destroy Stream Definition(s)
    </button>
  </div>
</div>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""