2 Copyright 2018 ZTE Corporation.
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
16 import {Component, OnInit} from '@angular/core';
17 import {ModalService} from '../correlation-modal/modal.service';
18 import {RuleModel} from './alarmRule';
19 import {RuleRequest} from './ruleRequest';
20 import {Router} from '@angular/router';
21 import {AlarmRuleService} from './alarmRule.service';
24 selector: 'alarmRule',
25 templateUrl: './alarmRule.component.html',
26 styleUrls: ['./alarmRule.component.css']
28 export class AlarmRule implements OnInit {
34 enable_on = "enabled";
35 enable_off = "disabled"
36 totalcount: number = 0;
38 ruleRequest: RuleRequest;
41 activeStatus = ["option_all", "common_enabled", "common_disabled"];
43 constructor(public _alarmRuleService: AlarmRuleService, private modalService: ModalService,
44 private router: Router) {
47 switch(select: string): void {
49 if (select == "common_enabled") {
50 this.ruleModel.enabled = 1;
51 } else if (select == "common_disabled") {
52 this.ruleModel.enabled = 0;
55 this.ruleModel.enabled = null;
60 setActiveText(): void {
61 if (this.ruleModel.enabled == 1) {
62 this.activeText = "common_enabled";
63 this.ruleRequest.enabled = 1;
65 else if (this.ruleModel.enabled == 0) {
66 this.activeText = "common_disabled";
67 this.ruleRequest.enabled = 0;
69 this.activeText = "option_all";
70 this.ruleRequest.enabled = null;
75 this._alarmRuleService.getRules().then(rules => {
76 this.rules = rules.correlationRules;
77 this.rules.map(x => x['showModal'] = false);
78 console.log(this.rules);
79 this.totalcount = rules.totalCount;
83 public searchRules(): void {
84 if (this.ruleModel.enabled == null) {
85 this.ruleRequest.enabled = null;
87 this.ruleRequest.ruleName = this.ruleModel.ruleName;
88 console.log(this.ruleRequest.enabled, this.ruleRequest.ruleName);
90 this._alarmRuleService
91 .searchrules(this.ruleRequest)
94 this.totalcount = rules.length;
98 public updateRule(rule: RuleModel): void {
99 this.router.navigate(['ruleInfo/', rule.ruleId]);
102 public delete(rule: any): void {
103 rule.showModal = true;
106 public on_off(rule: RuleModel) {
107 rule.enabled == 0 ? rule.enabled = 1 : rule.enabled = 0;
108 this._alarmRuleService
115 public reset(): void {
116 this.ruleModel.ruleName = null;
117 this.activeText = 'option_all';
118 this.ruleModel.enabled = null;
122 deleteRule(ruleId: string): void {
123 this._alarmRuleService.delete(ruleId).then(() => {
124 this.cancelModal(ruleId);
127 this.cancelModal(ruleId);
131 cancelModal(ruleId: string): void {
132 this.rules.find(x => x.ruleId === ruleId).showModal = false;
135 public ngOnInit(): void {
136 this.activeText = 'option_all';