Skip to content

Commit

Permalink
Merge pull request #8 from OpenPlaceGuide/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
amenk authored Jun 2, 2024
2 parents 767aa83 + 7d8c8bc commit 6089e2d
Show file tree
Hide file tree
Showing 52 changed files with 9,051 additions and 147 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Dockerfile
vendor/
.git
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
APP_NAME=Laravel
APP_NAME=map.et
APP_TECHNICAL_CONTACT=
APP_ENV=local
APP_KEY=
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Docker Image CI

on:
push:
branches: [ "main" ]

jobs:

build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Login to Github Packages
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GHCR_PAT }}
- name: Build the Docker image
if: github.ref == 'refs/heads/opg-master'
run: |
docker build . --file Dockerfile --tag ghcr.io/openplaceguide/opg-pages:latest
docker push ghcr.io/openplaceguide/opg-pages:latest
6 changes: 5 additions & 1 deletion .github/workflows/laravel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ jobs:
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
run: |
composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
npm install
- name: Generate key
run: php artisan key:generate
- name: Directory Permissions
Expand All @@ -28,6 +30,8 @@ jobs:
run: |
cd storage/app/repositories/
git clone https://github.com/OpenPlaceGuide/data/ opg-data-ethiopia
- name: Build
run: npm run build
- name: Execute tests (Unit and Feature tests) via PHPUnit
env:
DB_CONNECTION: sqlite
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/public/assets/*
/storage/*.key
/vendor
/tests/cypress/screenshots
.env
.env.backup
.env.production
Expand Down
37 changes: 37 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM composer:2.6.6 as composer

FROM php:8.1-apache-buster

RUN apt-get update && apt-get install -y zip

RUN apt-get -y update \
&& apt-get install -y libicu-dev \
&& docker-php-ext-configure intl \
&& docker-php-ext-install intl

RUN apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libwebp-dev \
libxpm-dev \
zlib1g-dev && \
docker-php-ext-configure gd --enable-gd --with-webp --with-jpeg \
--with-xpm --with-freetype && \
docker-php-ext-install gd

RUN a2enmod rewrite

ENV LOG_CHANNEL=stderr

RUN sed -ri -e 's!/var/www/html!/var/www/html/public!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!/var/www/html/public!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf

RUN sed -ri -e 's!^</!<Directory "/var/www/html/public">\nAllowOverride all\n</Directory>\n</!g' /etc/apache2/sites-available/*.conf

COPY . /var/www/html
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

COPY --from=composer /usr/bin/composer /usr/bin/composer
RUN composer install --no-dev
96 changes: 88 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ License: Undecided, please contact us if you are interested to use any of this.
* Laravel 10
* PHP 8.1

## Symlinking repository

* Checkout data repository to storage/app/repositories, for example https://github.com/OpenPlaceGuide/data
* Link to assets
* ```opg-pages/public/assets$ ls -al
ethiopia -> ../../storage/app/repositories/opg-data-ethiopia/places
```

## Fonts for Static Map

see `resources/fonts/README.md`
Expand Down Expand Up @@ -49,3 +41,91 @@ The place / business page features
* the name
* multiple or a single branch with location
* optional: contact form

## Caching

The data from OpenStreetMap and the data repository is cached. If you changed something, wait 5 minute and use Ctrl+F5 to refresh
the necessary page from the source.

## Development

### Local Setup

Clone this repository (`git clone https://github.com/OpenPlaceGuide/opg-pages.git`) and `cd opg-pages`

Clone the data repository and symlink to public assets

```bash
cd storage/app/repositories/
git clone https://github.com/OpenPlaceGuide/data/ opg-data-ethiopia
cd ../../../public/assets
ln -s ../../storage/app/repositories/opg-data-ethiopia/places ethiopia
```

Install dependencies

```bash
composer install
npm install
```

Open vite

```bash
npm run dev
```

or build with

```bash
npm run build
```

Possible pages:

* /bole/
* /bole/banks
* /nefas-silk/businesses
* /bandira
* /am/bandira
* /zemen-bank

Warning: The root page (/) is currently not existing.

### PHPUnit

```bash
vendor/bin/phpunit
```

PHPunit tests are automatically executed in the GitHub action.

### Cypress

```bash
npx cypress open --e2e --browser chrome
```

## Deployment blended together with osmapp via Docker

This is meant to work together with [OsmApp, OpenPlaceGuide fork](https://github.com/OpenPlaceGuide/osmapp) which runs
on the root path of the page and proxies all other requests to opg-pages.

* build osmapp and Docker-Tag as `osmapp` (in the osmapp folder)

```bash
cd ../osmapp && docker build --build-arg PROXY_BACKEND=http://opg-pages/ . -t osmapp
```

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

Start
```bash
docker compose up -d
```

Access http://localhost:3000

2 changes: 1 addition & 1 deletion app/Facades/FallbackImplementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function resolve($objectOrArray, $language = null): string
return $array[App::getFallbackLocale()];
}

return '(empty)';
return '';
}

public function field($objectOrArray, $field, $delimiter = ':', $language = null): string
Expand Down
63 changes: 47 additions & 16 deletions app/Http/Controllers/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace App\Http\Controllers;

use App\Facades\Fallback;
use App\Models\Branch;
use App\Models\OsmId;
use App\Services\Language;
use App\Services\Overpass;
use App\Services\Repository;
Expand Down Expand Up @@ -46,40 +46,63 @@ public function place(string $slug)

$branchesInfo = $this->fetchOsmInfo($place->branches);
$main = $branchesInfo[0];
$type = Repository::getInstance()->resolveType($main);

$githubUrl = sprintf('https://github.com/OpenPlaceGuide/data/tree/main/places/%s/', $slug);

$logoUrl = $place->getLogoUrl();

return view('page.page')
return view('page.place')
->with('place', $place)
->with('logoUrl', $logoUrl)
->with('slug', $slug)
->with('main', $main)
->with('gallery', $place->getProcessedGallery('en'))
->with('gallery', $place->getProcessedGallery())
->with('branches', $branchesInfo)
->with('newPlaceUrl', null);
->with('newPlaceUrl', null)
->with('githubUrl', $githubUrl)
->with('type', $type)
->with('color', $place->color ?? $type->color ?? 'gray')
->with('icon', $place->icon ?? $type->icon);

}

public function osmPlace($type, $id)
{
$branch = new Branch($type, $id);
$main = $this->fetchOsmInfo([$branch])[0];
// FIXME: forward to slug based page if existing
$idInfo = new OsmId($type, $id);

if ($place = Repository::getInstance()->resolvePlace($idInfo)) {
return redirect()->to($place->getUrl($idInfo));
}

$main = $this->fetchOsmInfo([$idInfo])[0];

$newPlaceContent = <<<YAML
osm:
id: {$branch->osmId}
type: {$branch->osmType}
id: {$idInfo->osmId}
type: {$idInfo->osmType}
YAML;

$name = Language::slug(Fallback::field($main->tags, 'name', language: 'en'));
// FIXME: don't hard code the data repository
$newPlaceUrl = sprintf('https://github.com/OpenPlaceGuide/data/new/main?filename=places/%s/place.yaml&value=%s', $name, urlencode($newPlaceContent));
return view('page.page')

$type = Repository::getInstance()->resolveType($main);

$logoUrl = $type->getLogoUrl();

return view('page.place')
->with('place', null)
->with('logoUrl', null)
->with('logoUrl', $logoUrl)
->with('slug', null)
->with('main', $main)
->with('gallery', [])
->with('branches', [$main])
->with('newPlaceUrl', $newPlaceUrl);
->with('newPlaceUrl', $newPlaceUrl)
->with('type', $type)
->with('color', $type->color ?? 'gray')
->with('icon', $type->icon);

}

Expand All @@ -98,32 +121,40 @@ public function typePage(string $areaSlug, string $typeSlug)

$places = (new Overpass())->fetchOsmOverview($type, $area);

$logoUrl = $type->getLogoUrl();


return view('page.overview')
->with('area', $area)
->with('type', $type)
->with('places', $places);
->with('logoUrl', $logoUrl)
->with('places', $places)
->with('color', $type->color)
->with('logo', $type->logo);
}

/**
* POI overview page
*/
public function area(string $slug)
{
$types = $this->repository->listTypes($slug);
$types = $this->repository->listTypes();

$area = $this->repository->getAreaInfo($slug);

return view('page.area')
->with('area', $area)
->with('types', $types);
->with('types', $types)
->with('color', $area->color);
}

