From 0fe8e83b8f0d8fe5cdfebbf3ee1cf507b2c28926 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Mon, 16 Mar 2020 20:20:34 +0100 Subject: [PATCH] - Fixed duplicate wormhole select options, #916 - Fixed visible paginate buttons in local overlay --- js/app/lib/prototypes.js | 11 +++++ js/app/map/local.js | 2 +- js/app/ui/module/system_intel.js | 46 +++++++++++-------- js/app/ui/module/system_signature.js | 34 ++++++++++++-- public/js/v2.0.0/app/lib/prototypes.js | 11 +++++ public/js/v2.0.0/app/map/local.js | 2 +- .../js/v2.0.0/app/ui/module/system_intel.js | 46 +++++++++++-------- .../v2.0.0/app/ui/module/system_signature.js | 34 ++++++++++++-- public/templates/dialog/settings.html | 8 ++-- 9 files changed, 140 insertions(+), 54 deletions(-) diff --git a/js/app/lib/prototypes.js b/js/app/lib/prototypes.js index 23182801..29954370 100644 --- a/js/app/lib/prototypes.js +++ b/js/app/lib/prototypes.js @@ -59,6 +59,17 @@ define([ return this.filter(i => a.includes(i)); }; + /** + * inverse of Array.filter(), + * [1,2,3,4,5].not(val => val === 3) => [1, 2, 4, 5] + * [1,2,3,4,5].filter(val => val === 3) => [3] + * @param callback + * @returns {*[]} + */ + Array.prototype.not = function(callback) { + return this.filter((...args) => !callback(...args)); + }; + /** * compares two arrays if all elements in a are also in b * element order is ignored diff --git a/js/app/map/local.js b/js/app/map/local.js index 9170ecaf..0a789579 100644 --- a/js/app/map/local.js +++ b/js/app/map/local.js @@ -411,7 +411,7 @@ define([ }); let localTable = table.DataTable({ - pageLength: 5, + pageLength: 3, // default page length, smaller then max page length (4) if map is vertical resized to min. paging: true, pagingType: 'simple', lengthChange: false, diff --git a/js/app/ui/module/system_intel.js b/js/app/ui/module/system_intel.js index 60a25464..2ff912de 100644 --- a/js/app/ui/module/system_intel.js +++ b/js/app/ui/module/system_intel.js @@ -381,20 +381,20 @@ define([ } }; - let tableApiStructure = $(structureTableEl).DataTable($.extend(true, {}, module.getDataTableDefaults(module), structureDataTableOptions)); + this._tableApiStructure = $(structureTableEl).DataTable($.extend(true, {}, module.getDataTableDefaults(module), structureDataTableOptions)); // "Responsive" Datatables Plugin - new $.fn.dataTable.Responsive(tableApiStructure); + new $.fn.dataTable.Responsive(this._tableApiStructure); - tableApiStructure.on('responsive-resize', function(e, tableApi, columns){ + this._tableApiStructure.on('responsive-resize', function(e, tableApi, columns){ // rowGroup length changes as well -> trigger draw() updates rowGroup length (see drawCallback()) tableApi.draw(); }); // "Select" Datatables Plugin - tableApiStructure.select(); + this._tableApiStructure.select(); - tableApiStructure.on('user-select', function(e, tableApi, type, cell, originalEvent){ + this._tableApiStructure.on('user-select', function(e, tableApi, type, cell, originalEvent){ let rowData = tableApi.row(cell.index().row).data(); if(Util.getObjVal(rowData, 'rowGroupData.id') !== corporationId){ e.preventDefault(); @@ -402,7 +402,7 @@ define([ }); // "Buttons" Datatables Plugin - let buttons = new $.fn.dataTable.Buttons(tableApiStructure, { + let buttons = new $.fn.dataTable.Buttons(this._tableApiStructure, { dom: { container: { tag: 'h5', @@ -489,7 +489,7 @@ define([ ] }); - tableApiStructure.buttons().container().appendTo(module.moduleElement.querySelector('.' + module._config.headClassName)); + this._tableApiStructure.buttons().container().appendTo(module.moduleElement.querySelector('.' + module._config.headClassName)); } /** @@ -723,11 +723,11 @@ define([ } }; - let tableApiStation = $(stationTableEl).DataTable($.extend(true, {}, module.getDataTableDefaults(module), stationDataTableOptions)); + this._tableApiStation = $(stationTableEl).DataTable($.extend(true, {}, module.getDataTableDefaults(module), stationDataTableOptions)); - new $.fn.dataTable.Responsive(tableApiStation); + new $.fn.dataTable.Responsive(this._tableApiStation); - tableApiStation.on('responsive-resize', function(e, tableApi, columns){ + this._tableApiStation.on('responsive-resize', function(e, tableApi, columns){ // rowGroup length changes as well -> trigger draw() updates rowGroup length (see drawCallback()) tableApi.draw(); }); @@ -1284,20 +1284,26 @@ define([ update(systemData){ return super.update(systemData).then(systemData => new Promise(resolve => { // update structure table data ------------------------------------------------------------------------ - let structureContext = { - tableApi: $(this.moduleElement.querySelector('.' + this._config.systemStructuresTableClass)).DataTable(), - removeMissing: true - }; + if(this._tableApiStructure){ + let structureContext = { + tableApi: this._tableApiStructure, + removeMissing: true + }; - this.callbackUpdateTableRows(structureContext, Util.getObjVal(systemData, 'structures')); + this.callbackUpdateTableRows(structureContext, Util.getObjVal(systemData, 'structures')); + }else{ + console.warn('DataTable "structures" not initialized. Can not update "intel" module'); + } // update station table data -------------------------------------------------------------------------- - let stationContext = { - tableApi: $(this.moduleElement.querySelector('.' + this._config.systemStationsTableClass)).DataTable(), - removeMissing: false - }; + if(this._tableApiStation){ + let stationContext = { + tableApi: this._tableApiStation, + removeMissing: false + }; - this.callbackUpdateTableRows(stationContext, Util.getObjVal(systemData, 'stations'), 'stations'); + this.callbackUpdateTableRows(stationContext, Util.getObjVal(systemData, 'stations'), 'stations'); + } $(this.moduleElement).hideLoadingAnimation(); diff --git a/js/app/ui/module/system_signature.js b/js/app/ui/module/system_signature.js index c466dae5..9a34bb61 100644 --- a/js/app/ui/module/system_signature.js +++ b/js/app/ui/module/system_signature.js @@ -2885,6 +2885,7 @@ define([ newSelectOptions = []; // get new Options ---------- // get all possible "static" signature names by the selected groupId + // -> for groupId == 5 (wormholes) this give you "wandering" whs let tempSelectOptions = Util.getSignatureTypeNames(systemTypeId, areaIds, groupId); // format options into array with objects advantages: keep order, add more options (whs), use optgroup @@ -2903,7 +2904,7 @@ define([ if(newSelectOptionsCount > 0){ if(groupId === 5){ // "wormhole" selected => multiple available - newSelectOptions.push({ text: 'Wandering', children: fixSelectOptions}); + newSelectOptions.push({text: 'Wandering', children: fixSelectOptions}); }else{ newSelectOptions = fixSelectOptions; } @@ -2927,7 +2928,7 @@ define([ } if(frigateWHData.length > 0){ - newSelectOptions.push({ text: 'Frigate', children: frigateWHData}); + newSelectOptions.push({text: 'Frigate', children: frigateWHData}); } // add potential drifter holes (k-space only) @@ -2944,7 +2945,7 @@ define([ } if(drifterWHData.length > 0){ - newSelectOptions.push({ text: 'Drifter', children: drifterWHData}); + newSelectOptions.push({text: 'Drifter', children: drifterWHData}); } } @@ -2978,16 +2979,21 @@ define([ // add static WH(s) for this system if(statics){ let staticWHData = []; + let filterOptionCallback = text => option => option.text !== text; + for(let wormholeName of statics){ let wormholeData = Object.assign({}, Init.wormholes[wormholeName]); let staticWHName = wormholeData.name + ' - ' + wormholeData.security; + // filter staticWHName from existing options -> prevent duplicates in + SystemSignatureModule.filterGroupedOptions(newSelectOptions, filterOptionCallback(staticWHName)); + newSelectOptionsCount++; staticWHData.push({value: newSelectOptionsCount, text: staticWHName}); } if(staticWHData.length > 0){ - newSelectOptions.unshift({ text: 'Static', children: staticWHData}); + newSelectOptions.unshift({text: 'Static', children: staticWHData}); } } } @@ -2995,6 +3001,26 @@ define([ return newSelectOptions; } + /** + * filter out some options from nested select options + * @param obj + * @param callback + * @param key + */ + static filterGroupedOptions(obj, callback = () => true, key = 'children'){ + for(let [i, val] of Object.entries(obj)){ + // pre-check if filter callback will some, prevents unnecessary cloning + if( + typeof val === 'object' && + val.hasOwnProperty(key) && + val[key].not(callback).length + ){ + // clone object, apply filter to key prop + obj[i] = Object.assign({}, obj[i], {[key]: val[key].filter(callback)}); + } + } + } + /** * get possible frig holes that could spawn in a system * filtered by "systemTypeId" diff --git a/public/js/v2.0.0/app/lib/prototypes.js b/public/js/v2.0.0/app/lib/prototypes.js index 23182801..29954370 100644 --- a/public/js/v2.0.0/app/lib/prototypes.js +++ b/public/js/v2.0.0/app/lib/prototypes.js @@ -59,6 +59,17 @@ define([ return this.filter(i => a.includes(i)); }; + /** + * inverse of Array.filter(), + * [1,2,3,4,5].not(val => val === 3) => [1, 2, 4, 5] + * [1,2,3,4,5].filter(val => val === 3) => [3] + * @param callback + * @returns {*[]} + */ + Array.prototype.not = function(callback) { + return this.filter((...args) => !callback(...args)); + }; + /** * compares two arrays if all elements in a are also in b * element order is ignored diff --git a/public/js/v2.0.0/app/map/local.js b/public/js/v2.0.0/app/map/local.js index 9170ecaf..0a789579 100644 --- a/public/js/v2.0.0/app/map/local.js +++ b/public/js/v2.0.0/app/map/local.js @@ -411,7 +411,7 @@ define([ }); let localTable = table.DataTable({ - pageLength: 5, + pageLength: 3, // default page length, smaller then max page length (4) if map is vertical resized to min. paging: true, pagingType: 'simple', lengthChange: false, diff --git a/public/js/v2.0.0/app/ui/module/system_intel.js b/public/js/v2.0.0/app/ui/module/system_intel.js index 60a25464..2ff912de 100644 --- a/public/js/v2.0.0/app/ui/module/system_intel.js +++ b/public/js/v2.0.0/app/ui/module/system_intel.js @@ -381,20 +381,20 @@ define([ } }; - let tableApiStructure = $(structureTableEl).DataTable($.extend(true, {}, module.getDataTableDefaults(module), structureDataTableOptions)); + this._tableApiStructure = $(structureTableEl).DataTable($.extend(true, {}, module.getDataTableDefaults(module), structureDataTableOptions)); // "Responsive" Datatables Plugin - new $.fn.dataTable.Responsive(tableApiStructure); + new $.fn.dataTable.Responsive(this._tableApiStructure); - tableApiStructure.on('responsive-resize', function(e, tableApi, columns){ + this._tableApiStructure.on('responsive-resize', function(e, tableApi, columns){ // rowGroup length changes as well -> trigger draw() updates rowGroup length (see drawCallback()) tableApi.draw(); }); // "Select" Datatables Plugin - tableApiStructure.select(); + this._tableApiStructure.select(); - tableApiStructure.on('user-select', function(e, tableApi, type, cell, originalEvent){ + this._tableApiStructure.on('user-select', function(e, tableApi, type, cell, originalEvent){ let rowData = tableApi.row(cell.index().row).data(); if(Util.getObjVal(rowData, 'rowGroupData.id') !== corporationId){ e.preventDefault(); @@ -402,7 +402,7 @@ define([ }); // "Buttons" Datatables Plugin - let buttons = new $.fn.dataTable.Buttons(tableApiStructure, { + let buttons = new $.fn.dataTable.Buttons(this._tableApiStructure, { dom: { container: { tag: 'h5', @@ -489,7 +489,7 @@ define([ ] }); - tableApiStructure.buttons().container().appendTo(module.moduleElement.querySelector('.' + module._config.headClassName)); + this._tableApiStructure.buttons().container().appendTo(module.moduleElement.querySelector('.' + module._config.headClassName)); } /** @@ -723,11 +723,11 @@ define([ } }; - let tableApiStation = $(stationTableEl).DataTable($.extend(true, {}, module.getDataTableDefaults(module), stationDataTableOptions)); + this._tableApiStation = $(stationTableEl).DataTable($.extend(true, {}, module.getDataTableDefaults(module), stationDataTableOptions)); - new $.fn.dataTable.Responsive(tableApiStation); + new $.fn.dataTable.Responsive(this._tableApiStation); - tableApiStation.on('responsive-resize', function(e, tableApi, columns){ + this._tableApiStation.on('responsive-resize', function(e, tableApi, columns){ // rowGroup length changes as well -> trigger draw() updates rowGroup length (see drawCallback()) tableApi.draw(); }); @@ -1284,20 +1284,26 @@ define([ update(systemData){ return super.update(systemData).then(systemData => new Promise(resolve => { // update structure table data ------------------------------------------------------------------------ - let structureContext = { - tableApi: $(this.moduleElement.querySelector('.' + this._config.systemStructuresTableClass)).DataTable(), - removeMissing: true - }; + if(this._tableApiStructure){ + let structureContext = { + tableApi: this._tableApiStructure, + removeMissing: true + }; - this.callbackUpdateTableRows(structureContext, Util.getObjVal(systemData, 'structures')); + this.callbackUpdateTableRows(structureContext, Util.getObjVal(systemData, 'structures')); + }else{ + console.warn('DataTable "structures" not initialized. Can not update "intel" module'); + } // update station table data -------------------------------------------------------------------------- - let stationContext = { - tableApi: $(this.moduleElement.querySelector('.' + this._config.systemStationsTableClass)).DataTable(), - removeMissing: false - }; + if(this._tableApiStation){ + let stationContext = { + tableApi: this._tableApiStation, + removeMissing: false + }; - this.callbackUpdateTableRows(stationContext, Util.getObjVal(systemData, 'stations'), 'stations'); + this.callbackUpdateTableRows(stationContext, Util.getObjVal(systemData, 'stations'), 'stations'); + } $(this.moduleElement).hideLoadingAnimation(); diff --git a/public/js/v2.0.0/app/ui/module/system_signature.js b/public/js/v2.0.0/app/ui/module/system_signature.js index c466dae5..9a34bb61 100644 --- a/public/js/v2.0.0/app/ui/module/system_signature.js +++ b/public/js/v2.0.0/app/ui/module/system_signature.js @@ -2885,6 +2885,7 @@ define([ newSelectOptions = []; // get new Options ---------- // get all possible "static" signature names by the selected groupId + // -> for groupId == 5 (wormholes) this give you "wandering" whs let tempSelectOptions = Util.getSignatureTypeNames(systemTypeId, areaIds, groupId); // format options into array with objects advantages: keep order, add more options (whs), use optgroup @@ -2903,7 +2904,7 @@ define([ if(newSelectOptionsCount > 0){ if(groupId === 5){ // "wormhole" selected => multiple available - newSelectOptions.push({ text: 'Wandering', children: fixSelectOptions}); + newSelectOptions.push({text: 'Wandering', children: fixSelectOptions}); }else{ newSelectOptions = fixSelectOptions; } @@ -2927,7 +2928,7 @@ define([ } if(frigateWHData.length > 0){ - newSelectOptions.push({ text: 'Frigate', children: frigateWHData}); + newSelectOptions.push({text: 'Frigate', children: frigateWHData}); } // add potential drifter holes (k-space only) @@ -2944,7 +2945,7 @@ define([ } if(drifterWHData.length > 0){ - newSelectOptions.push({ text: 'Drifter', children: drifterWHData}); + newSelectOptions.push({text: 'Drifter', children: drifterWHData}); } } @@ -2978,16 +2979,21 @@ define([ // add static WH(s) for this system if(statics){ let staticWHData = []; + let filterOptionCallback = text => option => option.text !== text; + for(let wormholeName of statics){ let wormholeData = Object.assign({}, Init.wormholes[wormholeName]); let staticWHName = wormholeData.name + ' - ' + wormholeData.security; + // filter staticWHName from existing options -> prevent duplicates in + SystemSignatureModule.filterGroupedOptions(newSelectOptions, filterOptionCallback(staticWHName)); + newSelectOptionsCount++; staticWHData.push({value: newSelectOptionsCount, text: staticWHName}); } if(staticWHData.length > 0){ - newSelectOptions.unshift({ text: 'Static', children: staticWHData}); + newSelectOptions.unshift({text: 'Static', children: staticWHData}); } } } @@ -2995,6 +3001,26 @@ define([ return newSelectOptions; } + /** + * filter out some options from nested select options + * @param obj + * @param callback + * @param key + */ + static filterGroupedOptions(obj, callback = () => true, key = 'children'){ + for(let [i, val] of Object.entries(obj)){ + // pre-check if filter callback will some, prevents unnecessary cloning + if( + typeof val === 'object' && + val.hasOwnProperty(key) && + val[key].not(callback).length + ){ + // clone object, apply filter to key prop + obj[i] = Object.assign({}, obj[i], {[key]: val[key].filter(callback)}); + } + } + } + /** * get possible frig holes that could spawn in a system * filtered by "systemTypeId" diff --git a/public/templates/dialog/settings.html b/public/templates/dialog/settings.html index 4de5da48..c2cda8dc 100644 --- a/public/templates/dialog/settings.html +++ b/public/templates/dialog/settings.html @@ -186,7 +186,7 @@ {{#corporation}}

  Corporation maps "{{name}}"

- {{#hasRightCorporationShareUpdate}} + {{#hasRightCorporationShare}}
- {{/hasRightCorporationShareUpdate}} - {{^hasRightCorporationShareUpdate}} + {{/hasRightCorporationShare}} + {{^hasRightCorporationShare}}
Restricted You don“t have the required roles.
- {{/hasRightCorporationShareUpdate}} + {{/hasRightCorporationShare}} {{/corporation}} {{#alliance}}