feature/MAPG-231-make-it-possible-to-create-unlisted-maps #52

Merged
bence merged 2 commits from feature/MAPG-231-make-it-possible-to-create-unlisted-maps into develop 2022-05-26 14:34:48 +02:00
8 changed files with 39 additions and 4 deletions
Showing only changes of commit d02aa4abe0 - Show all commits

View File

@ -0,0 +1,2 @@
ALTER TABLE `maps`
ADD `unlisted` TINYINT(1) NOT NULL DEFAULT 0;

View File

@ -13,6 +13,10 @@ div.mapItem.new {
align-items: center; align-items: center;
} }
div.mapItem.unlisted {
opacity: 0.6;
}
div.mapItem>div.title { div.mapItem>div.title {
background-color: #28a745; background-color: #28a745;
color: white; color: white;

View File

@ -18,6 +18,7 @@
MapEditor.metadata.name = form.elements.name.value; MapEditor.metadata.name = form.elements.name.value;
MapEditor.metadata.description = form.elements.description.value; MapEditor.metadata.description = form.elements.description.value;
MapEditor.metadata.unlisted = form.elements.unlisted.checked;
document.getElementById('mapName').innerHTML = form.elements.name.value ? form.elements.name.value : '[unnamed map]'; document.getElementById('mapName').innerHTML = form.elements.name.value ? form.elements.name.value : '[unnamed map]';
@ -254,6 +255,9 @@
if (MapEditor.metadata.description !== null) { if (MapEditor.metadata.description !== null) {
data.append('description', MapEditor.metadata.description); data.append('description', MapEditor.metadata.description);
} }
if (MapEditor.metadata.unlisted !== null) {
data.append('unlisted', MapEditor.metadata.unlisted);
}
for (var placeId in MapEditor.added) { for (var placeId in MapEditor.added) {
if (!MapEditor.added.hasOwnProperty(placeId)) { if (!MapEditor.added.hasOwnProperty(placeId)) {

View File

@ -81,6 +81,7 @@ class MapAdminController implements ISecured
'mapId' => $mapId, 'mapId' => $mapId,
'mapName' => $map->getName(), 'mapName' => $map->getName(),
'mapDescription' => str_replace('<br>', "\n", $map->getDescription()), 'mapDescription' => str_replace('<br>', "\n", $map->getDescription()),
'mapUnlisted' => $map->getUnlisted(),
'bounds' => $map->getBounds()->toArray(), 'bounds' => $map->getBounds()->toArray(),
'places' => &$places 'places' => &$places
]); ]);
@ -175,6 +176,9 @@ class MapAdminController implements ISecured
if (isset($_POST['description'])) { if (isset($_POST['description'])) {
$map->setDescription(str_replace(["\n", "\r\n"], '<br>', $_POST['description'])); $map->setDescription(str_replace(["\n", "\r\n"], '<br>', $_POST['description']));
} }
if (isset($_POST['unlisted'])) {
$map->setUnlisted((bool)$_POST['unlisted']);
}
$this->pdm->saveToDb($map); $this->pdm->saveToDb($map);

View File

@ -30,12 +30,19 @@ class MapsController
['maps', 'bound_north_lat'], ['maps', 'bound_north_lat'],
['maps', 'bound_east_lng'], ['maps', 'bound_east_lng'],
['maps', 'area'], ['maps', 'area'],
['maps', 'unlisted'],
new RawExpression('COUNT(places.id) AS num_places') new RawExpression('COUNT(places.id) AS num_places')
]); ]);
$select->leftJoin('places', ['places', 'map_id'], '=', ['maps', 'id']); $select->leftJoin('places', ['places', 'map_id'], '=', ['maps', 'id']);
$select->groupBy(['maps', 'id']); $select->groupBy(['maps', 'id']);
$select->orderBy('name'); $select->orderBy('name');
$user = $this->request->user();
$isAdmin = $user !== null && $user->hasPermission(IUser::PERMISSION_ADMIN);
if (!$isAdmin) {
$select->where(['maps', 'unlisted'], '=', false);
}
$result = $select->execute(); $result = $select->execute();
$maps = []; $maps = [];
@ -45,11 +52,10 @@ class MapsController
$maps[] = $map; $maps[] = $map;
} }
$user = $this->request->user();
return new HtmlContent('maps', [ return new HtmlContent('maps', [
'maps' => $maps, 'maps' => $maps,
'isLoggedIn' => $user !== null, 'isLoggedIn' => $user !== null,
'isAdmin' => $user !== null && $user->hasPermission(IUser::PERMISSION_ADMIN) 'isAdmin' => $isAdmin
]); ]);
} }

View File

@ -6,7 +6,7 @@ class Map extends Model
{ {
protected static string $table = 'maps'; protected static string $table = 'maps';
protected static array $fields = ['name', 'description', 'bound_south_lat', 'bound_west_lng', 'bound_north_lat', 'bound_east_lng', 'area']; protected static array $fields = ['name', 'description', 'bound_south_lat', 'bound_west_lng', 'bound_north_lat', 'bound_east_lng', 'area', 'unlisted'];
private string $name = ''; private string $name = '';
@ -16,6 +16,8 @@ class Map extends Model
private float $area = 0.0; private float $area = 0.0;
private bool $unlisted = false;
public function __construct() public function __construct()
{ {
$this->bounds = Bounds::createDirectly(-90.0, -180.0, 90.0, 180.0); $this->bounds = Bounds::createDirectly(-90.0, -180.0, 90.0, 180.0);
@ -61,6 +63,11 @@ class Map extends Model
$this->area = $area; $this->area = $area;
} }
public function setUnlisted(bool $unlisted): void
{
$this->unlisted = $unlisted;
}
public function getName(): string public function getName(): string
{ {
return $this->name; return $this->name;
@ -100,4 +107,9 @@ class Map extends Model
{ {
return $this->area; return $this->area;
} }
public function getUnlisted(): bool
{
return $this->unlisted;
}
} }

View File

@ -54,6 +54,9 @@
<form id="metadataForm" class="marginTop" data-no-submit="true"> <form id="metadataForm" class="marginTop" data-no-submit="true">
<input class="fullWidth" type="text" name="name" value="<?= $mapName ?>" placeholder="Name of the map"> <input class="fullWidth" type="text" name="name" value="<?= $mapName ?>" placeholder="Name of the map">
<textarea class="fullWidth marginTop" name="description" rows="4" placeholder="Description of the map"><?= $mapDescription ?></textarea> <textarea class="fullWidth marginTop" name="description" rows="4" placeholder="Description of the map"><?= $mapDescription ?></textarea>
<div class="marginTop">
<input type="checkbox" id="unlisted" name="unlisted" <?= $mapUnlisted ? 'checked' : '' ?>><label for="unlisted">Unlisted</label>
</div>
<div class="right"> <div class="right">
<button class="marginTop marginRight" type="submit">Apply</button><!-- <button class="marginTop marginRight" type="submit">Apply</button><!--
--><button id="closeMetadataButton" class="gray marginTop" type="button">Close</button> --><button id="closeMetadataButton" class="gray marginTop" type="button">Close</button>

View File

@ -86,7 +86,7 @@ TODO: condition!
@section(main) @section(main)
<div id="mapContainer"> <div id="mapContainer">
<?php foreach ($maps as $map): ?> <?php foreach ($maps as $map): ?>
<div class="mapItem"> <div class="mapItem <?= $map['unlisted'] ? 'unlisted' : '' ?>">
<div class="title"> <div class="title">
<p class="title"><?= $map['name'] ?></p> <p class="title"><?= $map['name'] ?></p>
</div> </div>