/**
* @param array<Branch> $places
* @param array<OsmId> $places
* @return array<OsmInfo>
*/
private function fetchOsmInfo(array $places): array
{
return (new Overpass())->fetchOsmInfo($places);
return (new Overpass())->fetchOsmInfo($places, Repository::getInstance()->listLeafAreas());
}

public function tripleZoomMap($lat, $lon, Request $request)
Expand Down
40 changes: 39 additions & 1 deletion app/Models/Area.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,50 @@

namespace App\Models;

use App\Facades\Fallback;
use App\Services\Repository;
use Illuminate\Support\Facades\App;

class Area
{
public function __construct(public readonly Repository $repository, readonly public string $slug, readonly public array $names, readonly public array $descriptions, readonly public array $tags) {
public \stdClass $tags;

public function __construct(
public readonly Repository $repository,
readonly public ?OsmId $idInfo,
readonly public string $slug,
readonly public array $names,
readonly public array $descriptions,
readonly public string $color,
readonly public array $subAreas
)
{

}

public function getKey()
{
return $this->idInfo?->getAreaId() ?? $this->slug;
}

public function getUrl()
{
$url = route('page.' . App::currentLocale(), ['slug' => $this->slug]);
return $url;
}

public function getFullName()
{
$result = Fallback::field($this->tags, 'name');

if ($part = Fallback::field($this->tags, 'is_in:state')) {
$result .= ' - ' . $part;
}

if ($part = Fallback::field($this->tags, 'is_in:country')) {
$result .= ', ' . $part;
}

return $result;
}
}
Loading

0 comments on commit 6089e2d

Please sign in to comment.