From 5a1c384c17d8f6cca37c4039a6ceae44623e855f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Wed, 10 Jun 2020 23:11:55 +0200 Subject: [PATCH 1/8] MAPG-119 fix maps query --- src/Controller/MapsController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Controller/MapsController.php b/src/Controller/MapsController.php index d56dd59..95b37a0 100644 --- a/src/Controller/MapsController.php +++ b/src/Controller/MapsController.php @@ -32,6 +32,7 @@ class MapsController new RawExpression('COUNT(places.id) AS num_places') ]); $select->leftJoin('places', ['places', 'map_id'], '=', ['maps', 'id']); + $select->groupBy(['maps', 'id']); $select->orderBy('name'); $result = $select->execute(); From 5237c3f454294c1db7df3f0a79f980db527edf56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Wed, 10 Jun 2020 23:12:30 +0200 Subject: [PATCH 2/8] MAPG-119 prevent endless loop for place selection --- src/Repository/PlaceRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Repository/PlaceRepository.php b/src/Repository/PlaceRepository.php index 831d221..2a6b325 100644 --- a/src/Repository/PlaceRepository.php +++ b/src/Repository/PlaceRepository.php @@ -34,7 +34,7 @@ class PlaceRepository $panoId = $this->requestPanoId($place); if ($panoId === null) { - $placesWithoutPano[] = $place['id']; + $placesWithoutPano[] = $exclude[] = $place['id']; } } while ($panoId === null); From 6fc83c94594a5d218e78ba875957b8d9a6ba7a0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Wed, 10 Jun 2020 23:14:19 +0200 Subject: [PATCH 3/8] MAPG-119 handle the case if no mapId is present when editing map --- public/index.php | 2 +- src/Controller/MapAdminController.php | 37 +++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/public/index.php b/public/index.php index 8c3d2bd..7f8b3d1 100644 --- a/public/index.php +++ b/public/index.php @@ -23,7 +23,7 @@ Container::$routeCollection->group('game', function (MapGuesser\Routing\RouteCol $routeCollection->post('guess-json', '{mapId}/guess.json', [MapGuesser\Controller\GameFlowController::class, 'evaluateGuess']); }); Container::$routeCollection->group('admin', function (MapGuesser\Routing\RouteCollection $routeCollection) { - $routeCollection->get('admin.mapEditor', 'mapEditor/{mapId}', [MapGuesser\Controller\MapAdminController::class, 'getMapEditor']); + $routeCollection->get('admin.mapEditor', 'mapEditor/{mapId?}', [MapGuesser\Controller\MapAdminController::class, 'getMapEditor']); $routeCollection->get('admin.place', 'place.json/{placeId}', [MapGuesser\Controller\MapAdminController::class, 'getPlace']); $routeCollection->post('admin.saveMap', 'saveMap/{mapId}/json', [MapGuesser\Controller\MapAdminController::class, 'saveMap']); }); diff --git a/src/Controller/MapAdminController.php b/src/Controller/MapAdminController.php index 2a240d4..76a1592 100644 --- a/src/Controller/MapAdminController.php +++ b/src/Controller/MapAdminController.php @@ -17,6 +17,8 @@ use MapGuesser\Util\Geo\Position; class MapAdminController implements ISecured { + private static string $unnamedMapName = '[unnamed map]'; + private IRequest $request; private MapRepository $mapRepository; @@ -41,9 +43,18 @@ class MapAdminController implements ISecured { $mapId = (int) $this->request->query('mapId'); - $map = $this->mapRepository->getById($mapId); - $bounds = Bounds::createDirectly($map['bound_south_lat'], $map['bound_west_lng'], $map['bound_north_lat'], $map['bound_east_lng']); - $places = $this->getPlaces($mapId); + if ($mapId) { + $map = $this->mapRepository->getById($mapId); + $bounds = Bounds::createDirectly($map['bound_south_lat'], $map['bound_west_lng'], $map['bound_north_lat'], $map['bound_east_lng']); + $places = $this->getPlaces($mapId); + } else { + $map = [ + 'name' => self::$unnamedMapName, + 'description' => '' + ]; + $bounds = Bounds::createDirectly(-90.0, -180.0, 90.0, 180.0); + $places = []; + } $data = ['mapId' => $mapId, 'mapName' => $map['name'], 'mapDescription' => str_replace('
', "\n", $map['description']), 'bounds' => $bounds->toArray(), 'places' => &$places]; return new HtmlContent('admin/map_editor', $data); @@ -63,6 +74,10 @@ class MapAdminController implements ISecured { $mapId = (int) $this->request->query('mapId'); + if (!$mapId) { + $mapId = $this->addNewMap(); + } + if (isset($_POST['added'])) { $addedIds = []; foreach ($_POST['added'] as $placeRaw) { @@ -107,7 +122,7 @@ class MapAdminController implements ISecured ]; if (isset($_POST['name'])) { - $map['name'] = $_POST['name'] ? $_POST['name'] : '[unnamed map]'; + $map['name'] = $_POST['name'] ? $_POST['name'] : self::$unnamedMapName; } if (isset($_POST['description'])) { $map['description'] = str_replace(["\n", "\r\n"], '
', $_POST['description']); @@ -115,7 +130,7 @@ class MapAdminController implements ISecured $this->saveMapData($mapId, $map); - $data = ['added' => $addedIds]; + $data = ['mapId' => $mapId, 'added' => $addedIds]; return new JsonContent($data); } @@ -135,6 +150,18 @@ class MapAdminController implements ISecured return $bounds; } + private function addNewMap(): int + { + $modify = new Modify(\Container::$dbConnection, 'maps'); + $modify->fill([ + 'name' => self::$unnamedMapName, + 'description' => '' + ]); + $modify->save(); + + return $modify->getId(); + } + private function saveMapData(int $mapId, array $map): void { $modify = new Modify(\Container::$dbConnection, 'maps'); From 947ce6b18330fbfbf281275df26c4d52e2c5c0bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Wed, 10 Jun 2020 23:15:02 +0200 Subject: [PATCH 4/8] MAPG-119 view and JS adaptations for new map creation --- public/static/js/map_editor.js | 7 ++++++- views/admin/map_editor.php | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/public/static/js/map_editor.js b/public/static/js/map_editor.js index 494ee00..ef1108c 100644 --- a/public/static/js/map_editor.js +++ b/public/static/js/map_editor.js @@ -291,6 +291,11 @@ MapEditor.replacePlaceIdsToReal(this.response.added); + if (mapId === 0) { + mapId = this.response.mapId; + window.history.replaceState(null, '', '/admin/mapEditor/' + mapId); + } + MapEditor.added = {}; MapEditor.edited = {}; MapEditor.deleted = {}; @@ -370,7 +375,7 @@ ppi: highResData.ppi, tileSize: highResData.tileSize, zoomOffset: highResData.zoomOffset, - minZoom: 0, + minZoom: 2, maxZoom: 20 }).addTo(MapEditor.map); diff --git a/views/admin/map_editor.php b/views/admin/map_editor.php index cb776df..7f65a5f 100644 --- a/views/admin/map_editor.php +++ b/views/admin/map_editor.php @@ -62,9 +62,9 @@ From ec7e806277bc3c8f1118f3b6422254158dcce8f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Wed, 10 Jun 2020 23:17:13 +0200 Subject: [PATCH 5/8] MAPG-119 'add new map' button and some desing improvements on maps page --- public/static/css/mapguesser.css | 20 +++++++++++++++++++- public/static/css/maps.css | 17 ++++++++++++++--- views/maps.php | 22 ++++++++++++++++++---- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/public/static/css/mapguesser.css b/public/static/css/mapguesser.css index 7bedd39..16b5f28 100644 --- a/public/static/css/mapguesser.css +++ b/public/static/css/mapguesser.css @@ -146,6 +146,16 @@ button.fullWidth, a.button.fullWidth { width: 100%; } +button.noLeftRadius, a.button.noLeftRadius { + border-top-left-radius: 0; + border-bottom-left-radius: 0; +} + +button.noRightRadius, a.button.noRightRadius { + border-top-right-radius: 0; + border-bottom-right-radius: 0; +} + button.gray, a.button.gray { background-color: #808080; } @@ -170,6 +180,14 @@ button.yellow:hover, button.yellow:focus, a.button.yellow:hover, a.button.yellow background-color: #c37713; } +button.green, a.button.green { + background-color: #28a745; +} + +button.green:hover, button.green:focus, a.button.green:hover, a.button.green:focus { + background-color: #1b7d31; +} + input, select, textarea { background-color: #f9fafb; border: solid #c8d2e1 1px; @@ -291,7 +309,7 @@ div.box { div.header.small h1 span { display: none; } - button { + button, a.button { padding: 0; width: 100%; } diff --git a/public/static/css/maps.css b/public/static/css/maps.css index 323d772..c239535 100644 --- a/public/static/css/maps.css +++ b/public/static/css/maps.css @@ -4,11 +4,15 @@ div.mapItem { width: 350px; - background-color: #eeeeee; - border-radius: 3px; margin: 10px auto; } +div.mapItem.new { + display: flex; + justify-content: center; + align-items: center; +} + div.mapItem>div.title { background-color: #28a745; color: white; @@ -27,6 +31,7 @@ div.mapItem>img { } div.mapItem>div.inner { + background-color: #eeeeee; padding: 10px 8px; } @@ -43,6 +48,12 @@ div.mapItem>div.inner>div.info>p:nth-child(2) { text-align: right; } +div.mapItem>div.buttonContainer { + display: grid; + grid-auto-columns: 1fr; + grid-auto-flow: column; +} + @media screen and (min-width: 1504px) { #mapContainer { grid-template-columns: auto auto auto auto; @@ -69,6 +80,6 @@ div.mapItem>div.inner>div.info>p:nth-child(2) { @media screen and (max-width: 374px) { div.mapItem { - width: initial; + width: 100%; } } diff --git a/views/maps.php b/views/maps.php index c63ea29..f7a8ba1 100644 --- a/views/maps.php +++ b/views/maps.php @@ -30,14 +30,28 @@

- Play this map - Edit this map +
+ Play this map + Edit + +
+ + Play this map - - + + + +
+ + +
From 805d91c0c0d738d5942e1373b02563562ca55efa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Wed, 10 Jun 2020 23:17:27 +0200 Subject: [PATCH 6/8] MAPG-119 small fixes for game --- src/Controller/GameController.php | 2 -- views/game.php | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Controller/GameController.php b/src/Controller/GameController.php index 84538ce..e2f9146 100644 --- a/src/Controller/GameController.php +++ b/src/Controller/GameController.php @@ -1,7 +1,5 @@ From ff201c2e8e5ee49ab4493d8e15fcf9143825f776 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Wed, 10 Jun 2020 23:51:09 +0200 Subject: [PATCH 7/8] MAPG-119 add more area categories --- src/Controller/MapsController.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Controller/MapsController.php b/src/Controller/MapsController.php index 95b37a0..33da754 100644 --- a/src/Controller/MapsController.php +++ b/src/Controller/MapsController.php @@ -53,10 +53,18 @@ class MapsController private function formatMapAreaForHuman(float $area): array { - if ($area < 100000.0) { + if ($area < 100.0) { $digits = 0; $rounded = round($area, 0); $unit = 'm'; + } elseif ($area < 100000.0) { + $digits = 0; + $rounded = round($area, -2); + $unit = 'm'; + } elseif ($area < 1000000.0) { + $digits = 2; + $rounded = round($area / 1000000.0, 2); + $unit = 'km'; } elseif ($area < 100000000.0) { $digits = 0; $rounded = round($area / 1000000.0, 0); From be8f0a148688fe9e57eca639d0c1cb15a8a2aaff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Wed, 10 Jun 2020 23:58:09 +0200 Subject: [PATCH 8/8] MAPG-119 fix distribution of the ids of the newly created places --- src/Controller/MapAdminController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/MapAdminController.php b/src/Controller/MapAdminController.php index 76a1592..cf3acbc 100644 --- a/src/Controller/MapAdminController.php +++ b/src/Controller/MapAdminController.php @@ -83,7 +83,7 @@ class MapAdminController implements ISecured foreach ($_POST['added'] as $placeRaw) { $placeRaw = json_decode($placeRaw, true); - $addedIds[] = ['tempId' => $placeRaw['id'], $this->placeRepository->addToMap($mapId, [ + $addedIds[] = ['tempId' => $placeRaw['id'], 'id' => $this->placeRepository->addToMap($mapId, [ 'lat' => (float) $placeRaw['lat'], 'lng' => (float) $placeRaw['lng'], 'pano_id_cached_timestamp' => $placeRaw['panoId'] === -1 ? (new DateTime('-1 day'))->format('Y-m-d H:i:s') : null