-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathalert-complete.component.ts
More file actions
85 lines (80 loc) · 3.36 KB
/
Copy pathalert-complete.component.ts
File metadata and controls
85 lines (80 loc) · 3.36 KB
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
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {NgbActiveModal, NgbModal} from '@ng-bootstrap/ng-bootstrap';
import {UtmToastService} from '../../../../../shared/alert/utm-toast.service';
import {FALSE_POSITIVE_OBJECT} from '../../../../../shared/constants/alert/alert-field.constant';
import {CLOSED, IGNORED} from '../../../../../shared/constants/alert/alert-status.constant';
import {AlertTags} from '../../../../../shared/types/alert/alert-tag.type';
import {AlertRuleType} from '../../../alert-rules/alert-rule.type';
import {AlertUpdateTagBehavior} from '../../behavior/alert-update-tag.behavior';
import {AlertManagementService} from '../../services/alert-management.service';
import {AlertRulesService} from '../../services/alert-rules.service';
import {AlertRuleCreateComponent} from '../alert-rule-create/alert-rule-create.component';
@Component({
selector: 'app-alert-complete',
templateUrl: './alert-complete.component.html',
styleUrls: ['./alert-complete.component.scss']
})
export class AlertCompleteComponent implements OnInit {
@Input() alertsIDs: string[] = [];
@Input() status: number;
@Input() alert: any;
@Input() canCreateRule = true;
@Input() asFalsePositive = false;
CLOSED = CLOSED;
IGNORED = IGNORED;
@Output() statusChange: EventEmitter<string> = new EventEmitter();
@Output() statusClose: EventEmitter<string> = new EventEmitter();
observations: string;
creating: boolean;
rule: AlertRuleType;
constructor(public activeModal: NgbActiveModal,
public modalService: NgbModal,
private alertRulesService: AlertRulesService,
private utmToastService: UtmToastService,
private alertUpdateTagBehavior: AlertUpdateTagBehavior,
private alertServiceManagement: AlertManagementService) {
}
ngOnInit() {
this.observations = '';
}
changeStatus() {
this.creating = true;
this.alertServiceManagement.updateAlertStatus(this.alertsIDs,
this.status, this.observations, this.asFalsePositive).subscribe(al => {
if (this.canCreateRule && this.rule) {
this.alertRulesService.create(this.rule).subscribe(value => {
this.utmToastService.showSuccessBottom('Rule ' + this.rule.name + ' created successfully');
this.alertServiceManagement.updateAlertTags(this.alertsIDs, this.rule.tags.map(value1 => value1.tagName), true)
.subscribe(tagsResponse => {
this.alertUpdateTagBehavior.$tagRefresh.next(true);
this.utmToastService.showSuccessBottom('Tags added successfully');
});
});
}
this.statusChange.emit('success');
this.activeModal.close();
this.creating = false;
},_err=>{
this.creating = false;
this.statusChange.emit('failed');
});
}
createRule() {
const modal = this.modalService.open(AlertRuleCreateComponent, {
centered: true,
size: 'lg',
windowClass: 'alert-rule-modal'
});
const falsePositive: AlertTags[] = [FALSE_POSITIVE_OBJECT];
if (this.rule) {
modal.componentInstance.rule = this.rule;
}
modal.componentInstance.alert = this.alert;
modal.componentInstance.action = 'select';
modal.componentInstance.isForComplete = true;
modal.componentInstance.tags = falsePositive;
modal.componentInstance.ruleAdd.subscribe(rule => {
this.rule = rule;
});
}
}