Permalink
Browse files

[Updated] Add page to explore all changes of gyms over time (#331)

* add gymhistory

* add readme for required SQL stuff

* make scrutinizer happier

* fix copy&paste error introduced with last commit

* correct inital SQL statement in readme

* fix last history entry not showing differences

* do not show undefined pokemon in empty gyms

* minor style change

* css indentation

* fix another mistake in the SQL statement for table creation

* refactor hiding of gym history tables

* fix window.history handling, refactor duplicated code

* add separate gym history loader, fix window.history handling finally

* minor style improvements

* update SQL statement for event creation, since it missed the delimiter part
(sorry folks, I should more often test my own stuff)

* change delimiter sign, make keyword uppercase

* add htaccess entry for gymhistory url

* comply with rocketmaps latest db eoncoding changes

* update charset to utf8mb4 as well

* filter out duplicated gym pokemon

* update sql statements

* adapt gymhistory to recent changes

* Merge remote-tracking branch 'brusselopole/master' into PR-gymhistory

* fix pokemon order

* fix pokemon order for history entries

* add option to hide only cp changes in gym history, add menu entry

* restore pokemon list, always show "load more" button since we may filter out entries on server side

* do filtering on client-side

* add history link

* fix ONLY_FULL_GROUP_BY incompatibility

* add gymhistory

* add readme for required SQL stuff

* make scrutinizer happier

* fix copy&paste error introduced with last commit

* correct inital SQL statement in readme

* fix last history entry not showing differences

* do not show undefined pokemon in empty gyms

* minor style change

* css indentation

* fix another mistake in the SQL statement for table creation

* refactor hiding of gym history tables

* fix window.history handling, refactor duplicated code

* add separate gym history loader, fix window.history handling finally

* minor style improvements

* update SQL statement for event creation, since it missed the delimiter part
(sorry folks, I should more often test my own stuff)

* change delimiter sign, make keyword uppercase

* add htaccess entry for gymhistory url

* comply with rocketmaps latest db eoncoding changes

* update charset to utf8mb4 as well

* filter out duplicated gym pokemon

* update sql statements

* adapt gymhistory to recent changes

* Merge remote-tracking branch 'brusselopole/master' into PR-gymhistory

* fix pokemon order

* fix pokemon order for history entries

* minor style fix
  • Loading branch information...
michikrug authored and Obihoernchen committed Feb 1, 2018
1 parent ab5ba73 commit 172c83bdbd0bc5fbb452f729f35e425cf03814ea
@@ -460,11 +460,18 @@ div#levelMeter .progress{
div#gymPrestige{
position: absolute;
left:120px;
left: 120px;
top: 70px;
font-size: 14px;
}
div#gymHistory{
position: absolute;
left: 220px;
top: 70px;
font-size: 14px;
}
div#gymLastScanned{
position: absolute;
left:120px;
@@ -491,11 +498,11 @@ trainers details styles
trainers search styles
****************/
#searchTrainer button {
#searchTrainer button, #searchGyms button {
height: 40px;
}
#searchTrainer input {
#searchTrainer input, #searchGyms input {
height: 40px;
}
@@ -579,4 +586,71 @@ raids styles
#raidsTable>tbody>tr>td, #raidsTable>tbody>tr>th, #raidsTable>tfoot>tr>td, #raidsTable>tfoot>tr>th, #raidsTable>thead>tr>td, #raidsTable>thead>tr>th {
padding: 6px
}
}
}
#gymsContainer td {
vertical-align: middle;
line-height: 2em;
}
#gymsContainer .gymhistory table td:first-child, #gymsContainer .gymhistory table th:first-child {
padding-left: 10px;
}
#gymsContainer td.level {
width: 68px;
}
#gymsContainer td.level img {
margin-right: .5em;
}
#gymsContainer td.loss {
color: rgb(210,118,118);
}
#gymsContainer td.gain {
color: rgb(62,150,62);
}
#gymsContainer td ul {
margin-bottom: 0;
min-height: 65px;
line-height: initial;
}
#gymsContainer td ul li {
width: 5em;
overflow: hidden;
text-align: center;
border-radius: 5px;
margin-right: 2px;
}
#gymsTable > thead > tr > th:nth-child(1) {
width: 6.5em;
}
@media (max-width: 768px) {
#gymsContainer td ul li {
display: none;
}
#gymsTable > thead > tr > th:last-child, #gymsTable > tbody > tr:nth-child(2n-1) > td:last-child {
display: none;
}
}
#gymsContainer td ul li.new {
background-color: rgba(62,150,62,.25);
display: inline-block !important;
}
#gymsContainer td ul li.old {
background-color: rgba(210,118,118,.25);
display: inline-block !important;
}
.no-link {
text-decoration: none;
color: inherit;
}
@@ -240,6 +240,30 @@
<meta name="twitter:title" content="<?= $config->infos->site_name ?> | <?= $locales->NAV_RAIDS ?>" />
<meta name="twitter:image" content="<?= HOST_URL ?>core/img/logo.jpg" />
<?php
break;
case 'gymhistory':
?>
<title><?= $config->infos->site_name ?> | Gym History</title>
<link rel="canonical" href="<?= HOST_URL ?>gymhistory" />
<base href="<?= HOST_URL ?>">
<meta property="og:locale" content="en_US" />
<meta property="og:type" content="website" />
<meta property="og:title" content="<?= $config->infos->site_name ?> | Gym History" />
<meta property="og:description" content="Gym History" />
<meta property="og:url" content="<?= HOST_URL ?>gymhistory" />
<meta property="og:site_name" content="<?= $config->infos->site_name ?>" />
<meta property="og:image" content="<?= HOST_URL ?>core/img/logo.jpg" />
<meta name="twitter:card" content="summary" />
<meta name="twitter:description" content="Gym History" />
<meta name="twitter:title" content="<?= $config->infos->site_name ?> | Gym History" />
<meta name="twitter:image" content="<?= HOST_URL ?>core/img/logo.jpg" />
<?php
break;
}
@@ -133,6 +133,7 @@ function setGymDetails(gym) {
imgurl = imgurl.replace(/^http:\/\//i, 'https://');
$('#gym_details_template #circleImage').css('background', 'url(' + imgurl + ') no-repeat center');
$('#gym_details_template #gymName').html(gym.gymDetails.gymInfos.name);
$('#gym_details_template #gymHistory a').attr('href', 'gymhistory?name=' + gym.gymDetails.gymInfos.name);
$('#gym_details_template #gymDescription').html(gym.gymDetails.gymInfos.description);
$('#gym_details_template #gymDefenders').html(gym.infoWindow);
$('#gym_details_template #gymPrestigeDisplay').html(gym.gymDetails.gymInfos.points);
@@ -0,0 +1,205 @@
/** global: gymName */
$(function () {
$.getJSON("core/json/variables.json", function(variables) {
var pokeimg_suffix = variables['system']['pokeimg_suffix'];
var hide_cp_changes = variables['system']['gymhistory_hide_cp_changes'];
$('.gymLoader').hide();
var page = 0;
var teamSelector = ''; //''=all; 0=neutral; 1=Blue; 2=Red; 3=Yellow
var rankingFilter = 0; //0=Level & Gyms; 1=Level; 2=Gyms
$('input#name').filter(':visible').val(gymName);
$('#loadMoreButton').click(function () {
loadGyms(page, $('input#name').filter(':visible').val(), teamSelector, rankingFilter, pokeimg_suffix, hide_cp_changes, true);
page++;
}).trigger('click');
$('#searchGyms').submit(function ( event ) {
page = 0;
$('#gymsContainer').empty();
$('#loadMoreButton').trigger('click');
event.preventDefault();
});
$('.teamSelectorItems').click(function ( event ) {
switch ($(this).attr('id')) {
case 'NeutralTeamsFilter':
teamSelector=0;
break;
case 'BlueTeamFilter':
teamSelector=1;
break;
case 'RedTeamFilter':
teamSelector=2;
break;
case 'YellowFilter':
teamSelector=3;
break;
default:
teamSelector='';
}
$('#teamSelectorText').html($(this).html());
event.preventDefault();
$('#searchGyms').submit();
});
$('.rankingOrderItems').click(function ( event ) {
switch ($(this).attr('id')) {
case 'changedFirst':
rankingFilter=0;
break;
case 'nameFirst':
rankingFilter=1;
break;
case 'totalcpFirst':
rankingFilter=2;
break;
default:
rankingFilter=0;
}
$('#rankingOrderText').html($(this).html());
event.preventDefault();
$('#searchGyms').submit();
});
window.onpopstate = function() {
if (window.history.state && 'gymhistory' === window.history.state.page) {
$('input#name').filter(':visible').val(window.history.state.name);
page = 0;
$('#gymsContainer').empty();
loadGyms(page, $('input#name').filter(':visible').val(), teamSelector, rankingFilter, hide_cp_changes, pokeimg_suffix, false);
page++;
} else {
window.history.back();
}
};
});
});
function loadGyms(page, name, teamSelector, rankingFilter, pokeimg_suffix, hide_cp_changes, stayOnPage) {
$('.gymLoader').show();
if (stayOnPage) {
// build a state for this name
var state = {name: name, page: 'gymhistory'};
window.history.pushState(state, 'gymhistory', 'gymhistory?name=' + name);
}
$.ajax({
'async': true,
'type': 'GET',
'global': false,
'dataType': 'json',
'url': 'core/process/aru.php',
'data': {
'type' : 'gyms',
'page' : page,
'name' : name,
'team' : teamSelector,
'ranking' :rankingFilter
}
}).done(function (data) {
var internalIndex = 0;
$.each(data.gyms, function (idx, gym) {
internalIndex++
printGym(gym, pokeimg_suffix, hide_cp_changes);
});
if (internalIndex < 10) {
$('#loadMoreButton').hide();
} else {
$('#loadMoreButton').removeClass('hidden').show();
}
$('.gymLoader').hide();
});
}
function loadGymHistory(page, gym_id, pokeimg_suffix, hide_cp_changes) {
$('#gymHistory_'+gym_id).addClass('active').show();
$('#gymHistory_'+gym_id).find('.gymHistoryLoader').show();
$.ajax({
'async': true,
'type': 'GET',
'global': false,
'dataType': 'json',
'url': 'core/process/aru.php',
'data': {
'type' : 'gymhistory',
'page' : page,
'gym_id' : gym_id
}
}).done(function (data) {
var internalIndex = 0;
$.each(data.entries, function(idx, entry) {
internalIndex++
if (entry.only_cp_changed && hide_cp_changes) return;
printGymHistory(gym_id, entry, pokeimg_suffix);
});
if (internalIndex < 10) {
$('#gymHistory_'+gym_id).find('.loadMoreButtonHistory').hide();
} else {
$('#gymHistory_'+gym_id).find('.loadMoreButtonHistory').removeClass('hidden').data('page', page+1).show();
}
$('#gymHistory_'+gym_id).find('.gymHistoryLoader').hide();
});
}
function printPokemonList(pokemons, pokeimg_suffix) {
var gymPokemon = $('<ul>',{class: 'list-inline'});
$.each(pokemons, function(idx, pokemon) {
var list = $('<li>', {class: pokemon.class});
list.append($('<a>', { class: 'no-link', href : 'pokemon/'+pokemon.pokemon_id }).append($('<img />', { src: 'core/pokemons/'+pokemon.pokemon_id+pokeimg_suffix }).css('height', '2em')));
list.append($('<br><span class="small">'+pokemon.cp+' CP</span>'));
list.append($('<br><span style="font-size:70%"><a href="trainer?name='+pokemon.trainer_name+'" class="no-link">'+pokemon.trainer_name+'</a></span>'));
gymPokemon.append(list);
});
return gymPokemon;
}
function printGymHistory(gym_id, entry, pokeimg_suffix) {
var gymHistory = $('<tr>').css('border-bottom', '2px solid '+(entry.team_id=='3'?'#ffbe08':entry.team_id=='2'?'#ff7676':entry.team_id=='1'?'#00aaff':'#ddd'));
gymHistory.append($('<td>',{text: entry.last_modified}));
gymHistory.append($('<td>',{text: entry.pokemon_count, class: 'level'}).prepend($('<img />', {src:'core/img/map_'+(entry.team_id=='1'?'blue':entry.team_id=='2'?'red':entry.team_id=='3'?'yellow':'white')+'.png'})));
gymHistory.append($('<td>',{text: parseInt(entry.total_cp).toLocaleString('de-DE'), class: entry.class}).append(
entry.total_cp_diff !== 0 ? $('<span class="small"> ('+(entry.total_cp_diff > 0 ? '+' : '')+entry.total_cp_diff+')</span>') : null
));
var gymPokemon = printPokemonList(entry.pokemon, pokeimg_suffix);
gymHistory.append($('<td>').append(gymPokemon));
$('#gymHistory_'+gym_id).find('tbody').append(gymHistory);
}
function hideGymHistoryTables(gymHistoryTables) {
gymHistoryTables.removeClass('active').hide();
gymHistoryTables.find('tbody tr').remove();
gymHistoryTables.find('.loadMoreButtonHistory').hide();
gymHistoryTables.find('.gymHistoryLoader').hide();
}
function printGym(gym, pokeimg_suffix, hide_cp_changes) {
var gymsInfos = $('<tr>',{id: 'gymInfos_'+gym.gym_id}).css('cursor', 'pointer').css('border-bottom', '2px solid '+(gym.team_id=='3'?'#ffbe08':gym.team_id=='2'?'#ff7676':gym.team_id=='1'?'#00aaff':'#ddd')).click(function() {
if (!$('#gymHistory_'+gym.gym_id).hasClass('active')) {
hideGymHistoryTables($('#gymsContainer').find('.gymhistory'));
loadGymHistory(0, gym.gym_id, pokeimg_suffix, hide_cp_changes);
} else {
hideGymHistoryTables($('#gymHistory_'+gym.gym_id));
}
});
gymsInfos.append($('<td>',{text: gym.last_modified}));
if (gym.name.length > 50) { gym.name = gym.name.substr(0, 50) + ''; }
gymsInfos.append($('<td>',{text: gym.name}));
gymsInfos.append($('<td>',{text: gym.pokemon_count, class: 'level'}).prepend($('<img />', {src:'core/img/map_'+(gym.team_id=='1'?'blue':gym.team_id=='2'?'red':gym.team_id=='3'?'yellow':'white')+'.png'})));
gymsInfos.append($('<td>',{text: parseInt(gym.total_cp).toLocaleString('de-DE')}));
var gymPokemon = printPokemonList(gym.pokemon, pokeimg_suffix);
gymsInfos.append($('<td>').append(gymPokemon));
$('#gymsContainer').append(gymsInfos);
var historyTable = $('<table>',{class: 'table'});
historyTable.append('<thead><tr><th style="min-width:7em">Time</th><th>Level</th><th>Total CP</th><th>Pokémon</th></tr></thead>');
historyTable.append('<tbody></tbody>');
historyTable.append('<tfoot><tr class="loadMore text-center"><td colspan="4"><button class="loadMoreButtonHistory btn btn-default btn-sm hidden">Load more</button></td></tr><tr class="gymHistoryLoader"><td colspan="4"><div class="loader"></div></td></tr></tfoot>');
historyTable.find('.loadMoreButtonHistory').data('page', 0).click(function() {
loadGymHistory($(this).data('page'), gym.gym_id, pokeimg_suffix, hide_cp_changes);
});
var row = $('<td>',{colspan: 6});
row.append(historyTable);
$('#gymsContainer').append($('<tr>', {id: 'gymHistory_'+gym.gym_id, class: 'gymhistory'}).hide().append(row));
}
@@ -36,7 +36,8 @@
"default_lang" : "en",
"location_url" : "/map/?lat={latitude}&lon={longitude}&zoom=17",
"trainer_blacklist" : ["cheater1", "cheater2"],
"rm_pokemon_file" : null
"rm_pokemon_file" : null,
"gymhistory_hide_cp_changes" : false
},
"menu":[
{
@@ -51,6 +52,12 @@
"locale" : "GYMS",
"icon" : "fa-shield"
},
{
"type" : "link",
"href" : "gymhistory",
"text" : "Gym Changes",
"icon" : "fa-history"
},
{
"type" : "link",
"href" : "raids",
Oops, something went wrong.

0 comments on commit 172c83b

Please sign in to comment.