From a359496b7e8e99c4d33d327ef11a54f12af2f76d Mon Sep 17 00:00:00 2001 From: Exodus4D Date: Sun, 14 Aug 2016 02:10:03 +0200 Subject: [PATCH] - added "default map" local storage, closed #117 --- app/main/controller/api/map.php | 7 +++ js/app/map/map.js | 8 +-- js/app/map/util.js | 94 +++++++++++++++++++++--------- js/app/mappage.js | 22 +++---- js/app/module_map.js | 71 ++++++++++------------ js/app/util.js | 25 +++++++- public/js/v1.1.3/app/map/map.js | 8 +-- public/js/v1.1.3/app/map/util.js | 94 +++++++++++++++++++++--------- public/js/v1.1.3/app/mappage.js | 22 +++---- public/js/v1.1.3/app/module_map.js | 71 ++++++++++------------ public/js/v1.1.3/app/util.js | 25 +++++++- 11 files changed, 271 insertions(+), 176 deletions(-) diff --git a/app/main/controller/api/map.php b/app/main/controller/api/map.php index ab77b251..8acbfdaa 100644 --- a/app/main/controller/api/map.php +++ b/app/main/controller/api/map.php @@ -510,6 +510,7 @@ class Map extends Controller\AccessController { */ public function updateData(\Base $f3){ $mapData = (array)$f3->get('POST.mapData'); + $userDataRequired = (bool)$f3->get('POST.getUserData'); $activeCharacter = $this->getCharacter(); @@ -628,6 +629,12 @@ class Map extends Controller\AccessController { $return = $f3->get($cacheKey); } + // if userData is requested -> add it as well + // -> Only first trigger call should request this data! + if($userDataRequired){ + $return->userData = $activeCharacter->getUser()->getData(); + } + echo json_encode( $return ); } diff --git a/js/app/map/map.js b/js/app/map/map.js index a2850e30..de55da41 100644 --- a/js/app/map/map.js +++ b/js/app/map/map.js @@ -820,10 +820,10 @@ define([ if(connectionId > 0){ connectionCache[mapId][connectionId] = connection; }else{ - console.error('updateConnectionCache', 'connectionId missing'); + console.warn('updateConnectionCache', 'connectionId missing'); } }else{ - console.error('updateConnectionCache', 'missing data'); + console.warn('updateConnectionCache', 'missing data'); } }; @@ -3273,7 +3273,7 @@ define([ var mapWrapper = mapContainer.parents('.' + config.mapWrapperClass); // auto scroll map to previous position - var promiseStore = MapUtil.getMapData( mapContainer.data('id') ); + var promiseStore = MapUtil.getLocaleData('map', mapContainer.data('id') ); promiseStore.then(function(data) { // This code runs once the value has been loaded // from the offline store. @@ -3314,7 +3314,7 @@ define([ // scroll complete var mapElement = $(this).find('.' + config.mapClass); // store new map scrollOffset -> localDB - MapUtil.storeMapData( mapElement.data('id'), 'offsetX', Math.abs(this.mcs.left) ); + MapUtil.storeLocalData('map', mapElement.data('id'), 'offsetX', Math.abs(this.mcs.left) ); }, onScrollStart: function(){ // hide all open xEditable fields diff --git a/js/app/map/util.js b/js/app/map/util.js index e41b0934..ba0fe488 100644 --- a/js/app/map/util.js +++ b/js/app/map/util.js @@ -11,7 +11,8 @@ define([ var config = { // local storage - mapLocalStoragePrefix: 'map_', // prefix for map local storage key + characterLocalStoragePrefix: 'character_', // prefix for character data local storage key + mapLocalStoragePrefix: 'map_', // prefix for map data local storage key }; /** @@ -382,7 +383,7 @@ define([ // check if desktop notification was already send var mapId = system.data('mapid'); var systemId = system.data('id'); - var promiseStore = getMapData(mapId); + var promiseStore = getLocaleData('map', mapId); promiseStore.then(function(data) { // This code runs once the value has been loaded // from the offline store. @@ -401,7 +402,7 @@ define([ rallyPokeData[this.systemId] !== rallyUpdated // already send to that system but in the past ){ rallyPokeData[this.systemId] = rallyUpdated; - storeMapData(this.mapId, 'rallyPoke', rallyPokeData); + storeLocalData('map', this.mapId, 'rallyPoke', rallyPokeData); notificationOptions.type = 'info'; Util.showNotify(notificationOptions, {desktop: true, stack: 'barBottom'}); @@ -428,71 +429,105 @@ define([ }; /** - * get stored map data from client cache (IndexedDB) + * store mapId for current user (IndexedDB) * @param mapId - * @returns {*} promise */ - var getMapData = function(mapId){ + var storeDefaultMapId = function(mapId){ if(mapId > 0){ - var mapStorageKey = config.mapLocalStoragePrefix + mapId; - return Util.localforage.getItem(mapStorageKey); - }else{ - console.error('Map local storage requires mapId > 0'); + var userData = Util.getCurrentUserData(); + if( + userData && + userData.character + ){ + storeLocalData('character', userData.character.id, 'defaultMapId', mapId); + } } }; /** - * store local map config to client cache (IndexedDB) - * @param mapId + * get key prefix for local storage data + * @param type + * @returns {boolean} + */ + var getLocalStoragePrefixByType = function(type){ + var prefix = false; + switch(type){ + case 'character': prefix = config.characterLocalStoragePrefix; break; + case 'map': prefix = config.mapLocalStoragePrefix; break; + default: prefix = config.mapLocalStoragePrefix; + } + return prefix; + }; + + /** + * get stored local data from client cache (IndexedDB) + * @param type + * @param objectId + * @returns {*} + */ + var getLocaleData = function(type, objectId){ + if(objectId > 0){ + var storageKey = getLocalStoragePrefixByType(type) + objectId; + return Util.localforage.getItem(storageKey); + }else{ + console.warn('Local storage requires object id > 0'); + } + }; + + /** + * store local config data to client cache (IndexedDB) + * @param type + * @param objectId * @param key * @param value */ - var storeMapData = function(mapId, key, value){ - if(mapId > 0){ + var storeLocalData = function(type, objectId, key, value){ + if(objectId > 0){ // get current map config - var mapStorageKey = config.mapLocalStoragePrefix + mapId; - Util.localforage.getItem(mapStorageKey).then(function(data) { + var storageKey = getLocalStoragePrefixByType(type) + objectId; + Util.localforage.getItem(storageKey).then(function(data) { // This code runs once the value has been loaded // from the offline store. data = (data === null) ? {} : data; // set/update value data[this.key] = this.value; - Util.localforage.setItem(this.mapStorageKey, data); + Util.localforage.setItem(this.storageKey, data); }.bind({ key: key, value: value, - mapStorageKey: mapStorageKey + storageKey: storageKey })).catch(function(err) { // This code runs if there were any errors console.error('Map local storage can not be accessed!'); }); }else{ - console.error('storeMapData(): Local storage requires mapId > 0'); + console.warn('storeLocalData(): Local storage requires object id > 0'); } }; /** * delete local map configuration by key (IndexedDB) - * @param mapId + * @param type + * @param objectId * @param key */ - var deleteMapData = function(mapId, key){ - if(mapId > 0){ + var deleteLocalData = function(type, objectId, key){ + if(objectId > 0){ // get current map config - var mapStorageKey = config.mapLocalStoragePrefix + mapId; + var storageKey = getLocalStoragePrefixByType(type) + objectId; Util.localforage.getItem(mapStorageKey).then(function(data) { if( data && data.hasOwnProperty(key) ){ delete data[key]; - Util.localforage.setItem(this.mapStorageKey, data); + Util.localforage.setItem(this.storageKey, data); } }.bind({ - mapStorageKey: mapStorageKey + storageKey: storageKey })); }else{ - console.error('deleteMapData(): Local storage requires mapId > 0'); + console.warn('deleteLocalData(): Local storage requires object id > 0'); } }; @@ -512,8 +547,9 @@ define([ getDefaultConnectionTypeByScope: getDefaultConnectionTypeByScope, setConnectionWHStatus: setConnectionWHStatus, getScopeInfoForConnection: getScopeInfoForConnection, - getMapData: getMapData, - storeMapData: storeMapData, - deleteMapData: deleteMapData + storeDefaultMapId: storeDefaultMapId, + getLocaleData: getLocaleData, + storeLocalData: storeLocalData, + deleteLocalData: deleteLocalData }; }); \ No newline at end of file diff --git a/js/app/mappage.js b/js/app/mappage.js index f28b1666..08f16fc8 100644 --- a/js/app/mappage.js +++ b/js/app/mappage.js @@ -112,10 +112,10 @@ define([ } // get updated map data - var updatedMapData = mapModule.getMapModuleDataForUpdate(); - - // wrap array to object - updatedMapData = {mapData: updatedMapData}; + var updatedMapData = { + mapData: mapModule.getMapModuleDataForUpdate(), + getUserData: ( Util.getCurrentUserData() ) ? 0 : 1 + }; // start log Util.timeStart(logKeyServerMapData); @@ -139,9 +139,13 @@ define([ // 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) + Util.setCurrentUserData(data.userData); + } + if(data.mapData.length === 0){ // clear all existing maps mapModule.clearMapModule(); @@ -228,14 +232,6 @@ define([ // 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); diff --git a/js/app/module_map.js b/js/app/module_map.js index 17f5a5b9..70bfd3cb 100644 --- a/js/app/module_map.js +++ b/js/app/module_map.js @@ -76,16 +76,13 @@ define([ * @param mapContentModule */ $.fn.setTabContentObserver = function(){ - return this.each(function(){ // update Tab Content with system data information $(this).on('pf:drawSystemModules', function(e){ - drawSystemModules($( e.target )); }); $(this).on('pf:removeSystemModules', function(e){ - removeSystemModules($( e.target )); }); }); @@ -113,7 +110,6 @@ define([ * @param tabContentElement */ var drawSystemModules = function(tabContentElement){ - var currentSystemData = Util.getCurrentSystemData(); // get Table cell for system Info @@ -187,7 +183,6 @@ define([ } } }); - }; @@ -239,7 +234,6 @@ define([ * load all structure elements into a TabsContent div (tab body) */ $.fn.initContentStructure = function(){ - return this.each(function(){ // init bootstrap Grid var contentStructure = $('
', { @@ -254,7 +248,6 @@ define([ }) ); - // append grid structure $(this).append(contentStructure); }); @@ -266,7 +259,6 @@ define([ * @returns {*|jQuery|HTMLElement} */ var getTabElement = function(options){ - var tabElement = $('
', { id: config.mapTabElementId }); @@ -332,12 +324,10 @@ define([ if( listElement.hasClass('active') ){ tabClasses.push('active'); } - listElement.removeClass().addClass( tabClasses.join(' ') ); // set title for tooltip if(options.type.name !== undefined){ - tabLinkTextElement.attr('title', options.type.name + ' map'); } @@ -362,7 +352,6 @@ define([ * @returns {{listElement: (*|void), contentElement: (*|HTMLElement)}} */ $.fn.addTab = function(options){ - var tabElement = $(this); var tabBar = tabElement.find('ul.nav-tabs'); var tabContent = tabElement.find('div.tab-content'); @@ -424,7 +413,6 @@ define([ } if(mapTabChangeBlocked === false){ - var tabLinkElement = $(this); var mapId = tabLinkElement.data('map-id'); @@ -448,11 +436,9 @@ define([ }else{ tabLinkElement.tab('show'); } - } }); - return { listElement: newListElement, contentElement: contentElement @@ -464,11 +450,8 @@ define([ * @param mapId */ $.fn.deleteTab = function(mapId){ - var tabElement = $(this); - var linkElement = tabElement.find('a[href="#' + config.mapTabIdPrefix + mapId + '"]'); - var deletedTabName = ''; if(linkElement.length > 0){ @@ -502,9 +485,7 @@ define([ * clear all active maps */ $.fn.clearMapModule = function(){ - var mapModuleElement = $(this); - var tabMapElement = $('#' + config.mapTabElementId); if(tabMapElement.length > 0){ @@ -527,7 +508,6 @@ define([ * @returns {boolean} */ $.fn.updateMapModule = function(mapData){ - if(mapData.length === 0){ return true; } @@ -560,7 +540,6 @@ define([ var mapId = tabElement.data('map-id'); if(mapId > 0){ - var tabMapData = Util.getCurrentMapData(mapId); if(tabMapData !== false){ @@ -571,7 +550,6 @@ define([ if(tabMapData.config.updated !== tabElement.data('updated')){ tabElement.updateTabData(tabMapData.config); } - }else{ // map data not available -> remove tab var deletedTabName = tabMapElement.deleteTab(mapId); @@ -587,7 +565,6 @@ define([ // add new tabs for new maps $.each(tempMapData, function(i, data){ - if( activeMapIds.indexOf( data.config.id ) === -1 ){ // add new map tab @@ -612,7 +589,6 @@ define([ Util.showNotify({title: 'Map added', text: data.config.name + ' added', type: 'success'}); } - }); // get current active map @@ -624,11 +600,11 @@ define([ if(activeMapData !== false){ // update active map with new mapData var currentTabContentElement = $('#' + config.mapTabIdPrefix + activeMapId); + $( currentTabContentElement).loadMap( activeMapData, {} ); } }else{ // create Tab Element - tabsChanged = true; var options = { @@ -657,25 +633,40 @@ define([ tabMapElement.addTab(tabAddOptions); - mapModuleElement.prepend(tabMapElement); - // set first Tab active - tabMapElement.find('.' + config.mapTabClass + ':first a').tab('show'); + var currentUserData = Util.getCurrentUserData(); + var promiseStore = MapUtil.getLocaleData('character', currentUserData.character.id); - // ============================================================== + promiseStore.then(function(data) { + // array key where map data is available (0 == first map found) + var mapDataIndex = 0; + // tab dom selector + var mapKeyTabSelector = 'first'; - // this new created module - var tabContentElements = tabMapElement.find('.' + config.mapTabContentClass); + if( + data && + data.defaultMapId + ){ + mapDataIndex = Util.getCurrentMapDataIndex(data.defaultMapId); + mapKeyTabSelector = 'nth-child(' + ( mapDataIndex + 1 ) + ')' + } - // set observer for manually triggered map events - tabContentElements.setTabContentObserver(); + // ============================================================== - // load all the structure elements for ALL Tab Content Body - tabContentElements.initContentStructure(); + // this new created module + var tabContentElements = tabMapElement.find('.' + config.mapTabContentClass); + + // set observer for manually triggered map events + tabContentElements.setTabContentObserver(); + + // load all the structure elements for ALL Tab Content Body + tabContentElements.initContentStructure(); + + // set first Tab active + tabMapElement.find('.' + config.mapTabClass + ':' + mapKeyTabSelector + ' a').tab('show'); + }); - // load first map i in first tab content container - $( tabContentElements[0] ).loadMap( tempMapData[0], {showAnimation: true} ); } if(tabsChanged === true){ @@ -691,7 +682,10 @@ define([ allTabElements.on('show.bs.tab', function (e) { var mapId = $(e.target).data('map-id'); - if(mapId === 0){ + if(mapId > 0){ + // save mapId as new "default" (local storage) + var userData = MapUtil.storeDefaultMapId(mapId); + }else{ // add new Tab selected $(document).trigger('pf:menuShowMapSettings', {tab: 'new'}); e.preventDefault(); @@ -719,7 +713,6 @@ define([ }); allTabElements.on('hide.bs.tab', function (e) { - var newMapId = $(e.relatedTarget).data('map-id'); var oldMapId = $(e.target).data('map-id'); diff --git a/js/app/util.js b/js/app/util.js index ee92c871..b94e5524 100644 --- a/js/app/util.js +++ b/js/app/util.js @@ -1433,7 +1433,6 @@ define([ * @returns {boolean} */ var getCurrentMapData = function(mapId){ - var currentMapData = false; if( mapId === parseInt(mapId, 10) ){ @@ -1452,6 +1451,27 @@ define([ return currentMapData; }; + /** + * get mapData array index by mapId + * @param mapId + * @returns {boolean|int} + */ + var getCurrentMapDataIndex = function(mapId){ + var mapDataIndex = false; + + if( mapId === parseInt(mapId, 10) ){ + for(var i = 0; i < Init.currentMapData.length; i++){ + if(Init.currentMapData[i].config.id === mapId){ + mapDataIndex = i; + break; + } + } + } + + return mapDataIndex; + }; + + /** * set currentUserData as "global" variable * this function should be called continuously after data change @@ -1459,7 +1479,6 @@ define([ * @param userData */ var setCurrentUserData = function(userData){ - Init.currentUserData = userData; // check if function is available @@ -1507,7 +1526,6 @@ define([ */ var getCurrentUserInfo = function(option){ var currentUserData = getCurrentUserData(); - var userInfo = false; if(currentUserData){ @@ -1753,6 +1771,7 @@ define([ getCurrentMapUserData: getCurrentMapUserData, setCurrentMapData: setCurrentMapData, getCurrentMapData: getCurrentMapData, + getCurrentMapDataIndex: getCurrentMapDataIndex, setCurrentUserData: setCurrentUserData, getCurrentUserData: getCurrentUserData, setCurrentSystemData: setCurrentSystemData, diff --git a/public/js/v1.1.3/app/map/map.js b/public/js/v1.1.3/app/map/map.js index a2850e30..de55da41 100644 --- a/public/js/v1.1.3/app/map/map.js +++ b/public/js/v1.1.3/app/map/map.js @@ -820,10 +820,10 @@ define([ if(connectionId > 0){ connectionCache[mapId][connectionId] = connection; }else{ - console.error('updateConnectionCache', 'connectionId missing'); + console.warn('updateConnectionCache', 'connectionId missing'); } }else{ - console.error('updateConnectionCache', 'missing data'); + console.warn('updateConnectionCache', 'missing data'); } }; @@ -3273,7 +3273,7 @@ define([ var mapWrapper = mapContainer.parents('.' + config.mapWrapperClass); // auto scroll map to previous position - var promiseStore = MapUtil.getMapData( mapContainer.data('id') ); + var promiseStore = MapUtil.getLocaleData('map', mapContainer.data('id') ); promiseStore.then(function(data) { // This code runs once the value has been loaded // from the offline store. @@ -3314,7 +3314,7 @@ define([ // scroll complete var mapElement = $(this).find('.' + config.mapClass); // store new map scrollOffset -> localDB - MapUtil.storeMapData( mapElement.data('id'), 'offsetX', Math.abs(this.mcs.left) ); + MapUtil.storeLocalData('map', mapElement.data('id'), 'offsetX', Math.abs(this.mcs.left) ); }, onScrollStart: function(){ // hide all open xEditable fields diff --git a/public/js/v1.1.3/app/map/util.js b/public/js/v1.1.3/app/map/util.js index e41b0934..ba0fe488 100644 --- a/public/js/v1.1.3/app/map/util.js +++ b/public/js/v1.1.3/app/map/util.js @@ -11,7 +11,8 @@ define([ var config = { // local storage - mapLocalStoragePrefix: 'map_', // prefix for map local storage key + characterLocalStoragePrefix: 'character_', // prefix for character data local storage key + mapLocalStoragePrefix: 'map_', // prefix for map data local storage key }; /** @@ -382,7 +383,7 @@ define([ // check if desktop notification was already send var mapId = system.data('mapid'); var systemId = system.data('id'); - var promiseStore = getMapData(mapId); + var promiseStore = getLocaleData('map', mapId); promiseStore.then(function(data) { // This code runs once the value has been loaded // from the offline store. @@ -401,7 +402,7 @@ define([ rallyPokeData[this.systemId] !== rallyUpdated // already send to that system but in the past ){ rallyPokeData[this.systemId] = rallyUpdated; - storeMapData(this.mapId, 'rallyPoke', rallyPokeData); + storeLocalData('map', this.mapId, 'rallyPoke', rallyPokeData); notificationOptions.type = 'info'; Util.showNotify(notificationOptions, {desktop: true, stack: 'barBottom'}); @@ -428,71 +429,105 @@ define([ }; /** - * get stored map data from client cache (IndexedDB) + * store mapId for current user (IndexedDB) * @param mapId - * @returns {*} promise */ - var getMapData = function(mapId){ + var storeDefaultMapId = function(mapId){ if(mapId > 0){ - var mapStorageKey = config.mapLocalStoragePrefix + mapId; - return Util.localforage.getItem(mapStorageKey); - }else{ - console.error('Map local storage requires mapId > 0'); + var userData = Util.getCurrentUserData(); + if( + userData && + userData.character + ){ + storeLocalData('character', userData.character.id, 'defaultMapId', mapId); + } } }; /** - * store local map config to client cache (IndexedDB) - * @param mapId + * get key prefix for local storage data + * @param type + * @returns {boolean} + */ + var getLocalStoragePrefixByType = function(type){ + var prefix = false; + switch(type){ + case 'character': prefix = config.characterLocalStoragePrefix; break; + case 'map': prefix = config.mapLocalStoragePrefix; break; + default: prefix = config.mapLocalStoragePrefix; + } + return prefix; + }; + + /** + * get stored local data from client cache (IndexedDB) + * @param type + * @param objectId + * @returns {*} + */ + var getLocaleData = function(type, objectId){ + if(objectId > 0){ + var storageKey = getLocalStoragePrefixByType(type) + objectId; + return Util.localforage.getItem(storageKey); + }else{ + console.warn('Local storage requires object id > 0'); + } + }; + + /** + * store local config data to client cache (IndexedDB) + * @param type + * @param objectId * @param key * @param value */ - var storeMapData = function(mapId, key, value){ - if(mapId > 0){ + var storeLocalData = function(type, objectId, key, value){ + if(objectId > 0){ // get current map config - var mapStorageKey = config.mapLocalStoragePrefix + mapId; - Util.localforage.getItem(mapStorageKey).then(function(data) { + var storageKey = getLocalStoragePrefixByType(type) + objectId; + Util.localforage.getItem(storageKey).then(function(data) { // This code runs once the value has been loaded // from the offline store. data = (data === null) ? {} : data; // set/update value data[this.key] = this.value; - Util.localforage.setItem(this.mapStorageKey, data); + Util.localforage.setItem(this.storageKey, data); }.bind({ key: key, value: value, - mapStorageKey: mapStorageKey + storageKey: storageKey })).catch(function(err) { // This code runs if there were any errors console.error('Map local storage can not be accessed!'); }); }else{ - console.error('storeMapData(): Local storage requires mapId > 0'); + console.warn('storeLocalData(): Local storage requires object id > 0'); } }; /** * delete local map configuration by key (IndexedDB) - * @param mapId + * @param type + * @param objectId * @param key */ - var deleteMapData = function(mapId, key){ - if(mapId > 0){ + var deleteLocalData = function(type, objectId, key){ + if(objectId > 0){ // get current map config - var mapStorageKey = config.mapLocalStoragePrefix + mapId; + var storageKey = getLocalStoragePrefixByType(type) + objectId; Util.localforage.getItem(mapStorageKey).then(function(data) { if( data && data.hasOwnProperty(key) ){ delete data[key]; - Util.localforage.setItem(this.mapStorageKey, data); + Util.localforage.setItem(this.storageKey, data); } }.bind({ - mapStorageKey: mapStorageKey + storageKey: storageKey })); }else{ - console.error('deleteMapData(): Local storage requires mapId > 0'); + console.warn('deleteLocalData(): Local storage requires object id > 0'); } }; @@ -512,8 +547,9 @@ define([ getDefaultConnectionTypeByScope: getDefaultConnectionTypeByScope, setConnectionWHStatus: setConnectionWHStatus, getScopeInfoForConnection: getScopeInfoForConnection, - getMapData: getMapData, - storeMapData: storeMapData, - deleteMapData: deleteMapData + storeDefaultMapId: storeDefaultMapId, + getLocaleData: getLocaleData, + storeLocalData: storeLocalData, + deleteLocalData: deleteLocalData }; }); \ No newline at end of file diff --git a/public/js/v1.1.3/app/mappage.js b/public/js/v1.1.3/app/mappage.js index f28b1666..08f16fc8 100644 --- a/public/js/v1.1.3/app/mappage.js +++ b/public/js/v1.1.3/app/mappage.js @@ -112,10 +112,10 @@ define([ } // get updated map data - var updatedMapData = mapModule.getMapModuleDataForUpdate(); - - // wrap array to object - updatedMapData = {mapData: updatedMapData}; + var updatedMapData = { + mapData: mapModule.getMapModuleDataForUpdate(), + getUserData: ( Util.getCurrentUserData() ) ? 0 : 1 + }; // start log Util.timeStart(logKeyServerMapData); @@ -139,9 +139,13 @@ define([ // 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) + Util.setCurrentUserData(data.userData); + } + if(data.mapData.length === 0){ // clear all existing maps mapModule.clearMapModule(); @@ -228,14 +232,6 @@ define([ // 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); diff --git a/public/js/v1.1.3/app/module_map.js b/public/js/v1.1.3/app/module_map.js index 17f5a5b9..70bfd3cb 100644 --- a/public/js/v1.1.3/app/module_map.js +++ b/public/js/v1.1.3/app/module_map.js @@ -76,16 +76,13 @@ define([ * @param mapContentModule */ $.fn.setTabContentObserver = function(){ - return this.each(function(){ // update Tab Content with system data information $(this).on('pf:drawSystemModules', function(e){ - drawSystemModules($( e.target )); }); $(this).on('pf:removeSystemModules', function(e){ - removeSystemModules($( e.target )); }); }); @@ -113,7 +110,6 @@ define([ * @param tabContentElement */ var drawSystemModules = function(tabContentElement){ - var currentSystemData = Util.getCurrentSystemData(); // get Table cell for system Info @@ -187,7 +183,6 @@ define([ } } }); - }; @@ -239,7 +234,6 @@ define([ * load all structure elements into a TabsContent div (tab body) */ $.fn.initContentStructure = function(){ - return this.each(function(){ // init bootstrap Grid var contentStructure = $('
', { @@ -254,7 +248,6 @@ define([ }) ); - // append grid structure $(this).append(contentStructure); }); @@ -266,7 +259,6 @@ define([ * @returns {*|jQuery|HTMLElement} */ var getTabElement = function(options){ - var tabElement = $('
', { id: config.mapTabElementId }); @@ -332,12 +324,10 @@ define([ if( listElement.hasClass('active') ){ tabClasses.push('active'); } - listElement.removeClass().addClass( tabClasses.join(' ') ); // set title for tooltip if(options.type.name !== undefined){ - tabLinkTextElement.attr('title', options.type.name + ' map'); } @@ -362,7 +352,6 @@ define([ * @returns {{listElement: (*|void), contentElement: (*|HTMLElement)}} */ $.fn.addTab = function(options){ - var tabElement = $(this); var tabBar = tabElement.find('ul.nav-tabs'); var tabContent = tabElement.find('div.tab-content'); @@ -424,7 +413,6 @@ define([ } if(mapTabChangeBlocked === false){ - var tabLinkElement = $(this); var mapId = tabLinkElement.data('map-id'); @@ -448,11 +436,9 @@ define([ }else{ tabLinkElement.tab('show'); } - } }); - return { listElement: newListElement, contentElement: contentElement @@ -464,11 +450,8 @@ define([ * @param mapId */ $.fn.deleteTab = function(mapId){ - var tabElement = $(this); - var linkElement = tabElement.find('a[href="#' + config.mapTabIdPrefix + mapId + '"]'); - var deletedTabName = ''; if(linkElement.length > 0){ @@ -502,9 +485,7 @@ define([ * clear all active maps */ $.fn.clearMapModule = function(){ - var mapModuleElement = $(this); - var tabMapElement = $('#' + config.mapTabElementId); if(tabMapElement.length > 0){ @@ -527,7 +508,6 @@ define([ * @returns {boolean} */ $.fn.updateMapModule = function(mapData){ - if(mapData.length === 0){ return true; } @@ -560,7 +540,6 @@ define([ var mapId = tabElement.data('map-id'); if(mapId > 0){ - var tabMapData = Util.getCurrentMapData(mapId); if(tabMapData !== false){ @@ -571,7 +550,6 @@ define([ if(tabMapData.config.updated !== tabElement.data('updated')){ tabElement.updateTabData(tabMapData.config); } - }else{ // map data not available -> remove tab var deletedTabName = tabMapElement.deleteTab(mapId); @@ -587,7 +565,6 @@ define([ // add new tabs for new maps $.each(tempMapData, function(i, data){ - if( activeMapIds.indexOf( data.config.id ) === -1 ){ // add new map tab @@ -612,7 +589,6 @@ define([ Util.showNotify({title: 'Map added', text: data.config.name + ' added', type: 'success'}); } - }); // get current active map @@ -624,11 +600,11 @@ define([ if(activeMapData !== false){ // update active map with new mapData var currentTabContentElement = $('#' + config.mapTabIdPrefix + activeMapId); + $( currentTabContentElement).loadMap( activeMapData, {} ); } }else{ // create Tab Element - tabsChanged = true; var options = { @@ -657,25 +633,40 @@ define([ tabMapElement.addTab(tabAddOptions); - mapModuleElement.prepend(tabMapElement); - // set first Tab active - tabMapElement.find('.' + config.mapTabClass + ':first a').tab('show'); + var currentUserData = Util.getCurrentUserData(); + var promiseStore = MapUtil.getLocaleData('character', currentUserData.character.id); - // ============================================================== + promiseStore.then(function(data) { + // array key where map data is available (0 == first map found) + var mapDataIndex = 0; + // tab dom selector + var mapKeyTabSelector = 'first'; - // this new created module - var tabContentElements = tabMapElement.find('.' + config.mapTabContentClass); + if( + data && + data.defaultMapId + ){ + mapDataIndex = Util.getCurrentMapDataIndex(data.defaultMapId); + mapKeyTabSelector = 'nth-child(' + ( mapDataIndex + 1 ) + ')' + } - // set observer for manually triggered map events - tabContentElements.setTabContentObserver(); + // ============================================================== - // load all the structure elements for ALL Tab Content Body - tabContentElements.initContentStructure(); + // this new created module + var tabContentElements = tabMapElement.find('.' + config.mapTabContentClass); + + // set observer for manually triggered map events + tabContentElements.setTabContentObserver(); + + // load all the structure elements for ALL Tab Content Body + tabContentElements.initContentStructure(); + + // set first Tab active + tabMapElement.find('.' + config.mapTabClass + ':' + mapKeyTabSelector + ' a').tab('show'); + }); - // load first map i in first tab content container - $( tabContentElements[0] ).loadMap( tempMapData[0], {showAnimation: true} ); } if(tabsChanged === true){ @@ -691,7 +682,10 @@ define([ allTabElements.on('show.bs.tab', function (e) { var mapId = $(e.target).data('map-id'); - if(mapId === 0){ + if(mapId > 0){ + // save mapId as new "default" (local storage) + var userData = MapUtil.storeDefaultMapId(mapId); + }else{ // add new Tab selected $(document).trigger('pf:menuShowMapSettings', {tab: 'new'}); e.preventDefault(); @@ -719,7 +713,6 @@ define([ }); allTabElements.on('hide.bs.tab', function (e) { - var newMapId = $(e.relatedTarget).data('map-id'); var oldMapId = $(e.target).data('map-id'); diff --git a/public/js/v1.1.3/app/util.js b/public/js/v1.1.3/app/util.js index ee92c871..b94e5524 100644 --- a/public/js/v1.1.3/app/util.js +++ b/public/js/v1.1.3/app/util.js @@ -1433,7 +1433,6 @@ define([ * @returns {boolean} */ var getCurrentMapData = function(mapId){ - var currentMapData = false; if( mapId === parseInt(mapId, 10) ){ @@ -1452,6 +1451,27 @@ define([ return currentMapData; }; + /** + * get mapData array index by mapId + * @param mapId + * @returns {boolean|int} + */ + var getCurrentMapDataIndex = function(mapId){ + var mapDataIndex = false; + + if( mapId === parseInt(mapId, 10) ){ + for(var i = 0; i < Init.currentMapData.length; i++){ + if(Init.currentMapData[i].config.id === mapId){ + mapDataIndex = i; + break; + } + } + } + + return mapDataIndex; + }; + + /** * set currentUserData as "global" variable * this function should be called continuously after data change @@ -1459,7 +1479,6 @@ define([ * @param userData */ var setCurrentUserData = function(userData){ - Init.currentUserData = userData; // check if function is available @@ -1507,7 +1526,6 @@ define([ */ var getCurrentUserInfo = function(option){ var currentUserData = getCurrentUserData(); - var userInfo = false; if(currentUserData){ @@ -1753,6 +1771,7 @@ define([ getCurrentMapUserData: getCurrentMapUserData, setCurrentMapData: setCurrentMapData, getCurrentMapData: getCurrentMapData, + getCurrentMapDataIndex: getCurrentMapDataIndex, setCurrentUserData: setCurrentUserData, getCurrentUserData: getCurrentUserData, setCurrentSystemData: setCurrentSystemData,