-
Notifications
You must be signed in to change notification settings - Fork 0
/
template_web.html
1701 lines (1605 loc) · 64.6 KB
/
template_web.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>myHouse</title>
<!-- Tell the browser to be responsive to screen width -->
<meta
content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<!-- jQuery -->
<script src="web/jquery/jquery.min.js"></script>
<!-- Bootstrap -->
<script src="web/bootstrap/bootstrap.min.js"></script>
<link rel="stylesheet" href="web/bootstrap/bootstrap.min.css">
<!-- Font Awesome -->
<link rel="stylesheet" href="web/font-awesome/font-awesome.min.css">
<!-- <link rel="stylesheet" href="web/font-awesome/font-awesome-animation.min.css"> -->
<!-- SlimScroll -->
<script src="web/slimScroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="web/fastclick/fastclick.min.js"></script>
<!-- Bootstrap-notify -->
<script src="web/bootstrap-notify/bootstrap-notify.min.js"></script>
<!-- JsonEditor -->
<script src="web/jsoneditor/jsoneditor.min.js"></script>
<!-- Touchspin -->
<script src="web/touchspin/touchspin.min.js"></script>
<link rel="stylesheet" href="web/touchspin/touchspin.min.css" />
<!-- TitaToggle -->
<link rel="stylesheet" href="web/titatoggle/titatoggle.min.css" />
<!-- Datatables -->
<script src="web/datatables/datatables.min.js"></script>
<script src="web/datatables-plugins/dataTables.responsive.min.js"></script>
<script src="web/datatables-plugins/dataTables.colResize.js"></script>
<link rel="stylesheet" href="web/datatables/datatables.min.css" />
<link rel="stylesheet" href="web/datatables-plugins/dataTables.fontAwesome.css" />
<link rel="stylesheet" href="web/datatables-plugins/responsive.dataTables.min.css" />
<!-- dhtmlxscheduler -->
<script src="web/dhtmlxscheduler/dhtmlxscheduler.js"></script>
<script src="web/dhtmlxscheduler/ext/dhtmlxscheduler_recurring.js"></script>
<script src="web/dhtmlxscheduler/ext/dhtmlxscheduler_serialize.js"></script>
<script src="web/dhtmlxscheduler/ext/dhtmlxscheduler_quick_info.js"></script>
<script src="web/dhtmlxscheduler/ext/dhtmlxscheduler_key_nav.js"></script>
<script src="web/dhtmlxscheduler/ext/dhtmlxscheduler_collision.js"></script>
<script src="web/dhtmlxscheduler/ext/dhtmlxscheduler_minical.js"></script>
<script src="web/dhtmlxscheduler/ext/dhtmlxscheduler_limit.js"></script>
<script src="web/dhtmlxscheduler/ext/dhtmlxscheduler_responsive.js"></script>
<link rel="stylesheet" href="web/dhtmlxscheduler/dhtmlxscheduler_flat.css" />
<link rel="stylesheet" href="web/dhtmlxscheduler/ext/dhtmlxscheduler_responsive.css" />
<!-- Highstock -->
<script src="web/highstock/highstock.js"></script>
<script src="web/highstock/highcharts-more.js"></script>
<script src="web/highstock/modules/exporting.js"></script>
<script src="web/highstock/modules/offline-exporting.js"></script>
<!-- AdminLTE -->
<link rel="stylesheet" href="web/AdminLTE/AdminLTE.css">
<link rel="stylesheet" href="web/AdminLTE/all-skins.css">
<!-- IE8 Respond -->
<!--[if lt IE 9]>
<script src="web/IE8/html5shiv.min.js"></script>
<script src="web/IE8/respond.min.js"></script>
<![endif]-->
</head>
<style>
th.dt-center, td.dt-center { text-align: center; }
.center-block {float: none !important}
.col-centered{
margin: 0 auto;
float: none;
}
.modal-dialog {
width: 100%;
margin: 0;
padding: 0;
}
.modal-content {
height: auto;
border-radius: 0;
}
</style>
<body class="hold-transition sidebar-mini">
<div class="wrapper">
<!-- =============================================== -->
<header class="main-header">
<a href="/" class="logo">
<span class="logo-mini"><b>my</b>H</span>
<span class="logo-lg"><b><i class="fa fa-home"></i>
my</b>House</span>
</a>
<nav class="navbar navbar-static-top" role="navigation">
<a href="" id="sidebar-button" class="sidebar-toggle" data-toggle="offcanvas" role="button">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<div class="navbar-custom-menu">
<ul class="nav navbar-nav">
<li class="dropdown notifications-menu hidden" id="clock_container">
<a class="logo">
<span class="logo-mini"><i class="fa fa-clock-o"></i></span>
<span class="logo-lg"><b><i class="fa fa-clock-o"></i></b> <span id="clock"></span>
</a>
</li>
<li class="dropdown notifications-menu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-ban"></i>
<span class="label label-danger" id="notification_alert_count"></span>
</a>
<ul class="dropdown-menu">
<li>
<ul class="menu" id="notification_alert"></ul>
</li>
<li class="footer"><a href="#alerts">View all</a></li>
</ul>
</li>
<li class="dropdown notifications-menu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-warning"></i>
<span class="label label-warning" id="notification_warning_count"></span>
</a>
<ul class="dropdown-menu">
<li>
<ul class="menu" id="notification_warning"></ul>
</li>
<li class="footer"><a href="#alerts">View all</a></li>
</ul>
</li>
<li class="dropdown notifications-menu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-info"></i>
<span class="label label-success" id="notification_info_count"></span>
</a>
<ul class="dropdown-menu">
<li>
<ul class="menu" id="notification_info"></ul>
</li>
<li class="footer"><a href="#alerts">View all</a></li>
</ul>
</li>
<li>
<a href="#" data-toggle="control-sidebar"><i class="fa fa-gears"></i></a>
</li>
</ul>
</div>
</nav>
</header>
<!-- =============================================== -->
<aside class="main-sidebar">
<section class="sidebar">
<ul class="sidebar-menu">
<li class="header"><a id="status"><i
class="fa fa-circle text-red"></i> Offline</a></li>
</ul>
<ul class="sidebar-menu" id="menu">
</ul>
</section>
</aside>
<!-- =============================================== -->
<div class="content-wrapper">
<section class="content-header">
<h1 id="title"></h1>
</section>
<section class="content">
<div id="body"></div>
<div style="padding: 10px 0px; text-align: center;">
<div class="text-muted"><a href="#">Go to Top</a></div>
</div>
</section>
</div>
<!-- =============================================== -->
<div class="modal fade modal-fullscreen force-fullscreen" id="popup">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="popup_title"></h4>
</div>
<div class="modal-body">
<div class="row"><div class="col-lg-12 center-block" id="popup_body"></div></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary pull-rigth" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- =============================================== -->
<footer class="main-footer" id="footer">
<div class="pull-right hidden-xs">
<b>Version</b> <span id="version"></span>
</div>
<strong>Copyright © 2017 <a href="http://my-house.sourceforge.net" target="_new">myHouse</a>.
</strong> All rights reserved.
</footer>
<!-- =============================================== -->
<aside class="control-sidebar hidden control-sidebar-dark">
<ul class="nav nav-tabs nav-justified control-sidebar-tabs">
<li><a><i class='fa fa-paint-brush'></i></a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="control-sidebar-skin-tab">
<div>
<ul class="list-unstyled clearfix">
<li style="float:left; width: 33.33333%; padding: 5px;"><a href="javascript:void(0);" data-skin="blue" style="display: block; box-shadow: 0 0 3px rgba(0,0,0,0.4)" class="clearfix full-opacity-hover"><div><span style="display:block; width: 20%; float: left; height: 7px; background: #367fa9;"></span><span class="bg-light-blue" style="display:block; width: 80%; float: left; height: 7px;"></span></div><div><span style="display:block; width: 20%; float: left; height: 20px; background: #222d32;"></span><span style="display:block; width: 80%; float: left; height: 20px; background: #f4f5f7;"></span></div></a><p class="text-center no-margin">Blue</p></li>
<li style="float:left; width: 33.33333%; padding: 5px;"><a href="javascript:void(0);" data-skin="black" style="display: block; box-shadow: 0 0 3px rgba(0,0,0,0.4)" class="clearfix full-opacity-hover"><div style="box-shadow: 0 0 2px rgba(0,0,0,0.1)" class="clearfix"><span style="display:block; width: 20%; float: left; height: 7px; background: #fefefe;"></span><span style="display:block; width: 80%; float: left; height: 7px; background: #fefefe;"></span></div><div><span style="display:block; width: 20%; float: left; height: 20px; background: #222;"></span><span style="display:block; width: 80%; float: left; height: 20px; background: #f4f5f7;"></span></div></a><p class="text-center no-margin">Black</p></li>
<li style="float:left; width: 33.33333%; padding: 5px;"><a href="javascript:void(0);" data-skin="purple" style="display: block; box-shadow: 0 0 3px rgba(0,0,0,0.4)" class="clearfix full-opacity-hover"><div><span style="display:block; width: 20%; float: left; height: 7px;" class="bg-purple-active"></span><span class="bg-purple" style="display:block; width: 80%; float: left; height: 7px;"></span></div><div><span style="display:block; width: 20%; float: left; height: 20px; background: #222d32;"></span><span style="display:block; width: 80%; float: left; height: 20px; background: #f4f5f7;"></span></div></a><p class="text-center no-margin">Purple</p></li>
<li style="float:left; width: 33.33333%; padding: 5px;"><a href="javascript:void(0);" data-skin="green" style="display: block; box-shadow: 0 0 3px rgba(0,0,0,0.4)" class="clearfix full-opacity-hover"><div><span style="display:block; width: 20%; float: left; height: 7px;" class="bg-green-active"></span><span class="bg-green" style="display:block; width: 80%; float: left; height: 7px;"></span></div><div><span style="display:block; width: 20%; float: left; height: 20px; background: #222d32;"></span><span style="display:block; width: 80%; float: left; height: 20px; background: #f4f5f7;"></span></div></a><p class="text-center no-margin">Green</p></li>
<li style="float:left; width: 33.33333%; padding: 5px;"><a href="javascript:void(0);" data-skin="red" style="display: block; box-shadow: 0 0 3px rgba(0,0,0,0.4)" class="clearfix full-opacity-hover"><div><span style="display:block; width: 20%; float: left; height: 7px;" class="bg-red-active"></span><span class="bg-red" style="display:block; width: 80%; float: left; height: 7px;"></span></div><div><span style="display:block; width: 20%; float: left; height: 20px; background: #222d32;"></span><span style="display:block; width: 80%; float: left; height: 20px; background: #f4f5f7;"></span></div></a><p class="text-center no-margin">Red</p></li>
<li style="float:left; width: 33.33333%; padding: 5px;"><a href="javascript:void(0);" data-skin="yellow" style="display: block; box-shadow: 0 0 3px rgba(0,0,0,0.4)" class="clearfix full-opacity-hover"><div><span style="display:block; width: 20%; float: left; height: 7px;" class="bg-yellow-active"></span><span class="bg-yellow" style="display:block; width: 80%; float: left; height: 7px;"></span></div><div><span style="display:block; width: 20%; float: left; height: 20px; background: #222d32;"></span><span style="display:block; width: 80%; float: left; height: 20px; background: #f4f5f7;"></span></div></a><p class="text-center no-margin">Yellow</p></li>
<li style="float:left; width: 33.33333%; padding: 5px;"><a href="javascript:void(0);" data-skin="blue-light" style="display: block; box-shadow: 0 0 3px rgba(0,0,0,0.4)" class="clearfix full-opacity-hover"><div><span style="display:block; width: 20%; float: left; height: 7px; background: #367fa9;"></span><span class="bg-light-blue" style="display:block; width: 80%; float: left; height: 7px;"></span></div><div><span style="display:block; width: 20%; float: left; height: 20px; background: #f9fafc;"></span><span style="display:block; width: 80%; float: left; height: 20px; background: #f4f5f7;"></span></div></a><p class="text-center no-margin" style="font-size: 12px">Blue Light</p></li>
<li style="float:left; width: 33.33333%; padding: 5px;"><a href="javascript:void(0);" data-skin="black-light" style="display: block; box-shadow: 0 0 3px rgba(0,0,0,0.4)" class="clearfix full-opacity-hover"><div style="box-shadow: 0 0 2px rgba(0,0,0,0.1)" class="clearfix"><span style="display:block; width: 20%; float: left; height: 7px; background: #fefefe;"></span><span style="display:block; width: 80%; float: left; height: 7px; background: #fefefe;"></span></div><div><span style="display:block; width: 20%; float: left; height: 20px; background: #f9fafc;"></span><span style="display:block; width: 80%; float: left; height: 20px; background: #f4f5f7;"></span></div></a><p class="text-center no-margin" style="font-size: 12px">Black Light</p></li>
<li style="float:left; width: 33.33333%; padding: 5px;"><a href="javascript:void(0);" data-skin="purple-light" style="display: block; box-shadow: 0 0 3px rgba(0,0,0,0.4)" class="clearfix full-opacity-hover"><div><span style="display:block; width: 20%; float: left; height: 7px;" class="bg-purple-active"></span><span class="bg-purple" style="display:block; width: 80%; float: left; height: 7px;"></span></div><div><span style="display:block; width: 20%; float: left; height: 20px; background: #f9fafc;"></span><span style="display:block; width: 80%; float: left; height: 20px; background: #f4f5f7;"></span></div></a><p class="text-center no-margin" style="font-size: 12px">Purple Light</p></li>
<li style="float:left; width: 33.33333%; padding: 5px;"><a href="javascript:void(0);" data-skin="green-light" style="display: block; box-shadow: 0 0 3px rgba(0,0,0,0.4)" class="clearfix full-opacity-hover"><div><span style="display:block; width: 20%; float: left; height: 7px;" class="bg-green-active"></span><span class="bg-green" style="display:block; width: 80%; float: left; height: 7px;"></span></div><div><span style="display:block; width: 20%; float: left; height: 20px; background: #f9fafc;"></span><span style="display:block; width: 80%; float: left; height: 20px; background: #f4f5f7;"></span></div></a><p class="text-center no-margin" style="font-size: 12px">Green Light</p></li>
<li style="float:left; width: 33.33333%; padding: 5px;"><a href="javascript:void(0);" data-skin="red-light" style="display: block; box-shadow: 0 0 3px rgba(0,0,0,0.4)" class="clearfix full-opacity-hover"><div><span style="display:block; width: 20%; float: left; height: 7px;" class="bg-red-active"></span><span class="bg-red" style="display:block; width: 80%; float: left; height: 7px;"></span></div><div><span style="display:block; width: 20%; float: left; height: 20px; background: #f9fafc;"></span><span style="display:block; width: 80%; float: left; height: 20px; background: #f4f5f7;"></span></div></a><p class="text-center no-margin" style="font-size: 12px">Red Light</p></li>
<li style="float:left; width: 33.33333%; padding: 5px;"><a href="javascript:void(0);" data-skin="yellow-light" style="display: block; box-shadow: 0 0 3px rgba(0,0,0,0.4)" class="clearfix full-opacity-hover"><div><span style="display:block; width: 20%; float: left; height: 7px;" class="bg-yellow-active"></span><span class="bg-yellow" style="display:block; width: 80%; float: left; height: 7px;"></span></div><div><span style="display:block; width: 20%; float: left; height: 20px; background: #f9fafc;"></span><span style="display:block; width: 80%; float: left; height: 20px; background: #f4f5f7;"></span></div></a><p class="text-center no-margin" style="font-size: 12px;">Yellow Light</p></li>
</ul>
</div>
</div>
</div>
</aside>
<div class="control-sidebar-bg"></div>
<!-- =============================================== -->
</div>
<script src="web/AdminLTE/app.js"></script>
<script type="text/javascript">
// current module
var current_module = '';
// configuration
var conf = {};
// refresher
var refresher;
// hostname
var hostname = '';
// available skins
var skins = [
"skin-blue",
"skin-black",
"skin-red",
"skin-yellow",
"skin-purple",
"skin-green",
"skin-blue-light",
"skin-black-light",
"skin-red-light",
"skin-yellow-light",
"skin-purple-light",
"skin-green-light"
];
// scheduler's events
var scheduler_events = [];
/**
MAIN ENTRY POINT
**/
$(document).ready(function(){
// request the configuration first
$.getJSON(hostname+"config",function(data) {
conf = data;
//Add the change skin listener
$("[data-skin]").on('click', function (e) {
e.preventDefault();
// save the skin
setting_save('skin',$(this).data('skin'));
// load the skin
load_skin($(this).data('skin'));
});
// load the default or saved skin
load_skin(conf["gui"]["skin"])
// set the version
load_version();
// load the status
load_status();
// load the side menu
load_menu();
// load the clock
if (conf["gui"]["clock"]["enabled"]) {
$("#clock_container").removeClass("hidden");
setInterval(load_clock, 1000);
}
// load the alerts
load_alerts();
// load the given module
current_module = conf['gui']['default_module'];
if (location.hash) current_module = location.hash.replace('#','');
load_module(current_module);
// whenever the hash changes, load the requested module
window.onhashchange = function() {
if (location.hash) current_module = location.hash.replace('#','');
load_module(current_module);
};
});
});
/**
LOAD MAIN PAGE COMPONENTS
**/
// load the internet status and public hostname
function load_status() {
log("info","loading internet status");
$.getJSON(hostname+"internet_status",function(data) {
$("#status").html('<i class="fa fa-circle text-success"></i><span title="'+data.hostname+' ('+data.region+')">'+data.hostname+'</span>');
log("info","current hostname: "+data.hostname);
});
}
// load menu
function load_menu() {
log("info","loading menu");
// empty the menu
$("#menu").empty()
for (var i = 0; i < conf["gui"]["sections"].length; i++) {
var section = conf["gui"]["sections"][i];
var section_id = section["section_id"]
var label = lang(section["display_name"])
$("#menu").append('<li class="header">'+label.toUpperCase()+'</li>');
for (var j = 0; j < conf["modules"].length; j++) {
var module = conf['modules'][j];
if (! module["enabled"]) continue;
if (module["section_id"] != section_id) continue;
log("info","adding menu item "+lang(module['display_name']));
$("#menu").append('<li id="menu_item_'+module["module_id"]+'"><a href="#'+module['module_id']+'"> <i class="fa '+module['icon']+'"></i> <span>'+capitalizeFirst(lang(module['display_name']))+'</span></a></li>');
// close the menu on click on mobile devices
$("#menu_item_"+module["module_id"]).click(function(){
if ($("body").hasClass('sidebar-open')) $("body").removeClass('sidebar-open').removeClass('sidebar-collapse').trigger('collapsed.pushMenu');
})
}
}
}
// load version
function load_version() {
log("info","setting version to "+conf['constants']['version']);
$("#version").html(conf['constants']['version']);
}
// load the clock
function load_clock() {
clock_conf = conf["gui"]["clock"];
var date = new Date();
var h = date.getHours();
var meridiem = "";
if (clock_conf["24_hours"]) h = pad_number(h);
else {
if (h >= 12) meridiem = " PM";
else meridiem = " AM";
if (h > 12) h = h - 12;
else if (h === 0) h = 12;
}
var m = pad_number(date.getMinutes());
var s = pad_number(date.getSeconds());
var clock = h+":"+m;
if (clock_conf["show_seconds"]) clock = clock+":"+s;
clock = clock + meridiem;
$("#clock").html(clock);
}
// add a trailing 0 to a number
function pad_number(number) {
if (number < 10) return "0" + number;
return number
}
// load alerts
function load_alerts() {
log("info","loading alerts");
severity = ['alert','warning','info']
for (var i = 0; i < severity.length; i++) {
// retrieve the alerts
$.getJSON(hostname+"alerts/"+severity[i]+"/recent",function(severity) {
return function (data) {
var widget = "#notification_"+severity;
var widget_counter = "#notification_"+severity+"_count"
// empty the widget
$(widget).empty()
$(widget_counter).html("")
// set the counter
if (data.length > 0) $(widget_counter).html(data.length)
for (var j = 0; j < data.length; j++) {
// for each alert, add it to the list
$(widget).prepend('<li><a href="#alerts" title="'+data[j][1]+'">'+data[j][1]+'</a></li>')
}
};
}(severity[i]));
}
}
// load module
function load_module(module_id) {
log("info","loading module "+module_id);
var module = get_module(module_id);
if (module == null) return;
// set auto-refresh
var minutes = conf["gui"]["auto_refresh_min"]
if ("auto_refresh_min" in module) minutes = module["auto_refresh_min"]
auto_refresh(minutes*60);
// clean up the body
$("#body").empty();
// load data from the sensors of the current module
load_widgets(module_id);
}
// load data the widgets of the current module
function load_widgets(module_id) {
$("#body").append('<div id="widgets"></div>');
var module = get_module(module_id);
$("#title").text(lang(module["display_name"]));
if (module == null) return;
if (! ('widgets' in module)) return;
for (var i = 0; i < module["widgets"].length; i++) {
// for each row
var row = module_id+"_"+i;
$("#widgets").append('<div class="row" id="'+row+'">');
for (var j = 0; j < module["widgets"][i].length; j++) {
// for each widget
widget = module["widgets"][i][j];
log("info","["+module_id+"] loading widget "+widget["widget_id"]);
if (! widget["enabled"]) continue;
// add an empty widget template
tag = "#"+widget["widget_id"];
var offset = 0;
if ("offset" in widget) offset = widget["offset"]
$("#"+row).append(get_widget_template(tag,lang(widget["display_name"]),widget["size"],offset));
// load the widget
load_widget(tag,widget)
// configure the refresh button
$(tag+"_refresh").click(function(tag,widget) {
return function () {
// clear the widget and load it
$(tag).html("");
load_widget(tag,widget)
};
}(tag,widget));
// configure the maximize button
$(tag+"_popup").click(function(tag,widget) {
return function () {
// clear the widget and load it
$("#popup_body").html("");
$("#popup_title").html(lang(widget["display_name"]));
load_widget("#popup_body",widget)
$("#popup").modal()
};
}(tag,widget));
}
// end of the row
$("#"+row).append('</div>');
}
}
// load a given widget
function load_widget(tag,widget) {
if (! ('layout' in widget)) return;
// search for the "current_header" layout
var current_header_layout = get_current_header_layout(widget)
// add the current layout if requested
if (current_header_layout != null) add_current_header(tag,widget["layout"][current_header_layout])
else add_empty_header(tag)
// load each layout in the widget
for (var i = 0; i < widget["layout"].length; i++) {
layout = widget["layout"][i]
layout["current_header_layout"] = current_header_layout
if (layout["type"] == "sensor_group_summary") add_sensor_group_summary_chart(tag+"_body",layout)
else if (layout["type"] == "image") add_sensor_image(tag+"_body",layout)
else if (layout["type"] == "sensor_group_timeline") add_sensor_group_timeline_chart(tag+"_body",layout)
else if (layout["type"] == "chart_short_inverted" || layout["type"] == "chart_short") add_sensor_chart(tag+"_body",layout)
else if (layout["type"] == "alerts") add_alerts_widget(tag+"_body",layout)
else if (layout["type"] == "checkbox") add_html_control(tag+"_body",tag+"_body_"+i,layout)
else if (layout["type"] == "input") add_html_control(tag+"_body",tag+"_body_"+i,layout)
else if (layout["type"] == "separator") add_html_separator(tag+"_body",tag+"_body_"+i,layout)
else if (layout["type"] == "clock") add_clock(tag+"_body",tag+"_body_"+i,layout)
else if (layout["type"] == "current_measure") add_current_measure(tag+"_body",tag+"_body_"+i,layout)
else if (layout["type"] == "button") add_button(tag+"_body",tag+"_body_"+i,layout)
else if (layout["type"] == "calendar") add_calender_widget(tag+"_body",layout)
else if (layout["type"] == "configuration") add_configuration_widget(tag+"_body",layout)
else if (layout["type"] == "data") add_sensor_data(tag+"_body",layout)
else if (layout["type"] == "table") add_sensor_table(tag+"_body",layout)
else if (layout["type"] == "map") add_sensor_map(tag+"_body",layout)
else if (layout["type"] == "current_header") continue
else log("warning","unknown layout "+layout["type"])
}
}
/**
WIDGETS
**/
// add a sensor summary widget
function add_sensor_group_summary_chart(tag,layout) {
if ("group" in layout) {
sensors = get_group_string(layout["group"])
if (sensors == null) return;
}
else if ("sensors" in layout) {
sensors = []
for (var i = 0; i < layout["sensors"].length; i++) {
// for each sensor, retrieve it and add it to the array
var sensor_string = layout["sensors"][i]
var sensor = get_sensor_string(sensor_string)
if (sensor != null) sensors.push(sensor)
}
if (sensors.length == 0) return
}
else return
var options = $.extend(true,{}, conf["constants"]["charts"]["chart_sensor_group_summary"]);
if (layout["current_header_layout"] != null) options["chart"]["height"] = conf["constants"]["chart_short_height"]
$(tag).highcharts(options);
var chart = $(tag).highcharts();
// for each sensor
for (var i = 0; i < sensors.length; i++) {
var sensor = sensors[i];
var sensor_url = sensor["module_id"]+"/"+sensor["group_id"]+"/"+sensor["sensor_id"];
if ("exclude" in layout && layout["exclude"].indexOf(sensor_url.replaceAll("/",":")) > -1) continue
// skip flags
if (sensor['format'] == 'string') continue;
var is_flag = false;
if ("series" in sensor) {
for (var j = 0; j < sensor["series"].length; j++) {
if ("type" in sensor["series"][j] && sensor["series"][j]["type"] == "flags") is_flag = true;
}
if (is_flag) continue;
}
// add the sensor to the xAxis
chart['xAxis'][0]['categories'].push(lang(sensor["display_name"]));
// apply the suffix to the today's series
chart.series[1].update({"dataLabels":{"enabled": true,"format":'{y}'+conf['constants']['formats'][sensor["format"]]['suffix']}});
// add the point for yesterday's range
add_point(chart,sensor_url+"/yesterday/range",0,i);
// add the point for today's range
add_point(chart,sensor_url+"/today/range",1,i);
}
// make the chart adapting to the modal
$('#popup').on('show.bs.modal', function() {
$(tag).css('visibility', 'hidden');
});
$('#popup').on('shown.bs.modal', function() {
$(tag).css('visibility', 'initial');
chart.reflow();
});
}
// add a sensor timeline widget
function add_sensor_group_timeline_chart(tag,layout) {
if ("group" in layout) {
sensors = get_group_string(layout["group"])
if (sensors == null) return;
}
else if ("sensors" in layout) {
sensors = []
for (var i = 0; i < layout["sensors"].length; i++) {
// for each sensor, retrieve it and add it to the array
var sensor_string = layout["sensors"][i]
var sensor = get_sensor_string(sensor_string)
if (sensor != null) sensors.push(sensor)
}
if (sensors.length == 0) return
}
else return
var options = $.extend(true,{},conf["constants"]["charts"]["chart_"+layout["type"]+"_"+layout["timeframe"]]);
if (layout["current_header_layout"] != null) options["chart"]["height"] = conf["constants"]["chart_short_height"]
$(tag).highcharts('StockChart',options);
var chart = $(tag).highcharts();
// for each sensor
for (var i = 0; i < sensors.length; i++) {
var sensor = sensors[i];
var sensor_url = sensor["module_id"]+"/"+sensor["group_id"]+"/"+sensor["sensor_id"];
if (! ("series" in sensor)) continue;
// add each series, to the chart
for (var j = 0; j < sensor["series"].length; j++) {
series = sensor["series"][j]
if ("exclude" in layout && (layout["exclude"].indexOf(sensor_url.replaceAll("/",":")) > -1 || layout["exclude"].indexOf(sensor_url.replaceAll("/",":")+","+series["series_id"]) > -1)) continue
// ignore range series for realtime charts
if (layout["timeframe"] == "realtime" && series["series_id"] == "range") continue
// add the series to the chart
add_series(chart,sensor_url+"/"+layout["timeframe"]+"/"+series["series_id"],sensor,j);
}
}
// make the chart adapting to the modal
$('#popup').on('show.bs.modal', function() {
$(tag).css('visibility', 'hidden');
});
$('#popup').on('shown.bs.modal', function() {
$(tag).css('visibility', 'initial');
chart.reflow();
});
}
// add a generic sensor chart widget
function add_sensor_chart(tag,layout) {
if (!("sensor" in layout)) return
sensor = get_sensor_string(layout["sensor"])
if (sensor == null) return;
var sensor_url = sensor["module_id"]+"/"+sensor["group_id"]+"/"+sensor["sensor_id"];
// add the chart
var options = $.extend(true,{}, conf["constants"]["charts"][layout["type"]]);
if (layout["current_header_layout"] != null) options["chart"]["height"] = conf["constants"]["chart_short_height"]
// set min/max based on the format
if (sensor["format"] == "percentage") options["yAxis"]["max"] = 100;
$(tag).highcharts(options);
var chart = $(tag).highcharts();
// add each series to the chart
if (! ("series" in sensor)) return;
for (var i = 0; i < sensor["series"].length; i++) {
series = sensor["series"][i];
if ("exclude" in layout && (layout["exclude"].indexOf(sensor_url.replaceAll("/",":")) > -1 || layout["exclude"].indexOf(sensor_url.replaceAll("/",":")+","+series["series_id"]) > -1)) continue
add_series(chart,sensor_url+"/"+layout["timeframe"]+"/"+series["series_id"],sensor,i);
}
// make the chart adapting to the modal
$('#popup').on('show.bs.modal', function() {
$(tag).css('visibility', 'hidden');
});
$('#popup').on('shown.bs.modal', function() {
$(tag).css('visibility', 'initial');
chart.reflow();
});
}
// add an image widget
function add_sensor_image(tag,layout) {
if (!("sensor" in layout)) return
sensor = get_sensor_string(layout["sensor"])
if (sensor == null) return;
var sensor_url = sensor["module_id"]+"/"+sensor["group_id"]+"/"+sensor["sensor_id"];
// add the image to the layout
$(tag).html('<img class="img-responsive" src="'+sensor_url+'/current'+'?timestamp='+Date.now()+'" />');
}
// add a map widget
function add_sensor_map(tag,layout) {
var id = tag.replace("#","")
$(tag).html('<div id="'+id+'_map" style="width:100%; height:'+conf["gui"]["maps"]["size_x"]+'px;"></div>')
// load google maps api (lazy loading since we need the api_key from the conf)
var script = document.createElement('script');
script.src = "http://maps.google.com/maps/api/js?key="+conf["gui"]["maps"]["api_key"];
script.onload = function(tag,layout) {
return function () {
var script = document.createElement('script');
script.src = "web/gmaps/gmaps.min.js";
// load gmaps
script.onload = function(tag,layout) {
return function () {
//create the map
map = new GMaps({
div: tag+"_map",
lat: 0,
lng: 0,
mapType: conf["gui"]["maps"]["type"],
zoom: 2
});
// retrieve the sensors belonging to the group
if (!("group" in layout)) return
sensors = get_group_string(layout["group"])
if (sensors == null) return;
for (var i = 0; i < sensors.length; i++) {
// for each sensor
var sensor = sensors[i];
var sensor_url = sensor["module_id"]+"/"+sensor["group_id"]+"/"+sensor["sensor_id"];
// request the data
$.getJSON(sensor_url+"/"+layout["timeframe"]+"/avg",function(tag,layout,map) {
return function (data) {
if (data.length == 0) return
var waypoints = []
for (var i = 0; i < data.length; i++) {
// for each position of the sensor
var position = JSON.parse(data[i][1])
if (!("latitude" in position)) continue;
// add a marker
var options = {
lat: position["latitude"],
lng: position["longitude"],
label: position["label"],
icon: null,
infoWindow: { content: position["text"]}
}
// customize the layout of the marker when tracking position
if (layout["tracking"]) {
if (i == (data.length-1)) {
// this is the last position, if the position is not accurate, draw a circle around it
if (position["accuracy"] > 500) {
map.drawCircle({
lat: position["latitude"],
lng: position["longitude"],
radius: position["accuracy"],
strokeColor: '#BBD8E9',
strokeOpacity: 1,
strokeWeight: 3,
fillColor: '#BBD8E9',
fillOpacity: 0.6
});
}
} else {
// for intermediate positions, remote the label and use a small blue dot as icon
options["label"] = null;
options["icon"] = "https://maps.gstatic.com/intl/en_us/mapfiles/markers2/measle_blue.png";
}
}
// add the marker to the map
map.addMarker(options)
// keep track of the waypoint
waypoints.push({location:position["latitude"]+","+position["longitude"],stopover: true})
}
// auto zoom the map
map.fitZoom();
if (layout["tracking"]) {
// build the route
if (waypoints.length < 2) return;
// set origin and destination
var first = JSON.parse(data[0][1])
var last = JSON.parse(data[(data.length-1)][1])
// draw the route
map.drawRoute({
origin: [first["latitude"],first["longitude"]],
destination: [last["latitude"],last["longitude"]],
travelMode: 'driving',
strokeColor: get_color(),
strokeOpacity: 0.6,
strokeWeight: 6,
waypoints: waypoints
});
}
// auto zoom the map
map.fitZoom();
}; // end return function()
}(tag,layout,map));// end get json
} // end for each sensor
}; // end function ()
}(tag,layout); // onload gmaps.js
// append gmaps to head
document.head.appendChild(script);
}; // end function ()
}(tag,layout); // onload google maps
// append google api to head
document.head.appendChild(script);
}
// add a sensor table data widget
function add_sensor_table(tag,layout) {
tag = tag.replace("#","")
// define and add the table html
var table_html = '<table id="'+tag+'_table" class="table table-bordered table-striped"><thead><tr>';
var columns = layout["columns"].split(",")
for (var i = 0; i < columns.length; i++) {
table_html = table_html+"<th>"+columns[i]+"</th>";
}
table_html = table_html+ '</tr></thead><tbody></tbody></table>';
tag = "#"+tag
$(tag).append(table_html);
// define datatables options
var options = {
"responsive": true,
"dom": "Zlfrtip",
"fixedColumns": false,
"paging": true,
"lengthChange": false,
"searching": true,
"ordering": false,
"info": true,
"autoWidth": true,
};
// add the table
$(tag+"_table").DataTable(options);
var table = $(tag+"_table").DataTable();
// load the table
if (!("sensor" in layout)) return
sensor = get_sensor_string(layout["sensor"])
if (sensor == null) return;
var sensor_url = sensor["module_id"]+"/"+sensor["group_id"]+"/"+sensor["sensor_id"];
// add the image to the layout
$.getJSON(sensor_url+"/current",function(table) {
return function (data) {
if (data.length == 0) return
var lines = data[0].split("\n")
for (var i = 0; i < lines.length; i++) {
var line = lines[i]
var columns = line.split("|_|")
table.row.add(columns).draw();
}
};
}(table));
}
// add a sensor data widget
function add_sensor_data(tag,layout) {
if (!("sensor" in layout)) return
sensor = get_sensor_string(layout["sensor"])
if (sensor == null) return;
var sensor_url = sensor["module_id"]+"/"+sensor["group_id"]+"/"+sensor["sensor_id"];
// add the image to the layout
$.getJSON(sensor_url+"/current",function(tag) {
return function (data) {
data[0] = data[0].replaceAll("\n","<br>")
if (data.length > 0) $(tag).html('<div class="mailbox-read-message" align="left">'+data[0]+'</div>')
};
}(tag));
}
// add an alert widget
function add_alerts_widget(tag,layout) {
// define the alerts table
var table_html = '<table id="alerts_table" class="table table-bordered table-striped">\
<thead>\
<tr>\
<th>Severity</th>\
<th>Time</th>\
<th>Message</th>\
</tr>\
</thead>\
<tbody></tbody>\
</table>';
// define datatables options
var options = {
"responsive": true,
"dom": "Zlfrtip",
"paging": true,
"lengthChange": false,
"searching": true,
"ordering": true,
"info": true,
"autoWidth": true,
"columnDefs": [
{
"targets": 0,
"width": "10%",
"render": function ( data, type, row ) {
if (data == "alert") { icon = "ban"; color = "#dd4b39" }
else if (data == "warning") { icon = "warning"; color = "#f39c12" }
else if (data == "info") { icon = "info"; color = "#0073b7" }
return '<i class="icon fa fa-'+icon+'" style="color:'+color+'"></i>'
},
"className": "dt-center",
},
{
"targets": 1,
"width": "10%",
"className": "dt-center",
},
{
"targets": 2,
"width": "80%",
},
],
};
// create the widget and the table
$(tag).append(table_html);
$("#alerts_table").DataTable(options);
var table = $("#alerts_table").DataTable();
// add alerts to the table
var severity = ['alert','warning','info']
for (var i = 0; i < severity.length; i++) {
// retrieve the alerts
$.getJSON(hostname+"alerts/"+severity[i]+"/history",function(severity) {
return function (data) {
for (var j = 0; j < data.length; j++) {
// for each alert, add it to the table
table.row.add([severity,data[j][0],data[j][1]]).draw(false);
}
// reorder the data
table.order( [ 1, 'desc' ] ).draw();
};
}(severity[i]));
}
}
// add a configuration widget
function add_configuration_widget(tag,layout) {
var editor_id = "json_editor"
var buttons_html = '\
<div class="row">\
<div class="col-md-12">\
<button id="save" class="btn btn-default">Save</button>\
<button id="restart_service" class="btn btn-primary">Restart Service</button>\
</div>\
</div>'
// add the buttons and the editor
$(tag).append(buttons_html)
$(tag).append('<div class="row"><div id="'+editor_id+'" class="col-md-12" style="text-align:left;"></div></div>');
// configure the editor
var options = {
startval: JSON.parse(conf["config_json"]),
schema: JSON.parse(conf["constants"]["config_schema_json"]),
}
JSONEditor.defaults.theme = 'bootstrap3';
JSONEditor.defaults.iconlib = 'fontawesome4';
JSONEditor.defaults.editors.object.options.collapsed = true;
// add it
var editor = new JSONEditor($("#"+editor_id)[0],options)
// configure the save button
$("#save").unbind().on('click',function() {
var errors = editor.validate();
if (errors.length) {
notify("danger","Invalid configuration. See the console for the errors")
console.log(errors)
}
else {
$.post(hostname+"/save_config", {"configuration": JSON.stringify(editor.getValue())}, function (data) {
if (data != '"OK"')
notify("danger","Unable to save the configuration")
else notify("success","The configuration has been saved. Restart the service to apply the changes")
});
}
});
// configure the restart button
$("#restart_service").unbind().on('click',function() {
$.get(hostname+"/restart")
var notify_object = $.notify('<strong>Restarting the service,</strong> please wait...', {
allow_dismiss: false,
showProgressbar: true,
});
auto_refresh(null);
setTimeout(function() {
notify_object.update({'type': 'success', 'message': '<strong>Success</strong>, reloading...'});
location.reload();
}, 5500);
});
}
// add a custom form widget
function add_form_widget(tag,widget) {
$(tag).html("")
$(tag).append('<div class="container">')
for (var i = 0; i < widget["layout"].length; i++) add_html_control(tag,tag+"_"+i,widget["layout"][i])
$(tag).append('</div>')
}
// add a html separator
function add_html_separator(body,tag,layout) {
var style = "";
if ("color" in layout) style = style + "border-color: "+layout["color"]+";";
if ("height" in layout) style = style + "border-width: "+layout["height"]+"px;";
$(body).append('<hr style="'+style+'"></hr>');
}
// add a clock
function add_clock(body,tag,layout) {
tag = tag.replace("#","");
// add the clock placeholder
var clock_html = '<div class="text-center" id="'+tag+'_clock"></div>';
$(body).append(clock_html);
// Create the chart
var now = getNow();
Highcharts.chart(tag+"_clock", {
chart: {
type: 'gauge',
plotBackgroundColor: null,
plotBackgroundImage: null,
plotBorderWidth: 0,
plotShadow: false,
height: 200
},
credits: { enabled: false },
title: { text: '' },
pane: {
background: [
{ },
{
backgroundColor: Highcharts.svg ? {
radialGradient: {
cx: 0.5,
cy: -0.4,
r: 1.9
},
stops: [
[0.5, 'rgba(255, 255, 255, 0.2)'],
[0.5, 'rgba(200, 200, 200, 0.2)']
]