feature/MAPG-231-make-it-possible-to-create-unlisted-maps #52
@ -0,0 +1,2 @@
|
||||
ALTER TABLE `maps`
|
||||
ADD `unlisted` TINYINT(1) NOT NULL DEFAULT 0;
|
@ -13,6 +13,10 @@ div.mapItem.new {
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
div.mapItem.unlisted {
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
div.mapItem>div.title {
|
||||
background-color: #28a745;
|
||||
color: white;
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
MapEditor.metadata.name = form.elements.name.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]';
|
||||
|
||||
@ -254,6 +255,9 @@
|
||||
if (MapEditor.metadata.description !== null) {
|
||||
data.append('description', MapEditor.metadata.description);
|
||||
}
|
||||
if (MapEditor.metadata.unlisted !== null) {
|
||||
data.append('unlisted', MapEditor.metadata.unlisted);
|
||||
}
|
||||
|
||||
for (var placeId in MapEditor.added) {
|
||||
if (!MapEditor.added.hasOwnProperty(placeId)) {
|
||||
|
@ -81,6 +81,7 @@ class MapAdminController implements ISecured
|
||||
'mapId' => $mapId,
|
||||
'mapName' => $map->getName(),
|
||||
'mapDescription' => str_replace('<br>', "\n", $map->getDescription()),
|
||||
'mapUnlisted' => $map->getUnlisted(),
|
||||
'bounds' => $map->getBounds()->toArray(),
|
||||
'places' => &$places
|
||||
]);
|
||||
@ -175,6 +176,9 @@ class MapAdminController implements ISecured
|
||||
if (isset($_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);
|
||||
|
||||
|
@ -30,12 +30,19 @@ class MapsController
|
||||
['maps', 'bound_north_lat'],
|
||||
['maps', 'bound_east_lng'],
|
||||
['maps', 'area'],
|
||||
['maps', 'unlisted'],
|
||||
new RawExpression('COUNT(places.id) AS num_places')
|
||||
]);
|
||||
$select->leftJoin('places', ['places', 'map_id'], '=', ['maps', 'id']);
|
||||
$select->groupBy(['maps', 'id']);
|
||||
$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();
|
||||
|
||||
$maps = [];
|
||||
@ -45,11 +52,10 @@ class MapsController
|
||||
$maps[] = $map;
|
||||
}
|
||||
|
||||
$user = $this->request->user();
|
||||
return new HtmlContent('maps', [
|
||||
'maps' => $maps,
|
||||
'isLoggedIn' => $user !== null,
|
||||
'isAdmin' => $user !== null && $user->hasPermission(IUser::PERMISSION_ADMIN)
|
||||
'isAdmin' => $isAdmin
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ class Map extends Model
|
||||
{
|
||||
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 = '';
|
||||
|
||||
@ -16,6 +16,8 @@ class Map extends Model
|
||||
|
||||
private float $area = 0.0;
|
||||
|
||||
private bool $unlisted = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->bounds = Bounds::createDirectly(-90.0, -180.0, 90.0, 180.0);
|
||||
@ -61,6 +63,11 @@ class Map extends Model
|
||||
$this->area = $area;
|
||||
}
|
||||
|
||||
public function setUnlisted(bool $unlisted): void
|
||||
{
|
||||
$this->unlisted = $unlisted;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
@ -100,4 +107,9 @@ class Map extends Model
|
||||
{
|
||||
return $this->area;
|
||||
}
|
||||
|
||||
public function getUnlisted(): bool
|
||||
{
|
||||
return $this->unlisted;
|
||||
}
|
||||
}
|
||||
|
@ -54,6 +54,9 @@
|
||||
<form id="metadataForm" class="marginTop" data-no-submit="true">
|
||||
<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>
|
||||
<div class="marginTop">
|
||||
<input type="checkbox" id="unlisted" name="unlisted" <?= $mapUnlisted ? 'checked' : '' ?>><label for="unlisted">Unlisted</label>
|
||||
</div>
|
||||
<div class="right">
|
||||
<button class="marginTop marginRight" type="submit">Apply</button><!--
|
||||
--><button id="closeMetadataButton" class="gray marginTop" type="button">Close</button>
|
||||
|
@ -86,7 +86,7 @@ TODO: condition!
|
||||
@section(main)
|
||||
<div id="mapContainer">
|
||||
<?php foreach ($maps as $map): ?>
|
||||
<div class="mapItem">
|
||||
<div class="mapItem <?= $map['unlisted'] ? 'unlisted' : '' ?>">
|
||||
<div class="title">
|
||||
<p class="title"><?= $map['name'] ?></p>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user