annotate views/bottledash_view.tpl @ 25:05e5441c5160

charts will now be displayed as they should!
author sean
date Fri, 14 Aug 2015 00:31:48 +0200
parents 7d431b779512
children af280057d5fa
rev   line source
16
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
1 <!-- This tempalte is a part of bottledash
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
2 author: sean engelhardt >sean.engelhardt@intevation.de
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
3 License: GNU GPL >= v2. See LICENSE for details. -->
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
4
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
5 <%
21
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
6 import math, os, sys, subprocess, html.parser
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
7 from datetime import date
16
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
8
21
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
9 PATH = os.path.abspath(os.path.dirname(sys.argv[0]))
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
10 sys.path.append(PATH + "/modules")
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
11 import web_view
16
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
12
21
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
13 #################
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
14 # settings #
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
15 #################
16
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
16
21
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
17 show_top_bar = settings["show_top_bar"]
16
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
18
21
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
19 #################
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
20 # date and time #
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
21 #################
16
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
22
21
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
23 today = date.today()
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
24 weekday = ("Montag", "Dienstag", "Mittwoch", "Donnerstag",
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
25 "Freitag", "Samstag", "Sonntag")[today.weekday()]
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
26 month_name = ("Januar", "Februar", "März", "Aprill", "Mai",
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
27 "Juni", "Juli", "August", "September", "Oktober",
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
28 "November", "Dezember")[today.month-1]
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
29
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
30 number_of_rows = 2
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
31
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
32 #################
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
33 # viewport size #
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
34 #################
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
35 vp_size = "17px"
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
36 #if len(tiles) <= 2:
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
37 # vp_size = "6vw"
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
38 #elif len(tiles) >2 and len(tiles) <=4 :
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
39 # vp_size = "5vw"
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
40 #elif len(tiles) >4 and len(tiles) <=6 :
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
41 # vp_size = "4vw"
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
42 #elif len(tiles) >6 and len(tiles) <=8 :
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
43 # vp_size = "3vw"
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
44 #end
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
45 %>
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
46
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
47 <html>
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
48 <head>
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
49 <!-- <meta http-equiv="refresh" content="5" /> -->
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
50 <link rel="stylesheet" type="text/css" href="/static/dash_style.css">
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
51 <style>
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
52 #content{
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
53 min-width: 100%;
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
54 % if show_top_bar == "True":
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
55 height: 95%;
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
56 % else :
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
57 height: 100%;
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
58 %end
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
59 }
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
60
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
61 .statusmon{
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
62 color: white;
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
63 font-size: {{vp_size}};
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
64 }
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
65
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
66 .chart{
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
67 font-size: {{vp_size}};
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
68 }
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
69 </style>
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
70
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
71 </head>
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
72 <body>
16
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
73
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
74
21
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
75 <script type="text/javascript">
16
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
76
21
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
77 var global_width;
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
78 var global_height;
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
79 var tile_width;
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
80 var tile_height;
16
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
81
21
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
82 var tiles = document.getElementsByClassName("tile");
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
83 var border_width = 1;
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
84 var space_between_tiles = 8;
20
1a13a4ecf931 can not recive post-requests wich should deliver if a server is up or down. Updated after a refresh of the webpage, wich will automatically done after 5 seconds
sean
parents: 19
diff changeset
85
21
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
86 var mon_tile_ips = [];
20
1a13a4ecf931 can not recive post-requests wich should deliver if a server is up or down. Updated after a refresh of the webpage, wich will automatically done after 5 seconds
sean
parents: 19
diff changeset
87
16
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
88
21
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
89 //save the IPs if the mon-tiles
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
90 % for tile in tiles:
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
91 % if tile["type"] == "mon":
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
92 mon_tile_ips.push('{{tile["source"]}}');
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
93 % end
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
94 % end
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
95
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
96 var space_lr_borders;
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
97 var space_lr_margin;
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
98
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
99 function calc_tile_with(){
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
100 var tiles_per_row = Math.floor(tiles.length / {{number_of_rows}});
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
101 var distance = (space_between_tiles*2) + (border_width*2);
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
102 var tile_width = ((global_width / tiles_per_row ) - distance);
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
103 return tile_width;
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
104 }
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
105
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
106 function calc_tile_height(){
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
107 var distance = (space_between_tiles*2) + (border_width*2);
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
108 var tile_height = ((global_height / {{number_of_rows}} ) - distance);
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
109 return tile_height;
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
110 }
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
111
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
112 function resize_content(){
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
113 global_width = document.getElementById("content").clientWidth;
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
114 global_height = document.getElementById("content").clientHeight;
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
115
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
116
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
117 tile_width = calc_tile_with();
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
118 tile_height = calc_tile_height();
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
119
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
120 for(var tile = 0; tile < tiles.length; tile++){
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
121 tiles[tile].style.width= tile_width + 'px';
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
122 tiles[tile].style.height= tile_height + 'px';
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
123 }
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
124 }
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
125
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
126 function set_mon_tile_status(ip, status){
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
127 document.getElementById(ip).className = "tile statusmon " + status;
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
128 }
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
129
22
3dfa9ed1dd8b added static files
sean
parents: 21
diff changeset
130 //check current state of an IP
21
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
131 function check_server_state(ip){
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
132 var request = new XMLHttpRequest();
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
133 var params = "service=" + ip;
23
f63737665ac5 fixed an URL rediretion problem
sean
parents: 22
diff changeset
134 request.open('POST', window.location.href + "ask-systemstate", false);
21
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
135 request.send(params);
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
136 // console.log(request.responseText);
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
137 return request.responseText
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
138 }
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
139
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
140 function check_server_state_loop() {
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
141 for (var i = 0; i < mon_tile_ips.length; i++) {
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
142 var state = check_server_state(mon_tile_ips[i])
24
7d431b779512 working connection with MON
sean
parents: 23
diff changeset
143 if (state == "UPALERT" || state == "UP") {
21
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
144 set_mon_tile_status(mon_tile_ips[i], "active")
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
145 } else {
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
146 set_mon_tile_status(mon_tile_ips[i], "dead")
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
147 }
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
148 }
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
149 }
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
150 setInterval(check_server_state_loop, 10000); // Time in milliseconds
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
151
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
152 window.onresize = function(){
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
153 resize_content();
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
154 }
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
155
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
156 document.addEventListener("DOMContentLoaded", function(event) {
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
157 resize_content();
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
158 });
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
159
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
160 </script>
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
161
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
162 <div id = "wrapper">
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
163 % if show_top_bar == "True":
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
164 <div id = "topbar">
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
165 <b>{{weekday}}</b> {{today.day}}. {{month_name}}
16
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
166 </div>
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
167 % end
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
168
21
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
169 <div id = "content">
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
170 <%
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
171 for tile in tiles :
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
172 type = ""
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
173 tile_content = ""
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
174 status = ""
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
175 uid = ""
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
176
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
177 if tile["type"] == "mon" :
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
178 type = "statusmon"
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
179 tile_content = tile["source"]
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
180 uid = tile["source"]
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
181 if tile["status"] == "up" :
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
182 status = "active"
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
183 else :
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
184 status = "dead"
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
185 end
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
186
25
05e5441c5160 charts will now be displayed as they should!
sean
parents: 24
diff changeset
187 elif tile["type"] == "web_view" :
05e5441c5160 charts will now be displayed as they should!
sean
parents: 24
diff changeset
188 type = tile["type"]
21
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
189 uid = tile["div_name"]
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
190 tile_content = web_view.make_chart(tile["script"], tile["div_name"])
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
191 end
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
192 %>
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
193
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
194 <div class = "tile {{type}} {{status}}" id = {{uid}}>
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
195 {{!tile_content}}
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
196 </div>
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
197
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
198 % end
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
199 </div>
16
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
200 </div>
21
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
201 </body>
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
202 </html>
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)