Changeset 82eff76


Ignore:
Timestamp:
May 4, 2020, 8:34:54 PM (7 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
debian/bullseye, master
Children:
ac05b52
Parents:
9b8dd22
Message:

Moved webclient for gnuboat device from src/webapp/webclient to deviceservice_impl. And improved it

Location:
src/gnuboat
Files:
4 added
33 deleted
3 edited
1 moved

Legend:

Unmodified
Added
Removed
  • src/gnuboat/common/js/GnuBoat.js

    r9b8dd22 r82eff76  
    11/*
    22
    3     Copyright (C) 2016 - 2018 EngSaS - Langenbach. All rights reserved.
     3    Copyright (C) 2016 - 2020 EngSaS - Langenbach. All rights reserved.
    44
    55    This library is free software; you can redistribute it and/or
    … …  
    3131        $(text).appendTo("#message");
    3232        location.hash = "#messages";
     33        $('#message').show();
     34        setTimeout(function(){ $('#message').hide(); }, 60000);
    3335}
    3436
  • src/gnuboat/deviceservice_impl/static/css/GnuBoat.Webclient.css

    r9b8dd22 r82eff76  
    11/*
    2     Copyright (C) 2016 - 2018 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
     2    Copyright (C) 2016 - 2020 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
    33
    44    This program is free software: you can redistribute it and/or modify
    … …  
    1616*/
    1717
    18 @import url("GnuBoat.Colors.css");
     18@import url("/client/common/css/GnuBoat.Colors.css");
    1919
    2020.l-box {
    … …  
    2929#display {
    3030        background-color: var(--gnuboat-primary-light);
    31         height: 9em;
    32         min-width: 14em;
    33         font-size: 12pt;
     31        font-size: 1.5em;
    3432        font-weight: normal;
    35         padding: 0mm;
    36         position:relative;
     33        padding-left: 0.5em;
     34        padding-right: 0.5em;
     35        padding-top: 0.25em;
     36        padding-bottom: 0.25em;
    3737        line-height: 1.5em;
    3838        color: black;
    3939}
    4040
     41.display-row:after {
     42        content: "";
     43        display: table;
     44        clear: both;
     45}
     46
     47.display-1-2 {
     48        flex: 50%;
     49        min-width: 50%;
     50        float: left;
     51}
     52
     53.display-1-4 {
     54        flex: 25%;
     55        min-width: 25%;
     56        float: left;
     57}
     58
    4159#display h2 {
    42         font-size: 12pt;
     60        font-size: 1em;
    4361        font-weight: normal;
    4462        margin: 0em;
    … …  
    4765
    4866#display span {
    49         font-size: 24pt;
     67        font-size: 1em;
    5068        font-weight: bold;
    5169        margin: 0em;
    … …  
    5371}
    5472
    55 #display #speedthroughwater {
    56         position: absolute;
    57         top: 0.5em;
    58         left: 0.5em;
    59 }
    60 
    6173#display .important {
    62         font-size: 40pt;
     74        font-size: 2em;
    6375        line-height: 0.6em;
    6476}
    6577
    66 #display #speedoverground {
    67         position: absolute;
    68         top:  0.5em;
    69         left: 7em;
    70 }
    71 
    72 #display #waterdepth {
    73         position: absolute;
    74         top: 5em;
    75         left: 0.5em;
    76 }
    77 
    78 #display #watertemperature {
    79         position: absolute;
    80         top: 5em;
    81         left: 7em;
    82 }
    83 
    84 #display #gpsfix {
    85         position: absolute;
    86         top: 5em;
    87         left: 11em;
     78#mapserviceStatusIcon {
     79        height: 1.5em;
     80        width: auto;
    8881}
    8982
    … …  
    10598        width: 100%;
    10699        margin-top: 3em;
     100}
     101
     102.button-remove {
     103  background: var(--gnuboat-warning);
     104  color: white;
     105}
     106
     107.button-add {
     108  background: var(--gnuboat-green-dark);
     109  color: white;
    107110}
    108111
    … …  
    134137        text-align: right;
    135138}
     139
     140.button-gnuboat {
     141        color: white;
     142        background: var(--gnuboat-turquois-dark);
     143}
     144
     145#mapFileInputDiv {
     146    position: relative;
     147    overflow: hidden;
     148    margin: 10px;
     149}
     150
     151#mapFileInputDiv input{
     152        position: absolute;
     153    top: 0;
     154    right: 0;
     155    margin: 0;
     156    padding: 0;
     157    font-size: 20px;
     158    cursor: pointer;
     159    opacity: 0;
     160    filter: alpha(opacity=0);
     161}
  • src/gnuboat/deviceservice_impl/static/index.html

    r9b8dd22 r82eff76  
    11<!--
    2     Copyright (C) 2016 - 2018 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
     2    Copyright (C) 2016 - 2020 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
    33
    44    This program is free software: you can redistribute it and/or modify
    … …  
    2020                <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    2121                <meta name="viewport" content="width=device-width, initial-scale=1.0">
    22                 <link rel="icon" type="image/png" href="resources/gnuboat-256-256-transparent.png"/>
     22                <link rel="icon" type="image/png" href="/client/common/icon/gnuboat-256-256-transparent.png"/>
    2323                <title>GNUBoat Web Application</title>
    2424               
    25                 <link rel="stylesheet" href="lib/css/pure/pure-min.css" type="text/css"/>
     25                <link rel="stylesheet" href="/client/common/lib/css/pure/pure-min.css" type="text/css"/>
    2626                <!--[if lte IE 8]>
    2727                <link rel="stylesheet" content="text/css" href="lib/css/pure/grids-responsive-old-ie-min.css">
    2828                <![endif]-->
    2929                <!--[if gt IE 8]><!-->
    30                 <link rel="stylesheet" content="text/css" href="lib/css/pure/grids-responsive-min.css">
     30                <link rel="stylesheet" content="text/css" href="/client/common/lib/css/pure/grids-responsive-min.css">
    3131                <!--<![endif]-->
    32                 <link rel="stylesheet" content="text/css" href="lib/css/leaflet/leaflet.css"/>
     32                <link rel="stylesheet" href="/client/common/lib/js/jquery-ui/jquery-ui.min.css" type="text/css"/>
     33                <link rel="stylesheet" content="text/css" href="/client/common/lib/css/leaflet/leaflet.css"/>
    3334               
    34                 <script src="lib/js/jquery-3.2.1.min.js" type="text/javascript"></script>
    35                 <script src="lib/js/jquery.validate.min.js" type="text/javascript"></script>
    36                 <script src="lib/js/additional-methods.min.js" type="text/javascript"></script>
    37                 <script src="lib/js/leaflet.js" type="text/javascript"></script>
    38                 <script src="lib/js/leaflet.hotline.min.js" type="text/javascript"></script>
    39                 <script src="lib/js/three.min.js"></script>
    40                 <script src="lib/js/three.OrbitControls.js"></script>
     35                <script src="/client/common/lib/js/jquery-3.2.1.min.js" type="text/javascript"></script>
     36                <script src="/client/common/lib/js/jquery.validate.min.js" type="text/javascript"></script>
     37                <script src="/client/common/lib/js/jquery-ui/jquery-ui.min.js" type="text/javascript"></script>
     38                <script src="/client/common/lib/js/additional-methods.min.js" type="text/javascript"></script>
     39                <script src="/client/common/lib/js/leaflet.js" type="text/javascript"></script>
     40                <script src="/client/common/lib/js/leaflet.hotline.min.js" type="text/javascript"></script>
     41                <script src="/client/common/lib/js/three.min.js"></script>
     42                <script src="/client/common/lib/js/three.OrbitControls.js"></script>
    4143               
    42                 <link rel="stylesheet" href="css/GnuBoat.css" type="text/css"/>
    43                 <link rel="stylesheet" href="css/side-menu.css" type="text/css"/>
    44                 <script language="javascript" src="js/GnuBoat.js" type="text/javascript"></script>
    45                 <script language="javascript" src="js/GnuBoat.Webclient.js" type="text/javascript"></script>
     44                <link rel="stylesheet" href="/client/css/GnuBoat.Webclient.css" type="text/css"/>
     45                <link rel="stylesheet" href="/client/common/css/side-menu.css" type="text/css"/>
     46                <script language="javascript" src="/client/common/js/GnuBoat.js" type="text/javascript"></script>
     47                <script language="javascript" src="/client/js/GnuBoat.Webclient.js" type="text/javascript"></script>
    4648                <script language="javascript" type="text/javascript">
    4749                        var active = 'active';
    … …  
    7476
    7577                                GnuBoat.Webclient.initialize();
    76                                 GnuBoat.Webclient.setServer("../webservice");
     78                                GnuBoat.Webclient.setServer("/deviceservice/v1");
    7779                                GnuBoat.Webclient.start();
     80                               
     81                                // To workaround the not stylable browse button of input type file
     82                                document.getElementById("mapFileInput").onchange = function () {
     83                                        document.getElementById("mapFileInputDummy").value = this.value;
     84                                };
    7885                        });
    7986                </script>
    … …  
    97104                        <div id="main">
    98105                                <div class="header">
    99                                         <h1><img src="resources/gnuboat-256-256-transparent.png" />Boat</h1>
     106                                        <h1><img src="/client/common/icon/gnuboat-256-256-transparent.png" />Boat</h1>
    100107                                </div>
    101108                                <div class="content">
    … …  
    105112                                                                <div id="display">
    106113                                                                        <a name="display"></a>
    107                                                                         <div id="speedthroughwater">
    108                                                                                 <h2>STW</h2>
    109                                                                                 <span id="value" class="important">-</span> kts
     114                                                                        <div class="display-row">
     115                                                                                <div id="speedThroughWater" class="display-1-2">
     116                                                                                        <h2>STW</h2>
     117                                                                                        <span id="value" class="important">-</span> kts
     118                                                                                </div>
     119                                                                                <div id="speedOverGround" class="display-1-2">
     120                                                                                        <h2>SOG</h2>
     121                                                                                        <span id="value" class="important">-</span> kts
     122                                                                                </div>
    110123                                                                        </div>
    111                                                                         <div id="speedoverground">
    112                                                                                 <h2>SOG</h2>
    113                                                                                 <span id="value" class="important">-</span> kts
    114                                                                         </div>
    115                                                                         <div id="waterdepth">
    116                                                                                 <h2>Depth</h2>
    117                                                                                 <span id="value">-</span> m
    118                                                                         </div>
    119                                                                         <div id="watertemperature">
    120                                                                                 <h2>Water</h2>
    121                                                                                 <span id="value">-</span>&#176;C
    122                                                                         </div>
    123                                                                         <div id="gpsfix">
    124                                                                                 <h2>Fix</h2>
    125                                                                                 <span id="value">-</span>
     124                                                                        <div class="display-row">
     125                                                                                <div id="waterDepth" class="display-1-4">
     126                                                                                        <h2>Depth</h2>
     127                                                                                        <span id="value">-</span> m
     128                                                                                </div>
     129                                                                                <div id="waterTemperature" class="display-1-4">
     130                                                                                        <h2>Water</h2>
     131                                                                                        <span id="value">-</span>&#176;C
     132                                                                                </div>
     133                                                                                <div id="gpsFix" class="display-1-4">
     134                                                                                        <h2>Fix</h2>
     135                                                                                        <span id="value">-</span>
     136                                                                                </div>
     137                                                                                <div id="mapserviceStatus" class="display-1-4">
     138                                                                                        <h2>Remote</h2>
     139                                                                                        <img id="mapserviceStatusIcon" src='/client/resources/mapservice-offline.svg' title='No connection to the remote Mapservice'>
     140                                                                                </div>
    126141                                                                        </div>
    127142                                                                </div>
    … …  
    129144                                                </div>
    130145                                                <div class="pure-u-1 pure-u-md-1-2 pure-u-lg-1-2">
    131                                                         <div id="shutdown" class="l-box">
     146                                                        <div id="messageBox" class="l-box">
    132147                                                                <a name="messages"></a>
    133                                                                 <p id="message"/>
    134 <!--                                                            <button type="button" class="pure-button shutdown-button" id="shutdownButton">SHUTDOWN</button> -->
     148                                                                <div id="message"></div>
    135149                                                        </div>
    136150                                                </div>
    … …  
    163177                                                        <legend>Map Upload</legend>
    164178                                                        <div class="pure-control-group">
    165                                                                 <label for="mapName">Map Name:</label>
    166                                                                 <input id="mapName" type="text" name="mapName" value="" placeholder="Name of your map" required>
    167                                                         </div>
    168                                                         <div class="pure-control-group">
    169179                                                                <label for="mapFileInput">MBTiles File:</label>
    170                                                                 <input id="mapFileInput" type="file" name="mapFile" value="" placeholder="Path to MAPTile file" required><progress id="mapTileUploadProgress"></progress>
    171                                                         </div>
    172                                                         <input type="submit" class="pure-button pure-button-primary" name="mapUploadButton" value="Upload"/>
     180                                                                <!-- To workaround the not stylable browse button of input type file -->
     181                                                                <input id="mapFileInputDummy" placeholder="Choose Map" disabled="disabled">
     182                                                                <div id="mapFileInputDiv" class="pure-button button-gnuboat">
     183                                                                        <span>Browse</span>
     184                                                                        <input id="mapFileInput" name="mapFile" type="file" class="upload">
     185                                                                </div>
     186                                                                <!-- End of workaround the not stylable browse button of input type file -->
     187                                                                <progress id="mapTileUploadProgress"></progress>
     188                                                                <p>Make sure the map has a name set!</p>
     189                                                                <input id='mapUploadButton' type="submit" class="pure-button button-add" name="mapUploadButton" value="Upload"/>
     190                                                        </div>
    173191                                                </fieldset>
    174192                                        </form>
    … …  
    189207                                        <div>
    190208                                                <a name="logfiles"></a>
    191                                                 <form id="logfilesForm" class="pure-form" method="POST" action="../webservice/?request=logfiles"></form>
     209                                                <p id='logfilesNone'></p>
     210                                                <form id="logfilesForm" class="pure-form pure-form-stacked">
     211                                                        <fieldset id='logfilesFieldset'>
     212                                                                <select id='logfilesSelect' class='pure-input-1' multiple></select>
     213                                                                <div class="pure-controls">
     214                                                                        <input type="button" class='pure-button button-add' id='logfilesUploadStart' value='Upload'/>
     215                                                                        <input type="button" class='pure-button button-gnuboat' id='logfilesDownload' value='Download'/>
     216                                                                </div>
     217                                                        </fieldset>
     218                                                </form>
     219                                                <h2 id='logfilesUploadMessage'></h2>
     220                                                <form id='logfilesUploadForm' class='pure-form pure-form-aligned'>
     221                                                        <fieldset id='logfilesUploadFieldset'>
     222                                                                <input type='hidden' id='logfilesUploadLogfile' name='logfilesUploadLogfile' value=''>
     223                                                                <div class="pure-control-group">
     224                                                                        <label for='logfilesUploadWater'>Water:</label>
     225                                                                        <input type='text' name='water' id='logfilesUploadWater' placeholder='Start typing to query for waters'>
     226                                                                        <span class="pure-form-message-inline">Required</span>
     227                                                                </div>
     228                                                                <div class="pure-control-group">
     229                                                                        <label for='logfilesUploadGauge'>Gauge:</label>
     230                                                                        <input type='text' name='gauge' id='logfilesUploadGauge' placeholder='Start typing to query for gauges'>
     231                                                                        <span class="pure-form-message-inline">Required</span>
     232                                                                </div>
     233                                                                <div class="pure-control-group">
     234                                                                        <label for='logfilesUploadGaugeHeight'>Gauge Height:</label>
     235                                                                        <input type='number' name='gaugeHeight' id='logfilesUploadGaugeHeight' placeholder='Relative to reference gauge level'>
     236                                                                        <span id='logfilesUploadGaugeHeightReference' class="pure-form-message-inline"></span>
     237                                                                        <span class="pure-form-message-inline">Required</span>
     238                                                                </div>
     239                                                                <div class="pure-controls">
     240                                                                        <label for='logfilesUploadDelete' class='pure-checkbox'>
     241                                                                                <input type='checkbox' name='delete' id='logfilesUploadDelete' checked>
     242                                                                                Delete logfile after successfull uploading
     243                                                                        </label>
     244                                                                </div>
     245                                                                <div class="pure-control-group">
     246                                                                        <label for='logfilesUploadComment'>Comment:</label>
     247                                                                        <textarea name='comment' id='logfilesUploadGauge' placeholder='Your optional comment'></textarea>
     248                                                                </div>
     249                                                                <div class="pure-controls">
     250                                                                        <input type="submit" class='pure-button button-add' id='logfilesUploadUpload' value='Upload'/>
     251                                                                        <input type="button" class='pure-button button-remove' id='logfilesUploadCancel' value='Cancel'/>
     252                                                                </div>
     253                                                        </fieldset>
     254                                                </form>
    192255                                        </div>
    193256                                       
  • src/gnuboat/deviceservice_impl/static/js/GnuBoat.Webclient.js

    r9b8dd22 r82eff76  
    11/*
    22
    3     Copyright (C) 2016 - 2018 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
     3    Copyright (C) 2016 - 2020 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
    44
    55    This library is free software; you can redistribute it and/or
    … …  
    4646{
    4747        if(GnuBoat.Webclient.private.serverBaseUrl == null){
    48                 GnuBoat.displayMessage('<span class="error">No server set/found</span>');
     48                GnuBoat.displayMessage('<p class="error">No server set/found</p>');
    4949                return;
    5050        }
    5151        var gnuboatApi = GnuBoat.Webclient.private.serverBaseUrl;
    52         $.getJSON(gnuboatApi, GnuBoat.Webclient.private.displayDataSet);
     52        $.getJSON(gnuboatApi +'instrumentdata', GnuBoat.Webclient.private.displayDataSet).fail(GnuBoat.Webclient.private.displayHttpError);
    5353};
    5454
    55 /**
    56  * @brief Gets the metadata of all maps, provided by the tileserver
    57  */
    58 GnuBoat.Webclient.getMapInfos = function()
    59 {
     55
     56/**
     57 * @brief Fetches the track to display on the map
     58 */
     59GnuBoat.Webclient.trackGet = function()
     60{
     61        if(!GnuBoat.Webclient.private.mapModusLive || GnuBoat.Webclient.private.map == null)
     62                return;
    6063        if(GnuBoat.Webclient.private.serverBaseUrl == null){
    6164                GnuBoat.displayMessage('<span class="error">No server set/found</span>');
    6265                return;
    6366        }
    64         $.getJSON(GnuBoat.Webclient.private.serverBaseUrl +"tileserver.php?/index.json", GnuBoat.Webclient.private.mapInfos);
     67        var gnuboatApi = GnuBoat.Webclient.private.serverBaseUrl;
     68        $.getJSON(gnuboatApi +'track').done(GnuBoat.Webclient.private.trackSet).fail(GnuBoat.Webclient.private.displayHttpError);
    6569};
    6670
    6771/**
    68  * @brief Fetches the list of available logfiles and adds them to the log file download form
    69  */
    70 GnuBoat.Webclient.logfilesLoad = function()
     72 * @brief Gets the metadata of all maps, provided by the tileserver
     73 */
     74GnuBoat.Webclient.getMapInfos = function()
    7175{
    7276        if(GnuBoat.Webclient.private.serverBaseUrl == null){
    … …  
    7478                return;
    7579        }
    76         $("#logfilesForm").empty();
    77         $.getJSON(GnuBoat.Webclient.private.serverBaseUrl +"?request=logfiles", function(data){
     80        $.getJSON(GnuBoat.Webclient.private.serverBaseUrl +"maps", GnuBoat.Webclient.private.mapInfos);
     81};
     82
     83/**
     84 * @brief Fetches the list of available logfiles and adds them to the log file download form
     85 */
     86GnuBoat.Webclient.logfilesLoad = function()
     87{
     88        if(GnuBoat.Webclient.private.serverBaseUrl == null){
     89                GnuBoat.displayMessage('<span class="error">No server set/found</span>');
     90                return;
     91        }
     92       
     93        $('#logfilesNone').empty();
     94        $('#logfilesSelect').empty();
     95        $('#logfilesNone').hide();
     96        $('#logfilesSelect').hide();
     97        $('#logfilesDownload').hide();
     98       
     99        $.getJSON(GnuBoat.Webclient.private.serverBaseUrl +"/logfiles", function(data){
    78100                GnuBoat.Webclient.private.updateMapModus(data);
    79101                if(!Array.isArray(data) || data.length < 1){
    80                         $("<p>No Logfiles found!</p>").appendTo("#logfilesForm");
    81                         console.log(data);
    82                         return;
    83                 }
    84                 if(("error" in data) && data["error"] == 1){
    85                         GnuBoat.displayMessage('<span class="error">Failed to get log files: '+ data["errormessage"] +'</span>');
    86                         $("<p>No Logfiles found!</p>").appendTo("#logfilesForm");
    87                         console.log(data);
    88                         return;
    89                 }
    90                 $("<select id=\"logfilesSelect\" name=\"logfilesSelected[]\" class=\"pure-input-1\" multiple></select>").appendTo("#logfilesForm");
    91                 $("<input type=\"submit\" class=\"pure-button pure-button-primary\" name=\"logfilesDownload\" value=\"Download\"/>").appendTo("#logfilesForm");
     102                        $("<span>No Logfiles found!</span>").appendTo("#logfilesNone");
     103                        $('#logfilesNone').show();
     104                        return;
     105                }
    92106                data.forEach(function(value, index){
    93107                        $("<option value=\""+ value +"\">"+ value +"</option>").appendTo("#logfilesSelect");
    94108                });
    95         });
     109                $('#logfilesSelect').show();
     110                $('#logfilesDownload').show();
     111        }).fail(GnuBoat.Webclient.private.displayHttpError);
    96112};
    97 /**
    98  * @brief Sends a shutdown request to the webservice
    99  */
    100 GnuBoat.Webclient.shutdown = function()
     113
     114
     115GnuBoat.Webclient.logfileDownload = function()
    101116{
    102117        if(GnuBoat.Webclient.private.serverBaseUrl == null){
    … …  
    104119                return;
    105120        }
    106         $.getJSON(GnuBoat.Webclient.private.serverBaseUrl +"?request=shutdown", function(data){
    107                 var shutdownTime = data["shutdownstart"];
    108                 var shutdownDate = Date.parse(shutdownTime);
    109                 var currentDate = new Date();
    110                 var shutdownHint = '<span class="info">Shutting down in '+ Math.floor((shutdownDate - currentDate)/1000) +"s at "+ shutdownTime.toLocaleString() +"</span>";
    111                 if(shutdownTime == -1){
    112                         shutdownHint = '<span class="error">Failed to initiate shutdown: '+ data["errormessage"] +"</span>";
    113                 }
    114                 GnuBoat.displayMessage(shutdownHint);
    115         });
     121        var logfiles = $('#logfilesSelect option:selected');
     122        if(logfiles.length < 1){
     123                GnuBoat.displayMessage('<span class="error">No logfile selected</span>');
     124                return;
     125        }
     126        else if(logfiles.length == 1){
     127                window.location = GnuBoat.Webclient.private.serverBaseUrl +'logfiles/'+ logfiles[0].value;
     128                return
     129        }
     130        else{
     131                var files = Array();
     132                for(var i = 0; i < logfiles.length; i++){
     133                        files.push(logfiles[i].value);
     134                }
     135                files.join(',');
     136                window.location = GnuBoat.Webclient.private.serverBaseUrl +'logfiles/'+ files.join(',');
     137        }
     138}
     139
     140/**
     141 * @brief Sends a shutdown request to the webservice
     142 */
     143GnuBoat.Webclient.shutdown = function()
     144{
     145        if(GnuBoat.Webclient.private.serverBaseUrl == null){
     146                GnuBoat.displayMessage('<span class="error">No server set/found</span>');
     147                return;
     148        }
     149        $.ajax({
     150                url: GnuBoat.Webclient.private.serverBaseUrl +"shutdown",
     151        }).done(function(){ GnuBoat.displayMessage('<h2>Shutting down</h2>'); })
     152        .fail(GnuBoat.Webclient.private.displayHttpError);
    116153};
    117154
    118155/**
    119  * @brief Uploads a map and refreshes the maps metadata on success
    120  */
    121 GnuBoat.Webclient.uploadMap = function(form)
     156 * @brief Queries the status of the remote mapservice
     157 */
     158GnuBoat.Webclient.mapserviceStatusGet = function()
    122159{
    123160        if(GnuBoat.Webclient.private.serverBaseUrl == null){
    … …  
    125162                return;
    126163        }
     164        $.getJSON(GnuBoat.Webclient.private.serverBaseUrl +"/mapservice", function(data){
     165                switch(data){
     166                        case 'NO_API_KEY':
     167                                var source = 'mapservice-error.svg';
     168                                var description = 'Specifiy API_KEY for the mapservice in deviceservice config file';
     169                                break;
     170                        case 'NO_DEVICE':
     171                                var source = 'mapservice-error.svg';
     172                                var description = 'Specifiy device id for the mapservice in deviceservice config files option DEVICE';
     173                                break;
     174                        case 'DEVICE_NOT_FOUND':
     175                                var source = 'mapservice-error.svg';
     176                                var description = 'Specifiy a valid device id for the mapservice in deviceservice config files option DEVICE';
     177                                break;
     178                        case 'OK':
     179                                var source = 'mapservice-ok.svg';
     180                                var description = 'Connected and Configured';
     181                                $('#logfilesUploadStart').prop('disabled', false);
     182                                break;
     183                        default:
     184                                source = 'mapservice-offline.svg';
     185                                description = 'Mapservice is offline';
     186                }
     187                var imgTag = $('#mapserviceStatusIcon');
     188                imgTag.attr('src', '/client/resources/'+ source);
     189                imgTag.attr('title', description);
     190        }).fail(GnuBoat.Webclient.private.displayHttpError);
     191};
     192
     193/**
     194 * @brief Uploads a map and refreshes the maps metadata on success
     195 */
     196GnuBoat.Webclient.uploadMap = function(form)
     197{
     198        if(GnuBoat.Webclient.private.serverBaseUrl == null){
     199                displayMessage('<span class="error">No server set/found</span>');
     200                return;
     201        }
    127202        $("#mapFileInput").hide();
    128203        $("#mapTileUploadProgress").show();
    129         $.ajax({
    130                 type: 'POST',
    131                 url: GnuBoat.Webclient.private.serverBaseUrl +'?request=map',
    132                 data: new FormData($("#mapTileUpload")[0]),
    133                 contentType: false,
    134                 processData: false,
    135                 success: function(data){
    136                         if(("error" in data) && data["error"] == 1){
    137                                 GnuBoat.displayMessage('<span class="error">Failed to upload map: '+ data["errormessage"] +'</span>');
    138                                 $("#mapTileUploadProgress").hide();
    139                                 $("#mapFileInput").show();
    140                                 return;
    141                         }
    142                         GnuBoat.displayMessage('<span class="error">Map upload successfully</span>');
     204       
     205        var fileReader = new FileReader();
     206        fileReader.onload = function(e) {
     207                if(fileReader.result == null){
     208                        GnuBoat.displayMessage('<span class="error">Could not read map file.</span>');
     209                        return;
     210                }
     211                var data = fileReader.result.replace('data:application/octet-stream;base64','')
     212                $.ajax({
     213                        type: 'POST',
     214                        url: GnuBoat.Webclient.private.serverBaseUrl +'maps',
     215                        data: data,
     216                        contentType: 'application/octet-stream',
     217                        processData: false,
     218                }).progress(function(e){
     219                        $("#mapTileUploadProgress").attr({value: e.oloaded, max: e.total});
     220                }).done(function(data){
     221                        GnuBoat.displayMessage('<h2>Map upload successfully</h2>');
    143222                        $("#mapTileUploadProgress").hide();
    144223                        $("#mapFileInput").show();
    145                         GnuBoat.Webclient.getMapInfos();
    146                 },
    147                 error: function(jqXHR, exception, errorThrown){
    148                         GnuBoat.displayMessage('<span class="error">Failed to upload map (XHR): '+ exception +'</span>');
     224                        GnuBoat.Webclient.private.mapInfos(data);
     225                }).fail(function(error){
    149226                        $("#mapTileUploadProgress").hide();
    150227                        $("#mapFileInput").show();
    151                 }
    152         }).progress(function(e){
    153                 $("#mapTileUploadProgress").attr({value: e.oloaded, max: e.total});
    154         });
     228                        console.log(error);
     229                        GnuBoat.Webclient.private.displayHttpError(error);
     230                });
     231    };
     232    fileReader.readAsDataURL($('#mapFileInput')[0].files[0]);
    155233};
    156234
    … …  
    164242        $("#logfilesReload").click(GnuBoat.Webclient.logfilesLoad);
    165243        $("#shutdownButton").click(GnuBoat.Webclient.shutdown);
     244    $('#error').hide();
    166245
    167246        $("#mapTileUpload").validate({
    … …  
    179258        });
    180259       
     260        $('#logfilesNone').hide();
     261        $('#logfilesSelect').hide();
     262        $('#logfilesUploadMessage').hide();
     263        $('#logfilesDownload').hide();
     264        $('#logfilesDownload').click(GnuBoat.Webclient.logfileDownload);
     265        $('#logfilesUploadStart').prop('disabled', true);
     266        $('#logfilesUploadStart').click(function(){
     267                var logfiles = $('#logfilesSelect option:selected');
     268                if(logfiles.length > 1){
     269                        $('#logfilesUploadMessage').show();
     270                        $('#logfilesUploadMessage').text('Only one logfile could be uploaded at a time');
     271                        setTimeout(function(){ $('#logfilesUploadMessage').hide(); $('#logfilesUploadMessage').empty(); }, 60000);
     272                        return;
     273                }
     274                console.log(logfiles[0]);
     275                $('#logfilesUploadLogfile').val($(logfiles[0]).val());
     276                $('#logfilesUploadForm').show();
     277                $('#logfilesUploadStart').prop('disabled', true);
     278                $('#logfilesUploadGauge').prop('disabled', true);
     279                $('#logfilesUploadGaugeHeight').prop('disabled', true);
     280        });
    181281        $("#logfilesForm").validate({
    182282                rules: {
    … …  
    187287        });
    188288       
     289        $("#logfilesUploadWater").autocomplete({
     290                minLength: 3,
     291                source: GnuBoat.Webclient.private.uploadAutocompleteWaterGet,
     292                select: GnuBoat.Webclient.private.uploadAutocompleteWaterSelected,
     293        });
     294        $("#logfilesUploadGauge").autocomplete({
     295                minLength: 0,
     296                source: [],
     297                select: GnuBoat.Webclient.private.uploadAutocompleteGaugeSelected,
     298        });
     299        $('#logfilesUploadForm').hide();
     300        $('#logfilesUploadCancel').click(GnuBoat.Webclient.private.logfilesUploadFormClear);
     301        $("#logfilesUploadForm").validate({
     302                submitHandler: GnuBoat.Webclient.private.uploadLogfile,
     303                invalidHandler: function(){
     304                        var errors = validator.numberOfInvalids();
     305                        if (errors) {
     306                                var message = errors == 1 ? 'You missed 1 field. It has been highlighted' : 'You missed ' + errors + ' fields. They have been highlighted';
     307                                $('#logfilesUploadMessage').text(message);
     308                                $('#logfilesUploadMessage').show();
     309                                setTimeout(function(){ $('#logfilesUploadMessage').hide(); $('#logfilesUploadMessage').empty(); }, 60000);
     310                        }
     311                },
     312                rules: {
     313                        logfilesUploadLogfile: {
     314                                required: true,
     315                                minlength: 1
     316                        },
     317                        logfilesUploadWater: {
     318                                required: true
     319                        },
     320                        logfilesUploadGauge: {
     321                                required: true
     322                        },
     323                        logfilesUploadGaugeHeight: {
     324                                required: true,
     325                                number: true
     326                        },
     327                       
     328                }
     329        });
     330       
    189331        $("#rendering").empty();
    190332        var width = $("#rendering").width();
    … …  
    224366        GnuBoat.Webclient.getMapInfos();
    225367        GnuBoat.Webclient.displayDataGet();
     368        GnuBoat.Webclient.mapserviceStatusGet();
    226369        if(GnuBoat.Webclient.private.timerDisplay == null)
    227                 GnuBoat.Webclient.private.timerDisplay = setInterval(GnuBoat.Webclient.displayDataGet, 10000);
     370                GnuBoat.Webclient.private.timerDisplay = setInterval(GnuBoat.Webclient.displayDataGet, 3000);
     371        if(GnuBoat.Webclient.private.timerTracks == null)
     372                GnuBoat.Webclient.private.timerTracks = setInterval(GnuBoat.Webclient.trackGet, 30000);
     373        if(GnuBoat.Webclient.private.timerMapservice == null)
     374                GnuBoat.Webclient.private.timerMapservice = setInterval(GnuBoat.Webclient.mapserviceStatusGet, 30000);
    228375        GnuBoat.Webclient.logfilesLoad();
    229376       
    … …  
    246393 */
    247394GnuBoat.Webclient.private = {
     395    // Nautical mile in m
     396    nauticalMile: 1.852001 * 1000,
     397   
    248398        map: null,
    249399        mapLayerCurrent: null,
    … …  
    255405        mapHotlineGradientDefault: { absolute: false, palette: { 0.0: 'green', 0.5: 'yellow', 1.0: 'red' } },
    256406        dataMappings: {
    257                 speedthroughwater: {display: true, map: true, mapActive: false, titleLong: "Speed Through Water", titleShort: "STW", unit: "kts"},
    258                 speedoverground:  {display: true, map: true, mapActive: false, titleLong: "Speed Over Ground", titleShort: "SOG", unit: "kts"},
    259                 waterdepth: {
     407                speedThroughWater: {display: true, map: true, mapActive: false, titleLong: "Speed Through Water", titleShort: "STW", unit: "kts"},
     408                speedOverGround:  {display: true, map: true, mapActive: false, titleLong: "Speed Over Ground", titleShort: "SOG", unit: "kts"},
     409                waterDepth: {
    260410                        display: true, map: true, mapActive: true, titleLong: "Waterdepth", titleShort: "Depth", unit: "m",
    261411                        gradient: {
    … …  
    264414                        }
    265415                },
    266                 watertemperature: {display: true, map: true, mapActive: false, titleLong: "Watertemperature", titleShort: "Water", unit: "°C"},
    267                 gpsfix: {display: true, map: false, mapActive: false, titleLong: "GPS Fix", titleShort: "Fix", unit: ""},
     416                waterTemperature: {display: true, map: true, mapActive: false, titleLong: "Watertemperature", titleShort: "Water", unit: "°C"},
     417                gpsFix: {display: true, map: false, mapActive: false, titleLong: "GPS Fix", titleShort: "Fix", unit: ""},
    268418        },
    269419        serverBaseUrl: null,
    … …  
    284434        displayDataSet: function(data)
    285435        {
    286 //              if(!Array.isArray(data) || data.length < 1){
    287 //                      console.log("No data array returned!");
    288 //                      console.log(data);
    289 //                      return;
    290 //              }
    291                 if(("error" in data) && data["error"] == 1){
    292                         GnuBoat.displayMessage('<span class="error">Failed to get display data and tracks: '+ data["errormessage"] +'</span>');
    293                         return;
    294                 }
    295 
    296436                var keysDisplay = [];
    297437                for(var key in GnuBoat.Webclient.private.dataMappings){
    … …  
    300440                }
    301441
    302                 if(!("lastvalid" in data)){
    303                                 console.log("No last valid values given!");
    304                 }
    305                 else{
    306                         var lastValid = data["lastvalid"];
    307                         for(var i = 0; i < keysDisplay.length; i++){
    308                                 var key = keysDisplay[i];
    309                                 var value = lastValid[key];
    310                                 if($.isNumeric(value)){
    311                                         var text = value.toFixed(1);
    312                                         if(key == "watertemperature"){
    313                                                 text = value.toFixed(0);
    314                                         }
    315                                         $("#display #"+ key +" #value").text(text);
     442                for(var i = 0; i < keysDisplay.length; i++){
     443                        var key = keysDisplay[i];
     444                        if(!key in data){ continue; }
     445                        var value = data[key];
     446                        if($.isNumeric(value)){
     447                                var text = value.toFixed(1);
     448                                if(key == "waterTemperature"){
     449                                        text = value.toFixed(0);
    316450                                }
    317                                 else if(key == "gpsfix"){
    318                                         $("#display #"+ key +" #value").text(value);
    319                                 }
    320                         }
    321                 }
    322                
    323                 // map displays logged data
     451                                else if(key == "speedThroughWater" || key == "speedOverGround"){
     452                    text = (value / GnuBoat.Webclient.private.nauticalMile * 3600.0).toFixed(1)
     453                }
     454                                $("#display #"+ key +" #value").text(text);
     455                        }
     456                        else if(key == "gpsFix"){
     457                                $("#display #"+ key +" #value").text(value);
     458                        }
     459                }
     460        },
     461   
     462    trackSet: function(data)
     463    {
     464        // map displays logged data
    324465                if(!GnuBoat.Webclient.private.mapModusLive)
    325466                        return;
    326                 else if(!("track" in data)){
    327                         console.log("No track given!");
    328                         return;
    329                 }
    330                 GnuBoat.Webclient.private.mapAddTracks(data["track"]);
    331         },
     467                GnuBoat.Webclient.private.mapAddTracks(data);
     468    },
    332469       
    333470        mapSetup: function ()
    334471        {
    335472                var mapMetadataIndex = $("#mapSelect").val();
     473                if(!mapMetadataIndex){ return; }
    336474                if(GnuBoat.Webclient.private.mapsMetadata == null){
    337475                        console.log("No mapsMetadata set");
    … …  
    345483                var mapMetadata = GnuBoat.Webclient.private.mapsMetadata[mapMetadataIndex];
    346484               
    347                 var latitudeTop = mapMetadata["bounds"][3];
    348                 var latitudeBottom = mapMetadata["bounds"][1];
    349                 var longitudeLeft = mapMetadata["bounds"][0];
    350                 var longitudeRight = mapMetadata["bounds"][2];
    351                
    352                 var mapZoomMin = mapMetadata["minzoom"];
    353                 var mapZoomMax = mapMetadata["maxzoom"];
     485                var latitudeTop = 90;
     486                var latitudeBottom = -90;
     487                var longitudeLeft = -180;
     488                var longitudeRight = 180;
     489                if('bounds' in mapMetadata){
     490                        latitudeTop = mapMetadata.bounds[3];
     491                        latitudeBottom = mapMetadata.bounds[1];
     492                        longitudeLeft = mapMetadata.bounds[0];
     493                        longitudeRight = mapMetadata.bounds[2];
     494                }
     495               
     496                var mapZoomMin = ('minzoom' in mapMetadata) ? mapMetadata.minzoom : 0;
     497                var mapZoomMax = ('maxzoom' in mapMetadata) ? mapMetadata.maxzoom : 19;
    354498               
    355499                var latitudeCenter = (latitudeTop - latitudeBottom)/2 + latitudeBottom;
    … …  
    378522                        minZoom: mapZoomMin, maxZoom: mapZoomMax,
    379523                        bounds: GnuBoat.Webclient.private.mapBounds,
    380                         attribution: mapMetadata["name"],
    381                         opacity: 0.85
     524                        attribution: mapMetadata.name,
     525                        opacity: 0.85,
     526                        tms: true,
    382527                        }).addTo(GnuBoat.Webclient.private.map);
    383528                if(GnuBoat.Webclient.private.mapControl != null)
    … …  
    398543                var selected = "selected";
    399544                data.forEach(function(value, index){
    400                         $("<option value=\""+ index.toString() +"\" "+ selected +">"+ value["name"] +"</option>").appendTo("#mapSelect");
     545                        $("<option value=\""+ index.toString() +"\" "+ selected +">"+ value.name +"</option>").appendTo("#mapSelect");
    401546                        selected = "";
    402547                });
    … …  
    544689                $('<option value="live"'+ selectedString +'>Live View</option>').appendTo("#mapModusSelect");
    545690                if(!Array.isArray(data) || data.length < 1){
    546                         console.log(data);
    547691                        return;
    548692                }
    … …  
    579723                }
    580724                GnuBoat.Webclient.private.mapModusLive = false;
    581                 $.post({
    582                         url: GnuBoat.Webclient.private.serverBaseUrl +'?request=replay',
    583                         data: { logfile: modus },
    584                         success: function(data){
    585 //                              if(!Array.isArray(data) || data.length < 1){
    586 //                                      console.log("No data array returned!");
    587 //                                      console.log(data);
    588 //                                      return;
    589 //                              }
    590                                 if(("error" in data) && data["error"] == 1){
    591                                         GnuBoat.displayMessage('<span class="error">Failed to get logged tracks: '+ data["errormessage"] +'</span>');
    592                                         return;
    593                                 }
    594                                 if(!("track" in data)){
    595                                         console.log("No track given!");
    596                                         return;
    597                                 }
    598                                 GnuBoat.Webclient.private.mapAddTracks(data["track"]);
    599                         }
    600                 });
     725                $.getJSON({
     726                        url: GnuBoat.Webclient.private.serverBaseUrl +'logfiles/'+ modus +'/track',
     727                }).done(GnuBoat.Webclient.private.mapAddTracks).fail(GnuBoat.Webclient.private.displayHttpError);
    601728        },
    602729       
    … …  
    627754                        for(var i = 0; i < keysMap.length; i++){
    628755                                var key = keysMap[i];
     756                                if(!key in track[time]){ continue; }
    629757                                var value = track[time][key];
    630758                                if(!$.isNumeric(value))
    … …  
    638766                                else if(minimas[key] > value)
    639767                                        minimas[key] = value;
    640                                 points[key].push(new L.latLng(track[time]["latitude"], track[time]["longitude"], value));
    641                                 if(key == "waterdepth")
    642                                         densityPoints.push({latitude: track[time]["latitude"], longitude: track[time]["longitude"], depth: value});
     768                                points[key].push(new L.latLng(track[time].position[1], track[time].position[0], value));
     769                                if(key == "waterDepth")
     770                                        densityPoints.push({latitude: track[time].position[1], longitude: track[time].position[0], depth: value});
    643771                        }
    644772                }
    … …  
    701829                }
    702830                var gradient = GnuBoat.Webclient.private.mapHotlineGradientDefault.palette;
    703                 if("gradient" in GnuBoat.Webclient.private.dataMappings["waterdepth"])
    704                         gradient = GnuBoat.Webclient.private.dataMappings["waterdepth"]["gradient"];
    705                 GnuBoat.Webclient.private.drawDensityEstimation(densityPoints, gradient, maximas["waterdepth"], minimas["waterdepth"]);
     831                if("gradient" in GnuBoat.Webclient.private.dataMappings.waterDepth)
     832                        gradient = GnuBoat.Webclient.private.dataMappings.waterDepth.gradient;
     833                GnuBoat.Webclient.private.drawDensityEstimation(densityPoints, gradient, maximas["waterDepth"], minimas["waterDepth"]);
    706834        },
    707835       
    … …  
    777905                }
    778906        },
     907       
     908        /**
     909        * @brief Fetches waters from deviceservice and adds them to the autocompleter
     910    */
     911        uploadAutocompleteWaterGet: function(request, response)
     912        {
     913                if(GnuBoat.Webclient.private.serverBaseUrl == null){
     914                        displayMessage('<span class="error">No server set/found</span>');
     915                        return;
     916                }
     917                $.getJSON(GnuBoat.Webclient.private.serverBaseUrl +"/mapservice/waters?name="+ request.term, function(data){
     918                        var results = Array();
     919                        data.forEach(function(value, index){
     920                                results.push({ 'label': value.name, 'water': value });
     921                        });
     922                        response(results);
     923                }).fail(GnuBoat.Webclient.private.displayHttpError);
     924        },
     925       
     926        uploadAutocompleteWaterSelected: function(event, ui)
     927        {
     928                if(ui.item.water.gauges.length < 1){
     929                        $('#logfilesUploadMessage').text('Water ' + ui.item.water.name +' has no gauges. Please add them on the mapservice first!');
     930                        $('#logfilesUploadMessage').show();
     931                        setTimeout(function(){ $('#logfilesUploadMessage').hide(); $('#logfilesUploadMessage').empty(); }, 60000);
     932                       
     933                        $('#logfilesUploadGauge').prop('disabled', true);
     934                        $('#logfilesUploadGaugeHeight').prop('disabled', true);
     935                       
     936                        return;
     937                }
     938                $('#logfilesUploadWater').attr('data-waterId', ui.item.water.waterId);
     939                var gauges = Array();
     940                ui.item.water.gauges.forEach(function(value, index){
     941                        gauges.push({ 'value': value.name, 'gauge': value});
     942                });
     943                $('#logfilesUploadGauge').prop('disabled', false);
     944                $('#logfilesUploadGauge').autocomplete('option', 'source', gauges);
     945                $('#logfilesUploadGauge').autocomplete('search', '');
     946        },
     947   
     948        uploadAutocompleteGaugeSelected: function(event, ui)
     949        {
     950                $('#logfilesUploadGauge').attr('data-gaugeId', ui.item.gauge.gaugeId);
     951                $('#logfilesUploadGaugeHeightReference').text('Reference Height: '+ ui.item.gauge.referenceWaterLevelGaugeHeight.toFixed(2).toString());
     952                $('#logfilesUploadGaugeHeight').prop('disabled', false);
     953        },
     954       
     955        uploadLogfile: function()
     956        {
     957                var logCreation = {
     958                                'water': Number($('#logfilesUploadWater').attr('data-waterId')),
     959                                'gauge': Number($('#logfilesUploadGauge').attr('data-gaugeId')),
     960                                'gaugeHeight': Number($('#logfilesUploadGaugeHeight').val()),
     961                                'delete': $('#logfilesUploadDelete').checked,
     962                                'comment': $('#logfilesUploadComment').val(),
     963                                'logfile': $('#logfilesUploadLogfile').val(),
     964                }
     965                $.ajax({
     966                        type: 'POST',
     967                        url: GnuBoat.Webclient.private.serverBaseUrl +'mapservice/log',
     968                        data: JSON.stringify(logCreation),
     969                        contentType: 'application/json',
     970                        dataType: 'json',
     971                }).done(function(data){
     972                        GnuBoat.displayMessage('<h2>Log '+ logCreation.logfile +' uploaded successfully</h2>');
     973                        GnuBoat.Webclient.private.logfilesUploadFormClear();
     974                        GnuBoat.Webclient.logfilesLoad();
     975                }).fail(function(error){
     976                        GnuBoat.Webclient.private.displayHttpError(error);
     977                });
     978        },
     979       
     980       
     981        logfilesUploadFormClear: function(){
     982                $('#logfilesUploadForm').hide();
     983                $('#logfilesUploadStart').prop('disabled', false);
     984                // clear up form
     985                $('#logfilesUploadLogfile').val('');
     986                $('#logfilesUploadFieldset').find('input:text').val('');
     987                $('#logfilesUploadGaugeHeight').val('');
     988                $('#logfilesUploadDelete').prop('checked', true);
     989                $('#logfilesUploadFieldset').find('textarea').val('');
     990                $('#logfilesUploadGaugeHeightReference').text('')
     991        },
     992       
     993        /**
     994        * @brief Shows an HttpError
     995        */
     996        displayHttpError: function(error, status)
     997        {
     998                if(error.status == 504){
     999                        // ignore 504 caused by Mapservice, because there is a status icon in the
     1000                        // display section
     1001                        console.log('Mapservice is not available. Status is: ' + error.statusText);
     1002                        return;
     1003                }
     1004                if(error && 'responseJSON' in error){
     1005                        error = error.responseJSON;
     1006                }
     1007                if(!error){
     1008                        console.log(error);
     1009                        error = {};
     1010                        error.status = 0;
     1011                        error.detail = 'Unknown error occured';
     1012                }
     1013                var detail = "No details available.";
     1014                if(error.detail != null && error.detail != undefined){ detail = error.detail; }
     1015                GnuBoat.displayMessage('<h2 class="error">Error '+ error.title +' ('+ error.status.toString() +')</h2><p>'+ detail +'</p>');
     1016        }
    7791017};
Note: See TracChangeset for help on using the changeset viewer.