Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More info #41

Merged
merged 10 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: Docker Image CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:

Expand All @@ -21,4 +23,9 @@ jobs:
- name: Build the Docker image
run: |
docker build . --file Dockerfile --tag ghcr.io/openplaceguide/opg-pages:latest
docker push ghcr.io/openplaceguide/opg-pages:latest
if [ "$CURRENT_BRANCH" = "main" ]; then
echo "On the 'main' branch. Pushing the Docker image..."
docker push ghcr.io/openplaceguide/opg-pages:latest
else
echo "Not on the 'main' branch. Skipping Docker push."
fi
4 changes: 2 additions & 2 deletions .github/workflows/laravel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ jobs:
git clone https://github.com/OpenPlaceGuide/data/ opg-data-ethiopia
- name: Build
run: npm run build
- name: Download TagInfo
run: curl https://taginfo.openstreetmap.org/download/taginfo-wiki.db.bz2 | bunzip2 > database/taginfo-wiki.db
- name: Execute tests (Unit and Feature tests) via PHPUnit
env:
DB_CONNECTION: sqlite
DB_DATABASE: database/database.sqlite
APP_TECHNICAL_CONTACT: [email protected]?subject=CI-Runner
run: vendor/bin/phpunit
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ yarn-error.log
/.idea
/.vscode
cache/
/database/*.db
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ EOF

EXPOSE 8000

RUN apk add --no-cache zip php-8.1 php-8.1-intl php-8.1-gd php-8.1-cgi php-8.1-phar php-8.1-iconv php-8.1-mbstring php-8.1-openssl php-8.1-dom php-8.1-curl php-8.1-simplexml
RUN apk add --no-cache zip php-8.1 php-8.1-intl php-8.1-gd php-8.1-cgi php-8.1-phar php-8.1-iconv php-8.1-mbstring php-8.1-openssl php-8.1-dom php-8.1-curl php-8.1-simplexml curl

#ENV LOG_CHANNEL=stderr

Expand All @@ -70,6 +70,7 @@ COPY . /var/www/html
RUN mkdir -p storage/framework/cache/data storage/framework/sessions storage/framework/views
RUN chown -R www-data:www-data /var/www/html/storage || true
RUN chown -R www-data:www-data /var/www/html/bootstrap/cache || true
RUN curl https://taginfo.openstreetmap.org/download/taginfo-wiki.db.bz2 | bunzip2 > database/taginfo-wiki.db

COPY --from=composer /var/www/html/vendor /var/www/html/vendor
COPY --from=composer /usr/bin/composer /usr/bin/composer
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ cd ../osmapp && docker build --build-arg PROXY_BACKEND=http://opg-pages/ . -t os

* build this app
```bash
docker build . -t opg-pages
docker build . --progress=plain -t opg-pages
```

Start
Expand Down
10 changes: 10 additions & 0 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,14 @@ public function register(): void
//
});
}

function render($request, Throwable $exception)
{
if ($this->isHttpException($exception)) {
if ($exception->getStatusCode() == 404) {
return response()->view('errors.404', [], 404);
}
}
return parent::render($request, $exception);
}
}
2 changes: 1 addition & 1 deletion app/Models/OsmInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class OsmInfo
{
public function __construct(public readonly OsmId $idInfo, public readonly float $lat, public readonly float $lon, public readonly stdClass $tags, public readonly ?Area $area)
public function __construct(public readonly OsmId $idInfo, public readonly float $lat, public readonly float $lon, public readonly stdClass $tags, public readonly ?Area $area = null)
{
}

Expand Down
3 changes: 3 additions & 0 deletions app/Services/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public static function getInstance(): Repository

public function getPlaceInfo($slug): Place
{
if (!file_exists($this->getPlaceFileName($slug))) {
abort(404);
}
$yamlSource = file_get_contents($this->getPlaceFileName($slug));

$parsed = Yaml::parse($yamlSource);
Expand Down
60 changes: 60 additions & 0 deletions app/Services/TagRenderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace App\Services;
use App\Models\OsmInfo;
use DateTimeZone;
use Illuminate\Support\Facades\DB;
use Ujamii\OsmOpeningHours\OsmStringToOpeningHoursConverter;

class TagRenderer
{
public function __construct(private readonly OsmInfo $osmInfo)
{
}


// phone: as is
// atm=yes taginfo
// name: print
// name:am print, too ?
// opening_hours: opening_hours.js https://github.com/opening-hours/opening_hours.js/
// operator: print
// website: print

public function getTagTexts(): array
{
$tags = $this->osmInfo->tags;
$lines = [];
foreach ($tags as $key=>$value) {
if ($key === 'opening_hours') {
$key = 'Opening Times';
$lines[] = $key . ": " . $value;
continue;
}

$tagInfo = $this->queryTagInfo($key, $value);
if ($tagInfo !== null) {
$lines[] = $tagInfo;
}
}

return $lines;
}

private function queryTagInfo($key, $value)
{
$row = DB::connection('sqlite_taginfo')
->table('wikipages')
->select('description')
->where('lang', 'en')
->where('key', $key)
->where('value', $value)
->get()->first();

if ($row === null) {
return null;
}

return $row->description;
}
}
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
"license": "MIT",
"require": {
"php": "^8.1",
"ext-dom": "*",
"ext-simplexml": "*",
"andreiio/blade-remix-icon": "^2.2",
"bame/staticmap": "dev-master",
"blade-ui-kit/blade-icons": "^1.5",
"guzzlehttp/guzzle": "^7.2",
"laravel/framework": "^10.0",
"laravel/sanctum": "^3.2",
"laravel/tinker": "^2.8",
"symfony/yaml": "^6.2",
"ext-simplexml": "*",
"ext-dom": "*"
"symfony/yaml": "^6.2"
},
"require-dev": {
"fakerphp/faker": "^1.9.1",
Expand Down
6 changes: 3 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@
*/

