Compare commits
5 Commits
feature/di
...
feature/fi
| Author | SHA1 | Date | |
|---|---|---|---|
| 0da1aa4ff6 | |||
| 59f10e620f | |||
| 9f322d874e | |||
| 10cd2c59a3 | |||
| 810643c18a |
@@ -1,7 +1,5 @@
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
workflow_dispatch:
|
||||
jobs:
|
||||
deploy-job:
|
||||
|
||||
@@ -76,8 +76,6 @@ class ScrapeWebsite extends Command
|
||||
$output->writeln('Update prices - DONE');
|
||||
$output->writeln('COMMAND - DONE');
|
||||
|
||||
file_put_contents('templates/lastscrape.html.twig', date('Y-m-d H:i:s'));
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
40
src/Controller/CountryController.php
Normal file
40
src/Controller/CountryController.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Krzysiej\RyobiCrawler\Controller;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Krzysiej\RyobiCrawler\Models\Country;
|
||||
use Krzysiej\RyobiCrawler\Models\Product;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
final class CountryController extends BaseController
|
||||
{
|
||||
#[Route('/country/{countryName?}', name: 'app_country')]
|
||||
public function __invoke(?string $countryName): Response
|
||||
{
|
||||
/** @var Product[] $products */
|
||||
$products = Product::with(['price', 'lowestPrice', 'country'])
|
||||
->join('countries', 'countries.id', '=', 'products.country_id')
|
||||
->where('countryName', $countryName)
|
||||
->orderByDesc('starred')
|
||||
->orderByDesc('created_by')
|
||||
->get();
|
||||
|
||||
$country = Country::where('countryName', $countryName)->first();
|
||||
|
||||
return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'country', 'country' => $country, 'countryStats' => $this->countryStats($countryName)]);
|
||||
}
|
||||
|
||||
private function countryStats(string $country): array
|
||||
{
|
||||
$countryProducts = Product::join('countries', 'countries.id', '=', 'products.country_id')
|
||||
->where('countryName', $country);
|
||||
|
||||
$stats = [];
|
||||
$stats['items'] = $countryProducts->get()->count();
|
||||
// $stats['items2'] = $countryProducts->dd();
|
||||
|
||||
return $stats;
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,32 @@ final class ProductController extends BaseController
|
||||
ksort($stockList);
|
||||
ksort($priceList);
|
||||
|
||||
return $this->render('product.html.twig', [
|
||||
'product' => $product,
|
||||
'price_list' => $this->prepareChartData($priceList),
|
||||
'stock_list' => $this->prepareChartData($stockList),
|
||||
'price_dates' => implode("','", $this->dateRange(array_key_first($priceList), array_key_last($priceList))),
|
||||
]);
|
||||
}
|
||||
#[Route('/product/model/{productModel}', name: 'app_product_model')]
|
||||
public function productModel(string $productModel): Response
|
||||
{
|
||||
|
||||
$product = Product::with([
|
||||
'price' => fn($query) => $query->orderBy('created_at', 'desc'),
|
||||
'stock' => fn($query) => $query->orderBy('created_at', 'desc'),
|
||||
])->where('subTitle', $productModel)->first();
|
||||
|
||||
if (null === $product) {
|
||||
throw $this->createNotFoundException('Product not found');
|
||||
}
|
||||
$priceList = $product->price()->pluck('price', 'created_at')->mapWithKeys(fn($price, $createdAt) => [explode(' ', $createdAt)[0] => $price])->toArray();
|
||||
$stockList = $product->stock()->pluck('stock', 'created_at')->mapWithKeys(fn($stock, $createdAt) => [explode(' ', $createdAt)[0] => $stock])->toArray();
|
||||
|
||||
ksort($stockList);
|
||||
ksort($priceList);
|
||||
|
||||
|
||||
return $this->render('product.html.twig', [
|
||||
'product' => $product,
|
||||
'price_list' => $this->prepareChartData($priceList),
|
||||
|
||||
@@ -7,9 +7,13 @@ use Krzysiej\RyobiCrawler\Twig\AppExtension;
|
||||
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
|
||||
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
|
||||
use Symfony\Bundle\TwigBundle\TwigBundle;
|
||||
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
|
||||
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
|
||||
use Twig\Extra\Cache\CacheExtension;
|
||||
use Twig\Extra\Cache\CacheRuntime;
|
||||
use Twig\Extra\TwigExtraBundle\TwigExtraBundle;
|
||||
|
||||
class Kernel extends BaseKernel
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Krzysiej\RyobiCrawler\Twig;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Krzysiej\RyobiCrawler\Models\Country;
|
||||
use Krzysiej\RyobiCrawler\Models\Price;
|
||||
use Krzysiej\RyobiCrawler\Models\Product;
|
||||
use Krzysiej\RyobiCrawler\Models\Stock;
|
||||
@@ -28,6 +29,7 @@ class AppExtension extends AbstractExtension
|
||||
new TwigFunction('discontinuedCount', [$this, 'discontinuedCount']),
|
||||
new TwigFunction('lowestPriceCount', [$this, 'lowestPriceCount']),
|
||||
new TwigFunction('renderCategoryTree', [$this, 'renderCategoryTree']),
|
||||
new TwigFunction('getCountries', [$this, 'getCountries']),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -66,6 +68,11 @@ class AppExtension extends AbstractExtension
|
||||
->count();
|
||||
}
|
||||
|
||||
public function getCountries(): array
|
||||
{
|
||||
return Country::get()->toArray();
|
||||
}
|
||||
|
||||
public function findByCreatedAtDate(Collection $items, string $date): Stock|Price|null
|
||||
{
|
||||
return $items->first(fn($item) => str_starts_with($item->created_at, $date));
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
<div class="container">
|
||||
<footer class="d-flex flex-wrap justify-content-between align-items-center py-3 my-4 border-top">
|
||||
<div class="col-md-4 d-flex align-items-center">
|
||||
<span class="mb-md-0 text-body-secondary">© 2025 Company, Inc</span>
|
||||
<a class="align-items-center text-decoration-none" data-bs-theme-value="light">☀️ Light</a>
|
||||
<a class="align-items-center text-decoration-none" data-bs-theme-value="dark">🌕 Dark</a>
|
||||
</div>
|
||||
<div class="col-md-4 text-end text-muted">
|
||||
{{ include('lastscrape.html.twig', ignore_missing: true) }}
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
@@ -11,7 +11,8 @@
|
||||
<td>
|
||||
<a href='{{ path('app_product', {'productId': product.id}) }}'
|
||||
class="text-decoration-none">{{ product.name }}</a>
|
||||
<a href="{{ path('app_search', {'search': product.subTitle}) }}"><span class="badge text-bg-secondary">{{ product.subTitle }}</span></a>
|
||||
<span class="badge text-bg-light"><a href="{{ path('app_product_model', {'productModel': product.subTitle}) }}"
|
||||
class="link-underline link-underline-opacity-0 link-dark">{{ product.subTitle }}</a></span>
|
||||
{% if product.promotions is not null and product.promotions.hasPromotion %}<a
|
||||
href="{{ path('app_promos', {'promo': product.promotions.slug}) }}"><span class="badge bg-info">PROMO: {{ product.promotions.tag }}</span>
|
||||
</a>{% endif %}
|
||||
|
||||
@@ -19,6 +19,12 @@
|
||||
</ul>
|
||||
{% endif %}
|
||||
|
||||
{% if listType == 'country' and country is not null%}
|
||||
<h2 class="text-muted mt-4 mx-4">{{ country.countryName }}</h2>
|
||||
<h5 class="mx-4 my-0">Currency: {{ country.currency }}</h5>
|
||||
{{ dump(countryStats) }}
|
||||
{% endif %}
|
||||
|
||||
|
||||
{% if (listType starts with 'category_' and category == null) or not (listType starts with 'category_') or (listType starts with 'category_' and category is not null) %}
|
||||
<div class="table-responsive">
|
||||
@@ -48,19 +54,22 @@
|
||||
class="text-decoration-none">{{ product.name }}</a>
|
||||
<br>
|
||||
{% if product.stock > 0 %}
|
||||
<span class="badge text-bg-secondary">stock: {{ product.stock }}</span>
|
||||
<span class="badge text-bg-light">stock: {{ product.stock }}</span>
|
||||
{% else %}
|
||||
<span class="badge text-bg-warning">out of stock</span>
|
||||
{% endif %}
|
||||
{% if product.isDiscontinued() %}
|
||||
<a href="{{ path('app_discontinued') }}"><span class="badge text-bg-secondary" data-bs-title="Last update: {{ product.lastSeen }}">is discontinued</span></a>
|
||||
<a href="{{ path('app_discontinued') }}"><span class="badge text-bg-secondary" data-bs-toggle="tooltip"
|
||||
data-bs-title="Last update: {{ product.lastSeen }}">is discontinued</span></a>
|
||||
{% endif %}
|
||||
{% if product.isNew() %}
|
||||
<a href="{{ path('app_new') }}"><span class="badge text-bg-success">is new</span></a>
|
||||
{% endif %}
|
||||
<a href="{{ path('app_search', {'search': product.subTitle}) }}"><span class="badge text-bg-secondary">{{ product.subTitle }}</span></a>
|
||||
<span class="badge text-bg-light"><a
|
||||
href="{{ path('app_product_model', {'productModel': product.subTitle}) }}"
|
||||
class="link-underline link-underline-opacity-0 link-dark">{{ product.subTitle }}</a></span>
|
||||
{% if product.promotions is not null and product.promotions.hasPromotion %}<a href="{{ path('app_promos', {'promo': product.promotions.slug}) }}"><span class="badge bg-info">PROMO: {{ product.promotions.tag }}</span></a>{% endif %}
|
||||
<span class="badge text-bg-secondary">{{ product.country.countryName }}</span>
|
||||
<span class="badge text-bg-light"><a href="{{ path('app_country', {'countryName': product.country.countryName}) }}" class="link-underline link-underline-opacity-0 link-dark">{{ product.country.countryName }}</a></span>
|
||||
</td>
|
||||
<td class="align-middle">
|
||||
<nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';">
|
||||
@@ -80,7 +89,7 @@
|
||||
{{ product.priceLowest | format_currency(product.country.currency, {}, product.country.locale) }}
|
||||
{% else %}
|
||||
{% if product.priceLowest != product.priceCurrent %}{{ product.priceLowest | format_currency(product.country.currency, {}, product.country.locale) }}{% else %}
|
||||
<span class="badge text-bg-info">now lowest</span>{% endif %}</td>
|
||||
<a href="{{ path('app_lowest_price') }}"><span class="badge bg-info">now lowest</span></a>{% endif %}</td>
|
||||
{% endif %}
|
||||
|
||||
<td class="align-middle text-end">{{ product.priceCurrent | format_currency(product.country.currency, {}, product.country.locale) }}</td>
|
||||
|
||||
@@ -1,75 +1,6 @@
|
||||
<!doctype html>
|
||||
<html lang="en" data-bs-theme="">
|
||||
<html lang="en" data-bs-theme="light">
|
||||
<head>
|
||||
<script>
|
||||
(() => {
|
||||
'use strict'
|
||||
|
||||
const getStoredTheme = () => localStorage.getItem('theme')
|
||||
const setStoredTheme = theme => localStorage.setItem('theme', theme)
|
||||
|
||||
const getPreferredTheme = () => {
|
||||
const storedTheme = getStoredTheme()
|
||||
if (storedTheme) {
|
||||
return storedTheme
|
||||
}
|
||||
|
||||
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
|
||||
}
|
||||
|
||||
const setTheme = theme => {
|
||||
if (theme === 'auto') {
|
||||
document.documentElement.setAttribute('data-bs-theme', (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'))
|
||||
} else {
|
||||
document.documentElement.setAttribute('data-bs-theme', theme)
|
||||
}
|
||||
}
|
||||
|
||||
setTheme(getPreferredTheme())
|
||||
|
||||
const showActiveTheme = (theme, focus = false) => {
|
||||
const themeSwitcher = document.querySelector('#bd-theme')
|
||||
|
||||
if (!themeSwitcher) {
|
||||
return
|
||||
}
|
||||
|
||||
const btnToActive = document.querySelector(`[data-bs-theme-value="${theme}"]`)
|
||||
|
||||
document.querySelectorAll('[data-bs-theme-value]').forEach(element => {
|
||||
element.classList.remove('active')
|
||||
})
|
||||
|
||||
btnToActive.classList.add('active')
|
||||
|
||||
if (focus) {
|
||||
themeSwitcher.focus()
|
||||
}
|
||||
}
|
||||
|
||||
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
|
||||
const storedTheme = getStoredTheme()
|
||||
if (storedTheme !== 'light' && storedTheme !== 'dark') {
|
||||
setTheme(getPreferredTheme())
|
||||
}
|
||||
})
|
||||
|
||||
window.addEventListener('DOMContentLoaded', () => {
|
||||
showActiveTheme(getPreferredTheme())
|
||||
|
||||
document.querySelectorAll('[data-bs-theme-value]')
|
||||
.forEach(toggle => {
|
||||
toggle.addEventListener('click', () => {
|
||||
const theme = toggle.getAttribute('data-bs-theme-value')
|
||||
setStoredTheme(theme)
|
||||
setTheme(theme)
|
||||
showActiveTheme(theme, true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})()
|
||||
|
||||
</script>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
@@ -82,8 +13,7 @@
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="{{ path('app_home') }}">Crawler</a>
|
||||
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
|
||||
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
@@ -103,6 +33,16 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link {% if app.request.pathinfo == path('app_discontinued') %}active shadow-sm bg-body rounded{% endif %}" aria-current="page" href="{{ path('app_discontinued') }}">Discontinued <span class="badge text-bg-secondary">{{ discontinuedCount() }}</span></a>
|
||||
</li>
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
Countries
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
{% for country in getCountries() %}
|
||||
<li><a class="dropdown-item" href="{{ path('app_country', {'countryName': country.countryName}) }}">{{ country.countryName }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<form class="form-floating d-flex col-lg-6 col-sm-8" role="search" action="{{ path('app_search') }}">
|
||||
@@ -115,7 +55,6 @@
|
||||
|
||||
</nav>
|
||||
{% block content %}{% endblock %}
|
||||
{{ include('footer.html.twig') }}
|
||||
<script src="/templates/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user