Files
pathfinder/js/app/mappage.js
Mark Friedrich e01f299d2b v1.1.1 (#233)
* fixed #194 PHP 5.6 error

* - closed #102 added "set waypoint/destination" context menu to route finder module
- update "Select2" 4.0.0 -> 4.0.3
- update "Font Awesome" 4.6.1 -> 4.6.3

* - added *.js files for develop branch

* - closed #195 fixed "BASE" dir for subDir installations
- fixed "Home" menu link

* -  #195 improved js load path

* - added "clear cache" function for manually cache clearing to /setup #200 #105 #158
- added cache size information to /setup
- added current pathfinder  "VERSION" to /setup
- updated "requireJs" 2.1.20 ->2.2.0
- removed unnecessary page cache timings from static templates (page cache)

* - added "document_root", "port", "protocol" and "PHP framework version" to /setup page
- added new "shattered" wormhole types to "signature table", closed #182, #179

* - added new "delete old signatures" option to "signature reader" dialog, closed #95

* - added new housekeeping cronjob für cached files, closed #200
- added new cache size information to /setup page

* - fixed signature groupId/typeId "overwriting" for already known signatures. closed #207
- improved system search dialog. Added trim(); before "api/signatures-> search" request

* updated README.me

* fixed PHP error "default object from empty value", closed #209

* reduced image file size

* - added local storage (IndexedDB)
- added local storage for map scroll position. closed #69

* - added "notice" panel for upcoming release information
- improved layout for "release dialog" (GitHub API)
- improved pagespeed (removed render blocking javascripts)
- improved map scrollbar configuration
- improved Chrome browser custom scrollbar layout
- removed "sign up" buttons from "map panels", closed #214

* - fixed some session and cookie  bugs

* - added new requirement check for `max_input_vars` to /setup URL, closed #224

* - fixed isWormhole(); bug

* -v1.1.1 added js build files
2016-07-05 20:44:12 +02:00

328 lines
12 KiB
JavaScript

/**
* Main map application
*/
define([
'jquery',
'app/init',
'app/util',
'app/render',
'app/logging',
'app/ccp',
'app/page',
'app/ui/form_element',
'app/module_map'
], function($, Init, Util, Render, Logging, CCP, Page) {
'use strict';
/**
* main init "map" page
*/
$(function(){
// load page
$('body').loadPageStructure();
// show app information in browser console
Util.showVersionInfo();
// init local storage
Util.localforage.config({
name: 'Pathfinder local storage'
});
// init logging
Logging.init();
if( !CCP.isTrusted() ){
// show trust message
$(document).trigger('pf:showTrustDialog');
return;
}
var mapModule = $('#' + Util.config.mapModuleId);
// map init load static data =======================================================
$.getJSON( Init.path.initMap, function( initData ) {
if( initData.error.length > 0 ){
for(var i = 0; i < initData.error.length; i++){
Util.showNotify({
title: initData.error[i].title,
text: initData.error[i].message,
type: initData.error[i].type
});
}
}
Init.timer = initData.timer;
Init.mapTypes = initData.mapTypes;
Init.mapScopes = initData.mapScopes;
Init.connectionScopes = initData.connectionScopes;
Init.systemStatus = initData.systemStatus;
Init.systemType = initData.systemType;
Init.characterStatus = initData.characterStatus;
Init.maxSharedCount = initData.maxSharedCount;
Init.routes = initData.routes;
// init tab change observer, Once the timers are available
Page.initTabChangeObserver();
// init map module
mapModule.initMapModule();
}).fail(function( jqXHR, status, error) {
var reason = status + ' ' + jqXHR.status + ': ' + error;
$(document).trigger('pf:shutdown', {reason: reason});
});
/**
* main function for init all map relevant trigger calls
*/
$.fn.initMapModule = function(){
var mapModule = $(this);
// log keys ------------------------------------------------------------------------
// ajax request update map data
var logKeyServerMapData = 'UPDATE_SERVER_MAP';
// update client map data
var logKeyClientMapData = 'UPDATE_CLIENT_MAP';
// ajax request update map user data
var logKeyServerUserData = 'UPDATE_SERVER_USER_DATA';
// update client map user data
var logKeyClientUserData = 'UPDATE_CLIENT_USER_DATA';
// main update intervals/trigger (heartbeat)
var updateTimeouts = {
mapUpdate: 0,
userUpdate: 0
};
var locationToggle = $('#' + Util.config.headMapTrackingId);
// ping for main map update ========================================================
var triggerMapUpdatePing = function(){
// check each execution time if map module is still available
var check = $('#' + mapModule.attr('id')).length;
if(check === 0){
// program crash stop any update
return;
}
// get updated map data
var updatedMapData = mapModule.getMapModuleDataForUpdate();
// wrap array to object
updatedMapData = {mapData: updatedMapData};
// start log
Util.timeStart(logKeyServerMapData);
// store updatedMapData
$.ajax({
type: 'POST',
url: Init.path.updateMapData,
data: updatedMapData,
dataType: 'json'
}).done(function(data){
// log request time
var duration = Util.timeStop(logKeyServerMapData);
Util.log(logKeyServerMapData, {duration: duration, type: 'server', description: 'request map data'});
if(
data.error &&
data.error.length > 0
){
// any error in the main trigger functions result in a user log-off
$(document).trigger('pf:menuLogout');
}else{
$(document).setProgramStatus('online');
if(data.mapData.length === 0){
// clear all existing maps
mapModule.clearMapModule();
// no map data available -> show "new map" dialog
$(document).trigger('pf:menuShowMapSettings', {tab: 'new'});
}else{
// map data found
// start log
Util.timeStart(logKeyClientMapData);
// load/update main map module
mapModule.updateMapModule(data.mapData);
// log client map update time
duration = Util.timeStop(logKeyClientMapData);
Util.log(logKeyClientMapData, {duration: duration, type: 'client', description: 'update map'});
}
// get the current update delay (this can change if a user is inactive)
var mapUpdateDelay = Util.getCurrentTriggerDelay( logKeyServerMapData, 0 );
// init new trigger
updateTimeouts.mapUpdate = setTimeout(function(){
triggerMapUpdatePing();
}, mapUpdateDelay);
// initial start for the userUpdate trigger
// this should only be called at the first time!
if(updateTimeouts.userUpdate === 0){
// start user update trigger after map loaded
updateTimeouts.userUpdate = setTimeout(function(){
triggerUserUpdatePing();
}, 3000);
}
}
}).fail(handleAjaxErrorResponse);
};
// ping for user data update =======================================================
var triggerUserUpdatePing = function(){
// IMPORTANT: Get user data for ONE map that is currently visible
// On later releases this can be easy changed to "full update" all maps for a user
//
var mapIds = [];
var activeMap = Util.getMapModule().getActiveMap();
if(activeMap){
mapIds = [ activeMap.data('id') ];
}
var updatedUserData = {
mapIds: mapIds,
systemData: Util.getCurrentSystemData(),
characterMapData: {
mapTracking: (locationToggle.is(':checked') ? 1 : 0) // location tracking
}
};
Util.timeStart(logKeyServerUserData);
$.ajax({
type: 'POST',
url: Init.path.updateUserData,
data: updatedUserData,
dataType: 'json'
}).done(function(data){
// log request time
var duration = Util.timeStop(logKeyServerUserData);
Util.log(logKeyServerUserData, {duration: duration, type: 'server', description:'request user data'});
if(data.error.length > 0){
// any error in the main trigger functions result in a user log-off
$(document).trigger('pf:menuLogout');
}else{
$(document).setProgramStatus('online');
if(data.userData !== undefined){
// store current user data global (cache)
var userData = Util.setCurrentUserData(data.userData);
if(userData.character === undefined){
// no active character found -> show settings dialog
Util.showNotify({title: 'Main character not set', text: 'Check your API data and set a main character', type: 'error'});
$(document).triggerMenuEvent('ShowSettingsDialog');
}
// store current map user data (cache)
if(data.mapUserData !== undefined){
Util.setCurrentMapUserData(data.mapUserData);
}
// start log
Util.timeStart(logKeyClientUserData);
// active character data found
mapModule.updateMapModuleData();
// log client user data update time
duration = Util.timeStop(logKeyClientUserData);
Util.log(logKeyClientUserData, {duration: duration, type: 'client', description:'update users'});
// update system info panels
if(data.system){
mapModule.updateSystemModuleData(data.system);
}
// get the current update delay (this can change if a user is inactive)
var mapUserUpdateDelay = Util.getCurrentTriggerDelay( logKeyServerUserData, 0 );
// init new trigger
updateTimeouts.userUpdate = setTimeout(function(){
triggerUserUpdatePing();
}, mapUserUpdateDelay);
}
}
}).fail(handleAjaxErrorResponse);
};
/**
* Ajax error response handler function for main-ping functions
* @param jqXHR
* @param status
* @param error
*/
var handleAjaxErrorResponse = function(jqXHR, status, error){
// clear both main update request trigger timer
clearUpdateTimeouts();
var reason = status + ' ' + jqXHR.status + ': ' + error;
var errorData = [];
if(jqXHR.responseText){
var errorObj = $.parseJSON(jqXHR.responseText);
if(
errorObj.error &&
errorObj.error.length > 0
){
errorData = errorObj.error;
}
}
$(document).trigger('pf:shutdown', {reason: reason, error: errorData});
};
/**
* clear both main update timeouts
* -> stop program from working -> shutdown
*/
var clearUpdateTimeouts = function(){
for(var intervalKey in updateTimeouts) {
if(updateTimeouts.hasOwnProperty(intervalKey)){
clearTimeout( updateTimeouts[intervalKey] );
}
}
};
// initial start of the map update function
triggerMapUpdatePing();
};
});
});