- Fixed duplicate wormhole select options, #916

- Fixed visible paginate buttons in local overlay
This commit is contained in:
Mark Friedrich
2020-03-16 20:20:34 +01:00
parent 9a3f45fdc7
commit 0fe8e83b8f
9 changed files with 140 additions and 54 deletions

View File

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

View File

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

View File

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

View File

@@ -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 <optgroup> 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 <optgroup>
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"

View File

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

View File

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

View File

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

View File

@@ -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 <optgroup> 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 <optgroup>
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"

View File

@@ -186,7 +186,7 @@
{{#corporation}}
<h4 class="pf-dynamic-area"><img src="{{ccpImageServer}}/Corporation/{{id}}_64.png">&nbsp;&nbsp;Corporation maps "<em class="pf-map-type-corporation">{{name}}</em>"</h4>
{{#hasRightCorporationShareUpdate}}
{{#hasRightCorporationShare}}
<div class="form-group">
<div class="col-sm-9">
<label class="control-label" for="corporationSharing">
@@ -196,13 +196,13 @@
</div>
<div class="col-sm-3"></div>
</div>
{{/hasRightCorporationShareUpdate}}
{{^hasRightCorporationShareUpdate}}
{{/hasRightCorporationShare}}
{{^hasRightCorporationShare}}
<div class="alert alert-info">
<span class="txt-color txt-color-info">Restricted</span>
<small>You don´t have the required roles.</small>
</div>
{{/hasRightCorporationShareUpdate}}
{{/hasRightCorporationShare}}
{{/corporation}}
{{#alliance}}