Skip to content

Commit

Permalink
- New map right "create map" added, closed exodus4d#927
Browse files Browse the repository at this point in the history
  • Loading branch information
exodus4d committed Mar 17, 2020
1 parent f7e7082 commit 3d42a8e
Show file tree
Hide file tree
Showing 15 changed files with 143 additions and 90 deletions.
1 change: 1 addition & 0 deletions app/Model/Pathfinder/CorporationModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class CorporationModel extends AbstractPathfinderModel {
* corp rights that can be stored to a corp
*/
const RIGHTS = [
'map_create',
'map_update',
'map_delete',
'map_import',
Expand Down
6 changes: 6 additions & 0 deletions app/Model/Pathfinder/RightModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ class RightModel extends AbstractPathfinderModel {
'name' => 'map_share',
'label' => 'share',
'description' => 'Map share right'
],
[
'id' => 6,
'name' => 'map_create',
'label' => 'create',
'description' => 'Map create right'
]
];

Expand Down
2 changes: 2 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
$composerAutoloader = 'vendor/autoload.php';
if(file_exists($composerAutoloader)){
require_once($composerAutoloader);
}else{
die("Couldn't find '$composerAutoloader'. Did you run `composer install`?");
}

$f3 = \Base::instance();
Expand Down
55 changes: 29 additions & 26 deletions js/app/map/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,44 +75,47 @@ define([

/**
* get all available map Types
* optional they can be filtered by current access level of a user
* @param {bool} filterByUser
* optional they can be filtered by current access level of current character
* @param {bool} filterByCharacter
* @param {string} filterRight
* @returns {Array}
*/
let getMapTypes = (filterByUser) => {
let getMapTypes = (filterByCharacter, filterRight) => {
let mapTypes = Object.assign({}, Init.mapTypes);

if(filterByUser === true){
if(filterByCharacter === true){
let authorizedMapTypes = [];
let checkMapTypes = ['private', 'corporation', 'alliance'];

for(let i = 0; i < checkMapTypes.length; i++){
let objectId = Util.getCurrentUserInfo(checkMapTypes[i] + 'Id');
if(objectId > 0){
// check if User could add new map with a mapType
let currentObjectMapData = Util.filterCurrentMapData('config.type.id', Util.getObjVal(mapTypes, checkMapTypes[i] + '.id'));
let maxCountObject = Util.getObjVal(mapTypes, checkMapTypes[i] + '.defaultConfig.max_count');
let checkMapTypes = [
{type: 'private', hasRight: false, selector: 'id'},
{type: 'corporation', hasRight: true, selector: 'corporation.id'},
{type: 'alliance', hasRight: true, selector: 'alliance.id'}
];

checkMapTypes.forEach(data => {
// check if current character is e.g. in alliance
if(Util.getCurrentCharacterData(data.selector)){
// check if User could add new map with a mapType -> check map limit
let currentObjectMapData = Util.filterCurrentMapData('config.type.id', Util.getObjVal(mapTypes, data.selector));
let maxCountObject = Util.getObjVal(mapTypes, `${data.type}.defaultConfig.max_count`);
if(currentObjectMapData.length < maxCountObject){
authorizedMapTypes.push(checkMapTypes[i]);
// check if character has the "right" for creating a map with this type
if((data.hasRight && filterRight) ? Util.hasRight(filterRight, data.type) : true){
authorizedMapTypes.push(data.type);
}
}
}
}
});

for(let mapType in mapTypes){
if(authorizedMapTypes.indexOf(mapType) < 0){
delete( mapTypes[mapType] );
}
}
mapTypes = Util.filterObjByKeys(mapTypes, authorizedMapTypes);
}

// convert to array
let mapTypesFlat = [];
for(let mapType in mapTypes){
mapTypes[mapType].name = mapType;
mapTypesFlat.push(mapTypes[mapType]);
}
// add "name" to mapType data
Object.entries(mapTypes).forEach(([mapType, data]) => {
data.name = mapType;
});

return mapTypesFlat;
// obj to array
return Object.keys(mapTypes).map(mapType => mapTypes[mapType]);
};

/**
Expand Down
9 changes: 1 addition & 8 deletions js/app/ui/dialog/map_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,7 @@ define([

// map type
let mapTypes = MapUtil.getMapTypes();
let mapType = null;

for(let i = 0; i < mapTypes.length; i++){
if(mapTypes[i].id === mapData.config.type.id){
mapType = mapTypes[i];
break;
}
}
let mapType = mapTypes.find(data => data.id === mapData.config.type.id);

// check max map limits (e.g. max systems per map) ------------------------------------------------------------
let percentageSystems = (100 / mapType.defaultConfig.max_systems) * countSystems;
Expand Down
23 changes: 15 additions & 8 deletions js/app/ui/dialog/map_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,17 @@ define([
let hasRightMapImport = MapUtil ? MapUtil.checkRight('map_import', mapData.config) : true;
let hasRightMapShare = MapUtil ? MapUtil.checkRight('map_share', mapData.config) : true;

// available map "types" for a new or existing map
let mapTypes = MapUtil.getMapTypes(true);
// available map "type" options data
// -> for "new" map tab
let mapTypesCreate = MapUtil.getMapTypes(true, 'map_create');
// -> for "edit" map tab
let mapTypesUpdate = MapUtil.getMapTypes(true, 'map_update');

// render main dialog ---------------------------------------------------------------------------------
let mapDialogData = {
id: config.newMapDialogId,
mapData: mapData,
type: mapTypes,
type: mapTypesCreate,

hasRightMapUpdate,
hasRightMapExport,
Expand Down Expand Up @@ -273,7 +276,6 @@ define([
let mapFormData = {
select2Class: Util.config.select2Class,
scope: MapUtil.getMapScopes(),
type: mapTypes,
icon: MapUtil.getMapIcons(),
formErrorContainerClass: Util.config.formErrorContainerClass,
formWarningContainerClass: Util.config.formWarningContainerClass,
Expand All @@ -282,6 +284,7 @@ define([

// render "new map" tab content -----------------------------------------------------------------------
let mapFormDataNew = Object.assign({}, mapFormData, {
type: mapTypesCreate,
hasRightMapForm: hasRightMapCreate,
nameInputId: config.newNameInputId,
iconSelectId: config.newIconSelectId,
Expand All @@ -300,6 +303,7 @@ define([
// render "edit map" tab content ----------------------------------------------------------------------
if(!hideEditTab){
let mapFormDataEdit = Object.assign({}, mapFormData, {
type: mapTypesUpdate,
hasRightMapForm: hasRightMapUpdate,
nameInputId: config.editNameInputId,
iconSelectId: config.editIconSelectId,
Expand Down Expand Up @@ -361,7 +365,10 @@ define([
formData[key] = (formData[key].length ? '#' : '') + formData[key];
});

MapOverlayUtil.getMapOverlay($(mapData.map.getContainer()), 'timer').startMapUpdateCounter();
if(mapData){
// no map data found -> probably new user
MapOverlayUtil.getMapOverlay(mapData.map.getContainer(), 'timer').startMapUpdateCounter();
}

let method = formData.id ? 'PATCH' : 'PUT';

Expand Down Expand Up @@ -427,8 +434,8 @@ define([

form.showFormMessage([{type: 'info', text: 'Creating new maps or change settings may take a few seconds'}]);

if(mapData === false){
// no map data found (probably new user
if(!mapData){
// no map data found -> probably new user
form.showFormMessage([{type: 'warning', text: 'No maps found. Create a new map before you can start'}]);
}

Expand All @@ -438,7 +445,7 @@ define([
// tab exists

// export map data ----------------------------------------------------------------------------
downloadTabElement.find('#' + config.buttonExportId).on('click', { mapData: mapData }, function(e){
downloadTabElement.find('#' + config.buttonExportId).on('click', {mapData}, function(e){

let exportForm = $('#' + config.dialogMapExportFormId);
let validExportForm = exportForm.isValidForm();
Expand Down
18 changes: 18 additions & 0 deletions js/app/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -3508,6 +3508,23 @@ define([
return combined;
};

/**
* filter object by allowed keys
* -> returns a NEW object. Does not change the source obj
* ({one: 'A', two: 'B'}).filterKeys(['one']) => {one: "A"}
* @param obj
* @param allowedKeys
* @returns {{}}
*/
let filterObjByKeys = (obj, allowedKeys = []) => {
return Object.keys(obj)
.filter(key => allowedKeys.includes(key))
.reduce((objAcc, key) => {
objAcc[key] = obj[key];
return objAcc;
}, {});
};

/**
* get deep json object value if exists
* -> e.g. key = 'first.last.third' string
Expand Down Expand Up @@ -3723,6 +3740,7 @@ define([
isValidHtml: isValidHtml,
isDomElement: isDomElement,
arrayToObject: arrayToObject,
filterObjByKeys: filterObjByKeys,
getObjVal: getObjVal,
redirect: redirect,
logout: logout,
Expand Down
4 changes: 2 additions & 2 deletions public/css/v2.0.0/pathfinder.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/css/v2.0.0/pathfinder.css.map

Large diffs are not rendered by default.

55 changes: 29 additions & 26 deletions public/js/v2.0.0/app/map/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,44 +75,47 @@ define([

/**
* get all available map Types
* optional they can be filtered by current access level of a user
* @param {bool} filterByUser
* optional they can be filtered by current access level of current character
* @param {bool} filterByCharacter
* @param {string} filterRight
* @returns {Array}
*/
let getMapTypes = (filterByUser) => {
let getMapTypes = (filterByCharacter, filterRight) => {
let mapTypes = Object.assign({}, Init.mapTypes);

if(filterByUser === true){
if(filterByCharacter === true){
let authorizedMapTypes = [];
let checkMapTypes = ['private', 'corporation', 'alliance'];

for(let i = 0; i < checkMapTypes.length; i++){
let objectId = Util.getCurrentUserInfo(checkMapTypes[i] + 'Id');
if(objectId > 0){
// check if User could add new map with a mapType
let currentObjectMapData = Util.filterCurrentMapData('config.type.id', Util.getObjVal(mapTypes, checkMapTypes[i] + '.id'));
let maxCountObject = Util.getObjVal(mapTypes, checkMapTypes[i] + '.defaultConfig.max_count');
let checkMapTypes = [
{type: 'private', hasRight: false, selector: 'id'},
{type: 'corporation', hasRight: true, selector: 'corporation.id'},
{type: 'alliance', hasRight: true, selector: 'alliance.id'}
];

checkMapTypes.forEach(data => {
// check if current character is e.g. in alliance
if(Util.getCurrentCharacterData(data.selector)){
// check if User could add new map with a mapType -> check map limit
let currentObjectMapData = Util.filterCurrentMapData('config.type.id', Util.getObjVal(mapTypes, data.selector));
let maxCountObject = Util.getObjVal(mapTypes, `${data.type}.defaultConfig.max_count`);
if(currentObjectMapData.length < maxCountObject){
authorizedMapTypes.push(checkMapTypes[i]);
// check if character has the "right" for creating a map with this type
if((data.hasRight && filterRight) ? Util.hasRight(filterRight, data.type) : true){
authorizedMapTypes.push(data.type);
}
}
}
}
});

for(let mapType in mapTypes){
if(authorizedMapTypes.indexOf(mapType) < 0){
delete( mapTypes[mapType] );
}
}
mapTypes = Util.filterObjByKeys(mapTypes, authorizedMapTypes);
}

// convert to array
let mapTypesFlat = [];
for(let mapType in mapTypes){
mapTypes[mapType].name = mapType;
mapTypesFlat.push(mapTypes[mapType]);
}
// add "name" to mapType data
Object.entries(mapTypes).forEach(([mapType, data]) => {
data.name = mapType;
});

return mapTypesFlat;
// obj to array
return Object.keys(mapTypes).map(mapType => mapTypes[mapType]);
};

/**
Expand Down
9 changes: 1 addition & 8 deletions public/js/v2.0.0/app/ui/dialog/map_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,7 @@ define([

// map type
let mapTypes = MapUtil.getMapTypes();
let mapType = null;

for(let i = 0; i < mapTypes.length; i++){
if(mapTypes[i].id === mapData.config.type.id){
mapType = mapTypes[i];
break;
}
}
let mapType = mapTypes.find(data => data.id === mapData.config.type.id);

// check max map limits (e.g. max systems per map) ------------------------------------------------------------
let percentageSystems = (100 / mapType.defaultConfig.max_systems) * countSystems;
Expand Down
23 changes: 15 additions & 8 deletions public/js/v2.0.0/app/ui/dialog/map_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,17 @@ define([
let hasRightMapImport = MapUtil ? MapUtil.checkRight('map_import', mapData.config) : true;
let hasRightMapShare = MapUtil ? MapUtil.checkRight('map_share', mapData.config) : true;

// available map "types" for a new or existing map
let mapTypes = MapUtil.getMapTypes(true);
// available map "type" options data
// -> for "new" map tab
let mapTypesCreate = MapUtil.getMapTypes(true, 'map_create');
// -> for "edit" map tab
let mapTypesUpdate = MapUtil.getMapTypes(true, 'map_update');

// render main dialog ---------------------------------------------------------------------------------
let mapDialogData = {
id: config.newMapDialogId,
mapData: mapData,
type: mapTypes,
type: mapTypesCreate,

hasRightMapUpdate,
hasRightMapExport,
Expand Down Expand Up @@ -273,7 +276,6 @@ define([
let mapFormData = {
select2Class: Util.config.select2Class,
scope: MapUtil.getMapScopes(),
type: mapTypes,
icon: MapUtil.getMapIcons(),
formErrorContainerClass: Util.config.formErrorContainerClass,
formWarningContainerClass: Util.config.formWarningContainerClass,
Expand All @@ -282,6 +284,7 @@ define([

// render "new map" tab content -----------------------------------------------------------------------
let mapFormDataNew = Object.assign({}, mapFormData, {
type: mapTypesCreate,
hasRightMapForm: hasRightMapCreate,
nameInputId: config.newNameInputId,
iconSelectId: config.newIconSelectId,
Expand All @@ -300,6 +303,7 @@ define([
// render "edit map" tab content ----------------------------------------------------------------------
if(!hideEditTab){
let mapFormDataEdit = Object.assign({}, mapFormData, {
type: mapTypesUpdate,
hasRightMapForm: hasRightMapUpdate,
nameInputId: config.editNameInputId,
iconSelectId: config.editIconSelectId,
Expand Down Expand Up @@ -361,7 +365,10 @@ define([
formData[key] = (formData[key].length ? '#' : '') + formData[key];
});

MapOverlayUtil.getMapOverlay($(mapData.map.getContainer()), 'timer').startMapUpdateCounter();
if(mapData){
// no map data found -> probably new user
MapOverlayUtil.getMapOverlay(mapData.map.getContainer(), 'timer').startMapUpdateCounter();
}

let method = formData.id ? 'PATCH' : 'PUT';

Expand Down Expand Up @@ -427,8 +434,8 @@ define([

form.showFormMessage([{type: 'info', text: 'Creating new maps or change settings may take a few seconds'}]);

if(mapData === false){
// no map data found (probably new user
if(!mapData){
// no map data found -> probably new user
form.showFormMessage([{type: 'warning', text: 'No maps found. Create a new map before you can start'}]);
}

Expand All @@ -438,7 +445,7 @@ define([
// tab exists

// export map data ----------------------------------------------------------------------------
downloadTabElement.find('#' + config.buttonExportId).on('click', { mapData: mapData }, function(e){
downloadTabElement.find('#' + config.buttonExportId).on('click', {mapData}, function(e){

let exportForm = $('#' + config.dialogMapExportFormId);
let validExportForm = exportForm.isValidForm();
Expand Down
Loading

0 comments on commit 3d42a8e

Please sign in to comment.