Custom Maps configurable new map defaults (#16212)

This commit is contained in:
Tony Murray
2024-07-17 16:05:44 -05:00
committed by GitHub
parent 1cceafb887
commit cf7b025fb1
9 changed files with 409 additions and 24 deletions

View File

@@ -48,9 +48,9 @@ class CustomMapController extends Controller
'maps' => CustomMap::orderBy('name')->get(['custom_map_id', 'name', 'menu_group'])->groupBy('menu_group')->sortKeys(),
'name' => 'New Map',
'menu_group' => null,
'node_align' => 10,
'edge_separation' => 10,
'reverse_arrows' => 0,
'node_align' => Config::get('custom_map.node_align', 10),
'edge_separation' => Config::get('custom_map.edge_seperation', 10),
'reverse_arrows' => Config::get('custom_map.reverse_arrows', false),
'legend' => [
'x' => -1,
'y' => -1,
@@ -59,10 +59,11 @@ class CustomMapController extends Controller
'hide_overspeed' => 0,
'font_size' => 14,
],
'background_type' => null,
'background_type' => Config::get('custom_map.background_type', 'none'),
'background_data' => Config::get('custom_map.background_data'),
'map_conf' => [
'height' => '800px',
'width' => '1800px',
'width' => Config::get('custom_map.width', '1800px'),
'height' => Config::get('custom_map.height', '800px'),
'interaction' => [
'dragNodes' => true,
'dragView' => false,
@@ -154,7 +155,57 @@ class CustomMapController extends Controller
public function store(CustomMapSettingsRequest $request): JsonResponse
{
return $this->update($request, new CustomMap);
// create a new map with default values
$map = new CustomMap;
$map->options = [
'interaction' => [
'dragNodes' => false,
'dragView' => false,
'zoomView' => false,
],
'manipulation' => [
'enabled' => false,
],
'physics' => [
'enabled' => false,
],
];
$map->newnodeconfig = [
'borderWidth' => 1,
'color' => [
'border' => Config::get('custom_map.node_border', '#2B7CE9'),
'background' => Config::get('custom_map.node_background', '#D2E5FF'),
],
'font' => [
'color' => Config::get('custom_map.node_font_color', '#343434'),
'size' => Config::get('custom_map.node_font_size', 14),
'face' => Config::get('custom_map.node_font_face', 'arial'),
],
'icon' => [],
'label' => true,
'shape' => Config::get('custom_map.node_type', 'box'),
'size' => Config::get('custom_map.node_size', 25),
];
$map->newedgeconfig = [
'arrows' => [
'to' => [
'enabled' => true,
],
],
'smooth' => [
'type' => 'dynamic',
],
'font' => [
'color' => Config::get('custom_map.edge_font_color', '#343434'),
'size' => Config::get('custom_map.edge_font_size', 12),
'face' => Config::get('custom_map.edge_font_face', 'arial'),
],
'label' => true,
];
$map->background_type = Config::get('custom_map.background_type', 'none');
$map->background_data = Config::get('custom_map.background_data');
return $this->update($request, $map);
}
public function update(CustomMapSettingsRequest $request, CustomMap $map): JsonResponse

View File

@@ -59,13 +59,6 @@ class CustomMap extends BaseModel
'background_data',
];
// default values for attributes
protected $attributes = [
'options' => '{"interaction":{"dragNodes":false,"dragView":false,"zoomView":false},"manipulation":{"enabled":false},"physics":{"enabled":false}}',
'newnodeconfig' => '{"borderWidth":1,"color":{"border":"#2B7CE9","background":"#D2E5FF"},"font":{"color":"#343434","size":14,"face":"arial"},"icon":[],"label":true,"shape":"box","size":25}',
'newedgeconfig' => '{"arrows":{"to":{"enabled":true}},"smooth":{"type":"dynamic"},"font":{"color":"#343434","size":12,"face":"arial"},"label":true}',
];
/**
* Get background data intended to be passed to javascript to configure the background
*/