- New map right "create map" added, closed #927

This commit is contained in:
Mark Friedrich
2020-03-17 20:24:08 +01:00
parent f7e7082b0a
commit 3d42a8e502
15 changed files with 141 additions and 88 deletions

View File

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

View File

@@ -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'
]
];

View File

@@ -8,6 +8,8 @@ session_name('pathfinder_session');
$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();

View File

@@ -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'];
let checkMapTypes = [
{type: 'private', hasRight: false, selector: 'id'},
{type: 'corporation', hasRight: true, selector: 'corporation.id'},
{type: 'alliance', hasRight: true, selector: 'alliance.id'}
];
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');
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]);
};
/**

View File

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

View File

@@ -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,
@@ -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,
@@ -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,
@@ -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,
@@ -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';
@@ -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'}]);
}
@@ -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();

View File

@@ -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
@@ -3723,6 +3740,7 @@ define([
isValidHtml: isValidHtml,
isDomElement: isDomElement,
arrayToObject: arrayToObject,
filterObjByKeys: filterObjByKeys,
getObjVal: getObjVal,
redirect: redirect,
logout: logout,

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -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'];
let checkMapTypes = [
{type: 'private', hasRight: false, selector: 'id'},
{type: 'corporation', hasRight: true, selector: 'corporation.id'},
{type: 'alliance', hasRight: true, selector: 'alliance.id'}
];
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');
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]);
};
/**

View File

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

View File

@@ -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,
@@ -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,
@@ -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,
@@ -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,
@@ -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';
@@ -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'}]);
}
@@ -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();

View File

@@ -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
@@ -3723,6 +3740,7 @@ define([
isValidHtml: isValidHtml,
isDomElement: isDomElement,
arrayToObject: arrayToObject,
filterObjByKeys: filterObjByKeys,
getObjVal: getObjVal,
redirect: redirect,
logout: logout,

View File

@@ -58,7 +58,8 @@
border: none;
//border-radius: $border-radius-large;
@include box-shadow(0 3px 9px rgba(0,0,0,.5));
background-clip: padding-box;
//background-clip: padding-box;
background-clip: initial;
// Remove focus outline from opened modal
outline: none;
}

View File

@@ -709,8 +709,9 @@
position: absolute;
right: 0;
top: 0;
margin: 4px 14px 0 0;
border-radius: 30%;
margin: 5px 14px 0 0;
border-radius: 5px;
width: 28px;
}
}