Browse Source

added unique rest interface for each service.

Signed-off-by: chanhoonseng <chanhoonseng3101@gmail.com>
chanhoonseng 7 years ago
parent
commit
e7f2bf0756
4 changed files with 79 additions and 43 deletions
  1. 1 0
      .gitignore
  2. 35 32
      core.py
  3. 26 6
      designer.html
  4. 17 5
      status.html

+ 1 - 0
.gitignore

@@ -4,3 +4,4 @@ style.yaml
 .tmp.yaml
 *.yaml
 backup
+static/dataimage/

+ 35 - 32
core.py

@@ -140,7 +140,6 @@ class SetTimerHandler(tornado.web.RequestHandler):
 
 class DesignerHandler(tornado.web.RequestHandler):
     def get(self):
-        self.set_current_user(username)
         print "In designer mode."
         with open("cache.yaml", 'r') as stream:
             try:
@@ -168,8 +167,12 @@ class DesignerHandler(tornado.web.RequestHandler):
         if "background" in config:
             data["background"] = config["background"]
 
-        self.render('designer.html', data=data)
+        if "title" in config:
+            data["title"] = config["title"]
+        else:
+            data["title"] = "BORA"
 
+        self.render('designer.html', data=data)
 
 
 class VersionHandler(tornado.web.RequestHandler):
@@ -246,7 +249,6 @@ class UpdateHandler(tornado.web.RequestHandler):
         rt.stop()
         with open("varname.yaml", 'r') as stream:
             try:
-                #print(yaml.load(stream))
                 cache_data = yaml.load(stream)
             except yaml.YAMLError as exc:
                 print(exc)
@@ -265,49 +267,48 @@ class UpdateHandler(tornado.web.RequestHandler):
                     tmp_str.append("db_mask=all")
                     continue
                 elif lhs == "db_server":
-                    db_server = rhs 
+                    db_server = rhs
 
                 tmp_str.append(adei_unit)
                 tmp_store.append(adei_unit)
             tmp_str.append("window=-1")
-        
+
             query = "&".join(tmp_str)
             dest = config['server'] + config['script']
             url = dest + "?" + query
 
-            data = requests.get(url, auth=(config['username'], config['password']))
+            data = requests.get(url, auth=(config['username'],
+                                config['password']))
             cr = data.content
             cr = cr.split(",")
 
-	    match_token = item
+            match_token = item
             if db_server != "lara" and db_server != "hiu":
                 # parameter name stored in ADEI with '-IST_Val' suffix
                 if "MOD" in item:
-	            match_token = item + "-MODUS_Val"
+                    match_token = item + "-MODUS_Val"
                 elif "GRA" in item:
-	            match_token = item + "-GRAD_Val"
+                    match_token = item + "-GRAD_Val"
                 elif "RPO" in item:
-	            match_token = item + "-ZUST_Val"
+                    match_token = item + "-ZUST_Val"
                 elif "VYS" in item:
-	            match_token = item + "-ZUST_Val"
-    	        elif "MSS" in item:
-	            match_token = item + "_Val"
-	        else:
-	            match_token = item + "-IST_Val"
+                    match_token = item + "-ZUST_Val"
+                elif "MSS" in item:
+                    match_token = item + "_Val"
+                else:
+                    match_token = item + "-IST_Val"
 
             db_mask = None
             for i, iter_item in enumerate(cr):
-                #print i, iter_item
                 if match_token == iter_item.strip():
                     db_mask = i - 1
-            if db_mask == None:
+            if db_mask is None:
                 continue
 
             tmp_store.append("db_mask="+str(db_mask))
-            #cache_data[item] = "&".join(tmp_str)
-       
+
             new_data[item] = "&".join(tmp_store)
-        
+
         with open("varname.yaml", 'w') as output:
             output.write(yaml.dump(new_data, default_flow_style=False))
             response = {"success": "Data entry inserted."}
