- New colour codes for (wh) connections added to "Signature" module, closed #703

This commit is contained in:
Mark Friedrich
2018-11-24 12:01:42 +01:00
parent b51c734f37
commit a8b51af028
11 changed files with 294 additions and 36 deletions

View File

@@ -135,8 +135,13 @@ class Signature extends Controller\AccessController {
$system->saveSignature($signature, $activeCharacter);
$updatedSignatureIds[] = $signature->_id;
$return->signatures[] = $signature->getData();
// TODO figure out why $system->connectionId is NULL after change/save
//-> workaround: get data from "new" $signature model
$signatureNew = Model\BasicModel::getNew('SystemSignatureModel');
$signatureNew->getById($signature->_id);
$updatedSignatureIds[] = $signatureNew->_id;
$return->signatures[] = $signatureNew->getData();
$signature->reset();
}

View File

@@ -194,11 +194,14 @@ class SystemSignatureModel extends AbstractMapTrackingModel {
$hasChanged = false;
foreach((array)$signatureData as $key => $value){
if(
$this->exists($key) &&
$this->$key != $value
){
$hasChanged = true;
if($this->exists($key)){
if($this->$key instanceof ConnectionModel){
$currentValue = $this->get($key, true);
}else{
$currentValue = $this->$key;
}
$hasChanged = $currentValue !== $value;
break;
}
}

View File

@@ -151,8 +151,29 @@ define([
let markup = '';
if(parts.length === 2){
// wormhole data -> 2 columns
let styleClass = ['pf-fake-connection-text'];
if(state.metaData){
let metaData = state.metaData;
if(metaData.type){
let type = metaData.type;
if(type.includes('wh_eol')){
styleClass.push('pf-wh-eol');
}
if(type.includes('wh_reduced')){
styleClass.push('pf-wh-reduced');
}
if(type.includes('wh_critical')){
styleClass.push('pf-wh-critical');
}
if(type.includes('frigate')){
styleClass.push('pf-wh-frig');
}
}
}
let securityClass = Util.getSecurityClassForSystem(parts[1]);
markup += '<span>' + parts[0] + '</span>&nbsp;&nbsp;';
markup += '<span class="' + styleClass.join(' ') + '">' + parts[0] + '</span>&nbsp;&nbsp;';
markup += '<span class="' + securityClass + '">' + parts[1] + '</span>';
}else{
markup += '<span>' + state.text + '</span>';
@@ -786,6 +807,11 @@ define([
return this.each(function(){
let selectElement = $(this);
// remove existing <options> from DOM in case "data" is explicit set
if(options.data){
selectElement.empty();
}
selectElement.select2(options);
// initial open dropDown

View File

@@ -405,6 +405,32 @@ define([
let newSelectOptions = [];
let connectionOptions = [];
/**
* get option data for a single connection
* @param type
* @param connectionData
* @param systemData
* @returns {{value: *, text: string, metaData: {type: *}}}
*/
let getOption = (type, connectionData, systemData) => {
let text = 'UNKNOWN';
if(type === 'source'){
text = connectionData.sourceAlias + ' - ' + systemData.security;
}else if(type === 'target'){
text = connectionData.targetAlias + ' - ' + systemData.security;
}
let option = {
value: connectionData.id,
text: text,
metaData: {
type: connectionData.type
}
};
return option;
};
for(let systemConnection of systemConnections){
let connectionData = MapUtil.getDataByConnection(systemConnection);
@@ -416,19 +442,13 @@ define([
let targetSystemData = MapUtil.getSystemData(mapId, connectionData.target);
if(targetSystemData){
// take target...
connectionOptions.push({
value: connectionData.id,
text: connectionData.targetAlias + ' - ' + targetSystemData.security
});
connectionOptions.push(getOption('target', connectionData, targetSystemData));
}
}else if(systemData.id !== connectionData.source){
let sourceSystemData = MapUtil.getSystemData(mapId, connectionData.source);
if(sourceSystemData){
// take source...
connectionOptions.push({
value: connectionData.id,
text: connectionData.sourceAlias + ' - ' + sourceSystemData.security
});
connectionOptions.push(getOption('source', connectionData, sourceSystemData));
}
}
}
@@ -1119,7 +1139,14 @@ define([
let editableConnectionOnShown = cell => {
$(cell).on('shown', function(e, editable){
let inputField = editable.input.$input;
inputField.addClass('pf-select2').initSignatureConnectionSelect();
// Select2 init would work without passing select options as "data", Select2 would grap data from DOM
// -> We want to pass "meta" data for each option into Select2 for formatting
let options = {
data: Util.convertXEditableOptionsToSelect2(editable)
};
inputField.addClass('pf-select2').initSignatureConnectionSelect(options);
});
};
@@ -1534,7 +1561,10 @@ define([
let selected = $.fn.editableutils.itemsByValue(value, sourceData);
if(selected.length && selected[0].value > 0){
let errorIcon = '<i class="fas fa-exclamation-triangle txt-color txt-color-danger hide"></i>&nbsp;';
$(this).html(FormElement.formatSignatureConnectionSelectionData({text: selected[0].text})).prepend(errorIcon);
$(this).html(FormElement.formatSignatureConnectionSelectionData({
text: selected[0].text,
metaData: selected[0].metaData
})).prepend(errorIcon);
}else{
$(this).empty();
}
@@ -2150,7 +2180,7 @@ define([
// xEditable field should not open -> on 'click'
// -> therefore disable "pointer-events" on "td" for some ms -> 'click' event is not triggered
$(this).css('pointer-events', 'none');
$(e.target.parentNode).toggleClass('selected');
$(e.target).closest('tr').toggleClass('selected');
// check delete button
checkDeleteSignaturesButton(e.data.tableApi);

View File

@@ -1011,6 +1011,61 @@ define([
});
};
/**
* convert XEditable Select <option> data into Select2 data format
* -> "prepend" (empty) options get added, too
* -> "metaData" can be used to pass custom data per <option>
* @param editable
* @returns {Array}
*/
let convertXEditableOptionsToSelect2 = editable => {
let data = [];
if(editable.options){
// collect all options + "prepend" option from xEditable...
let optionsPrepend = editable.options.prepend ? editable.options.prepend : [];
let options = editable.options.source();
let optionsAll = [];
optionsAll.push(...optionsPrepend, ...options);
/**
* convert a single option into Select2 format
* @param option
* @returns {{id: *, text: *}}
*/
let convertOption = (option) => {
let data = {
id: option.value,
text: option.text
};
if(editable.value === option.value){
data.selected = true;
}
// optional "metaData" that belongs to this option
if(option.hasOwnProperty('metaData')){
data.metaData = option.metaData;
}
return data;
};
// ... transform data into Select2 data format
data = optionsAll.map(group => {
if(group.children){
group.children = group.children.map(convertOption);
}else{
group = convertOption(group);
}
return group;
});
}
return data;
};
/**
* flatten XEditable array for select fields
* @param dataArray
@@ -3138,6 +3193,7 @@ define([
getCurrentUserInfo: getCurrentUserInfo,
getCurrentCharacterLog: getCurrentCharacterLog,
initPageScroll: initPageScroll,
convertXEditableOptionsToSelect2: convertXEditableOptionsToSelect2,
flattenXEditableSelectArray: flattenXEditableSelectArray,
getCharacterDataBySystemId: getCharacterDataBySystemId,
getNearBySystemData: getNearBySystemData,

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -151,8 +151,29 @@ define([
let markup = '';
if(parts.length === 2){
// wormhole data -> 2 columns
let styleClass = ['pf-fake-connection-text'];
if(state.metaData){
let metaData = state.metaData;
if(metaData.type){
let type = metaData.type;
if(type.includes('wh_eol')){
styleClass.push('pf-wh-eol');
}
if(type.includes('wh_reduced')){
styleClass.push('pf-wh-reduced');
}
if(type.includes('wh_critical')){
styleClass.push('pf-wh-critical');
}
if(type.includes('frigate')){
styleClass.push('pf-wh-frig');
}
}
}
let securityClass = Util.getSecurityClassForSystem(parts[1]);
markup += '<span>' + parts[0] + '</span>&nbsp;&nbsp;';
markup += '<span class="' + styleClass.join(' ') + '">' + parts[0] + '</span>&nbsp;&nbsp;';
markup += '<span class="' + securityClass + '">' + parts[1] + '</span>';
}else{
markup += '<span>' + state.text + '</span>';
@@ -786,6 +807,11 @@ define([
return this.each(function(){
let selectElement = $(this);
// remove existing <options> from DOM in case "data" is explicit set
if(options.data){
selectElement.empty();
}
selectElement.select2(options);
// initial open dropDown

View File

@@ -405,6 +405,32 @@ define([
let newSelectOptions = [];
let connectionOptions = [];
/**
* get option data for a single connection
* @param type
* @param connectionData
* @param systemData
* @returns {{value: *, text: string, metaData: {type: *}}}
*/
let getOption = (type, connectionData, systemData) => {
let text = 'UNKNOWN';
if(type === 'source'){
text = connectionData.sourceAlias + ' - ' + systemData.security;
}else if(type === 'target'){
text = connectionData.targetAlias + ' - ' + systemData.security;
}
let option = {
value: connectionData.id,
text: text,
metaData: {
type: connectionData.type
}
};
return option;
};
for(let systemConnection of systemConnections){
let connectionData = MapUtil.getDataByConnection(systemConnection);
@@ -416,19 +442,13 @@ define([
let targetSystemData = MapUtil.getSystemData(mapId, connectionData.target);
if(targetSystemData){
// take target...
connectionOptions.push({
value: connectionData.id,
text: connectionData.targetAlias + ' - ' + targetSystemData.security
});
connectionOptions.push(getOption('target', connectionData, targetSystemData));
}
}else if(systemData.id !== connectionData.source){
let sourceSystemData = MapUtil.getSystemData(mapId, connectionData.source);
if(sourceSystemData){
// take source...
connectionOptions.push({
value: connectionData.id,
text: connectionData.sourceAlias + ' - ' + sourceSystemData.security
});
connectionOptions.push(getOption('source', connectionData, sourceSystemData));
}
}
}
@@ -1119,7 +1139,14 @@ define([
let editableConnectionOnShown = cell => {
$(cell).on('shown', function(e, editable){
let inputField = editable.input.$input;
inputField.addClass('pf-select2').initSignatureConnectionSelect();
// Select2 init would work without passing select options as "data", Select2 would grap data from DOM
// -> We want to pass "meta" data for each option into Select2 for formatting
let options = {
data: Util.convertXEditableOptionsToSelect2(editable)
};
inputField.addClass('pf-select2').initSignatureConnectionSelect(options);
});
};
@@ -1534,7 +1561,10 @@ define([
let selected = $.fn.editableutils.itemsByValue(value, sourceData);
if(selected.length && selected[0].value > 0){
let errorIcon = '<i class="fas fa-exclamation-triangle txt-color txt-color-danger hide"></i>&nbsp;';
$(this).html(FormElement.formatSignatureConnectionSelectionData({text: selected[0].text})).prepend(errorIcon);
$(this).html(FormElement.formatSignatureConnectionSelectionData({
text: selected[0].text,
metaData: selected[0].metaData
})).prepend(errorIcon);
}else{
$(this).empty();
}
@@ -2150,7 +2180,7 @@ define([
// xEditable field should not open -> on 'click'
// -> therefore disable "pointer-events" on "td" for some ms -> 'click' event is not triggered
$(this).css('pointer-events', 'none');
$(e.target.parentNode).toggleClass('selected');
$(e.target).closest('tr').toggleClass('selected');
// check delete button
checkDeleteSignaturesButton(e.data.tableApi);

View File

@@ -1011,6 +1011,61 @@ define([
});
};
/**
* convert XEditable Select <option> data into Select2 data format
* -> "prepend" (empty) options get added, too
* -> "metaData" can be used to pass custom data per <option>
* @param editable
* @returns {Array}
*/
let convertXEditableOptionsToSelect2 = editable => {
let data = [];
if(editable.options){
// collect all options + "prepend" option from xEditable...
let optionsPrepend = editable.options.prepend ? editable.options.prepend : [];
let options = editable.options.source();
let optionsAll = [];
optionsAll.push(...optionsPrepend, ...options);
/**
* convert a single option into Select2 format
* @param option
* @returns {{id: *, text: *}}
*/
let convertOption = (option) => {
let data = {
id: option.value,
text: option.text
};
if(editable.value === option.value){
data.selected = true;
}
// optional "metaData" that belongs to this option
if(option.hasOwnProperty('metaData')){
data.metaData = option.metaData;
}
return data;
};
// ... transform data into Select2 data format
data = optionsAll.map(group => {
if(group.children){
group.children = group.children.map(convertOption);
}else{
group = convertOption(group);
}
return group;
});
}
return data;
};
/**
* flatten XEditable array for select fields
* @param dataArray
@@ -3138,6 +3193,7 @@ define([
getCurrentUserInfo: getCurrentUserInfo,
getCurrentCharacterLog: getCurrentCharacterLog,
initPageScroll: initPageScroll,
convertXEditableOptionsToSelect2: convertXEditableOptionsToSelect2,
flattenXEditableSelectArray: flattenXEditableSelectArray,
getCharacterDataBySystemId: getCharacterDataBySystemId,
getNearBySystemData: getNearBySystemData,

View File

@@ -1196,7 +1196,35 @@ table{
@include border-radius(3px);
}
}
}
// "fake connection" classes for inline text
.pf-fake-connection-text{
padding: 0 2px;
border-style: solid;
border-color: darken($gray-light, 5%);
border-width: 2px;
border-left: none;
border-right: none;
&.pf-wh-eol{
border-color: $pink-dark;
}
&.pf-wh-reduced{
background-color: $orange;
color: $black;
}
&.pf-wh-critical{
background-color: $red-darker;
color: $black;
}
&.pf-wh-frig{
border-top-style: dashed;
border-bottom-style: dashed;
}
}
// structure status ===============================================================================
@@ -1598,6 +1626,4 @@ Animate the stripes
100% {
background-position: 50px 50px;
}
}
}