-
Notifications
You must be signed in to change notification settings - Fork 118
/
streams-destroy.component.ts
95 lines (85 loc) · 2.94 KB
/
streams-destroy.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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 { 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$))
.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();
}, () => {
this.blockerService.unlock();
});
}
/**
* On Destroy operations
*/
ngOnDestroy() {
this.ngUnsubscribe$.next();
this.ngUnsubscribe$.complete();
}
}