src/app/streams/streams-undeploy/streams-undeploy.component.ts
selector | app-streams-undeploy |
templateUrl | ./streams-undeploy.component.html |
Properties |
|
Methods |
constructor(modalRef: BsModalRef, streamsService: StreamsService, loggerService: LoggerService, blockerService: BlockerService, notificationService: NotificationService)
|
||||||||||||||||||||||||
Initialize component
Parameters :
|
ngOnDestroy |
ngOnDestroy()
|
On Destroy operations
Returns :
void
|
open | ||||||||
open(args: literal type)
|
||||||||
Parameters :
Returns :
Observable<any>
|
undeploy |
undeploy()
|
Submit undeploy stream(s)
Returns :
void
|
confirm |
confirm:
|
Type : EventEmitter<string>
|
Emit after undeploy success |
Private ngUnsubscribe$ |
ngUnsubscribe$:
|
Type : Subject<any>
|
Unsubscribe |
streamDefinitions |
streamDefinitions:
|
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-streams-undeploy',
templateUrl: './streams-undeploy.component.html'
})
export class StreamsUndeployComponent 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);
}
open(args: { streamDefinitions: StreamDefinition[] }): Observable<any> {
this.streamDefinitions = args.streamDefinitions;
return this.confirm;
}
/**
* Submit undeploy stream(s)
*/
undeploy() {
this.loggerService.log(`Proceeding to undeploy ${this.streamDefinitions.length} stream definition(s).`, this.streamDefinitions);
this.blockerService.lock();
this.streamsService
.undeployMultipleStreamDefinitions(this.streamDefinitions)
.pipe(takeUntil(this.ngUnsubscribe$), finalize(() => this.blockerService.unlock()))
.subscribe((data) => {
this.notificationService.success(`${data.length} stream definition(s) undeploy.`);
this.confirm.emit('done');
this.cancel();
}, () => {
this.notificationService.error('An error occurred while undeploying 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 Undeploy Stream Definition(s)</h4>
<button type="button" class="close pull-right" aria-label="Close" (click)="cancel()">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body" *ngIf="streamDefinitions.length == 1">
<p>This action will undeploy the stream <strong>{{ streamDefinitions[0].name }}</strong>. Are you sure?</p>
</div>
<div class="modal-body" *ngIf="streamDefinitions.length > 1">
<p>
This action will undeploy 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-undeploy" type="button" class="btn btn-primary" (click)="undeploy()">
Undeploy Stream Definition(s)
</button>
</div>
</div>