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';
23 declare var jQuery: any;
26 selector: 'alarmRule',
27 templateUrl: './alarmRule.component.html',
28 styleUrls: ['./alarmRule.component.css']
30 export class AlarmRule implements OnInit {
36 enable_on = "enabled";
37 enable_off = "disabled"
38 totalcount: number = 0;
40 ruleRequest: RuleRequest;
43 activeStatus = ["option_all", "common_enabled", "common_disabled"];
45 constructor(public _alarmRuleService: AlarmRuleService, private modalService: ModalService,
46 private router: Router) {
49 switch(select: string): void {
51 if (select == "common_enabled") {
52 this.ruleModel.enabled = 1;
53 } else if (select == "common_disabled") {
54 this.ruleModel.enabled = 0;
57 this.ruleModel.enabled = null;
62 setActiveText(): void {
63 if (this.ruleModel.enabled == 1) {
64 this.activeText = "common_enabled";
65 this.ruleRequest.enabled = 1;
67 else if (this.ruleModel.enabled == 0) {
68 this.activeText = "common_disabled";
69 this.ruleRequest.enabled = 0;
71 this.activeText = "option_all";
72 this.ruleRequest.enabled = null;
77 this._alarmRuleService.getRules().then(rules => {
78 this.rules = rules.correlationRules;
79 this.rules.map(x => x['showModal'] = false);
80 console.log(this.rules);
81 this.totalcount = rules.totalCount;
85 public searchRules(): void {
86 if (this.ruleModel.enabled == null) {
87 this.ruleRequest.enabled = null;
89 this.ruleRequest.ruleName = this.ruleModel.ruleName;
90 console.log(this.ruleRequest.enabled, this.ruleRequest.ruleName);
92 this._alarmRuleService
93 .searchrules(this.ruleRequest)
96 this.totalcount = rules.length;
100 public updateRule(rule: RuleModel): void {
101 this.router.navigate(['ruleInfo/', rule.ruleId]);
104 public delete(rule: any): void {
105 rule.showModal = true;
108 public on_off(rule: RuleModel) {
109 rule.enabled == 0 ? rule.enabled = 1 : rule.enabled = 0;
110 this._alarmRuleService
117 public reset(): void {
118 this.ruleModel.ruleName = null;
119 this.activeText = 'option_all';
120 this.ruleModel.enabled = null;
124 deleteRule(ruleId: string): void {
125 this._alarmRuleService.delete(ruleId).then(() => {
126 this.cancelModal(ruleId);
129 this.cancelModal(ruleId);
133 cancelModal(ruleId: string): void {
134 this.rules.find(x => x.ruleId === ruleId).showModal = false;
137 public ngOnInit(): void {
138 this.activeText = 'option_all';