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