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

Develop #8

Merged
merged 53 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
67506b9
Add tailwind, alpinejs, basic styling, basic gallery
amenk Apr 26, 2023
0c0c882
Basic Page Styling, removed gallery, use scrolling instead
amenk Apr 29, 2023
3c91db9
Styling: Page height / button
amenk Apr 29, 2023
bad9b19
Adding blade-icons + phosphor icon set
amenk Apr 29, 2023
9266dcd
Remove phosphor icons, use bank icon from OsmAPP
amenk Apr 29, 2023
9ab481c
Support different colors for places, areas, types
amenk Apr 29, 2023
91b927e
Support icons / safelist colors
amenk Apr 29, 2023
fb67247
Use icons of type
amenk Apr 29, 2023
117fa3f
Fix tailwind safelisting / colors
amenk Apr 29, 2023
cc31802
Merge remote-tracking branch 'origin/main' into develop
amenk Apr 29, 2023
bd347d3
Build in workflow
amenk Apr 29, 2023
b28294b
Install npm dependencies
amenk Apr 29, 2023
164bf8b
Vite build to extra job
amenk Apr 29, 2023
fbbb359
Optimize safelist
amenk Apr 29, 2023
0f8d4ba
Allow cache refresh via hard reload for a given page
amenk Apr 30, 2023
2d05032
Overview: Grid style
amenk Apr 30, 2023
23d8b06
Rename view page->place
amenk Apr 30, 2023
723e8a8
Rename Branch->OsmId
amenk Apr 30, 2023
289bd23
Contribute button icon / styling
amenk Apr 30, 2023
b93eaa6
Style copyright (bottom right)
amenk Apr 30, 2023
4e719c5
Add cypress
amenk Apr 30, 2023
82abc15
Redirect OSM places with pages to page
amenk Apr 30, 2023
43b704b
Add place type on page
amenk Apr 30, 2023
e577fd0
Add GitHub URL / Make gallery resolve the correct language
amenk Apr 30, 2023
fe3ef23
Make github button a component
amenk Apr 30, 2023
8101197
Improve readme
amenk Apr 30, 2023
1f87da8
Use OsmIds for areas, remove Osm ID for addis ababa as it is divided …
amenk May 1, 2023
cf631bd
Remove note from readme, it's already a code comment
amenk May 1, 2023
ffef75b
Query and assign areas for the OSM objects to link to the area
amenk May 1, 2023
1ef54a1
Only cache-clear once per key per request
amenk May 1, 2023
df4974e
Fetch only ids for areas
amenk May 1, 2023
7cb9592
Fetch area info
amenk May 1, 2023
ea35c1f
Use overpass-api.de
amenk May 1, 2023
d791878
Fetch area data on area page / show full name
amenk May 1, 2023
4c022c2
Fetch unenriched area if there is no osmid
amenk May 1, 2023
1b69ef1
Fix recursion (segfault)
amenk May 1, 2023
3b0d6c5
Fallback: Return empty string instead of (empty)
amenk Aug 12, 2023
a76123b
Show descriptions for areas
amenk Aug 12, 2023
c1eec51
Remove OsmId For Addis Ababa again / Fetch only one area
amenk Nov 11, 2023
f0d2dd6
Re add OSM ID for Addis Ababa, now filtering out those with subareas
amenk Nov 11, 2023
b45c6c1
Insert Logos
amenk Dec 16, 2023
42e4df1
Force Base URL (Important for Hosting behind OsmAPP Proxy)
amenk Dec 28, 2023
ebfead7
Add initial Docker setup
amenk Dec 28, 2023
a066c9d
Remove concat form
amenk Dec 30, 2023
1c12592
Add logo & description to Poitypes
amenk Jun 2, 2024
daac614
Linking / Fix names / style area page
amenk Jun 2, 2024
280449f
Fix typo
amenk Jun 2, 2024
f433386
Link to Main URL
amenk Jun 2, 2024
2011024
Remove robo
amenk Jun 2, 2024
0fcc238
Deployment instructions
amenk Jun 2, 2024
c48191f
#12 Build docker image
amenk Jun 2, 2024
24bff2e
Merge pull request #13 from OpenPlaceGuide/amenk-patch-1
amenk Jun 2, 2024
7d8c8bc
Push image to registry
amenk Jun 2, 2024
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
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
Loading