From 1c9c9f4563df12bbd3b79b9d286d66ec0695057b Mon Sep 17 00:00:00 2001 From: Exodus4D Date: Fri, 5 Aug 2016 19:35:56 +0200 Subject: [PATCH] - WIP: improve "Set rally point" context menu option for systems, #279 --- app/main/model/systemmodel.php | 27 ++++-- js/app/map/map.js | 141 +++++++++++++++++--------------- public/js/v1.1.3/app/map/map.js | 141 +++++++++++++++++--------------- 3 files changed, 170 insertions(+), 139 deletions(-) diff --git a/app/main/model/systemmodel.php b/app/main/model/systemmodel.php index 688422f2..a2d11ffe 100644 --- a/app/main/model/systemmodel.php +++ b/app/main/model/systemmodel.php @@ -111,10 +111,9 @@ class SystemModel extends BasicModel { 'nullable' => false, 'default' => 0 ], - 'rally' => [ - 'type' => Schema::DT_BOOL, - 'nullable' => false, - 'default' => 0 + 'rallyUpdated' => [ + 'type' => Schema::DT_TIMESTAMP, + 'default' => null ], 'description' => [ 'type' => Schema::DT_VARCHAR512, @@ -234,7 +233,7 @@ class SystemModel extends BasicModel { $systemData->status->name = is_object($this->statusId) ? $this->statusId->name : ''; $systemData->locked = $this->locked; - $systemData->rally = $this->rally; + $systemData->rallyUpdated = strtotime($this->rallyUpdated); $systemData->description = $this->description; $systemData->statics = $this->getStaticWormholeData(); @@ -313,6 +312,24 @@ class SystemModel extends BasicModel { return $posY; } + /** + * setter for system rally timestamp + * @param $rally + * @return bool|int|null|string + */ + public function set_rallyUpdated($rally){ + $rally = (int)$rally; + if($rally === 0){ + $rally = null; + }elseif($rally === 1){ + $rally = date('Y-m-d H:i:s'); + }else{ + $rally = date('Y-m-d H:i:s', $rally); + } + + return $rally; + } + /** * check object for model access * @param CharacterModel $characterModel diff --git a/js/app/map/map.js b/js/app/map/map.js index 98370ca3..369aebbe 100644 --- a/js/app/map/map.js +++ b/js/app/map/map.js @@ -450,6 +450,68 @@ define([ system.addClass( statusClass ); }; + /** + * set or change rallyPoint for systems + * @param rallyUpdated + * @param options + * @returns {*} + */ + $.fn.setSystemRally = function(rallyUpdated, options){ + rallyUpdated = rallyUpdated || 0; + + var defaultOptions = { + poke: false, + hideNotification: false, + hideCounter: false, + }; + options = $.extend({}, defaultOptions, options); + + return this.each(function(){ + var system = $(this); + var rally = system.data('rallyUpdated') || 0; + + if(rallyUpdated !== rally){ + // rally status changed + if( !options.hideCounter ){ + system.getMapOverlay('timer').startMapUpdateCounter(); + } + + var rallyClass = MapUtil.getInfoForSystem('rally', 'class'); + + if(rallyUpdated > 0){ + // new rally point set + system.addClass( rallyClass ); + + if( !options.hideNotification ){ + var systemName = system.getSystemInfo( ['alias'] ); + + var notificationOptions = { + title: 'Rally Point', + text: 'System: ' + systemName, + type: 'success' + }; + + if(options.poke){ + // desktop poke + Util.showNotify(notificationOptions, {desktop: true, stack: 'barBottom'}); + }else{ + Util.showNotify(notificationOptions, {stack: 'barBottom'}); + } + } + }else{ + // rally point removed + system.removeClass( rallyClass ); + + if( !options.hideNotification ){ + Util.showNotify({title: 'Rally point removed', type: 'success'}); + } + } + } + + system.data('rallyUpdated', rallyUpdated); + }); + }; + /** * returns a new system or updates an existing system * @param map @@ -606,9 +668,10 @@ define([ } // rally system - if( Boolean( system.data( 'rally') ) !== data.rally ){ - system.toggleRallyPoint(false, {hideNotification: true, hideCounter: true}); - } + system.setSystemRally(data.rallyUpdated, { + hideNotification: true, + hideCounter: true, + }); return system; }; @@ -1825,8 +1888,8 @@ define([ currentSystem.markAsChanged(); break; case 'set_rally': - // set rally point - if( ! currentSystem.data( 'rally' ) ){ + // toggle rally point + if( !currentSystem.data( 'rallyUpdated' ) ){ // show confirm dialog var rallyDialog = bootbox.dialog({ @@ -1844,7 +1907,9 @@ define([ label: ' Set rally and poke', className: 'btn-primary', callback: function() { - currentSystem.toggleRallyPoint(true, {}); + currentSystem.setSystemRally(1, { + poke: true + }); currentSystem.markAsChanged(); } }, @@ -1852,7 +1917,7 @@ define([ label: ' save', className: 'btn-success', callback: function() { - currentSystem.toggleRallyPoint(false, {}); + currentSystem.setSystemRally(1); currentSystem.markAsChanged(); } } @@ -1860,7 +1925,7 @@ define([ }); }else{ // remove rally point - currentSystem.toggleRallyPoint(false, {}); + currentSystem.setSystemRally(0); currentSystem.markAsChanged(); } break; @@ -2097,64 +2162,6 @@ define([ }; - /** - * toggle a system as rally point and display notifications - * @param poke - * @param options - */ - $.fn.toggleRallyPoint = function(poke, options){ - - var system = $(this); - - var rallyClass = MapUtil.getInfoForSystem('rally', 'class'); - - var hideNotification = false; - if(options.hideNotification === true){ - hideNotification = true; - } - - var hideCounter = false; - if(options.hideCounter === true){ - hideCounter = true; - } - - // check of system is already marked as rally - if( system.data( 'rally' ) === true ){ - system.removeClass( rallyClass ); - system.data( 'rally', false ); - - if(! hideNotification){ - Util.showNotify({title: 'Rally point removed', type: 'success'}); - } - }else{ - system.addClass( rallyClass ); - system.data( 'rally', true ); - - if(! hideNotification){ - var systemName = system.getSystemInfo( ['alias'] ); - - var notificationOptions = { - title: 'Rally Point', - text: 'System: ' + systemName, - type: 'success' - }; - - if(poke === true){ - // desktop poke - Util.showNotify(notificationOptions, {desktop: true, stack: 'barBottom'}); - }else{ - Util.showNotify(notificationOptions, {stack: 'barBottom'}); - } - } - - } - - if(! hideCounter){ - $(system).getMapOverlay('timer').startMapUpdateCounter(); - } - - }; - /** * get TabContentElement by any element on a map e.g. system * @param element @@ -3108,7 +3115,7 @@ define([ id: system.data('statusId') }; systemData.locked = system.data('locked') ? 1 : 0; - systemData.rally = system.data('rally') ? 1 : 0; + systemData.rallyUpdated = system.data('rallyUpdated') || 0; systemData.currentUser = system.data('currentUser'); // if user is currently in this system systemData.statics = system.data('statics'); systemData.updated = { diff --git a/public/js/v1.1.3/app/map/map.js b/public/js/v1.1.3/app/map/map.js index 98370ca3..369aebbe 100644 --- a/public/js/v1.1.3/app/map/map.js +++ b/public/js/v1.1.3/app/map/map.js @@ -450,6 +450,68 @@ define([ system.addClass( statusClass ); }; + /** + * set or change rallyPoint for systems + * @param rallyUpdated + * @param options + * @returns {*} + */ + $.fn.setSystemRally = function(rallyUpdated, options){ + rallyUpdated = rallyUpdated || 0; + + var defaultOptions = { + poke: false, + hideNotification: false, + hideCounter: false, + }; + options = $.extend({}, defaultOptions, options); + + return this.each(function(){ + var system = $(this); + var rally = system.data('rallyUpdated') || 0; + + if(rallyUpdated !== rally){ + // rally status changed + if( !options.hideCounter ){ + system.getMapOverlay('timer').startMapUpdateCounter(); + } + + var rallyClass = MapUtil.getInfoForSystem('rally', 'class'); + + if(rallyUpdated > 0){ + // new rally point set + system.addClass( rallyClass ); + + if( !options.hideNotification ){ + var systemName = system.getSystemInfo( ['alias'] ); + + var notificationOptions = { + title: 'Rally Point', + text: 'System: ' + systemName, + type: 'success' + }; + + if(options.poke){ + // desktop poke + Util.showNotify(notificationOptions, {desktop: true, stack: 'barBottom'}); + }else{ + Util.showNotify(notificationOptions, {stack: 'barBottom'}); + } + } + }else{ + // rally point removed + system.removeClass( rallyClass ); + + if( !options.hideNotification ){ + Util.showNotify({title: 'Rally point removed', type: 'success'}); + } + } + } + + system.data('rallyUpdated', rallyUpdated); + }); + }; + /** * returns a new system or updates an existing system * @param map @@ -606,9 +668,10 @@ define([ } // rally system - if( Boolean( system.data( 'rally') ) !== data.rally ){ - system.toggleRallyPoint(false, {hideNotification: true, hideCounter: true}); - } + system.setSystemRally(data.rallyUpdated, { + hideNotification: true, + hideCounter: true, + }); return system; }; @@ -1825,8 +1888,8 @@ define([ currentSystem.markAsChanged(); break; case 'set_rally': - // set rally point - if( ! currentSystem.data( 'rally' ) ){ + // toggle rally point + if( !currentSystem.data( 'rallyUpdated' ) ){ // show confirm dialog var rallyDialog = bootbox.dialog({ @@ -1844,7 +1907,9 @@ define([ label: ' Set rally and poke', className: 'btn-primary', callback: function() { - currentSystem.toggleRallyPoint(true, {}); + currentSystem.setSystemRally(1, { + poke: true + }); currentSystem.markAsChanged(); } }, @@ -1852,7 +1917,7 @@ define([ label: ' save', className: 'btn-success', callback: function() { - currentSystem.toggleRallyPoint(false, {}); + currentSystem.setSystemRally(1); currentSystem.markAsChanged(); } } @@ -1860,7 +1925,7 @@ define([ }); }else{ // remove rally point - currentSystem.toggleRallyPoint(false, {}); + currentSystem.setSystemRally(0); currentSystem.markAsChanged(); } break; @@ -2097,64 +2162,6 @@ define([ }; - /** - * toggle a system as rally point and display notifications - * @param poke - * @param options - */ - $.fn.toggleRallyPoint = function(poke, options){ - - var system = $(this); - - var rallyClass = MapUtil.getInfoForSystem('rally', 'class'); - - var hideNotification = false; - if(options.hideNotification === true){ - hideNotification = true; - } - - var hideCounter = false; - if(options.hideCounter === true){ - hideCounter = true; - } - - // check of system is already marked as rally - if( system.data( 'rally' ) === true ){ - system.removeClass( rallyClass ); - system.data( 'rally', false ); - - if(! hideNotification){ - Util.showNotify({title: 'Rally point removed', type: 'success'}); - } - }else{ - system.addClass( rallyClass ); - system.data( 'rally', true ); - - if(! hideNotification){ - var systemName = system.getSystemInfo( ['alias'] ); - - var notificationOptions = { - title: 'Rally Point', - text: 'System: ' + systemName, - type: 'success' - }; - - if(poke === true){ - // desktop poke - Util.showNotify(notificationOptions, {desktop: true, stack: 'barBottom'}); - }else{ - Util.showNotify(notificationOptions, {stack: 'barBottom'}); - } - } - - } - - if(! hideCounter){ - $(system).getMapOverlay('timer').startMapUpdateCounter(); - } - - }; - /** * get TabContentElement by any element on a map e.g. system * @param element @@ -3108,7 +3115,7 @@ define([ id: system.data('statusId') }; systemData.locked = system.data('locked') ? 1 : 0; - systemData.rally = system.data('rally') ? 1 : 0; + systemData.rallyUpdated = system.data('rallyUpdated') || 0; systemData.currentUser = system.data('currentUser'); // if user is currently in this system systemData.statics = system.data('statics'); systemData.updated = {