Add rule list gui source code
authorYILI <li.yi101@zte.com.cn>
Fri, 24 Feb 2017 07:48:20 +0000 (15:48 +0800)
committer6092002077 <li.yi101@zte.com.cn>
Fri, 24 Feb 2017 08:14:25 +0000 (16:14 +0800)
read rule manager gui list,inclode query and table list

Issue-ID:CLIENT-151

Change-Id: I647c840f0579c4b0a3876c8c98aff69007d8c9b9
Signed-off-by: YILI <li.yi101@zte.com.cn>
alarm-analysis/src/main/webapp/alarm/app/correlation-ruleList/alarmRule.component.html
alarm-analysis/src/main/webapp/alarm/app/correlation-ruleList/alarmRule.component.ts [new file with mode: 0644]
alarm-analysis/src/main/webapp/alarm/app/correlation-ruleList/alarmRule.service.ts [new file with mode: 0644]
alarm-analysis/src/main/webapp/alarm/app/correlation-ruleList/alarmRule.ts [new file with mode: 0644]
alarm-analysis/src/main/webapp/alarm/app/correlation-ruleList/ruleRequest.ts [new file with mode: 0644]

index 4d2969b..4898a01 100644 (file)
  See the License for the specific language governing permissions and\r
  limitations under the License.\r
 -->\r
-<div class="container">\r
+<div class="container" style="margin-top: 20px">\r
     <form  class="form-inline" >\r
         <div class="form-body">\r
-            \r
             <div class="row form-group col-xs-12">\r
-               \r
-                <div class="checkbox-list col-lg-4">\r
-                     <label class="col-lg-3 control-label myclass" >\r
+                <div class="col-xs-4">\r
+                     <label class="col-xs-3 control-label myclass" >\r
                         {{"common_status"|translate}}\r
                     </label>\r
                     <select #selection class="form-control" style="width: 60%" id="status" (change)="switch(selection.value)" [(ngModel)]="activeText" name="activestatus">\r
-                                               <option *ngFor="let a of activeStatus" [value]="a">{{a|translate}}</option>\r
-                        \r
-                                       </select>\r
+                      <option *ngFor="let a of activeStatus" [value]="a">{{a|translate}}</option>\r
+                    </select>\r
                 </div>\r
-                              \r
-                <div class="col-lg-4">\r
-                     <label for="userName" class="myclass">\r
+\r
+                <div class="col-xs-4">\r
+                     <label for="userName" class="col-xs-3 control-label myclass">\r
                         <span>{{"common_keyword"|translate}}</span>\r
                     </label>\r
                     <input class="form-control ng-untouched ng-pristine ng-valid" style="width: 60%"  placeholder='{{"field_rule_name"|translate}}'\r
-                        type="text"  [(ngModel)]="ruleModel.rulename" name="name" id="teseselect">\r
-                   \r
+                        type="text"  [(ngModel)]="ruleModel.rulename" name="name">\r
                 </div>\r
+\r
                 <div class="fmrule_btn_group display_table">\r
                     <div class="inline">\r
-                        <button id="batchDeleteButton" class="btn radius_s white" (click)="searchRules()">\r
-                            <span class="ict-Magnifier"></span>\r
+                        <button id="batchDeleteButton" class="btn btn-primary" (click)="searchRules()">\r
                             <span>{{"common_query"|translate}}</span>\r
+                            <span class="glyphicon glyphicon-search pull-right" style="padding-left: 10px"></span>\r
                         </button>\r
-                        <button class="btn radius_s white" (click)="reset()">\r
-                            <span class="ict-clearAlarm"></span>\r
+                        <button class="btn btn-secondary" (click)="reset()" style="margin-left: 10px">\r
+                            <span class="glyphicon glyphicon-refresh"></span>\r
                             <span>{{"common_reset"|translate}}</span>\r
-\r
                         </button>\r
                     </div>\r
-                    \r
                 </div>\r
             </div>\r
