- improved "set rally point" dialog

- fixed wrong character name on poke notifications, closed #297
This commit is contained in:
Exodus4D
2016-08-27 23:59:42 +02:00
parent bc71cd5633
commit 0e39f8c2d1
17 changed files with 222 additions and 133 deletions

View File

@@ -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();

View File

@@ -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){
}
/**

View File

@@ -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;
}
}

View File

@@ -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) );

View File

@@ -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);
}
}
}

View File

@@ -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;
}
/**

View File

@@ -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;

View File

@@ -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: '<i class="fa fa-fw fa-bullhorn"></i> set rally and poke',
className: 'btn-primary',
callback: function() {
currentSystem.setSystemRally(1, {
poke: true
});
currentSystem.markAsChanged();
}
},
success: {
label: '<i class="fa fa-fw fa-users"></i> set rally',
className: 'btn-success',
callback: function() {
currentSystem.setSystemRally(1);
currentSystem.markAsChanged();
}
}
}
});
$.fn.showRallyPointDialog(currentSystem);
}else{
// remove rally point
currentSystem.setSystemRally(0);

View File

@@ -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: '<i class="fa fa-fw fa-volume-up"></i> set rally and poke',
className: 'btn-primary',
callback: function() {
system.setSystemRally(1, {
poke: true
});
system.markAsChanged();
}
},
success: {
label: '<i class="fa fa-fw fa-users"></i> set rally',
className: 'btn-success',
callback: function() {
system.setSystemRally(1);
system.markAsChanged();
}
}
}
});
});
};
/**
* shows delete dialog for systems that should be deleted
* @param map

View File

@@ -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();

View File

@@ -192,7 +192,7 @@ define([
href: '#'
}).html('&nbsp;&nbsp;Notification test').prepend(
$('<i>',{
class: 'fa fa-bullhorn fa-fw'
class: 'fa fa-volume-up fa-fw'
})
).on('click', function(){
$(document).triggerMenuEvent('NotificationTest');

View File

@@ -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: '<i class="fa fa-fw fa-bullhorn"></i> set rally and poke',
className: 'btn-primary',
callback: function() {
currentSystem.setSystemRally(1, {
poke: true
});
currentSystem.markAsChanged();
}
},
success: {
label: '<i class="fa fa-fw fa-users"></i> set rally',
className: 'btn-success',
callback: function() {
currentSystem.setSystemRally(1);
currentSystem.markAsChanged();
}
}
}
});
$.fn.showRallyPointDialog(currentSystem);
}else{
// remove rally point
currentSystem.setSystemRally(0);

View File

@@ -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: '<i class="fa fa-fw fa-volume-up"></i> set rally and poke',
className: 'btn-primary',
callback: function() {
system.setSystemRally(1, {
poke: true
});
system.markAsChanged();
}
},
success: {
label: '<i class="fa fa-fw fa-users"></i> set rally',
className: 'btn-success',
callback: function() {
system.setSystemRally(1);
system.markAsChanged();
}
}
}
});
});
};
/**
* shows delete dialog for systems that should be deleted
* @param map

View File

@@ -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();

View File

@@ -192,7 +192,7 @@ define([
href: '#'
}).html('&nbsp;&nbsp;Notification test').prepend(
$('<i>',{
class: 'fa fa-bullhorn fa-fw'
class: 'fa fa-volume-up fa-fw'
})
).on('click', function(){
$(document).triggerMenuEvent('NotificationTest');

View File

@@ -7,7 +7,7 @@
<li class="{{dialogNavLiClass}}"><a data-target="#pf-manual-signature" href="#"><i class="fa fa-table fa-fw"></i>&nbsp;Signature</a></li>
<li class="{{dialogNavLiClass}}"><a data-target="#pf-manual-share" href="#"><i class="fa fa-share-alt fa-fw"></i>&nbsp;Share</a></li>
<li class="{{dialogNavLiClass}}"><a data-target="#pf-manual-chart" href="#"><i class="fa fa-bar-chart fa-fw"></i>&nbsp;Chart</a></li>
<li class="{{dialogNavLiClass}}"><a data-target="#pf-manual-notification" href="#"><i class="fa fa-bullhorn fa-fw"></i>&nbsp;Notification</a></li>
<li class="{{dialogNavLiClass}}"><a data-target="#pf-manual-notification" href="#"><i class="fa fa-volume-up fa-fw"></i>&nbsp;Notification</a></li>
</ul>
</div>
</nav>
@@ -188,7 +188,7 @@
<p>
Systems can be marked as a <span class="pf-system-info-rally"><span class="pf-system-head" style="padding: 0 5px;">Rally point</span></span>.<br>
Active pilot will be informed about new "Rally points" by a notice. Optional you can poke active pilots with "desktop push notifications"
<small>(<i class="fa fa-bullhorn fa-fw"></i><a href="#" data-target="#pf-manual-scrollspy-anchor-notification-desktop">more</a>)</small>.
<small>(<i class="fa fa-volume-up fa-fw"></i><a href="#" data-target="#pf-manual-scrollspy-anchor-notification-desktop">more</a>)</small>.
</p>
<h4 id="pf-manual-scrollspy-anchor-system-waypoint"><i class="fa fa-flag-checkered fa-fw"></i> Waypoints</h4>
<p>
@@ -395,7 +395,7 @@
<hr class="pf-manual-scroll-break">
{{! ================================================================================================================================================ }}
<h2 id="pf-manual-notification"><i class="fa fa-bullhorn fa-lg fa-fw"></i>&nbsp;&nbsp;Notification</h2>
<h2 id="pf-manual-notification"><i class="fa fa-volume-up fa-lg fa-fw"></i>&nbsp;&nbsp;Notification</h2>
<h4>Types</h4>

View File

@@ -0,0 +1,17 @@
Do you want poke active pilots?
<hr>
<h4>
<i class="fa fa-fw fa-volume-up"></i>
Desktop notification is
<kbd class="txt-color txt-color-success">enabled</kbd>.
</h4>
<h4>
<i class="fa fa-fw fa-envelope"></i>
Mail notification is
{{#notificationStatus}}
<kbd class="txt-color txt-color-success">enabled</kbd>.
{{/notificationStatus}}
{{^notificationStatus}}
<kbd>disabled</kbd>.
{{/notificationStatus}}
</h4>