From 9720e7d6a706d79f50778af6a39ce6fba79955ed Mon Sep 17 00:00:00 2001 From: GuangrongFu Date: Fri, 20 Jul 2018 09:26:29 +0800 Subject: Change the buiding tool to angular-cli Change-Id: Iacc77251238b9d8b2893dbbf311775f9fb7425d3 Issue-ID: HOLMES-111 Signed-off-by: GuangrongFu --- .../correlation-ruleList/alarmRule.component.html | 135 ++++++++++++++++ .../correlation-ruleList/alarmRule.component.ts | 172 +++++++++++++++++++++ .../app/correlation-ruleList/alarmRule.service.ts | 123 +++++++++++++++ .../src/app/correlation-ruleList/alarmRule.ts | 27 ++++ .../src/app/correlation-ruleList/ruleRequest.ts | 23 +++ 5 files changed, 480 insertions(+) create mode 100644 rulemgt-frontend/src/app/correlation-ruleList/alarmRule.component.html create mode 100644 rulemgt-frontend/src/app/correlation-ruleList/alarmRule.component.ts create mode 100644 rulemgt-frontend/src/app/correlation-ruleList/alarmRule.service.ts create mode 100644 rulemgt-frontend/src/app/correlation-ruleList/alarmRule.ts create mode 100644 rulemgt-frontend/src/app/correlation-ruleList/ruleRequest.ts (limited to 'rulemgt-frontend/src/app/correlation-ruleList') diff --git a/rulemgt-frontend/src/app/correlation-ruleList/alarmRule.component.html b/rulemgt-frontend/src/app/correlation-ruleList/alarmRule.component.html new file mode 100644 index 0000000..6e03db3 --- /dev/null +++ b/rulemgt-frontend/src/app/correlation-ruleList/alarmRule.component.html @@ -0,0 +1,135 @@ + +
+
+
+
+
+ + +
+ +
+ + +
+ +
+
+ + +
+
+
+ +
+
+
+ +
+
+
+
+ +
+
+
{{"common_total1"|translate}}{{totalcount}}{{"common_total2"|translate}}
+ + + + + + + + + + + + + + + + + + + + + + +
{{"field_rule_name_Add_Page"|translate}}{{"common_status"|translate}}{{"field_create_time"|translate}}{{"field_creator"|translate}}{{"field_update_time"|translate}}{{"common_operator"|translate}}
{{rule.rulename}}{{rule.createTime | date:'yyyy-MM-dd HH:mm:ss'}}{{rule.creator}}{{rule.updateTime | date:'yyyy-MM-dd HH:mm:ss'}} + + + + + + + + + + + + + + + + +
+
+ + + \ No newline at end of file diff --git a/rulemgt-frontend/src/app/correlation-ruleList/alarmRule.component.ts b/rulemgt-frontend/src/app/correlation-ruleList/alarmRule.component.ts new file mode 100644 index 0000000..65a5296 --- /dev/null +++ b/rulemgt-frontend/src/app/correlation-ruleList/alarmRule.component.ts @@ -0,0 +1,172 @@ +/* + Copyright 2017 ZTE Corporation. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ +import { Component, OnInit, ViewChild, ViewEncapsulation } from '@angular/core'; +import { ModalService } from '../correlation-modal/modal.service'; +import { RuleModel } from './alarmRule'; +import { RuleRequest } from './ruleRequest'; +import { Router } from '@angular/router'; +import { Http, Response, Jsonp, Headers, RequestOptions } from '@angular/http'; +import { AlarmRuleService } from './alarmRule.service'; +declare var jQuery: any; + +@Component({ + selector: 'alarmRule', + templateUrl: './alarmRule.component.html', + +}) +export class AlarmRule implements OnInit { + ruleModel: RuleModel; + rules: RuleModel[]; + queryRule: RuleModel; + activeText: string; + ruleName: string; + enable_on = "enabled"; + enable_off = "disabled" + totalcount: number; + model: any; + ruleRequest: RuleRequest; + solution = 'ANGULAR'; + selection = 'A' + activeStatus = ["option_all", "common_enabled", "common_disabled"]; + + constructor(public _alarmRuleService: AlarmRuleService, private modalService: ModalService, + private router: Router) { }; + + switch(select: string): void { + console.log(select); + if (select == "common_enabled") { + this.ruleModel.enabled = 1; + } else if (select == "common_disabled") { + this.ruleModel.enabled = 0; + } else { + + this.ruleModel.enabled = null; + } + this.setActiveText(); + }; + + setActiveText(): void { + if (this.ruleModel.enabled == 1) { + this.activeText = "common_enabled"; + this.ruleRequest.enabled = 1; + } + else if (this.ruleModel.enabled == 0) { + this.activeText = "common_disabled"; + this.ruleRequest.enabled = 0; + } else { + this.activeText = "option_all"; + this.ruleRequest.enabled = null; + } + }; + + getRules(): Promise { + return this._alarmRuleService + .getRules() + .then(rules => { + this.rules = rules.rules; + this.totalcount = rules.totalcount; + }); + } + + searchRules(): void { + if (this.ruleModel.enabled == null) { + this.ruleRequest.enabled = null; + } + this.ruleRequest.ruleName = this.ruleModel.ruleName; + console.log(this.ruleRequest.enabled, this.ruleRequest.ruleName); + + this._alarmRuleService + .searchrules(this.ruleRequest) + .then(rules => { + this.rules = rules; + this.totalcount = rules.length; + }); + } + updateRule(rule: RuleModel): void { + this.router.navigate(['ruleInfo/', rule.ruleId]); + } + + delete(rule: RuleModel): void { + rule.enabled == 1 ? this.deleteActiveRule(rule) : this.deleteModel(rule.ruleId, this._alarmRuleService, this); + } + + on_off(rule: RuleModel) { + rule.enabled == 0 ? rule.enabled = 1 : rule.enabled = 0; + this._alarmRuleService + .updateRule(rule) + .then(res => { + rule = res; + }); + } + + reset(): void { + this.ruleModel.ruleName = null; + this.activeText = 'option_all'; + this.ruleModel.enabled = null; + this.getRules(); + } + + deleteActiveRule(rule: RuleModel): void { + jQuery('#' + rule.ruleId).popModal({ + html: jQuery('#deleteActiveRuleContent'), + placement: 'leftTop', + showCloseBut: false, + onDocumentClickClose: true, + onOkBut: function () { + }, + }); + } + deleteModel(ruleId: string, alarm: AlarmRuleService, obj: any): void { + jQuery('#' + ruleId).popModal({ + html: jQuery('#deleteTimingTaskContent'), + placement: 'leftTop', + showCloseBut: false, + onDocumentClickClose: true, + onOkBut: function () { + jQuery('#deleteTimingTaskDlg').append(jQuery('#deleteTimingTaskContent')); + alarm.delete(ruleId); + obj.getRules(); + }, + onCancelBut: function () { + } + }); + } + + ngOnInit(): void { + this.activeText = 'option_all'; + this.ruleModel = { + ruleId: null, + ruleName: null, + description: '', + content: null, + createTime: null, + creator: null, + updateTime: null, + modifier: null, + enabled: 0, + loopControlName: '' + } + this.ruleRequest = { + ruleId: null, + ruleName: null, + creator: null, + modifier: null, + enabled: null, + loopControlName: '' + } + this.getRules(); + } +} diff --git a/rulemgt-frontend/src/app/correlation-ruleList/alarmRule.service.ts b/rulemgt-frontend/src/app/correlation-ruleList/alarmRule.service.ts new file mode 100644 index 0000000..33ea713 --- /dev/null +++ b/rulemgt-frontend/src/app/correlation-ruleList/alarmRule.service.ts @@ -0,0 +1,123 @@ +/* + Copyright 2017 ZTE Corporation. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ +import { Injectable } from '@angular/core'; +import { Http, Response, Headers } from '@angular/http'; + + +import { RuleModel } from './alarmRule'; +import { RuleRequest } from './ruleRequest'; +import { Router } from '@angular/router'; +import { ModalService } from '../correlation-modal/modal.service'; + +@Injectable() +export class AlarmRuleService { + private ruleUrl = "/api/holmes-rule-mgmt/v1/rule"; + private headers = new Headers({ 'Content-Type': 'application/json' }); + constructor(private http: Http, private modalService: ModalService, private router: Router) { } + + getRules(): Promise { + return this.http.get(this.ruleUrl) + .toPromise() + .then(res => res.json()) + .catch(this.handleError); + } + + private handleError(error: any): Promise { + console.error('An error occurred', error); + return Promise.reject(error._body || error); + } + + search(ruleId: string): Promise { + if (typeof (ruleId) == "string") { + let rule = [{ + ruleId: null, + ruleName: null, + description: null, + content: null, + createtime: null, + creator: null, + updatetime: null, + modifier: null, + enabled: 0, + }] + } + let data = { 'ruleId': ruleId }; + var queryrequest = JSON.stringify(data); + const url = `${this.ruleUrl}?queryrequest=${queryrequest}`; + return this.http.get(url, {headers:this.headers}) + .toPromise() + .then(res => res.json().rules as RuleModel) + .catch(this.handleError); + } + + searchrules(rule: RuleRequest): Promise { + let data = { ruleName: rule.ruleName, enabled: rule.enabled } + console.log(JSON.stringify(data)); + const url = `${this.ruleUrl}?queryrequest=${JSON.stringify(data)}` + return this.http.get(url, { body: data, headers: this.headers }) + .toPromise() + .then(res => res.json().rules as RuleModel[]) + .catch(this.handleError); + } + + checkContent(ruleContent: string): Promise { + const url = "/api/holmes-engine-mgmt/v1/rule"; + let data = { content: ruleContent }; + return this.http + .post(url, JSON.stringify(data), { headers: this.headers }) + .toPromise() + .then(res => res) + .catch(error => error); + } + + updateRule(rule: RuleModel): Promise { + let rules = { + "ruleId": rule.ruleId, + "description": rule.description, + "content": rule.content, + "enabled": rule.enabled + } + const url = `${this.ruleUrl}` + return this.http + .post(url, JSON.stringify(rules), { headers: this.headers }) + .toPromise() + .then(res => res) + .catch(error => error) + } + + save(rule: RuleModel): Promise { + let ruledata = { + "description": rule.description, + "content": rule.content, + "enabled": rule.enabled, + "ruleName": rule.ruleName + } + return this.http.put(this.ruleUrl, JSON.stringify(ruledata), { headers: this.headers }) + .toPromise() + .then(res => res) + .catch(error => error); + } + + public delete(ruleId: string): Promise { + const url = `${this.ruleUrl}` + '/' + ruleId; + return this.http.delete(url, { headers: this.headers }) + .toPromise() + .then(res => { + + }) + .catch(this.handleError); + } +} \ No newline at end of file diff --git a/rulemgt-frontend/src/app/correlation-ruleList/alarmRule.ts b/rulemgt-frontend/src/app/correlation-ruleList/alarmRule.ts new file mode 100644 index 0000000..9c36d30 --- /dev/null +++ b/rulemgt-frontend/src/app/correlation-ruleList/alarmRule.ts @@ -0,0 +1,27 @@ +/* + Copyright 2017 ZTE Corporation. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ +export class RuleModel { + ruleId: string; + ruleName: string; + description: string; + content: string; + createTime: Date; + creator: number; + updateTime: Date; + modifier: string; + loopControlName: string; + enabled?: any; +} \ No newline at end of file diff --git a/rulemgt-frontend/src/app/correlation-ruleList/ruleRequest.ts b/rulemgt-frontend/src/app/correlation-ruleList/ruleRequest.ts new file mode 100644 index 0000000..2719a90 --- /dev/null +++ b/rulemgt-frontend/src/app/correlation-ruleList/ruleRequest.ts @@ -0,0 +1,23 @@ +/* + Copyright 2017 ZTE Corporation. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ +export class RuleRequest { + ruleId: string; + ruleName: string; + creator: number; + modifier: string; + enabled: number; + loopControlName: string; +} \ No newline at end of file -- cgit 1.2.3-korg