From a8b51af028f79c30d72386bda9fa8c905bb6a209 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sat, 24 Nov 2018 12:01:42 +0100 Subject: [PATCH] - New colour codes for (wh) connections added to "Signature" module, closed #703 --- app/main/controller/api/signature.php | 9 ++- app/main/model/systemsignaturemodel.php | 13 +++-- js/app/ui/form_element.js | 28 +++++++++- js/app/ui/module/system_signature.js | 52 +++++++++++++---- js/app/util.js | 56 +++++++++++++++++++ public/css/v1.4.3/pathfinder.css | 2 +- public/css/v1.4.3/pathfinder.css.map | 2 +- public/js/v1.4.3/app/ui/form_element.js | 28 +++++++++- .../v1.4.3/app/ui/module/system_signature.js | 52 +++++++++++++---- public/js/v1.4.3/app/util.js | 56 +++++++++++++++++++ sass/layout/_main.scss | 32 ++++++++++- 11 files changed, 294 insertions(+), 36 deletions(-) diff --git a/app/main/controller/api/signature.php b/app/main/controller/api/signature.php index b930e18e..b9f563ba 100644 --- a/app/main/controller/api/signature.php +++ b/app/main/controller/api/signature.php @@ -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(); } diff --git a/app/main/model/systemsignaturemodel.php b/app/main/model/systemsignaturemodel.php index d218fe3d..80f4071a 100644 --- a/app/main/model/systemsignaturemodel.php +++ b/app/main/model/systemsignaturemodel.php @@ -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; } } diff --git a/js/app/ui/form_element.js b/js/app/ui/form_element.js index 71cad2b2..061f356f 100644 --- a/js/app/ui/form_element.js +++ b/js/app/ui/form_element.js @@ -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 += '' + parts[0] + '  '; + markup += '' + parts[0] + '  '; markup += '' + parts[1] + ''; }else{ markup += '' + state.text + ''; @@ -786,6 +807,11 @@ define([ return this.each(function(){ let selectElement = $(this); + + // remove existing from DOM in case "data" is explicit set + if(options.data){ + selectElement.empty(); + } selectElement.select2(options); // initial open dropDown diff --git a/js/app/ui/module/system_signature.js b/js/app/ui/module/system_signature.js index c48866a2..13821487 100644 --- a/js/app/ui/module/system_signature.js +++ b/js/app/ui/module/system_signature.js @@ -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 = ' '; - $(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); diff --git a/js/app/util.js b/js/app/util.js index 319c38b3..47f8f240 100644 --- a/js/app/util.js +++ b/js/app/util.js @@ -1011,6 +1011,61 @@ define([ }); }; + /** + * convert XEditable Select