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, ElementRef } 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';
22 import { Observable } from 'rxjs';
25 selector: 'alarmRule',
26 templateUrl: './alarmRule.component.html',
27 styleUrls: ['./alarmRule.component.css']
29 export class AlarmRule implements OnInit {
35 enable_on = "enabled";
36 enable_off = "disabled"
37 totalcount: number = 0;
39 ruleRequest: RuleRequest;
42 activeStatus = ["option_all", "common_enabled", "common_disabled"];
44 constructor(public _alarmRuleService: AlarmRuleService, private modalService: ModalService,
45 private router: Router, private ele: ElementRef) {
48 switch(select: string): void {
50 if (select == "common_enabled") {
51 this.ruleModel.enabled = 1;
52 } else if (select == "common_disabled") {
53 this.ruleModel.enabled = 0;
56 this.ruleModel.enabled = null;
61 setActiveText(): void {
62 if (this.ruleModel.enabled == 1) {
63 this.activeText = "common_enabled";
64 this.ruleRequest.enabled = 1;
66 else if (this.ruleModel.enabled == 0) {
67 this.activeText = "common_disabled";
68 this.ruleRequest.enabled = 0;
70 this.activeText = "option_all";
71 this.ruleRequest.enabled = 2;
76 this._alarmRuleService.getRules().then(rules => {
77 this.rules = rules.correlationRules;
78 this.rules.map(x => x['showModal'] = false);
79 console.log(this.rules);
80 this.totalcount = rules.totalCount;
84 public searchRules(): void {
85 if (this.ruleModel.enabled == null) {
86 this.ruleRequest.enabled = null;
88 this.ruleRequest.ruleName = this.ruleModel.ruleName;
89 console.log(this.ruleRequest.enabled, this.ruleRequest.ruleName);
91 this._alarmRuleService
92 .searchrules(this.ruleRequest)
95 this.totalcount = rules.length;
99 public updateRule(rule: RuleModel): void {
100 this.router.navigate(['ruleInfo/', rule.ruleId]);
103 public delete(rule: any): void {
104 rule.showModal = true;
107 public on_off(rule: RuleModel) {
108 rule.enabled == 0 ? rule.enabled = 1 : rule.enabled = 0;
109 this._alarmRuleService
116 public reset(): void {
117 this.ruleModel.ruleName = null;
118 this.activeText = 'option_all';
119 this.ruleModel.enabled = null;
123 deleteRule(ruleId: string): void {
124 this._alarmRuleService.delete(ruleId).then(() => {
125 this.cancelModal(ruleId);
128 this.cancelModal(ruleId);
132 cancelModal(ruleId: string): void {
133 this.rules.find(x => x.ruleId === ruleId).showModal = false;
136 public ngOnInit(): void {
137 this.activeText = 'option_all';
160 this.ele.nativeElement.querySelector('.container-fluid').style.height = window.innerHeight + 'px';
161 Observable.fromEvent(window, 'resize')
164 this.ele.nativeElement.querySelector('.container-fluid').style.height = window.innerHeight + 'px';