'connections' => [

'sqlite' => [
'sqlite_taginfo' => [
'driver' => 'sqlite',
'url' => env('DATABASE_URL'),
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'url' => '',
'database' => database_path('taginfo-wiki.db'),
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
'foreign_key_constraints' => true,
],

'mysql' => [
Expand Down
18 changes: 18 additions & 0 deletions resources/views/errors/404.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@extends('layouts.index')

@section('pageTitle')
Page not found on {{ config('app.name') }}
@endsection

@section('content')
<header>
<h1 class="text-3xl px-5 mt-10 md:flex text-center items-center max-w-5xl mx-auto">
Sorry - Page not found
</h1>
</header>
<section>
<div class="px-5 py-2 max-w-5xl mx-auto">
<a href="{{ config('app.url') }}">go to the homepage now</a>
</div>
</section>
@stop
2 changes: 1 addition & 1 deletion resources/views/layouts/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@vite('resources/js/app.js')
</head>
<body
class="relative text-gray-700 bg-gradient-to-br from-white to-{{ $color }}-100 border-t-2 border-{{ $color }}-900 min-h-screen">
class="relative text-gray-700 bg-gradient-to-br from-white to-{{ $color ?? 'black' }}-100 border-t-2 border-{{ $color ?? 'black' }}-900 min-h-screen">
<div class="pb-10">
@yield('content')
</div>
Expand Down
21 changes: 16 additions & 5 deletions resources/views/page/place.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@if($logoUrl)
<img class="h-20 mr-5 mb-4 inline aspect-square" src="{{ asset($logoUrl) }} ">
@else
{{-- @svg("icon-${icon}_11","h-20 w-20 mr-5 mb-4 inline aspect-square fill-current text-$color-900" )--}}
{{-- @svg("icon-${icon}_11","h-20 w-20 mr-5 mb-4 inline aspect-square fill-current text-$color-900" )--}}
@endif

<div class="hyphens-auto">
Expand All @@ -43,7 +43,9 @@
<x-github-button :href="$newPlaceUrl">Create URL / Add content</x-github-button>
@endif
</p>
Welcome to the <a href="{{ url('/') }}">{{ config('app.name') }}</a> page of <strong>{{ Fallback::field($main->tags, 'name') }}</strong>, a <strong>{{ Fallback::resolve($type->name) }}</strong></strong>.
Welcome to the <a href="{{ url('/') }}">{{ config('app.name') }}</a> page of
<strong>{{ Fallback::field($main->tags, 'name') }}</strong>, a
<strong>{{ Fallback::resolve($type->name) }}</strong></strong>.

<h2>Media</h2>

Expand All @@ -67,12 +69,21 @@
<h3>{{ Fallback::field($branch->tags, 'name') }}</h3>
<strong>{{ ucfirst(Fallback::resolve($type->name)) }}</strong>
@if($branch->area !== null)
in <strong><a href="<?php echo $branch->area->getUrl() ?>">{{ $branch->area->getFullName() }}</a></strong>
in <strong><a
href="<?php echo $branch->area->getUrl() ?>">{{ $branch->area->getFullName() }}</a></strong>
@endif

<ul class="space-y-2 list-disc pl-2">
@foreach((new \App\Services\TagRenderer($branch))->getTagTexts() as $line)
<li>{{ $line }}</li>
@endforeach
</ul>

@php($mainUrl = $branch->idInfo->getOsmUrl(url('/')))
<a href="{{ $mainUrl }}" target="_blank">
<img class="shadow-lg"
src="{{ route('tripleZoomMap', ['lat' => $branch->lat, 'lon' => $branch->lon, 'slug' => \App\Services\Language::slug(Fallback::field($branch->tags, 'name', language: 'en')), 'text' => Fallback::field($branch->tags, 'name')]) }}">
<img class="shadow-lg" width="699" height="300"
alt="Map showing the address of {{ Fallback::field($branch->tags, 'name') }} in three different zoom levels."
src="{{ route('tripleZoomMap', ['lat' => $branch->lat, 'lon' => $branch->lon, 'slug' => \App\Services\Language::slug(Fallback::field($branch->tags, 'name', language: 'en')), 'text' => Fallback::field($branch->tags, 'name')]) }}">
</a>
<ul class="flex">
<li><a href="{{ $branch->idInfo->getOsmUrl() }}" target="_blank">OSM Info</a></li>
Expand Down
2 changes: 1 addition & 1 deletion tests/Services/LanguageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static function transliterateData()
{
return [
'German' => ['Maeuse', 'Mäuse'],
'Amharic' => ['emarinya', 'አማርኛ'],
'Amharic' => ['amarna', 'አማርኛ'],
];
}
}
41 changes: 41 additions & 0 deletions tests/Services/TagRendererTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Tests\Services;

use App\Models\Area;
use App\Models\OsmId;
use App\Models\OsmInfo;
use App\Services\Repository;
use App\Services\TagRenderer;
use Tests\TestCase;

class TagRendererTest extends TestCase
{
public function testRender()
{
$zemen = $this->createOsmInfo();
$texts = (new TagRenderer($zemen))->getTagTexts();
self::assertNotEmpty($texts);
self::assertStringContainsString('Mo-Sa 08:00-18:00', implode("\n", $texts));
self::assertStringContainsString('A cash point/ATM (Automated Teller Machine) is available at this location.', implode("\n", $texts));

}

private function createOsmInfo()
{
return new OsmInfo(
new OsmId('node', 262991780),
8.9944064,
38.7902098,
(object)[
'addr:city' => 'Addis Ababa',
'addr:street' => 'Cameroon Street',
'amenity' => 'bank',
'atm' => 'yes',
'name' => 'Zemen Bank Bole MedhaneAlem Branch',
'name:am' => 'ዘመን ባንክ ቦሌ መድኃኔዓለም ቅ/ፍ',
'opening_hours' => 'Mo-Sa 08:00-18:00',
],
);
}
}
Loading