@@ -499,18 +500,20 @@ rt = RepeatedTimer(int(config["polling"]), fetchDataADEI)
 
 application = tornado.web.Application([
     (r"/auth/login/?", AuthLoginHandler),
-    (r"/version/?", VersionHandler),
-    (r"/list/?", ListHandler),
-    (r"/start/?", StartHandler),
-    (r"/backup/?", BackupHandler),
-    (r"/stop/?", StopHandler),
-    (r"/designer/?", DesignerHandler),
-    (r"/status/?", StatusHandler),
-    (r"/save/?", SaveHandler),
-    (r"/getdata/?", GetDataHandler),
-    (r"/timer/(?P<duration>[^\/]+)/?", SetTimerHandler),
-    (r"/add/(?P<db_server>[^\/]+)/?(?P<db_name>[^\/]+)/?"
-     "(?P<db_group>[^\/]+)/?(?P<sensor_name>[^\/]+)?", AdeiKatrinHandler)
+    (r"/"+config['title'].lower()+"/version/?", VersionHandler),
+    (r"/"+config['title'].lower()+"/list/?", ListHandler),
+    (r"/"+config['title'].lower()+"/start/?", StartHandler),
+    (r"/"+config['title'].lower()+"/backup/?", BackupHandler),
+    (r"/"+config['title'].lower()+"/stop/?", StopHandler),
+    (r"/"+config['title'].lower()+"/designer/?", DesignerHandler),
+    (r"/"+config['title'].lower()+"/status/?", StatusHandler),
+    (r"/"+config['title'].lower()+"/save/?", SaveHandler),
+    (r"/"+config['title'].lower()+"/getdata/?", GetDataHandler),
+    (r"/"+config['title'].lower()+"/timer/(?P<duration>[^\/]+)/?",
+     SetTimerHandler),
+    (r"/"+config['title'].lower()+"/add/(?P<db_server>[^\/]+)/?"
+     "(?P<db_name>[^\/]+)/?(?P<db_group>[^\/]+)/?(?P<sensor_name>[^\/]+)?",
+     AdeiKatrinHandler)
 ], debug=True, static_path=os.path.join(root, 'static'),
     js_path=os.path.join(root, 'js'), login_url="/auth/login",
     cookie_secret='L8LwECiNRxq2N0N2eGxx9MZlrpmuMEimlydNX/vt1LM=')

+ 26 - 6
designer.html

@@ -15,6 +15,7 @@
 
 <body>
 <div id="page_info">Designer Block. Generated by BORA 0.0.1</div>
+<div id="page_title_cache" style="display:none;">{{ data['title'] }}</div>
 
 {% if "background" in data %}
 <img src="{{ static_url( data['background'] ) }}"></img>    
