Skip to content

Commit

Permalink
- new tooltip for "planets" added to the UI, closed #648
Browse files Browse the repository at this point in the history
  • Loading branch information
exodus4d committed Jun 30, 2018
1 parent c0f3ebb commit c0546cd
Show file tree
Hide file tree
Showing 11 changed files with 195 additions and 72 deletions.
5 changes: 5 additions & 0 deletions app/main/model/systemmodel.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ public function getData(){
$systemData->region->id = $this->regionId;
$systemData->region->name = $this->region;

$systemData->planets = $this->planets ? : [];
$systemData->statics = $this->statics ? : [];

// max caching time for a system
Expand Down Expand Up @@ -454,6 +455,10 @@ public function get_statics(){
return $this->getStaticSystemValue('statics');
}

public function get_planets(){
return $this->getStaticSystemValue('planets');
}

/**
* Event "Hook" function
* @param self $self
Expand Down
7 changes: 2 additions & 5 deletions app/main/model/universe/planetmodel.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,10 @@ class PlanetModel extends BasicUniverseModel {
*/
public function getData(){
$planetData = (object) [];
$planetData->id = $this->_id;
$planetData->name = $this->name;

$planetData->position = (object) [];
$planetData->position->x = $this->x;
$planetData->position->y = $this->y;
$planetData->position->z = $this->z;
$planetData->type = (object) [];
$planetData->type->name = $this->typeId->name;

return $planetData;
}
Expand Down
2 changes: 2 additions & 0 deletions js/app/map/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ define([
system.data('region', data.region.name);
system.data('constellationId', parseInt(data.constellation.id));
system.data('constellation', data.constellation.name);
system.data('planets', data.planets);
system.data('shattered', data.shattered);
system.data('statics', data.statics);
system.data('updated', parseInt(data.updated.updated));
Expand Down Expand Up @@ -3285,6 +3286,7 @@ define([
systemData.rallyUpdated = system.data('rallyUpdated') || 0;
systemData.rallyPoke = system.data('rallyPoke') ? 1 : 0;
systemData.currentUser = system.data('currentUser'); // if user is currently in this system
systemData.planets = system.data('planets');
systemData.shattered = system.data('shattered') ? 1 : 0;
systemData.statics = system.data('statics');
systemData.updated = {
Expand Down
30 changes: 30 additions & 0 deletions js/app/map/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,36 @@ define([
});
};

/**
* add system planets tooltip
* @param planets
* @param options
* @returns {*}
*/
$.fn.addSystemPlanetsTooltip = function(planets, options){

let content = Util.getSystemPlanetsTable(planets);

let defaultOptions = {
placement: 'top',
html: true,
trigger: 'hover',
container: 'body',
title: 'Planets',
content: content,
delay: {
show: 150,
hide: 0
},
};

options = $.extend({}, defaultOptions, options);

return this.each(function(){
$(this).popover(options);
});
};

/**
* add a wormhole tooltip with wh specific data to elements
* @param tooltipData
Expand Down
41 changes: 23 additions & 18 deletions js/app/ui/system_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ define([

// info table
systemInfoTableClass: 'pf-module-table', // class for system info table
systemInfoNameInfoClass: 'pf-system-info-name', // class for "name" information element
systemInfoEffectInfoClass: 'pf-system-info-effect', // class for "effect" information element
systemInfoNameClass: 'pf-system-info-name', // class for "name" information element
systemInfoEffectClass: 'pf-system-info-effect', // class for "effect" information element
systemInfoPlanetsClass: 'pf-system-info-planets', // class for "planets" information element
systemInfoStatusLabelClass: 'pf-system-info-status-label', // class for "status" information element
systemInfoStatusAttributeName: 'data-status', // attribute name for status label
systemInfoWormholeClass: 'pf-system-info-wormhole-', // class prefix for static wormhole element
Expand Down Expand Up @@ -110,7 +111,7 @@ define([
if(systemId === systemData.id){
// update module

// system status =====================================================================================
// system status ==========================================================================================
let systemStatusLabelElement = moduleElement.find('.' + config.systemInfoStatusLabelClass);
let systemStatusId = parseInt( systemStatusLabelElement.attr( config.systemInfoStatusAttributeName ) );

Expand All @@ -127,7 +128,7 @@ define([
systemStatusLabelElement.attr( config.systemInfoStatusAttributeName, systemData.status.id);
}

// description textarea element ======================================================================
// description textarea element ===========================================================================
let descriptionTextareaElement = moduleElement.find('.' + config.descriptionTextareaElementClass);
let description = descriptionTextareaElement.editable('getValue', true);

Expand Down Expand Up @@ -157,9 +158,8 @@ define([
}
}

// created/updated tooltip ===========================================================================

let nameRowElement = $(moduleElement).find('.' + config.systemInfoNameInfoClass);
// created/updated tooltip ================================================================================
let nameRowElement = $(moduleElement).find('.' + config.systemInfoNameClass);

let tooltipData = {
created: systemData.created,
Expand Down Expand Up @@ -277,7 +277,7 @@ define([
}
});

// on xEditable open -------------------------------------------------------------------------
// on xEditable open ------------------------------------------------------------------------------
descriptionTextareaElement.on('shown', function(e, editable){
let textarea = editable.input.$input;

Expand All @@ -298,7 +298,7 @@ define([
});
});

// on xEditable close ------------------------------------------------------------------------
// on xEditable close -----------------------------------------------------------------------------
descriptionTextareaElement.on('hidden', function(e){
let value = $(this).editable('getValue', true);
if(value.length === 0){
Expand All @@ -311,7 +311,7 @@ define([
disableModuleUpdate = false;
});

// enable xEditable field on Button click ----------------------------------------------------
// enable xEditable field on Button click ---------------------------------------------------------
descriptionButton.on('click', function(e){
e.stopPropagation();
let descriptionButton = $(this);
Expand All @@ -325,20 +325,23 @@ define([
showToolsActionElement(descriptionButton.siblings('.' + config.tableToolsActionClass));
});

// init tooltips -----------------------------------------------------------------------------
// init tooltips ----------------------------------------------------------------------------------
let tooltipElements = tempModuleElement.find('[data-toggle="tooltip"]');
tooltipElements.tooltip();

// init system effect popover ----------------------------------------------------------------
$(moduleElement).find('.' + config.systemInfoEffectInfoClass).addSystemEffectTooltip(systemData.security, systemData.effect);
// init system effect popover ---------------------------------------------------------------------
$(moduleElement).find('.' + config.systemInfoEffectClass).addSystemEffectTooltip(systemData.security, systemData.effect);

// init planets popover ---------------------------------------------------------------------------
$(moduleElement).find('.' + config.systemInfoPlanetsClass).addSystemPlanetsTooltip(systemData.planets);

// init static wormhole information ----------------------------------------------------------
// init static wormhole information ---------------------------------------------------------------
for(let staticData of staticsData){
let staticRowElement = tempModuleElement.find('.' + config.systemInfoWormholeClass + staticData.name);
staticRowElement.addWormholeInfoTooltip(staticData);
}

// constellation popover ---------------------------------------------------------------------
// constellation popover --------------------------------------------------------------------------
tempModuleElement.find('a.popup-ajax').popover({
html: true,
trigger: 'hover',
Expand Down Expand Up @@ -369,13 +372,14 @@ define([
}
}
};

console.log(systemData)
let moduleData = {
system: systemData,
static: staticsData,
tableClass: config.systemInfoTableClass,
nameInfoClass: config.systemInfoNameInfoClass,
effectInfoClass: config.systemInfoEffectInfoClass,
nameInfoClass: config.systemInfoNameClass,
effectInfoClass: config.systemInfoEffectClass,
planetsInfoClass: config.systemInfoPlanetsClass,
wormholePrefixClass: config.systemInfoWormholeClass,
statusInfoClass: config.systemInfoStatusLabelClass,

Expand All @@ -401,6 +405,7 @@ define([
formatUrl: () => {
return (val, render) => render(val).replace(/ /g, '_');
},
planetCount: systemData.planets ? systemData.planets.length : 0,

shatteredClass: Util.getSecurityClassForSystem('SH'),

Expand Down
39 changes: 32 additions & 7 deletions js/app/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -1640,19 +1640,43 @@ define([
* @param data
* @returns {string}
*/
let getSystemEffectTable = function(data){
let getSystemEffectTable = effects => {
let table = '';
if(effects.length > 0){
table += '<table>';
for(let effect of effects){
table += '<tr>';
table += '<td>';
table += effect.effect;
table += '</td>';
table += '<td class="text-right">';
table += effect.value;
table += '</td>';
table += '</tr>';
}
table += '</table>';
}

if(data.length > 0){
return table;
};

/**
* get a HTML table with planet names
* e.g. for popover
* @param planets
* @returns {string}
*/
let getSystemPlanetsTable = planets => {
let table = '';
if(planets.length > 0){
table += '<table>';
for(let i = 0; i < data.length; i++){
for(let planet of planets){
table += '<tr>';
table += '<td>';
table += data[i].effect;
table += planet.name;
table += '</td>';
table += '<td class="text-right">';
table += data[i].value;
table += planet.type.name;
table += '</td>';
table += '</tr>';
}
Expand All @@ -1668,7 +1692,7 @@ define([
* @param data
* @returns {string}
*/
let getSystemsInfoTable = function(data){
let getSystemsInfoTable = data => {
let table = '';

if(data.length > 0){
Expand Down Expand Up @@ -1702,7 +1726,7 @@ define([
* @param sec
* @returns {string}
*/
let getSecurityClassForSystem = (sec) => {
let getSecurityClassForSystem = sec => {
let secClass = '';
if( Init.classes.systemSecurity.hasOwnProperty(sec) ){
secClass = Init.classes.systemSecurity[sec]['class'];
Expand Down Expand Up @@ -2613,6 +2637,7 @@ define([
getMapModule: getMapModule,
getSystemEffectData: getSystemEffectData,
getSystemEffectTable: getSystemEffectTable,
getSystemPlanetsTable: getSystemPlanetsTable,
getSystemsInfoTable: getSystemsInfoTable,
getStatusInfoForCharacter: getStatusInfoForCharacter,
getSecurityClassForSystem: getSecurityClassForSystem,
Expand Down
2 changes: 2 additions & 0 deletions public/js/v1.3.6/app/map/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ define([
system.data('region', data.region.name);
system.data('constellationId', parseInt(data.constellation.id));
system.data('constellation', data.constellation.name);
system.data('planets', data.planets);
system.data('shattered', data.shattered);
system.data('statics', data.statics);
system.data('updated', parseInt(data.updated.updated));
Expand Down Expand Up @@ -3285,6 +3286,7 @@ define([
systemData.rallyUpdated = system.data('rallyUpdated') || 0;
systemData.rallyPoke = system.data('rallyPoke') ? 1 : 0;
systemData.currentUser = system.data('currentUser'); // if user is currently in this system
systemData.planets = system.data('planets');
systemData.shattered = system.data('shattered') ? 1 : 0;
systemData.statics = system.data('statics');
systemData.updated = {
Expand Down
30 changes: 30 additions & 0 deletions public/js/v1.3.6/app/map/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,36 @@ define([
});
};

/**
* add system planets tooltip
* @param planets
* @param options
* @returns {*}
*/
$.fn.addSystemPlanetsTooltip = function(planets, options){

let content = Util.getSystemPlanetsTable(planets);

let defaultOptions = {
placement: 'top',
html: true,
trigger: 'hover',
container: 'body',
title: 'Planets',
content: content,
delay: {
show: 150,
hide: 0
},
};

options = $.extend({}, defaultOptions, options);

return this.each(function(){
$(this).popover(options);
});
};

/**
* add a wormhole tooltip with wh specific data to elements
* @param tooltipData
Expand Down
Loading

0 comments on commit c0546cd

Please sign in to comment.