From fe1480d31820d923ee7a61291f7e3d96f2531f15 Mon Sep 17 00:00:00 2001
From: versx <versx@ver.sx>
Date: Fri, 21 Aug 2020 21:51:44 -0700
Subject: [PATCH] Small fixes

---
 src/routes/api.js           |   1 -
 src/views/index-js.mustache | 120 +++++-------------------------------
 templates/gym.ejs           |  28 +++++++--
 templates/pokestop.ejs      |   4 +-
 4 files changed, 40 insertions(+), 113 deletions(-)

diff --git a/src/routes/api.js b/src/routes/api.js
index 69fa6665..127c01dc 100644
--- a/src/routes/api.js
+++ b/src/routes/api.js
@@ -29,7 +29,6 @@ router.post('/search', async (req, res) => {
 router.post('/get_template/:name', async (req, res) => {
     const template = req.params.name;
     const view = req.body.data;
-    view.error = false;
     const templateData = await utils.render(template, view);
     res.send(templateData);
 });
diff --git a/src/views/index-js.mustache b/src/views/index-js.mustache
index 77263b83..f3d872b8 100644
--- a/src/views/index-js.mustache
+++ b/src/views/index-js.mustache
@@ -2424,7 +2424,7 @@ function getPokemonPopupContent (pokemon) {
     //let content = '';
 
     let pokemonName;
-    if (pokemon.form !== 0 && pokemon.form !== null) {
+    if (pokemon.form > 0) {
         pokemonName = getFormName(pokemon.form) + ' ' + getPokemonName(pokemon.pokemon_id);
     } else {
         pokemonName = getPokemonName(pokemon.pokemon_id);
@@ -2439,15 +2439,13 @@ function getPokemonPopupContent (pokemon) {
     const pkmn = masterfile.pokemon[pokemon.pokemon_id];
     let pokemonTypes = [];
     if (pkmn && pkmn.types && pkmn.types.length > 0) {
-        if (pkmn) {
-            const types = pkmn.types;
-            if (types && types.length > 0) {
-                if (types.length === 2) {
-                    pokemonTypes.push(types[0].toLowerCase());
-                    pokemonTypes.push(types[1].toLowerCase());
-                } else {
-                    pokemonTypes.push(types[0].toLowerCase());
-                }
+        const types = pkmn.types;
+        if (types && types.length > 0) {
+            if (types.length === 2) {
+                pokemonTypes.push(types[0].toLowerCase());
+                pokemonTypes.push(types[1].toLowerCase());
+            } else {
+                pokemonTypes.push(types[0].toLowerCase());
             }
         }
     }
@@ -2809,7 +2807,7 @@ function getPokestopPopupContent (pokestop) {
     pokestop.time_since = getTimeSince(lastUpdatedDate);
     const templateData = getTemplateData('pokestop', pokestop);
     return templateData;
-
+    /*
     let content = '<div class="text-center">';
     if (pokestop.name === null || pokestop.name === '') {
         content += '<h6><b>Unknown Pokestop Name</b></h6>';
@@ -2907,12 +2905,15 @@ function getPokestopPopupContent (pokestop) {
         '</div>' +
     '</div>';
     return content;
+    */
 }
 
 function getGymPopupContent (gym) {
     const now = new Date();
     const raidBattleDate = new Date(gym.raid_battle_timestamp * 1000);
     const raidEndDate = new Date(gym.raid_end_timestamp * 1000);
+    const updatedDate = new Date(gym.updated * 1000);
+    const modifiedDate = new Date(gym.last_modified_timestamp * 1000);
 
     const isRaid = raidEndDate >= now && parseInt(gym.raid_level) > 0;
     const isRaidBattle = raidBattleDate <= now && isRaid;
@@ -2976,6 +2977,10 @@ function getGymPopupContent (gym) {
     gym.guarding_pokemon_name = getPokemonName(gym.guarding_pokemon_id);
     gym.team_name = getTeamName(gym.team_id);
     gym.icon_path = availableIconStyles[selectedIconStyle];
+    gym.time_until_battle = getTimeUntill(raidBattleDate);
+    gym.time_until_end = getTimeUntill(raidEndDate);
+    gym.time_since_updated = getTimeSince(updatedDate);
+    gym.time_since_modified = getTimeSince(modifiedDate);
     const templateData = getTemplateData('gym', gym);
     return templateData;
     /*
@@ -3163,45 +3168,11 @@ function getCellPopupContent (cell) {
     cell.time_since = getTimeSince(new Date(cell.updated * 1000));
     const templateData = getTemplateData('cell', cell);
     return templateData;
-    /*
-    let content = '<center>';
-    content += '<h6><b>Level ' + cell.level + ' S2 Cell</b></h6>';
-    content += '<b>Id:</b> ' + cell.id + '<br>';
-
-    const updatedDate = new Date(cell.updated * 1000);
-
-    content += '<b>Last Updated:</b> ' + updatedDate.toLocaleTimeString() + ' (' + getTimeSince(updatedDate) + ')';
-    content += '</center>';
-    return content;
-    */
 }
 
 function getSubmissionTypeCellPopupContent (cell) {
     const templateData = getTemplateData('submission_cell', cell);
     return templateData;
-    /*
-    let content = '<center>';
-    content += '<h6><b>Level ' + cell.level + ' S2 Cell</b></h6>';
-    content += '<b>Id:</b> ' + cell.id + '<br>';
-    content += '<b>Total Count:</b> ' + cell.count + '<br>';
-    content += '<b>Pokestop Count:</b> ' + cell.count_pokestops + '<br>';
-    content += '<b>Gym Count:</b> ' + cell.count_gyms + '<br>';
-
-    const gymThreshold = [2, 6, 20];
-
-    if (cell.count_gyms < 3) {
-        content += '<b>Submissions untill Gym:</b> ' + (gymThreshold[cell.count_gyms] - cell.count);
-    } else {
-        content += '<b>Submissions untill Gym:</b> Never';
-    }
-
-    if ((cell.count === 1 && cell.count_gyms < 1) || (cell.count === 5 && cell.count_gyms < 2) || (cell.count === 19 && cell.count_gyms < 3)) {
-        content += '<br><b>Next submission will cause a Gym!';
-    }
-
-    content += '</center>';
-    return content;
-    */
 }
 
 function degreesToCardinal (d) {
@@ -3218,32 +3189,6 @@ function getWeatherPopupContent (weather) {
     weather.time_since = getTimeSince(new Date(weather.updated * 1000));
     const templateData = getTemplateData('weather', weather);
     return templateData;
-
-    /*
-    let content = '<center>';
-    content += '<h6><b>' + weatherName + '</b><br></h6>';
-    content += '<b>Boosted Types:</b><br>' + weatherType + '<br>';
-    content += '<b>Cell ID:</b> ' + weather.id + '<br>';
-    content += '<b>Cell Level:</b> ' + weather.level + '<br>';
-    content += '<b>Lat:</b> ' + weather.latitude + '<br>';
-    content += '<b>Lon:</b> ' + weather.longitude + '<br>';
-    content += '<b>Gameplay Condition:</b> ' + weather.gameplay_condition + '<br>';
-    content += '<b>Wind Direction:</b> ' + weather.wind_direction + '° (' + degreesToCardinal(weather.wind_direction) + ')<br>';
-    content += '<b>Cloud Level:</b> ' + weather.cloud_level + '<br>';
-    content += '<b>Rain Level:</b> ' + weather.rain_level + '<br>';
-    content += '<b>Wind Level:</b> ' + weather.wind_level + '<br>';
-    content += '<b>Snow Level:</b> ' + weather.snow_level + '<br>';
-    content += '<b>Fog Level:</b> ' + weather.fog_level + '<br>';
-    content += '<b>Special Effects Level:</b> ' + weather.special_effect_level + '<br>';
-    content += '<b>Severity:</b> ' + weather.severity + '<br>';
-    content += '<b>Weather Warning:</b> ' + weather.warn_weather + '<br><br>';
-
-    const updatedDate = new Date(weather.updated * 1000);
-
-    content += '<b>Last Updated:</b> ' + updatedDate.toLocaleTimeString() + ' (' + getTimeSince(updatedDate) + ')';
-    content += '</center>';
-    return content;
-    */
 }
 
 function getNestPopupContent(nest) {
@@ -3251,33 +3196,11 @@ function getNestPopupContent(nest) {
     nest.last_updated = new Date(nest.updated * 1000);
     const templateData = getTemplateData('nest', nest);
     return templateData;
-    /*
-    let content = `
-    <center>
-        <h6>Park: <b>${nest.name}</b></h6>
-        Pokemon: <b>${pokemonName}</b><br>
-        Average: <b>${nest.pokemon_avg.toLocaleString()}</b><br>
-        Count: <b>${nest.pokemon_count.toLocaleString()}</b><br>
-        <br>
-        <small>Last Updated: <b>${lastUpdated.toLocaleString()}</b></small><br>
-    </center>
-    `;
-    return content;
-    */
 }
 
 function getScanAreaPopupContent(name, size) {
     const templateData = getTemplateData('scanarea', { name, size });
     return templateData;
-    /*
-    let content = `
-    <center>
-        <h6>Area: <b>${name}</b></h6>
-        Size: ${size} km<sup>2</sup>
-    </center>
-    `;
-    return content;
-    */
 }
 
 
@@ -3918,17 +3841,6 @@ function getDeviceMarker (device, ts) {
 function getDevicePopupContent (device) {
     const data = getTemplateData('device', device);
     return data;
-    /*
-    const lastSeenDate = new Date(device.last_seen * 1000);
-    const lastSeen = lastSeenDate.toLocaleTimeString() + ' (' + getTimeSince(lastSeenDate) + ')';
-    const ts = Math.round((new Date()).getTime() / 1000);
-    const isOffline = isDeviceOffline(device, ts);
-    const content = '<center><h6><b>' + device.uuid + '</b></h6></center><br>' +
-        '<b>Instance:</b> ' + device.instance_name + '<br>' +
-        '<b>Last Seen:</b> ' + lastSeen + '<br>' +
-        '<b>Status:</b> ' + (isOffline ? 'Offline' : 'Online');
-    return content;
-    */
 }
 
 function isDeviceOffline (device, ts) {
diff --git a/templates/gym.ejs b/templates/gym.ejs
index b93fd714..56d54654 100644
--- a/templates/gym.ejs
+++ b/templates/gym.ejs
@@ -21,13 +21,13 @@
             </div>
             <div class="row" style="margin:auto;">
             <% if (has_raid_boss && is_raid_battle) { %>
-                <div class="col text-nowrap">
                 <% if (pokemon_types && pokemon_types.length > 0) { %>
+                    <div class="col text-nowrap"></div>
                     <% pokemon_types.forEach(function(type) { %>
                         <img src="<%= icon_path %>/type/<%= type %>.png" height="16" width="16">&nbsp;
                     <% }); %>
+                    </div>
                 <% } %>
-                </div>
             <% } %>
             </div>
         </div>
@@ -81,22 +81,38 @@
         <div class="col-12 col-md-8 center-vertical p-4">
             <b>Team:</b> <%= team_name %><br>
             <b>Slots Available:</b> <%= available_slots %><br>
-        <% if (guarding_pokemon_id) { %>
+        <% if (guarding_pokemon_id > 0) { %>
             <b>Guard:</b> <%= guarding_pokemon_name %><br>
         <% } %>
-        <% if (total_cp) { %>
+        <% if (total_cp > 0) { %>
             <b>Total CP:</b> <%= total_cp.toLocaleString() %><br>
         <% } %>
-        <% if (in_battle) { %>
+        <% if (in_battle > 0) { %>
             <b>Gym is under attack!</b><br>
         <% } %>
-        <% if (ex_raid_eligible) { %>
+        <% if (ex_raid_eligible > 0) { %>
             <img src="<%= icon_path %>/misc/ex.png" height="24" width="32">
         <% } %>
         </div>
     </div>
     <br>
 <% } %>
+
+<div class="text-center">
+    <% if (is_raid && !is_raid_battle) { %>
+        <b>Raid Start:</b> <%= new Date(raid_battle_timestamp * 1000).toLocaleString() %> (<%= time_until_battle %>)<br>
+    <% } %>
+    <% if (is_raid) { %>
+        <b>Raid End:</b> <%= new Date(raid_end_timestamp * 1000).toLocaleString() %> (<%= time_until_end %>)<br><br>
+    <% } %>
+    </div>
+    <% if (updated) { %> %>
+        <small><b>Last Updated:</b> <%= new Date(updated * 1000).toLocaleString() %> (<%= time_since_updated %>)<br></small>
+    <% } %>
+    <% if (last_modified_timestamp) { %>
+        <small><b>Last Modified:</b> <%= new Date(last_modified_timestamp * 1000).toLocaleString() %> (<%= time_since_modified %>)<br></small>
+    <% } %>
+
 <br>
 <div class="row text-center text-nowrap">
     <div class="col">
diff --git a/templates/pokestop.ejs b/templates/pokestop.ejs
index bb2c3028..58ea3915 100644
--- a/templates/pokestop.ejs
+++ b/templates/pokestop.ejs
@@ -43,8 +43,8 @@
         <br>
     <% } %>
 
-    <% if (last_updated) { %>
-        <small><b>Last Updated:</b> <%= last_updated.toLocaleString() %> (<%= time_since %>)<br></small>
+    <% if (updated) { %>
+        <small><b>Last Updated:</b> <%= new Date(updated * 1000).toLocaleString() %> (<%= time_since %>)<br></small>
     <% } %>
 
     <br>