-<br>\r
-        <div class="row form-group col-xs-12">\r
-            <div class="fmrule_btn_group display_table">\r
+\r
+        <div class="row form-group col-xs-12" style="margin-top: 10px">\r
+            <div class="">\r
                 <div class="inline">\r
-                    <button type="button" routerLink='/ruleInfo' class="btn radius_s white">\r
-                    <span class="ict-new"></span>\r
+                    <button type="button" routerLink='/ruleInfo' class="btn btn-info">\r
+                    <span class="glyphicon glyphicon-plus"></span>\r
                     <span>{{"common_add"|translate}}</span>\r
                     </button>\r
                 </div>\r
             </div>\r
         </div>\r
-        </div>\r
-\r
+    </div>\r
+        \r
     </form>\r
-    <br>\r
 <div>\r
-    <br>\r
-    <br>\r
-    <br>\r
-    <p>{{"common_total1"|translate}}{{totalcount}}{{"common_total2"|translate}}</p>\r
-    <table class="table table-striped table-bordered fmrule_table_border table-hover dataTable" >\r
+    <div class="row form-group col-xs-12 myclass">{{"common_total1"|translate}}{{totalcount}}{{"common_total2"|translate}}</div>\r
+    <table class="table table-bordered table-striped customtable table-hover" >\r
         <thead class="nf_thead">\r
             <tr class="heading">\r
                 <td>{{"field_rule_name"|translate}}</td>\r
         <tbody>\r
             <tr *ngFor="let rule of rules">\r
                 <td><a routerLink="/ruleInfo/{{rule.ruleid}}&add">{{rule.rulename}}</a></td>\r
-                 \r
-                <td [hidden]="rule.enabled === 0" ><span class="ict-circle rule_table_btn" value=0></span></td>\r
-                <td [hidden]="rule.enabled === 1"><span class="ict-circle rule_table_btn"  value=1></span></td>\r
+                <td [hidden]="rule.enabled === 0" style="text-align: center"><span value=0><img src="../../../public/thirdparty/images/round_off.png" alt=""></span></td>\r
+                <td [hidden]="rule.enabled === 1" style="text-align: center"><span value=1><img src="../../../public/thirdparty/images/round_on.png" alt=""></span></td>\r
                 <td>{{rule.createtime | date:'yyyy-MM-dd HH:mm:ss'}}</td>\r
                 <td>{{rule.creator}}</td>\r
                 <td>{{rule.updatetime | date:'yyyy-MM-dd HH:mm:ss'}}</td>\r
                 <td>\r
-                    <button class="btn-xs radius_s white task_table_btn rule_table_btn" (click)="updateRule(rule); $event.stopPropagation()">{{"update"|translate}}</button>\r
-                   \r
-                    <button [hidden]="rule.enabled===0" class="btn-xs radius_s white task_table_btn rule_table_btn"  (click)="on_off(rule); $event.stopPropagation()">{{"off"|translate}}</button>\r
-                    <button [hidden]="rule.enabled===1" class="btn-xs radius_s white task_table_btn rule_table_btn" (click)="on_off(rule); $event.stopPropagation()">{{"on"|translate}}</button>\r
+                    <span (click)="updateRule(rule); $event.stopPropagation()" style="cursor: pointer;margin: 0 5px">\r
+                        <img src="../../../public/thirdparty/images/edit.png" alt="">\r
+                    </span>\r
+                    <span>\r
+                        \r
+                    </span>\r
+                    <span [hidden]="rule.enabled===0" class=""  (click)="on_off(rule); $event.stopPropagation()">\r
+                        <img src="../../../public/thirdparty/images/off.png" alt="">\r
+                    </span>\r
+                    <span [hidden]="rule.enabled===1" class="" (click)="on_off(rule); $event.stopPropagation()">\r
+                        <img src="../../../public/thirdparty/images/on.png" alt="">\r
+                    </span>\r
                 \r
