Changeset 2cf9b0b for src/webapp


Ignore:
Timestamp:
Jul 21, 2016, 8:27:37 AM (10 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
0.5, app-cordova, debian/bullseye, debian/jessie, master
Children:
d9af413, fefafdf
Parents:
1d2acb7 (diff), 09adf3e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Pulled upstream

Merge branch 'master' of ​https://svn.falaba.de/gnuboat

Location:
src/webapp
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/webapp/webclient/css/main.css

    r1d2acb7 r2cf9b0b  
    1818body {
    1919        margin: 1em;
     20        width: 58.3mm;
    2021}
    2122
    … …  
    3536#display {
    3637        background-color: #E6E6E6;
    37         width: 58.3mm;
     38        width: 100%;
    3839        height: 38.2mm;
    3940        font-size: 12pt;
    … …  
    9495
    9596#map {
    96         width: 58.3mm;
     97        width: 100%;
    9798        height: 76mm;
    9899        border: 1px solid black;
    … …  
    111112form p input {
    112113        border: 1px solid #ACDFAC;
    113         height: 2em;
    114         width: 58.3mm;
     114        height: 3em;
     115        width: 100%;
    115116}
    116117
    117118.formButtons {
    118         text-align: right;
    119         margin-right: 5em;
    120         margin-top: 1em;
     119        text-align: center;
     120        margin-top: 2em;
    121121}
    122122
    123123.button {
    124124        border: 0;
    125         height: 2em;
    126         width: 10em;
     125        height: 3em;
     126        width: 100%;
    127127        background-repeat: no-repeat;
    128128        background-position: 0.5em 0.25em;
    … …  
    133133
    134134}
     135
     136#shutdown {
     137        width: 100%;
     138        margin-top: 3em;
     139}
     140
     141#shutdown button {
     142        background-color: #8C1C00;
     143        color: white;
     144        font-weight: bold;
     145        font-size: 24pt;
     146        width: 100%;
     147        height: 3em;
     148}
  • src/webapp/webclient/javascript/main.js

    r1d2acb7 r2cf9b0b  
    102102}
    103103
     104function shutdown(){
     105        $.getJSON("../webservice/?request=shutdown", function(data){
     106                var shutdownTime = data["shutdownstart"];
     107                var shutdownDate = Date.parse(shutdownTime);
     108                var currentDate = new Date();
     109                var shutdownHint = "Shutting down in "+ Math.floor((shutdownDate - currentDate)/1000) +"s at "+ shutdownTime.toLocaleString();
     110                if(shutdownTime == -1){
     111                        shutdownHint = "Failed to initiate shutdown!";
     112                }
     113                $("#shutdownMessage").text(shutdownHint);
     114        });
     115}
     116
    104117$(document).ready(function() {
    105118        displayDataGet();
    … …  
    107120       
    108121        $.getJSON("../webservice/tileserver.php?/map.json", mapSetup);
     122       
     123        $("#shutdownButton").click(shutdown);
    109124});
  • src/webapp/webclient/root/index.php

    r1d2acb7 r2cf9b0b  
    100100                </div>
    101101        </form>
     102        <div id="shutdown">
     103                <p id="shutdownMessage"/>
     104                <form>
     105                        <button type="button" id="shutdownButton">SHUTDOWN</button>
     106                </form>
     107        </div>
    102108<?php
    103109require_once("inc/footer.php");
  • src/webapp/webservice/index.php

    r1d2acb7 r2cf9b0b  
    2121$dbFile = $config->databaseFile();
    2222
     23define("REQUEST_DATA", "data");
     24define("REQUEST_SHUTDOWN", "shutdown");
     25
     26
    2327// configure roundings per value (key) and precision (value)
    2428$configRound = array
    … …  
    3236);
    3337
     38function addRrdData($interval, $period, &$result, &$lastTime){
     39        global $dbFile;
     40        global $debug;
     41        global $configRound;
     42
     43        $data = rrd_fetch($dbFile, array( "AVERAGE", "--resolution", $interval, "--start", "-". $period, "--end", "start+". $period));
     44        if($data === false){
     45                echo json_encode($result);
     46                $message = "Failure reading rrd database ". $dbFile .": ". rrd_error();
     47                if($debug > 0)
     48                        echo $message;
     49                else
     50                        error_log($message);
     51        }
     52
     53        if($debug > 2){
     54                echo "<pre>";
     55                var_dump($data);
     56                echo "</pre>";
     57        }
     58
     59        $data = $data["data"];
     60
     61        // transform them into json format
     62        $i = 0;
     63        $lastTime = -1;
     64        $keys = array_keys($data);
     65        if(count($keys) < 0 ){
     66                error_log("No keys in fetched rrd data from ". $dbFile);
     67                echo json_encode("");
     68                exit;
     69        }
     70        if($debug > 0){
     71                echo "<p>Variables: ". count($keys) ."; Timeframes: ". count($data[$keys[0]]) ."</p>\n";
     72        }
     73        for($i = 0; $i < count($data[$keys[0]]); $i++){
     74                $time = array_keys($data[$keys[0]])[$i];
     75                $allValid = true;
     76                $tmp = array();
     77                foreach($keys as $key){
     78                        if($key == "gpsfix"){
     79                                switch($data[$key][$time]){
     80                                        case 1:
     81                                                $tmp[$key] = "2D";
     82                                                break;
     83                                        case 2:
     84                                                $tmp[$key] = "3D";
     85                                                break;
     86                                        default:
     87                                                $tmp[$key] = "-";
     88                                }
     89                        }
     90                        else{
     91                                $tmp[$key] = $data[$key][$time];
     92                                if(!is_numeric($tmp[$key]) || is_nan($tmp[$key])){
     93                                        $allValid = false;
     94                                }
     95                                elseif(array_key_exists($key, $configRound) && is_integer($configRound[$key]))
     96                                        $tmp[$key] = round($tmp[$key], $configRound[$key]);
     97                        }
     98                }
     99                // only add the timeframe to the track, if the values are valid and we had a gps fix at that time
     100                if($allValid && $tmp["gpsfix"] != "-"){
     101                        echo "want to add ". $time ."<br/>\n";
     102                        if(!array_key_exists($time, $result["track"])){
     103                                $result["track"][$time] = $tmp;
     104                        }
     105                        $lastTime = $time;
     106                }
     107                else{
     108                        if($debug > 1){
     109                                echo "Failed <pre>";
     110                                var_dump($tmp);
     111                                echo "</pre>\n";
     112                        }
     113                }
     114        }
     115
     116        ksort($result["track"]);
     117}
     118
    34119$debug = 0;
    35120if(array_key_exists("debug", $_GET))
    36121        $debug = $_GET["debug"];
    37122
     123$request = REQUEST_DATA;
     124if(array_key_exists("request", $_GET)){
     125        $request = $_GET["request"];
     126}
     127
    38128if($debug == 0)
    39129        header('Content-Type: application/json');
    40130
    41 $result["lastvalid"] = array();
    42 $result["track"] = array();
    43 
    44 // Fetch entries of the last 12hours
    45 $data = rrd_fetch($dbFile, array( "AVERAGE", "--start", "-12h"));
    46 if($data === false){
    47         echo json_encode($result);
    48         $message = "Could not open rrd database ". $dbFile;
    49         if($debug > 0)
    50                 echo $message;
    51         else
     131$result = array();
     132if($request == REQUEST_SHUTDOWN){
     133        $handle = @fopen("/var/spool/gnuboat/shutdown.request", "w");
     134        if($handle === false){
     135                $message = "Could not create file to indicate shutdown to the daemon (Timezone: ". date_default_timezone_get() .")";
     136                if($debug > 0)
     137                        echo $message;
    52138                error_log($message);
    53         exit;
    54 }
    55 
    56 if($debug > 2){
    57         echo "<pre>";
    58         var_dump($data);
    59         echo "</pre>";
    60 }
    61 
    62 $data = $data["data"];
    63 
    64 // transform them into json format
    65 $i = 0;
    66 $lastTime = -1;
    67 $keys = array_keys($data);
    68 if(count($keys) < 0 ){
    69         error_log("No keys in fetched rrd data from ". $dbFile);
    70         echo json_encode("");
    71         exit;
    72 }
    73 for($i = 0; $i < count($data[$keys[0]]); $i++){
    74         $time = array_keys($data[$keys[0]])[$i];
    75         $allValid = true;
    76         $tmp = array();
    77         foreach($keys as $key){
    78                 if($key == "gpsfix"){
    79                         switch($data[$key][$time]){
    80                                 case 1:
    81                                         $tmp[$key] = "2D";
    82                                         break;
    83                                 case 2:
    84                                         $tmp[$key] = "3D";
    85                                         break;
    86                                 default:
    87                                         $tmp[$key] = "-";
    88                         }
    89                 }
    90                 else{
    91                         $tmp[$key] = $data[$key][$time];
    92                         if(!is_numeric($tmp[$key]) || is_nan($tmp[$key])){
    93                                 $allValid = false;
    94                         }
    95                         elseif(array_key_exists($key, $configRound) && is_integer($configRound[$key]))
    96                                 $tmp[$key] = round($tmp[$key], $configRound[$key]);
    97                 }
    98         }
    99         // only add the timeframe to the track, if the values are valid and we had a gps fix at that time
    100         if($allValid && $tmp["gpsfix"] != "-"){
    101                 $result["track"][$time] = $tmp;
    102                 $lastTime = $time;
     139                $result["shutdownstart"] = -1;
    103140        }
    104141        else{
    105                 if($debug > 0){
    106                         echo "Failed <pre>";
    107                         var_dump($tmp);
    108                         echo "</pre>\n";
    109                 }
     142                $shutdownTime = new DateTime('NOW');
     143                $shutdownTime->modify("+15 seconds");
     144                fwrite($handle, $shutdownTime->format(DateTime::ISO8601));
     145                $result["shutdownstart"] = $shutdownTime->format(DateTime::ISO8601);
    110146        }
    111147}
    112 if($lastTime > -1){
    113         $result["lastvalid"] = $result["track"][$lastTime];
     148elseif($request == REQUEST_DATA){
     149        $result["lastvalid"] = array();
     150        $result["track"] = array();
     151
     152        if(!file_exists($dbFile)){
     153                echo json_encode("");
     154                if($debug > 0)
     155                        echo "Database file ". $dbFile ." does not exist!";
     156                error_log("Database file ". $dbFile ." does not exist");
     157                exit;
     158        }
     159        // Fetch entries of the last 30 seconds
     160        addRrdData("5s", "30s", $result, $lastTime);
     161        if($lastTime > -1){
     162                $result["lastvalid"] = $result["track"][$lastTime];
     163        }
     164        addRrdData("15s", "5minutes", $result, $lastTime);
     165        addRrdData("30s", "12h", $result, $lastTime);
    114166}
    115167
Note: See TracChangeset for help on using the changeset viewer.