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, Input } from '@angular/core';
17 import { RuleModel } from '../correlation-ruleList/alarmRule';
18 import { ActivatedRoute, Params, Router } from '@angular/router';
19 import { AlarmRuleService } from '../correlation-ruleList/alarmRule.service';
20 import { Http, Response, Headers } from '@angular/http';
21 import { ModalService } from '../correlation-modal/modal.service';
22 import { NgModel } from '@angular/forms';
26 templateUrl: './ruleInfo.component.html'
28 export class RuleInfo implements OnInit {
32 addBottonStatus: boolean;
33 constructor(private modalService: ModalService, private route: ActivatedRoute, private router: Router, private alarmRuleService: AlarmRuleService, http: Http) { };
36 this.queryRule.enabled = $('input:radio:checked').val();
37 if (!this.queryRule.content.startsWith('package ')) {
38 let msg = { title: 'exception_content_error', message: 'exception_package_error' };
39 this.modalService.getmodalObservable.next(msg);
41 this.alarmRuleService.checkContent(this.queryRule.content)
43 if (res.status == 200) {
44 this.alarmRuleService.updateRule(this.queryRule)
46 if (res.status == 200) {
47 let msg = { title: 'modalTitleUpdate', message: 'message_update_rule_success' };
48 this.modalService.getmodalObservable.next(msg);
49 this.router.navigate(['alarmRule']);
50 } else if (res.status == 499) {
51 let msg = { title: 'modalTitleUpdate', message: 'message_exception_rule_fail' };
52 this.modalService.getmodalObservable.next(msg);
54 let msg = { title: 'modalTitleUpdate', message: 'message_other_exception_rule_fail' };
55 this.modalService.getmodalObservable.next(msg);
59 let msg = { title: 'modalTitleUpdate', message: 'message_other_exception_rule_fail' };
60 this.modalService.getmodalObservable.next(msg);
64 } else if (res.status == 499) {
65 let msg = { 'title': 'modalTitleCheck', message: 'message_rule_content_repeat_error' };
66 this.modalService.getmodalObservable.next(msg);
69 let msg = { 'title': 'modalTitleCheck', message: 'message_other_exception_rule_fail' };
70 this.modalService.getmodalObservable.next(msg);
77 onSubmit(obj: NgModel) {
82 if (!this.queryRule.content.startsWith('package ')) {
83 let msg = { title: 'exception_content_error', message: 'exception_package_error' };
84 this.modalService.getmodalObservable.next(msg);
86 this.alarmRuleService.checkContent(this.queryRule.content).then(res => {
87 if (res.status == 200) {
88 this.alarmRuleService.save(this.queryRule).then(res => {
89 if (res.status == 200) {
90 let msg = { title: 'modalTitleDefault', message: 'message_add_rule_success' };
91 this.modalService.getmodalObservable.next(msg);
92 this.router.navigate(['alarmRule']);
93 } else if (res.status == 499) {
94 let msg = { title: 'modalTitleDefault', message: 'message_rule_name_repeat_error' };
95 this.modalService.getmodalObservable.next(msg);
97 let msg = { 'title': 'modalTitleCheck', message: 'message_other_exception_rule_fail' };
98 this.modalService.getmodalObservable.next(msg);
102 let msg = { title: 'modalTitleDefault', message: 'message_rule_name_repeat_error' };
103 this.modalService.getmodalObservable.next(msg);
106 } else if (res.status == 499) {
107 let msg = { 'title': 'modalTitleCheck', message: 'message_rule_content_repeat_error' };
108 this.modalService.getmodalObservable.next(msg);
111 let msg = { 'title': 'modalTitleCheck', message: 'message_other_exception_rule_fail' };
112 this.modalService.getmodalObservable.next(msg);
119 getRuleInfo(id: string): void {
120 this.route.params.switchMap((params: Params) => this.alarmRuleService.search(id))
122 rule[0].enabled = '' + rule[0].enabled;
123 this.queryRule = rule[0]
127 checkContent(judge: string): void {
128 if (!this.queryRule.content.startsWith('package ')) {
129 let msg = { title: 'exception_content_error', message: 'exception_package_error' };
130 this.modalService.getmodalObservable.next(msg);
132 this.alarmRuleService.checkContent(this.queryRule.content)
134 if (res.status == 200) {
135 let msg = { 'title': 'modalTitleCheck', message: 'message_checkContent_rule_success' };
136 this.modalService.getmodalObservable.next(msg);
137 } else if (res.status == 499) {
138 let msg = { 'title': 'modalTitleCheck', message: 'message_rule_content_repeat_error' };
139 this.modalService.getmodalObservable.next(msg);
142 let msg = { 'title': 'modalTitleCheck', message: 'message_other_exception_rule_fail' };
143 this.modalService.getmodalObservable.next(msg);
150 // alert(this.queryRule.enabled);
151 this.queryRule.enabled == '0' ? this.queryRule.enabled = '1' : this.queryRule.enabled = '0';
155 initUpload(queryRule: RuleModel): void {
156 $('#fileName').text('');
157 $('#importFailTip').addClass('hide_panel');
158 $('#fileupload').fileupload({
160 dropZone: $('#dropzone'),
162 maxChunkSize: 20000000,
164 add: function (e, data) {
165 let fileName = data.files[0].name;
167 $('#importFailTip').addClass('hide_panel');
168 let suffix = fileName.substring(fileName.lastIndexOf('.'), fileName.length)
170 if (suffix != '.txt') {
171 $('#importFailTip').removeClass('hide_panel');
175 $('#bar').css('width', '0%');
176 $('#persent').text('0%');
177 $('#fileName').text(fileName);
178 $('#fileremove').attr('disabled', false);
179 $('#filesubmit').attr('disabled', false);
180 $('#filesubmit').click(function () {
181 this.file = data.files[0]
182 var reader = new FileReader();
183 reader.readAsText(this.file);
184 reader.onload = function (data) {
185 queryRule.content = this.result;
187 $('#fileremove').click();
188 $('#importDiv').hide();
192 $('#fileremove').click(function () {
193 $('#bar').css('width', '0%');
194 $('#persent').text('0%');
195 $('#fileName').text('');
196 $('#filesubmit').attr('disabled', true);
197 $('#fileremove').attr('disabled', true);
200 done: function (e, data) {
203 fail: function (e, resp) {
205 always: function (e, data) {
206 $('.progress').removeClass('active');
207 $('#bar').css('width', '100%');
208 $('#persent').text('100%');
210 progressall: function (e, data) {
215 initImportDiv(queryRule: RuleModel): void {
216 this.initUpload(queryRule);
217 let importDiv = $('#importDiv');
219 $('#importBtn').click(function (e) {
221 $('[data-toggle="tooltip"]').tooltip();
222 $('#importFailTip').addClass('hide_panel');
224 $(document).one('click', function (e) {
229 $(importDiv).click(function (e) {
232 $('#filesubmit').attr('disabled', true);
233 $('#fileremove').attr('disabled', true);
236 $('#bar').css('width', '0%');
237 $('#persent').text('0%');
238 $(importDiv).fadeIn();
252 loopControlName: null
267 this.route.params.subscribe((params) => {
269 let id = params['id'];
270 if (typeof (id) == 'string') {
271 if (id.indexOf('&') == -1) {
272 $('#ruleNameInput').attr('disabled', true);
273 $('#saveLabel').hide();
275 this.addBottonStatus = false;
276 $('#saveLabel').hide();
277 $('#checkLabel').hide();
278 $('#updateLabel').hide();
281 let str = id.split('&');
282 this.getRuleInfo(str[0]);
283 } else if (typeof (id) != 'undefined') {
284 this.getRuleInfo(id);
286 $('#updateLabel').hide();
288 if (typeof (this.queryRule.enabled) === 'number') {
289 this.queryRule.enabled = '' + this.queryRule.enabled;
293 this.initImportDiv(this.queryRule);