-                    <button  class="btn-xs radius_s white task_table_btn rule_table_btn" id={{rule.ruleid}} (click)="delete(rule)">{{"delete"|translate}}</button>\r
+                    <span  class="" id={{rule.ruleid}} (click)="delete(rule)" style="cursor: pointer;margin: 0 5px">\r
+                         <img src="../../../public/thirdparty/images/delete.png" alt="">\r
+                    </span>\r
                 </td>\r
             </tr>\r
-           \r
         </tbody>\r
     </table>\r
 </div>\r
-\r
-\r
-\r
  <div id="deleteTimingTaskDlg" style="display: none;" >\r
         <div id="deleteTimingTaskContent">\r
             <div class="deletePromptMessage">\r
                 <span>{{"message_is_delete"|translate}}</span>\r
             </div>\r
-            <div style="float:right" class="">\r
-                <button class="btn-xs radius_s over-grey" type="button" data-popmodal-but="cancel">\r
+            <div style="float:rightl;padding-top: 10px;margin-bottom: -20px" class="">\r
+                <button class="btn btnDefault btnmrg" type="button" data-popmodal-but="cancel">\r
                     <span>{{"common_cancel"|translate}}</span>\r
                 </button>\r
-                <button class="blue1-active btn-xs white radius_s btn-dialog" data-popmodal-but="ok">\r
+                <button class="btn btnDefault btnmrg" data-popmodal-but="ok">\r
                     <span>{{"common_confirm"|translate}}</span>\r
                 </button>\r
             </div>\r
             <div class="deletePromptMessage">\r
                 <span>{{"warn_delete_info"|translate}}</span>\r
             </div>\r
-            <div style="float:right" >\r
-                <button class="blue1-active btn-xs white radius_s btn-dialog" data-popmodal-but="ok">\r
+            <div style="float:right;padding-top:10px" >\r
+                <button class="btn btnDefault btnmrg" data-popmodal-but="ok">\r
                     <span>{{"common_confirm"|translate}}</span>\r
                 </button>\r
             </div>\r
