From 0e39f8c2d1f451d744a925ada6a23823989c4f66 Mon Sep 17 00:00:00 2001 From: Exodus4D Date: Sat, 27 Aug 2016 23:59:42 +0200 Subject: [PATCH] - improved "set rally point" dialog - fixed wrong character name on poke notifications, closed #297 --- app/main/controller/api/map.php | 14 ++++ app/main/model/basicmodel.php | 59 ++++++++------- .../model/characterauthenticationmodel.php | 7 +- app/main/model/connectionmodel.php | 5 +- app/main/model/systemmodel.php | 75 ++++++++++++------- app/main/model/usercharactermodel.php | 7 +- app/main/model/usermodel.php | 5 +- js/app/map/map.js | 34 +-------- js/app/map/system.js | 43 +++++++++++ js/app/mappage.js | 1 + js/app/page.js | 2 +- public/js/v1.1.4/app/map/map.js | 34 +-------- public/js/v1.1.4/app/map/system.js | 43 +++++++++++ public/js/v1.1.4/app/mappage.js | 1 + public/js/v1.1.4/app/page.js | 2 +- public/templates/dialog/map_manual.html | 6 +- public/templates/dialog/system_rally.html | 17 +++++ 17 files changed, 222 insertions(+), 133 deletions(-) create mode 100644 public/templates/dialog/system_rally.html diff --git a/app/main/controller/api/map.php b/app/main/controller/api/map.php index 4b6ecb2d..37003668 100644 --- a/app/main/controller/api/map.php +++ b/app/main/controller/api/map.php @@ -8,6 +8,7 @@ namespace Controller\Api; use Controller; +use lib\Config; use Model; /** @@ -178,6 +179,11 @@ class Map extends Controller\AccessController { 'ssoLogin' => $this->getF3()->alias( 'sso', ['action' => 'requestAuthorization'] ) ]; + // get notification status ------------------------------------------------------------------------------------ + $return->notificationStatus = [ + 'rallySet' => (bool)Config::getNotificationMail('RALLY_SET') + ]; + // get SSO error messages that should be shown immediately ---------------------------------------------------- // -> e.g. errors while character switch from previous HTTP requests if( $f3->exists(Controller\Ccp\Sso::SESSION_KEY_SSO_ERROR) ){ @@ -574,6 +580,10 @@ class Map extends Controller\AccessController { if(is_object($filteredMap->systems)){ // update unset($systemData['updated']); + + /** + * @var $system Model\SystemModel + */ $system = $filteredMap->systems->current(); $system->setData($systemData); $system->updatedCharacterId = $activeCharacter; @@ -603,6 +613,10 @@ class Map extends Controller\AccessController { if(is_object($filteredMap->connections)){ // update unset($connectionData['updated']); + + /** + * @var $connection Model\ConnectionModel + */ $connection = $filteredMap->connections->current(); $connection->setData($connectionData); $connection->save(); diff --git a/app/main/model/basicmodel.php b/app/main/model/basicmodel.php index fa4e2566..49d16451 100644 --- a/app/main/model/basicmodel.php +++ b/app/main/model/basicmodel.php @@ -77,26 +77,26 @@ abstract class BasicModel extends \DB\Cortex { parent::__construct($db, $table, $fluid, $ttl); // events ----------------------------------------- - $this->afterinsert(function($self){ - $self->afterinsertEvent($self); + $this->afterinsert(function($self, $pkeys){ + $self->afterInsertEvent($self, $pkeys); $self->clearCacheData(); }); - $this->afterupdate( function($self){ - $self->afterupdateEvent($self); + $this->afterupdate( function($self, $pkeys){ + $self->afterUpdateEvent($self, $pkeys); $self->clearCacheData(); }); - $this->beforeinsert( function($self){ - $self->beforeInsertEvent($self); + $this->beforeinsert( function($self, $pkeys){ + $self->beforeInsertEvent($self, $pkeys); }); - $this->beforeerase( function($self){ - $self->beforeeraseEvent($self); + $this->beforeerase( function($self, $pkeys){ + $self->beforeEraseEvent($self, $pkeys); }); - $this->aftererase( function($self){ - $self->aftereraseEvent($self); + $this->aftererase( function($self, $pkeys){ + $self->afterEraseEvent($self, $pkeys); }); } @@ -409,8 +409,11 @@ abstract class BasicModel extends \DB\Cortex { * Event "Hook" function * can be overwritten * return false will stop any further action + * @param self $self + * @param $pkeys + * @return bool */ - public function beforeInsertEvent(){ + public function beforeInsertEvent($self, $pkeys){ if($this->exists('updated')){ $this->touch('updated'); } @@ -421,36 +424,40 @@ abstract class BasicModel extends \DB\Cortex { * Event "Hook" function * can be overwritten * return false will stop any further action + * @param self $self + * @param $pkeys */ - public function afterinsertEvent(){ - return true; + public function afterInsertEvent($self, $pkeys){ } /** * Event "Hook" function * can be overwritten * return false will stop any further action + * @param self $self + * @param $pkeys */ - public function afterupdateEvent(){ + public function afterUpdateEvent($self, $pkeys){ + } + + /** + * Event "Hook" function + * can be overwritten + * @param self $self + * @param $pkeys + * @return bool + */ + public function beforeEraseEvent($self, $pkeys){ return true; } /** * Event "Hook" function * can be overwritten - * @return bool + * @param self $self + * @param $pkeys */ - public function beforeeraseEvent($self){ - return true; - } - - /** - * Event "Hook" function - * can be overwritten - * @return bool - */ - public function aftereraseEvent($self){ - return true; + public function afterEraseEvent($self, $pkeys){ } /** diff --git a/app/main/model/characterauthenticationmodel.php b/app/main/model/characterauthenticationmodel.php index c5c4b82f..3b2ab69e 100644 --- a/app/main/model/characterauthenticationmodel.php +++ b/app/main/model/characterauthenticationmodel.php @@ -57,10 +57,11 @@ class CharacterAuthenticationModel extends BasicModel{ /** * Event "Hook" function * can be overwritten - * @param $self CharacterAuthenticationModel + * @param CharacterAuthenticationModel $self + * @param $pkeys * @return bool */ - public function beforeeraseEvent($self){ + public function beforeEraseEvent($self, $pkeys){ // clear existing client Cookies as well $cookieName = Controller\Controller::COOKIE_PREFIX_CHARACTER; $cookieName .= '_' . $this->characterId->getCookieName(); @@ -69,6 +70,4 @@ class CharacterAuthenticationModel extends BasicModel{ return true; } - - } \ No newline at end of file diff --git a/app/main/model/connectionmodel.php b/app/main/model/connectionmodel.php index df02fed3..a5144266 100644 --- a/app/main/model/connectionmodel.php +++ b/app/main/model/connectionmodel.php @@ -193,8 +193,11 @@ class ConnectionModel extends BasicModel{ * Event "Hook" function * can be overwritten * return false will stop any further action + * @param ConnectionModel $self + * @param $pkeys + * @return bool */ - public function beforeInsertEvent(){ + public function beforeInsertEvent($self, $pkeys){ // check for "default" connection type and add them if missing // -> get() with "true" returns RAW data! important for JSON table column check! $types = (array)json_decode( $this->get('type', true) ); diff --git a/app/main/model/systemmodel.php b/app/main/model/systemmodel.php index 7066b7d9..62be0624 100644 --- a/app/main/model/systemmodel.php +++ b/app/main/model/systemmodel.php @@ -323,25 +323,45 @@ class SystemModel extends BasicModel { /** * setter for system rally timestamp * @param $rally - * @return bool|int|null|string + * @return null|string */ public function set_rallyUpdated($rally){ $rally = (int)$rally; - if($rally === 0){ - $rally = null; - }elseif($rally === 1){ - // new rally point set - $currentTimestamp = time(); - $rally = date('Y-m-d H:i:s', $currentTimestamp); - // send rally point notification mail - $this->sendRallyPointMail($currentTimestamp); - }else{ - $rally = date('Y-m-d H:i:s', $rally); + + switch($rally){ + case 0: + $rally = null; + break; + case 1: + // new rally point set + $rally = date('Y-m-d H:i:s', time()); + // flag system for mail poke -> after save() + $this->virtual('newRallyPointSet', true); + break; + default: + $rally = date('Y-m-d H:i:s', $rally); + break; } return $rally; } + /** + * Event "Hook" function + * return false will stop any further action + * @param self $self + * @param $pkeys + */ + public function afterUpdateEvent($self, $pkeys){ + // check if rally point mail should be send + if( + $self->newRallyPointSet && + $self->rallyPoke + ){ + $self->sendRallyPointMail(); + } + } + /** * check object for model access * @param CharacterModel $characterModel @@ -491,28 +511,33 @@ class SystemModel extends BasicModel { } /** - * set rally point information - * @param $timestamp + * send rally point information by mail */ - protected function sendRallyPointMail($timestamp){ + protected function sendRallyPointMail(){ $recipient = Config::getNotificationMail('RALLY_SET'); if( $recipient && \Audit::instance()->email($recipient) ){ - $body = []; - $body[] = "Map:\t\t" . $this->mapId->name; - $body[] = "System:\t\t" . $this->name; - $body[] = "Region:\t\t" . $this->region; - $body[] = "Security:\t" . $this->security; - if(is_object($this->createdCharacterId)){ - $body[] = "Character:\t" . $this->createdCharacterId->name; - } - $body[] = "Time:\t\t" . date('g:i a; F j, Y', $timestamp); - $bodyMsg = implode("\r\n", $body); + $updatedCharacterId = (int) $this->get('updatedCharacterId', true); + /** + * @var $character CharacterModel + */ + $character = $this->rel('updatedCharacterId'); + $character->getById( $updatedCharacterId ); + if( !$character->dry() ){ + $body = []; + $body[] = "Map:\t\t" . $this->mapId->name; + $body[] = "System:\t\t" . $this->name; + $body[] = "Region:\t\t" . $this->region; + $body[] = "Security:\t" . $this->security; + $body[] = "Character:\t" . $character->name; + $body[] = "Time:\t\t" . date('g:i a; F j, Y', strtotime($this->rallyUpdated) ); + $bodyMsg = implode("\r\n", $body); - (new MailController())->sendRallyPoint($recipient, $bodyMsg); + (new MailController())->sendRallyPoint($recipient, $bodyMsg); + } } } diff --git a/app/main/model/usercharactermodel.php b/app/main/model/usercharactermodel.php index 5d661286..3f352c05 100644 --- a/app/main/model/usercharactermodel.php +++ b/app/main/model/usercharactermodel.php @@ -63,17 +63,16 @@ class UserCharacterModel extends BasicModel { /** * event "Hook" * -> remove user if there are no other characters bound to this user - * @param $self - * @return bool + * @param UserCharacterModel $self + * @param $pkeys */ - public function aftereraseEvent($self){ + public function afterEraseEvent($self, $pkeys){ if( is_object($self->userId) && is_null($self->userId->userCharacters) ){ $self->userId->erase(); } - return true; } /** diff --git a/app/main/model/usermodel.php b/app/main/model/usermodel.php index 4ce5fe5d..776c6b96 100644 --- a/app/main/model/usermodel.php +++ b/app/main/model/usermodel.php @@ -112,17 +112,18 @@ class UserModel extends BasicModel { /** * check if new user registration is allowed + * @param UserModel $self + * @param $pkeys * @return bool * @throws Exception\RegistrationException */ - public function beforeInsertEvent(){ + public function beforeInsertEvent($self, $pkeys){ $registrationStatus = Controller\Controller::getRegistrationStatus(); switch($registrationStatus){ case 0: $f3 = self::getF3(); throw new Exception\RegistrationException($f3->get('PATHFINDER.REGISTRATION.MSG_DISABLED')); - return false; break; case 1: return true; diff --git a/js/app/map/map.js b/js/app/map/map.js index de7e8ac3..d0d701d0 100644 --- a/js/app/map/map.js +++ b/js/app/map/map.js @@ -1727,39 +1727,7 @@ define([ case 'set_rally': // toggle rally point if( !currentSystem.data( 'rallyUpdated' ) ){ - - // show confirm dialog - var rallyDialog = bootbox.dialog({ - message: 'Do you want to poke active pilots?', - title: 'Set rally point for system "' + currentSystemName + '"', - buttons: { - close: { - label: 'cancel', - className: 'btn-default', - callback: function(){ - $(rallyDialog).modal('hide'); - } - }, - setRallyPoke: { - label: ' set rally and poke', - className: 'btn-primary', - callback: function() { - currentSystem.setSystemRally(1, { - poke: true - }); - currentSystem.markAsChanged(); - } - }, - success: { - label: ' set rally', - className: 'btn-success', - callback: function() { - currentSystem.setSystemRally(1); - currentSystem.markAsChanged(); - } - } - } - }); + $.fn.showRallyPointDialog(currentSystem); }else{ // remove rally point currentSystem.setSystemRally(0); diff --git a/js/app/map/system.js b/js/app/map/system.js index c8e83c62..a63c9403 100644 --- a/js/app/map/system.js +++ b/js/app/map/system.js @@ -16,6 +16,49 @@ define([ systemActiveClass: 'pf-system-active' // class for an active system in a map }; + /** + * show "set rally point" dialog for system + * @param system + */ + $.fn.showRallyPointDialog = (system) => { + requirejs(['text!templates/dialog/system_rally.html', 'mustache'], function(template, Mustache) { + var data = { + notificationStatus: Init.notificationStatus.rallySet + }; + + var content = Mustache.render(template, data); + + var rallyDialog = bootbox.dialog({ + message: content, + title: 'Set rally point for "' + system.getSystemInfo( ['alias'] ) + '"', + buttons: { + close: { + label: 'cancel', + className: 'btn-default' + }, + setRallyPoke: { + label: ' set rally and poke', + className: 'btn-primary', + callback: function() { + system.setSystemRally(1, { + poke: true + }); + system.markAsChanged(); + } + }, + success: { + label: ' set rally', + className: 'btn-success', + callback: function() { + system.setSystemRally(1); + system.markAsChanged(); + } + } + } + }); + }); + }; + /** * shows delete dialog for systems that should be deleted * @param map diff --git a/js/app/mappage.js b/js/app/mappage.js index 441f0de8..fcd959ab 100644 --- a/js/app/mappage.js +++ b/js/app/mappage.js @@ -61,6 +61,7 @@ define([ Init.characterStatus = initData.characterStatus; Init.maxSharedCount = initData.maxSharedCount; Init.routes = initData.routes; + Init.notificationStatus = initData.notificationStatus; // init tab change observer, Once the timers are available Page.initTabChangeObserver(); diff --git a/js/app/page.js b/js/app/page.js index 308899a4..d1b388d6 100644 --- a/js/app/page.js +++ b/js/app/page.js @@ -192,7 +192,7 @@ define([ href: '#' }).html('  Notification test').prepend( $('',{ - class: 'fa fa-bullhorn fa-fw' + class: 'fa fa-volume-up fa-fw' }) ).on('click', function(){ $(document).triggerMenuEvent('NotificationTest'); diff --git a/public/js/v1.1.4/app/map/map.js b/public/js/v1.1.4/app/map/map.js index de7e8ac3..d0d701d0 100644 --- a/public/js/v1.1.4/app/map/map.js +++ b/public/js/v1.1.4/app/map/map.js @@ -1727,39 +1727,7 @@ define([ case 'set_rally': // toggle rally point if( !currentSystem.data( 'rallyUpdated' ) ){ - - // show confirm dialog - var rallyDialog = bootbox.dialog({ - message: 'Do you want to poke active pilots?', - title: 'Set rally point for system "' + currentSystemName + '"', - buttons: { - close: { - label: 'cancel', - className: 'btn-default', - callback: function(){ - $(rallyDialog).modal('hide'); - } - }, - setRallyPoke: { - label: ' set rally and poke', - className: 'btn-primary', - callback: function() { - currentSystem.setSystemRally(1, { - poke: true - }); - currentSystem.markAsChanged(); - } - }, - success: { - label: ' set rally', - className: 'btn-success', - callback: function() { - currentSystem.setSystemRally(1); - currentSystem.markAsChanged(); - } - } - } - }); + $.fn.showRallyPointDialog(currentSystem); }else{ // remove rally point currentSystem.setSystemRally(0); diff --git a/public/js/v1.1.4/app/map/system.js b/public/js/v1.1.4/app/map/system.js index c8e83c62..a63c9403 100644 --- a/public/js/v1.1.4/app/map/system.js +++ b/public/js/v1.1.4/app/map/system.js @@ -16,6 +16,49 @@ define([ systemActiveClass: 'pf-system-active' // class for an active system in a map }; + /** + * show "set rally point" dialog for system + * @param system + */ + $.fn.showRallyPointDialog = (system) => { + requirejs(['text!templates/dialog/system_rally.html', 'mustache'], function(template, Mustache) { + var data = { + notificationStatus: Init.notificationStatus.rallySet + }; + + var content = Mustache.render(template, data); + + var rallyDialog = bootbox.dialog({ + message: content, + title: 'Set rally point for "' + system.getSystemInfo( ['alias'] ) + '"', + buttons: { + close: { + label: 'cancel', + className: 'btn-default' + }, + setRallyPoke: { + label: ' set rally and poke', + className: 'btn-primary', + callback: function() { + system.setSystemRally(1, { + poke: true + }); + system.markAsChanged(); + } + }, + success: { + label: ' set rally', + className: 'btn-success', + callback: function() { + system.setSystemRally(1); + system.markAsChanged(); + } + } + } + }); + }); + }; + /** * shows delete dialog for systems that should be deleted * @param map diff --git a/public/js/v1.1.4/app/mappage.js b/public/js/v1.1.4/app/mappage.js index 441f0de8..fcd959ab 100644 --- a/public/js/v1.1.4/app/mappage.js +++ b/public/js/v1.1.4/app/mappage.js @@ -61,6 +61,7 @@ define([ Init.characterStatus = initData.characterStatus; Init.maxSharedCount = initData.maxSharedCount; Init.routes = initData.routes; + Init.notificationStatus = initData.notificationStatus; // init tab change observer, Once the timers are available Page.initTabChangeObserver(); diff --git a/public/js/v1.1.4/app/page.js b/public/js/v1.1.4/app/page.js index 308899a4..d1b388d6 100644 --- a/public/js/v1.1.4/app/page.js +++ b/public/js/v1.1.4/app/page.js @@ -192,7 +192,7 @@ define([ href: '#' }).html('  Notification test').prepend( $('',{ - class: 'fa fa-bullhorn fa-fw' + class: 'fa fa-volume-up fa-fw' }) ).on('click', function(){ $(document).triggerMenuEvent('NotificationTest'); diff --git a/public/templates/dialog/map_manual.html b/public/templates/dialog/map_manual.html index 4b44a900..90ce6ddc 100644 --- a/public/templates/dialog/map_manual.html +++ b/public/templates/dialog/map_manual.html @@ -7,7 +7,7 @@
  •  Signature
  •  Share
  •  Chart
  • -
  •  Notification
  • +
  •  Notification
  • @@ -188,7 +188,7 @@

    Systems can be marked as a Rally point.
    Active pilot will be informed about new "Rally points" by a notice. Optional you can poke active pilots with "desktop push notifications" - (more). + (more).

    Waypoints

    @@ -395,7 +395,7 @@


    {{! ================================================================================================================================================ }} -

      Notification

    +

      Notification

    Types

    diff --git a/public/templates/dialog/system_rally.html b/public/templates/dialog/system_rally.html new file mode 100644 index 00000000..105f3c77 --- /dev/null +++ b/public/templates/dialog/system_rally.html @@ -0,0 +1,17 @@ +Do you want poke active pilots? +
    +

    + + Desktop notification is + enabled. +

    +

    + + Mail notification is + {{#notificationStatus}} + enabled. + {{/notificationStatus}} + {{^notificationStatus}} + disabled. + {{/notificationStatus}} +