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, 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);
42 this.alarmRuleService.checkContent(this.queryRule.content)
44 if (res.status == 200) {
45 this.alarmRuleService.updateRule(this.queryRule)
47 if (res.status == 200) {
48 let msg = { title: 'modalTitleUpdate', message: 'message_update_rule_success' };
49 this.modalService.getmodalObservable.next(msg);
50 this.router.navigate(['alarmRule']);
51 } else if (res.status == 499) {
52 let msg = { title: 'modalTitleUpdate', message: 'message_exception_rule_fail' };
53 this.modalService.getmodalObservable.next(msg);
55 let msg = { title: 'modalTitleUpdate', message: 'message_other_exception_rule_fail' };
56 this.modalService.getmodalObservable.next(msg);
60 let msg = { title: 'modalTitleUpdate', message: 'message_other_exception_rule_fail' };
61 this.modalService.getmodalObservable.next(msg);
65 } else if (res.status == 499) {
66 let msg = { 'title': 'modalTitleCheck', message: 'message_rule_content_repeat_error' };
67 this.modalService.getmodalObservable.next(msg);
70 let msg = { 'title': 'modalTitleCheck', message: 'message_other_exception_rule_fail' };
71 this.modalService.getmodalObservable.next(msg);
78 onSubmit(obj: NgModel) {
83 if (!this.queryRule.content.startsWith('package ')) {
84 let msg = { title: 'exception_content_error', message: 'exception_package_error' };
85 this.modalService.getmodalObservable.next(msg);
87 this.alarmRuleService.checkContent(this.queryRule.content).then(res => {
88 if (res.status == 200) {
89 this.alarmRuleService.save(this.queryRule).then(res => {
90 if (res.status == 200) {
91 let msg = { title: 'modalTitleDefault', message: 'message_add_rule_success' };
92 this.modalService.getmodalObservable.next(msg);
93 this.router.navigate(['alarmRule']);
94 } else if (res.status == 499) {
95 let msg = { title: 'modalTitleDefault', message: 'message_rule_name_repeat_error' };
96 this.modalService.getmodalObservable.next(msg);
98 let msg = { 'title': 'modalTitleCheck', message: 'message_other_exception_rule_fail' };
99 this.modalService.getmodalObservable.next(msg);
103 let msg = { title: 'modalTitleDefault', message: 'message_rule_name_repeat_error' };
104 this.modalService.getmodalObservable.next(msg);
107 } else if (res.status == 499) {
108 let msg = { 'title': 'modalTitleCheck', message: 'message_rule_content_repeat_error' };
109 this.modalService.getmodalObservable.next(msg);
112 let msg = { 'title': 'modalTitleCheck', message: 'message_other_exception_rule_fail' };
113 this.modalService.getmodalObservable.next(msg);
120 getRuleInfo(id: string): void {
121 this.route.params.switchMap((params: Params) => this.alarmRuleService.search(id))
123 rule[0].enabled = '' + rule[0].enabled;
124 this.queryRule = rule[0]
128 checkContent(judge: string): void {
129 if (!this.queryRule.content.startsWith('package ')) {
130 let msg = { title: 'exception_content_error', message: 'exception_package_error' };
131 this.modalService.getmodalObservable.next(msg);
133 this.alarmRuleService.checkContent(this.queryRule.content)
135 if (res.status == 200) {
136 let msg = { 'title': 'modalTitleCheck', message: 'message_checkContent_rule_success' };
137 this.modalService.getmodalObservable.next(msg);
138 } else if (res.status == 499) {
139 let msg = { 'title': 'modalTitleCheck', message: 'message_rule_content_repeat_error' };
140 this.modalService.getmodalObservable.next(msg);
143 let msg = { 'title': 'modalTitleCheck', message: 'message_other_exception_rule_fail' };
144 this.modalService.getmodalObservable.next(msg);
151 // alert(this.queryRule.enabled);
152 this.queryRule.enabled == '0' ? this.queryRule.enabled = '1' : this.queryRule.enabled = '0';
156 initUpload(queryRule: RuleModel): void {
157 $('#fileName').text('');
158 $('#importFailTip').addClass('hide_panel');
159 $('#fileupload').fileupload({
161 dropZone: $('#dropzone'),
163 maxChunkSize: 20000000,
165 add: function (e, data) {
166 let fileName = data.files[0].name;
168 $('#importFailTip').addClass('hide_panel');
169 let suffix = fileName.substring(fileName.lastIndexOf('.'), fileName.length)
171 if (suffix != '.txt') {
172 $('#importFailTip').removeClass('hide_panel');
176 $('#bar').css('width', '0%');
177 $('#persent').text('0%');
178 $('#fileName').text(fileName);
179 $('#fileremove').attr('disabled', false);
180 $('#filesubmit').attr('disabled', false);
181 $('#filesubmit').click(function () {
182 this.file = data.files[0]
183 var reader = new FileReader();
184 reader.readAsText(this.file);
185 reader.onload = function (data) {
186 queryRule.content = this.result;
188 $('#fileremove').click();
189 $('#importDiv').hide();
193 $('#fileremove').click(function () {
194 $('#bar').css('width', '0%');
195 $('#persent').text('0%');
196 $('#fileName').text('');
197 $('#filesubmit').attr('disabled', true);
198 $('#fileremove').attr('disabled', true);
201 done: function (e, data) {
204 fail: function (e, resp) {
206 always: function (e, data) {
207 $('.progress').removeClass('active');
208 $('#bar').css('width', '100%');
209 $('#persent').text('100%');
211 progressall: function (e, data) {
216 initImportDiv(queryRule: RuleModel): void {
217 this.initUpload(queryRule);
218 let importDiv = $('#importDiv');
220 $('#importBtn').click(function (e) {
222 $('[data-toggle="tooltip"]').tooltip();
223 $('#importFailTip').addClass('hide_panel');
225 $(document).one('click', function (e) {
230 $(importDiv).click(function (e) {
233 $('#filesubmit').attr('disabled', true);
234 $('#fileremove').attr('disabled', true);
237 $('#bar').css('width', '0%');
238 $('#persent').text('0%');
239 $(importDiv).fadeIn();
253 loopControlName: null
268 this.route.params.subscribe((params) => {
270 let id = params['id'];
271 if (typeof (id) == 'string') {
272 if (id.indexOf('&') == -1) {
273 $('#ruleNameInput').attr('disabled', true);
274 $('#saveLabel').hide();
276 this.addBottonStatus = false;
277 $('#saveLabel').hide();
278 $('#checkLabel').hide();
279 $('#updateLabel').hide();
282 let str = id.split('&');
283 this.getRuleInfo(str[0]);
284 } else if (typeof (id) != 'undefined') {
285 this.getRuleInfo(id);
287 $('#updateLabel').hide();
289 if (typeof (this.queryRule.enabled) === 'number') {
290 this.queryRule.enabled = '' + this.queryRule.enabled;
294 this.initImportDiv(this.queryRule);