diff --git a/alarm-analysis/src/main/webapp/alarm/app/correlation-ruleList/alarmRule.component.ts b/alarm-analysis/src/main/webapp/alarm/app/correlation-ruleList/alarmRule.component.ts
new file mode 100644 (file)
index 0000000..b8d4247
--- /dev/null
@@ -0,0 +1,170 @@
+/*\r
+ Copyright 2017 ZTE Corporation.\r
+\r
+ Licensed under the Apache License, Version 2.0 (the "License");\r
+ you may not use this file except in compliance with the License.\r
+ You may obtain a copy of the License at\r
+\r
+     http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+*/\r
+import {Component,OnInit,ViewChild,ViewEncapsulation} from '@angular/core';\r
+import {ModalService} from  '../correlation-modal/modal.service';\r
+import {RuleModel} from './alarmRule';\r
+import {RuleRequest} from './ruleRequest';\r
+import { Router } from '@angular/router';\r
+import {Http,Response,Jsonp,Headers,RequestOptions} from '@angular/http';\r
+import {AlarmRuleService} from './alarmRule.service';\r
+declare var jQuery: any;\r
+\r
+@Component({\r
+    selector:'alarmRule',\r
+    templateUrl:'./alarmRule.component.html',\r
+   \r
+})\r
+export class AlarmRule implements OnInit{\r
+    ruleModel:RuleModel;\r
+    rules:RuleModel[];\r
+    queryRule:RuleModel;\r
+    activeText:string;\r
+    ruleName:string;\r
+    enable_on="enabled";\r
+    enable_off="disabled"\r
+    totalcount:number;\r
+    model: any;\r
+    ruleRequest: RuleRequest;\r
+    solution = 'ANGULAR';\r
+    selection = 'A'\r
+    activeStatus=["option_all","common_enabled", "common_disabled"];\r
+\r
+    constructor(public _alarmRuleService:AlarmRuleService, private _ModalService:ModalService,\r
+    private router: Router){};\r
+\r
+    switch(select:string):void {\r
+        console.log(select);\r
+        if(select == "common_enabled") {\r
+            this.ruleModel.enabled = 1;\r
+        }else if(select=="common_disabled"){\r
+            this.ruleModel.enabled = 0;\r
+        }else{\r
+\r
+             this.ruleModel.enabled = null;\r
+        }\r
+        this.setActiveText();\r
+    };\r
+\r
+    setActiveText():void {\r
+        if(this.ruleModel.enabled == 1){\r
+            this.activeText = "common_enabled";\r
+            this.ruleRequest.enabled=1;\r
+        }\r
+        else if(this.ruleModel.enabled == 0){\r
+            this.activeText = "common_disabled";\r
+            this.ruleRequest.enabled=0;\r
+        }else{\r
+            this.activeText="option_all";\r
+            this.ruleRequest.enabled=null;\r
+        }\r
+    };\r
+  \r
+     getRules():Promise<any>{\r
+         return  this._alarmRuleService\r
+             .getRules()\r
+             .then(rules=>{\r
+                this.rules=rules.rules;\r
+                this.totalcount = rules.totalcount;\r
+                });\r
+     }\r
+\r
+     searchRules():void{\r
+         if(this.ruleModel.enabled == null){\r
+            this.ruleRequest.enabled =null;\r
+         }\r
+         this.ruleRequest.rulename = this.ruleModel.rulename;\r
+         console.log(this.ruleRequest.enabled,this.ruleRequest.rulename);\r
+         \r
+         this._alarmRuleService\r
+         .searchrules(this.ruleRequest)\r
+         .then(rules=>{\r
+             this.rules = rules;\r
+             this.totalcount = rules.length;\r
+            });\r
+     }\r
+     updateRule(rule:RuleModel):void{\r
+         this.router.navigate(['ruleInfo/',rule.ruleid]);\r
+     }\r
+\r
+     delete(rule: RuleModel):void{\r
+         rule.enabled == 1 ? this.deleteActiveRule(rule):this.deleteModel(rule.ruleid,this._alarmRuleService,this);\r
+     }\r
+\r
+     on_off(rule:RuleModel){\r
+         rule.enabled == 0 ? rule.enabled = 1: rule.enabled = 0;\r
+         this._alarmRuleService\r
+         .updateRule(rule)\r
+         .then(res => {\r
+             rule = res;\r
+            });\r
+     }\r
+\r
+     reset():void{\r
+        this.ruleModel.rulename = null;\r
+        this.activeText = "option_all";\r
+        this.ruleModel.enabled = null;\r
+        this.getRules();\r
+  }\r
+    \r
+     deleteActiveRule(rule:RuleModel):void{\r
+         jQuery("#"+rule.ruleid).popModal({\r
+            html: jQuery('#deleteActiveRuleContent'),\r
+            placement: 'leftTop',\r
+            showCloseBut: false,\r
+            onDocumentClickClose: true,\r
+            onOkBut: function () {\r
+            },\r
+        });\r
+     }\r
+      deleteModel(ruleid:string,alarm:AlarmRuleService,obj:any):void{\r
+          jQuery("#"+ruleid).popModal({\r
+            html: jQuery('#deleteTimingTaskContent'),\r
+            placement: 'leftTop',\r
+            showCloseBut: false,\r
+            onDocumentClickClose: true,\r
+            onOkBut: function () {\r
+                jQuery("#deleteTimingTaskDlg").append(jQuery('#deleteTimingTaskContent'));\r
+                 alarm.delete(ruleid);\r
+                 obj.getRules();\r
+            },\r
+            onCancelBut: function () {\r
+            }\r
+        });\r
+     }\r
+\r
+    ngOnInit():void{\r
+        this.activeText="option_all";\r
+        this.ruleModel={\r
+            ruleid:null,\r
+            rulename:null,\r
+            description:"",\r
+            content:null,\r
+            createtime:null,\r
+            creator:null,\r
+            updatetime:null,\r
+            modifier:null,\r
+            enabled:0,\r
+        }\r
+        this.ruleRequest={\r
+            ruleid:null,\r
+            rulename:null,\r
+            creator:null,\r
+            modifier:null,\r
+            enabled:null,\r
+        }\r
+        this.getRules();\r
+    }\r
+}\r
diff --git a/alarm-analysis/src/main/webapp/alarm/app/correlation-ruleList/alarmRule.service.ts b/alarm-analysis/src/main/webapp/alarm/app/correlation-ruleList/alarmRule.service.ts
new file mode 100644 (file)
index 0000000..f7b640b
--- /dev/null
@@ -0,0 +1,126 @@
+/*
+ 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 'rxjs/add/operator/toPromise';
+import 'rxjs/add/operator/map';
+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/correlation-mgt/v1/rule";
+    private headers = new Headers({'Content-Type': 'application/json'});
+    constructor(private http:Http,private _ModalService:ModalService,private router:Router){}
+
+    getRules():Promise<any>{
+        return this.http.get(this.ruleUrl)
+        .toPromise()
+        .then(res => res.json())
+        .catch(this.handleError);
+    }
+
+    private handleError(error: any): Promise<any> {
+        console.error('An error occurred', error); 
+        return Promise.reject(error._body || error);
+    }
+    
+     search(ruleid:string):Promise<RuleModel>{
+      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, this.headers)
+        .toPromise()
+        .then(res => res.json().rules as RuleModel)
+        .catch(this.handleError);
+  }
+  
+  searchrules(rule:RuleRequest):Promise<RuleModel[]>{
+     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<any>{
+      const url = "/api/correlation-engine/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<any>{
+      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<any>{
+      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<void>{
+      let ru = {'ruleid':ruleid};
+      const url = `${this.ruleUrl}`;
+      return this.http.delete(url,{body:JSON.stringify(ru),headers:this.headers})
+      .toPromise()
+      .then(res => {
+          if(res.status == 200){
+              
+          }
+      })
+      .catch(this.handleError);
+  }
+}
\ No newline at end of file
diff --git a/alarm-analysis/src/main/webapp/alarm/app/correlation-ruleList/alarmRule.ts b/alarm-analysis/src/main/webapp/alarm/app/correlation-ruleList/alarmRule.ts
new file mode 100644 (file)
index 0000000..a376aca
--- /dev/null
@@ -0,0 +1,26 @@
+/*\r
+ Copyright 2017 ZTE Corporation.\r
+\r
+ Licensed under the Apache License, Version 2.0 (the "License");\r
+ you may not use this file except in compliance with the License.\r
+ You may obtain a copy of the License at\r
+\r
+     http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+*/\r
+export class RuleModel{\r
+    ruleid:string;\r
+    rulename:string;\r
+    description:string; \r
+    content:string;\r
+    createtime:Date;\r
+    creator:number;\r
+    updatetime:Date;\r
+    modifier:string;\r
+    enabled?;\r
+}
\ No newline at end of file
diff --git a/alarm-analysis/src/main/webapp/alarm/app/correlation-ruleList/ruleRequest.ts b/alarm-analysis/src/main/webapp/alarm/app/correlation-ruleList/ruleRequest.ts
new file mode 100644 (file)
index 0000000..0abf632
--- /dev/null
@@ -0,0 +1,22 @@
+/*\r
+ Copyright 2017 ZTE Corporation.\r
+\r
+ Licensed under the Apache License, Version 2.0 (the "License");\r
+ you may not use this file except in compliance with the License.\r
+ You may obtain a copy of the License at\r
+\r
+     http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+*/\r
+export class RuleRequest{\r
+    ruleid:string;\r
+    rulename:string;\r
+    creator:number;\r
+    modifier:string;\r
+    enabled:number;\r
+}
\ No newline at end of file