2 Copyright 2017 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, ViewChild, ViewEncapsulation } 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 { Http, Response, Jsonp, Headers, RequestOptions } from '@angular/http';
22 import { AlarmRuleService } from './alarmRule.service';
23 declare var jQuery: any;
26 selector: 'alarmRule',
27 templateUrl: './alarmRule.component.html',
30 export class AlarmRule implements OnInit {
36 enable_on = "enabled";
37 enable_off = "disabled"
40 ruleRequest: RuleRequest;
43 activeStatus = ["option_all", "common_enabled", "common_disabled"];
45 constructor(public _alarmRuleService: AlarmRuleService, private modalService: ModalService,
46 private router: Router) { };
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 = null;
75 getRules(): Promise<any> {
76 return this._alarmRuleService
79 this.rules = rules.rules;
80 this.totalcount = rules.totalcount;
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;
98 updateRule(rule: RuleModel): void {
99 this.router.navigate(['ruleInfo/', rule.ruleId]);
102 delete(rule: RuleModel): void {
103 rule.enabled == 1 ? this.deleteActiveRule(rule) : this.deleteModel(rule.ruleId, this._alarmRuleService, this);
106 on_off(rule: RuleModel) {
107 rule.enabled == 0 ? rule.enabled = 1 : rule.enabled = 0;
108 this._alarmRuleService
116 this.ruleModel.ruleName = null;
117 this.activeText = 'option_all';
118 this.ruleModel.enabled = null;
122 deleteActiveRule(rule: RuleModel): void {
123 jQuery('#' + rule.ruleId).popModal({
124 html: jQuery('#deleteActiveRuleContent'),
125 placement: 'leftTop',
127 onDocumentClickClose: true,
128 onOkBut: function () {
132 deleteModel(ruleId: string, alarm: AlarmRuleService, obj: any): void {
133 jQuery('#' + ruleId).popModal({
134 html: jQuery('#deleteTimingTaskContent'),
135 placement: 'leftTop',
137 onDocumentClickClose: true,
138 onOkBut: function () {
139 jQuery('#deleteTimingTaskDlg').append(jQuery('#deleteTimingTaskContent'));
140 alarm.delete(ruleId);
143 onCancelBut: function () {
149 this.activeText = 'option_all';