@@ -30,7 +31,11 @@
 {% if data['style'][key]['type'] == "calc" %}
 <div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{
     data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px;
-    height:{{ data['style'][key]['height'] }}px; background-color:{{ data['style'][key]['background_color'] }};' 
+    height:{{ data['style'][key]['height'] }}px;
+{% if "background_color" in data['style'][key] %}
+  background-color:{{ data['style'][key]['background_color'] }};' 
+{% else %}
+{% end %}
 {% if "condition" in data['style'][key] %}
  data-cond="{{ data['style'][key]['condition'] }}"
 {% else%}position
@@ -57,7 +62,12 @@
 {% if data['style'][key]['type'] == "data" %}
 <div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{
     data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px;
-    height:{{ data['style'][key]['height'] }}px; background-color:{{ data['style'][key]['background_color'] }};'
+    height:{{ data['style'][key]['height'] }}px;
+    
+{% if "background_color" in data['style'][key] %}
+background-color:{{ data['style'][key]['background_color'] }};'
+{% else %}
+{% end %}
 {% if "condition" in data['style'][key] %}
  data-cond="{{ data['style'][key]['condition'] }}"
 {% else%}position
@@ -240,7 +250,12 @@
 {% if data['style'][key]['type'] == "integer-to-string" %}
 <div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{
     data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px;
-    height:{{ data['style'][key]['height'] }}px; background-color:{{ data['style'][key]['background_color'] }};' 
+    height:{{ data['style'][key]['height'] }}px;
+    
+{% if "background_color" in data['style'][key] %}
+background-color:{{ data['style'][key]['background_color'] }};' 
+{% else%}
+{% end%}
 {% if "cond" in data['style'][key] %}
  data-cond="{{ data['style'][key]['cond'] }}"
 {% else%}
@@ -262,7 +277,12 @@
 {% if data['style'][key]['type'] == "header" %}
 <div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{
     data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px;
-    height:{{ data['style'][key]['height'] }}px; background-color:{{ data['style'][key]['background_color'] }};' data-type="{{ data['style'][key]['type'] }}" class='varbox' id="{{ key }}">
+    height:{{ data['style'][key]['height'] }}px;
+{% if "background_color" in data['style'][key] %}    
+background-color:{{ data['style'][key]['background_color'] }};'
+{% else%}
+{% end%}
+data-type="{{ data['style'][key]['type'] }}" class='varbox' id="{{ key }}">
 <p><span style="color: #000; font-size: {{ data['style'][key]['header']['size'] }}px; font-weight: {{ data['style'][key]['header']['weight'] }};" class="title">{{ data['style'][key]['header']['title'] }} </span></p>
 </div>
 {% else %}
@@ -388,7 +408,7 @@ function inputEnable() {
 
 function backup() {
     $.ajax({
-        url: '/backup/',
+        url: '/'+$("#page_title_cache").text().toLowerCase()+'/backup/',
         type: 'POST',
         success: function (response) {
             alert("Backup success!");
@@ -1311,7 +1331,7 @@ function mysave(data) {
     var dataToSend = JSON.stringify(position);
     console.log(dataToSend);
     $.ajax({
-        url: '/save/',
+        url: '/'+$("#page_title_cache").text().toLowerCase()+'/save/',
         type: 'POST',
         data: dataToSend,
         success: function (response) {

+ 17 - 5
status.html

@@ -24,7 +24,12 @@
 {% if data['style'][key]['type'] == "calc" %}
 <div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{
     data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px;
-    height:{{ data['style'][key]['height'] }}px; background-color:{{ data['style'][key]['background_color'] }};' 
+    height:{{ data['style'][key]['height'] }}px;
+    
+{% if "background_color" in data['style'][key] %}     
+  background-color="{{ data['style'][key]['background_color'] }}"
+{% else%}
+{% end %}
 {% if "condition" in data['style'][key] %}
  data-cond="{{ data['style'][key]['condition'] }}"
 {% else%}position
@@ -56,7 +61,7 @@ data-type="{{ data['style'][key]['type'] }}" class='databox' id="{{ key }}">
 class="databox" style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{ data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px; height:{{ data['style'][key]['height'] }}px; 
 
 {% if "background_color" in data['style'][key] %}
-background-color:{{ data['style'][key]['background_color'] }};'
+  background-color:{{ data['style'][key]['background_color'] }};'
 {% else%}
 {% end%}
 
@@ -381,7 +386,12 @@ onclick="window.open( '{{ data["server"] }}#module=graph&{{ data['varname'][data
 {% if data['style'][key]['type'] == "header" %}
 <div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{
     data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px;
-    height:{{ data['style'][key]['height'] }}px; background-color:{{ data['style'][key]['background_color'] }};' data-type="{{
+    height:{{ data['style'][key]['height'] }}px;
+{% if "background_color" in data['style'][key] %}
+  background-color:{{ data['style'][key]['background_color'] }};'
+{% else %}
+{% end %}
+data-type="{{
     data['style'][key]['type'] }}" class='databox' id="{{ key }}">
 <p><span style="color: #000; font-size: {{ data['style'][key]['header']['size'] }}px; font-weight: {{ data['style'][key]['header']['weight'] }};" class="title">{{ data['style'][key]['header']['title'] }} </span></p>
 </div>
@@ -413,16 +423,18 @@ jQuery(window).load(function () {
 $(".databox").hover(function(){
     var key = $(this).attr('id');
     if ($("#" + key).attr('data-trend') == "true") {
-        $('#'+ key).append('<span class="popup"><img src="static/dataimage/'+key+'.png" width="600px" height="400px"/></span>');
+        $('#'+ key).append('<span class="popup"><img src="/static/dataimage/'+key+'.png" width="600px" height="400px"/></span>');
     }
 });
 
+
 myTimer();
 var myVar = setInterval(myTimer, 10000);
 function myTimer() {
     var dataToSend = {};
     $.ajax({
-        url: '/getdata/',
+        url: '/'+$("#page_title_cache").text().toLowerCase()+'/getdata/',
+        //url: '/wgts/getabcddata/',
         type: 'GET',
         data: dataToSend,
         success: function (response) {