39 Commits

Author SHA1 Message Date
Krzysztof Płaczek
2e4c79c87a Merge branch 'master' into feature/order-columns
# Conflicts:
#	Dockerfile
#	templates/productList.html.twig
2025-03-17 12:52:07 +01:00
6246ad8692 Merge pull request 'Table is responsive on mobile' (#24) from feature/table-responsive-on-mobile into master
Reviewed-on: #24
2025-02-19 15:29:52 +01:00
Krzysztof Płaczek
d18abc6159 Table is responsive on mobile 2025-02-19 15:29:31 +01:00
5832ac583f Merge pull request 'Add a slash to static files.' (#23) from fix/missing-script-files-when-in-category into master
Reviewed-on: #23
2025-02-16 10:49:09 +01:00
Krzysztof Płaczek
8f87a6bbf0 Add a slash to static files. 2025-02-16 10:48:55 +01:00
ef1b7b8a9e Merge pull request 'Update search field.' (#21) from feature/update-search-field into master
Reviewed-on: #21
2025-02-16 10:46:02 +01:00
b0134accfa Merge pull request 'feature/discontinued' (#22) from feature/discontinued into master
Reviewed-on: #22
2025-02-16 10:45:57 +01:00
Krzysztof Płaczek
ae0f9b3be7 Add an active state to the main menu 2025-02-16 10:45:15 +01:00
Krzysztof Płaczek
5c2777999a Add a tooltip with last update to discontinued items. 2025-02-16 10:22:09 +01:00
Krzysztof Płaczek
71279025ae Update search field. 2025-02-15 12:21:26 +01:00
f334ba0232 Merge pull request 'Keep track of discontinued items. That means items that were tracked, but then they were never updated.Added is discontinued badge.' (#20) from feature/discontinued into master
Reviewed-on: #20
2025-02-15 11:33:45 +01:00
Krzysztof Płaczek
81f9c863c7 Keep track of discontinued items. That means items that were tracked, but then they were never updated.Added is discontinued badge. 2025-02-15 11:33:24 +01:00
7eb7bf3eb2 Merge pull request 'Increase php memory limit' (#18) from feature/increase-memory-limit into master
Reviewed-on: #18
2025-02-04 21:00:43 +01:00
Krzysztof Płaczek
ac1f0af5ae Increase php memory limit 2025-02-04 21:00:12 +01:00
35aea9dd7e Merge pull request 'Increase php memory limit' (#17) from feature/increase-memory-limit into master
Reviewed-on: #17
2025-02-04 20:43:56 +01:00
Krzysztof Płaczek
62239bd052 Increase php memory limit 2025-02-04 20:43:33 +01:00
Krzysztof Płaczek
c947e470af Increase php memory limit 2025-02-04 20:41:58 +01:00
Krzysztof Płaczek
8eeba225ed Merge branch 'master' of 192.168.0.129:krzysiej/ryobi-crawler into feature/order-columns 2025-01-28 09:15:49 +01:00
22e59a2438 Merge pull request 'Display price badged inline.' (#16) from feature/tweak-displaing-badges-with-prices into master
Reviewed-on: #16
2025-01-28 08:23:21 +01:00
Krzysztof Płaczek
585f1336d2 Display price badged inline. 2025-01-28 08:23:03 +01:00
Krzysztof Płaczek
9b6bcd22be Start working on sorting products by different columns. 2025-01-27 12:10:15 +01:00
a26ad401df Merge pull request 'Add chart line to display stock as well as price.' (#15) from feature/display-stock-in-chart into master
Reviewed-on: #15
2025-01-26 11:42:38 +01:00
Krzysztof Płaczek
3705990be1 Add chart line to display stock as well as price. 2025-01-26 11:41:42 +01:00
c65f0fdb3e Merge pull request 'Add new items listing and counting' (#14) from feature/list-new-items into master
Reviewed-on: #14
2025-01-05 18:53:14 +01:00
d6bcffc3e1 Add new badge. Update screenshot. 2025-01-05 18:50:34 +01:00
faf9c8a480 Update src/Twig/AppExtension.php 2025-01-05 16:27:15 +01:00
14104f61a4 Add new items listing and counting 2025-01-05 16:19:49 +01:00
44254ed12a Merge pull request 'feature/breadcrumbs-as-categories' (#13) from feature/breadcrumbs-as-categories into master
Reviewed-on: #13
2024-11-28 11:55:25 +01:00
Krzysztof Płaczek
d9740a86d0 Use breadcrumbs to display categories 2024-11-28 11:51:14 +01:00
Krzysztof Płaczek
bd62a23854 Use breadcrumbs to display categories 2024-11-28 11:50:22 +01:00
2dc4dc778d Merge pull request 'Add bin/ commands' (#12) from feature/add-bin-commands into master
Reviewed-on: #12
2024-11-26 09:57:32 +01:00
Krzysztof Płaczek
85e32554ef Add bin/ commands 2024-11-26 09:57:16 +01:00
ebd48cfbf6 Merge pull request 'Remove duplicate products in category view due to the bug with the list of category.' (#11) from fix/duplicate-products-in-category-view into master
Reviewed-on: #11
2024-11-26 08:29:14 +01:00
Krzysztof Płaczek
369bacc38c Remove duplicate products in category view due to the bug with the list of category. 2024-11-26 08:28:23 +01:00
277257fda2 Merge pull request 'Add badge to single product view.' (#10) from feature/use-bootstrap-badges into master
Reviewed-on: #10
2024-11-23 12:01:37 +01:00
Krzysztof Płaczek
0e5d76313f Add badge to single product view. 2024-11-23 11:59:32 +01:00
54488f0b19 Merge pull request 'feature/use-bootstrap-badges' (#8) from feature/use-bootstrap-badges into master
Reviewed-on: #8
2024-11-23 11:34:46 +01:00
Krzysztof Płaczek
a6b108cb74 Add a badge for stock 2024-11-23 11:34:00 +01:00
Krzysztof Płaczek
0db4bacff4 Add some bootstrap badged in place of promos count, discount percent and previous price. 2024-11-21 10:05:55 +01:00
22 changed files with 309 additions and 96 deletions

View File

@@ -1,7 +1,8 @@
FROM php:8.3-cli FROM php:8.3-cli
WORKDIR /usr/src/app WORKDIR /usr/src/app
ENV PHP_MEMORY_LIMIT=512M
RUN echo "memory_limit=512M" > /usr/local/etc/php/conf.d/memory-limit.ini
RUN apt-get update && apt-get install -y \ RUN apt-get update && apt-get install -y \
git \ git \
unzip \ unzip \

2
bin/bash Executable file
View File

@@ -0,0 +1,2 @@
#!/usr/bin/env bash
bin/cli bash

3
bin/cli Executable file
View File

@@ -0,0 +1,3 @@
#!/usr/bin/env bash
[ -z "$1" ] && echo "Please specify a CLI command (ex. ls)" && exit
docker compose exec php-app "$@"

5
bin/update Executable file
View File

@@ -0,0 +1,5 @@
#!/usr/bin/env bash
echo "Updating project"
git pull origin master
bin/cli rm -rf var/cache
echo "Project updated"

View File

@@ -1,7 +1,6 @@
{ {
"require": { "require": {
"guzzlehttp/guzzle": "^7.0", "guzzlehttp/guzzle": "^7.0",
"symfony/var-dumper": "^7.0",
"illuminate/database": "11.26.0.0", "illuminate/database": "11.26.0.0",
"ext-json": "*", "ext-json": "*",
"symfony/console": "^7.0", "symfony/console": "^7.0",
@@ -18,5 +17,8 @@
"psr-4": { "psr-4": {
"Krzysiej\\RyobiCrawler\\": "src/" "Krzysiej\\RyobiCrawler\\": "src/"
} }
},
"require-dev": {
"symfony/var-dumper": "^7.1"
} }
} }

14
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "4eef5feb5e2635d7fb7c69c8ed01a84c", "content-hash": "a6920081bf40809334b8dda2da16752d",
"packages": [ "packages": [
{ {
"name": "brick/math", "name": "brick/math",
@@ -4123,16 +4123,16 @@
}, },
{ {
"name": "symfony/var-dumper", "name": "symfony/var-dumper",
"version": "v7.1.5", "version": "v7.1.8",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/var-dumper.git", "url": "https://github.com/symfony/var-dumper.git",
"reference": "e20e03889539fd4e4211e14d2179226c513c010d" "reference": "7bb01a47b1b00428d32b5e7b4d3b2d1aa58d3db8"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/var-dumper/zipball/e20e03889539fd4e4211e14d2179226c513c010d", "url": "https://api.github.com/repos/symfony/var-dumper/zipball/7bb01a47b1b00428d32b5e7b4d3b2d1aa58d3db8",
"reference": "e20e03889539fd4e4211e14d2179226c513c010d", "reference": "7bb01a47b1b00428d32b5e7b4d3b2d1aa58d3db8",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -4186,7 +4186,7 @@
"dump" "dump"
], ],
"support": { "support": {
"source": "https://github.com/symfony/var-dumper/tree/v7.1.5" "source": "https://github.com/symfony/var-dumper/tree/v7.1.8"
}, },
"funding": [ "funding": [
{ {
@@ -4202,7 +4202,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2024-09-16T10:07:02+00:00" "time": "2024-11-08T15:46:42+00:00"
}, },
{ {
"name": "symfony/var-exporter", "name": "symfony/var-exporter",

Binary file not shown.

Before

Width:  |  Height:  |  Size: 133 KiB

After

Width:  |  Height:  |  Size: 199 KiB

View File

@@ -40,7 +40,6 @@ class ScrapeWebsite extends Command
$products = $this->getProducts(); $products = $this->getProducts();
$progress->setMaxSteps(count($products)); $progress->setMaxSteps(count($products));
foreach ($products as $product) { foreach ($products as $product) {
//dd($product);
$this->saveProduct($product); $this->saveProduct($product);
$progress->advance(); $progress->advance();
} }
@@ -91,6 +90,7 @@ class ScrapeWebsite extends Command
$productModel->variantCode = $product->variantCode; $productModel->variantCode = $product->variantCode;
$productModel->modelCode = $product->modelCode; $productModel->modelCode = $product->modelCode;
$productModel->url = $product->url; $productModel->url = $product->url;
$productModel->touch('updated_at');
$productModel->save(); $productModel->save();
$priceExists = $productModel->price()->whereRaw("strftime('%Y-%m-%d', created_at) = ?", [date('Y-m-d')])->exists(); $priceExists = $productModel->price()->whereRaw("strftime('%Y-%m-%d', created_at) = ?", [date('Y-m-d')])->exists();

View File

@@ -2,7 +2,9 @@
namespace Krzysiej\RyobiCrawler\Controller; namespace Krzysiej\RyobiCrawler\Controller;
use Illuminate\Database\Eloquent\Builder;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Twig\Environment; use Twig\Environment;
use Illuminate\Database\Capsule\Manager as Capsule; use Illuminate\Database\Capsule\Manager as Capsule;
@@ -17,4 +19,19 @@ class BaseController extends AbstractController
$capsule->setAsGlobal(); $capsule->setAsGlobal();
$capsule->bootEloquent(); $capsule->bootEloquent();
} }
protected function handleOrderProducts(Builder $builder, Request $request): Builder
{
$builder->orderByDesc('starred')->orderByDesc('created_by');
if ($request->query->get('order')) {
$orderField = $request->query->get('order');
$direction = 'desc';
if (str_starts_with($orderField, '-')) {
$direction = 'asc';
}
$builder->orderBy($request->query->get('order'), $direction);
}
return $builder;
}
} }

View File

@@ -13,6 +13,7 @@ final class CategoryController extends BaseController
{ {
$products = Product::with('price') $products = Product::with('price')
->selectRaw('products.*') ->selectRaw('products.*')
->distinct('products.id')
->fromRaw('products, json_each(products.categories)') ->fromRaw('products, json_each(products.categories)')
->whereRaw('json_each.value = ?', [$category]) ->whereRaw('json_each.value = ?', [$category])
->orderByDesc('starred') ->orderByDesc('starred')

View File

@@ -0,0 +1,24 @@
<?php
namespace Krzysiej\RyobiCrawler\Controller;
use Krzysiej\RyobiCrawler\Models\Product;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use function Symfony\Component\Clock\now;
final class DiscontinuedController extends BaseController
{
#[Route('/discontinued', name: 'app_discontinued')]
public function __invoke(): Response
{
$products = Product::where('updated_at', '<', now()->format('Y-m-d'))
->orderByDesc('starred')
->orderByDesc('created_by')
->with(['currentPrice'])
->get();
return $this->render('productList.html.twig', ['products' => $products]);
}
}

View File

@@ -3,15 +3,17 @@
namespace Krzysiej\RyobiCrawler\Controller; namespace Krzysiej\RyobiCrawler\Controller;
use Krzysiej\RyobiCrawler\Models\Product; use Krzysiej\RyobiCrawler\Models\Product;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Routing\Attribute\Route;
final class IndexController extends BaseController final class IndexController extends BaseController
{ {
#[Route('/', name: 'app_home')] #[Route('/', name: 'app_home')]
public function __invoke(): Response public function __invoke(Request $request): Response
{ {
$products = Product::with('price')->orderByDesc('starred')->orderByDesc('created_by')->get(); $products = Product::with(['currentStock', 'price', 'currentPrice']);
$products = $this->handleOrderProducts($products, $request)->get();
return $this->render('productList.html.twig', ['products' => $products]); return $this->render('productList.html.twig', ['products' => $products]);
} }
} }

View File

@@ -0,0 +1,25 @@
<?php
namespace Krzysiej\RyobiCrawler\Controller;
use Illuminate\Database\Eloquent\Builder;
use Krzysiej\RyobiCrawler\Models\Product;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use function Symfony\Component\Clock\now;
final class NewController extends BaseController
{
#[Route('/new', name: 'app_new')]
public function __invoke(): Response
{
$products = Product::where('created_at', '>', now()->modify('-30 days')->format('Y-m-d'))
->orderByDesc('starred')
->orderByDesc('name')
->orderByDesc('created_by')
->with(['currentPrice'])
->get();
return $this->render('productList.html.twig', ['products' => $products]);
}
}

View File

@@ -26,9 +26,26 @@ final class ProductController extends BaseController
if (null === $product) { if (null === $product) {
throw $this->createNotFoundException('Product not found'); throw $this->createNotFoundException('Product not found');
} }
$priceList = $product->price()->pluck('price');
$stockList = $product->stock()->pluck('stock');
$priceDates = $product->price()->pluck('created_at')->map(fn($date) => $date->format('Y-m-d'))->toArray();
$stockDates = $product->stock()->pluck('created_at')->map(fn($date) => $date->format('Y-m-d'))->toArray();
$priceList = $product->price()->pluck('price')->implode(','); return $this->render('product.html.twig', [
$priceDates = $product->price()->pluck('created_at')->map(fn($date) => $date->format('Y-m-d'))->implode("','"); 'product' => $product,
return $this->render('product.html.twig', ['product' => $product, 'price_list' => $priceList, 'price_dates' => $priceDates]); 'price_list' => $this->prepareChartData($priceDates, $priceList),
'stock_list' => $this->prepareChartData($stockDates, $stockList),
'price_dates' => implode("','", $priceDates),
]);
}
private function prepareChartData($set1, $set2): string
{
$data = [];
foreach ($set1 as $key => $value) {
$data[] = ['x' => $value, 'y' => $set2[$key]];
}
$stringData = json_encode($data);
return str_replace(['"x"', '"y"'], ['x', 'y'], $stringData);
} }
} }

View File

@@ -13,7 +13,6 @@ final class SearchController extends BaseController
public function __invoke(Request $request): Response public function __invoke(Request $request): Response
{ {
$search = $request->query->get('search'); $search = $request->query->get('search');
//dd();
$products = Product::with('price') $products = Product::with('price')
->orWhere([['name', 'like', "%$search%"]]) ->orWhere([['name', 'like', "%$search%"]])
->orWhere([['subTitle', 'like', "%$search%"]])->get(); ->orWhere([['subTitle', 'like', "%$search%"]])->get();

View File

@@ -7,6 +7,8 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\Relations\HasOne;
use function Symfony\Component\Clock\now;
/** /**
* @property integer $skuID * @property integer $skuID
* @property string $name * @property string $name
@@ -44,6 +46,13 @@ class Product extends Model
return $this->hasMany(Stock::class); return $this->hasMany(Stock::class);
} }
public function currentStock(): HasOne
{
return $this->stock()->one()->ofMany()->withDefault(function (Stock $stock) {
$stock->stock = 0;
});
}
public function toggleStarred(): self public function toggleStarred(): self
{ {
$this->starred = !$this->starred; $this->starred = !$this->starred;
@@ -58,4 +67,13 @@ class Product extends Model
set: fn(array $value) => json_encode($value), set: fn(array $value) => json_encode($value),
); );
} }
public function isDiscontinued(): bool
{
return $this->updated_at->format('Y-m-d') < now()->format('Y-m-d');
}
public function isNew(): bool
{
return $this->created_at->format('Y-m-d') > now()->modify('-30 days')->format('Y-m-d');
}
} }

View File

@@ -11,12 +11,16 @@ use Twig\Extension\AbstractExtension;
use Twig\TwigFilter; use Twig\TwigFilter;
use Twig\TwigFunction; use Twig\TwigFunction;
use function Symfony\Component\Clock\now;
class AppExtension extends AbstractExtension class AppExtension extends AbstractExtension
{ {
public function getFunctions(): array public function getFunctions(): array
{ {
return [ return [
new TwigFunction('promosCount', [$this, 'promosCount']), new TwigFunction('promosCount', [$this, 'promosCount']),
new TwigFunction('newCount', [$this, 'newCount']),
new TwigFunction('discontinuedCount', [$this, 'discontinuedCount']),
]; ];
} }
@@ -32,6 +36,16 @@ class AppExtension extends AbstractExtension
return Product::whereHas('currentPrice', fn(Builder $query) => $query->whereColumn('price', '<', 'productStandardPrice'))->with(['currentPrice'])->count(); return Product::whereHas('currentPrice', fn(Builder $query) => $query->whereColumn('price', '<', 'productStandardPrice'))->with(['currentPrice'])->count();
} }
public function newCount(): int
{
return Product::where('created_at', '>', now()->modify('-30 days')->format('Y-m-d'))->count();
}
public function discontinuedCount(): int
{
return Product::where('updated_at', '<', now()->format('Y-m-d'))->count();
}
public function findByCreatedAtDate(Collection $items, string $date): Stock|Price|null public function findByCreatedAtDate(Collection $items, string $date): Stock|Price|null
{ {
return $items->first(fn($item) => str_starts_with($item->created_at, $date)); return $items->first(fn($item) => str_starts_with($item->created_at, $date));

6
templates/css/bootstrap.min.css vendored Normal file

File diff suppressed because one or more lines are too long

4
templates/js/script.js Normal file
View File

@@ -0,0 +1,4 @@
(function() {
const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]')
const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl))
})();

View File

@@ -1,31 +1,37 @@
{% extends "template.html.twig" %} {% extends "template.html.twig" %}
{% block content %} {% block content %}
<div class="table-responsive">
<table class='table table-hover'> <table class='table table-hover'>
<tr> <tr>
<td class="align-middle font-weight-bold h3"><a class="text-warning text-decoration-none" <td class="align-middle font-weight-bold h3"><a class="text-warning text-decoration-none"
href="{{ path('app_star', {'productId': product.id}) }}">{% if product.starred %}{% else %}{% endif %}</a></td> href="{{ path('app_star', {'productId': product.id}) }}">{% if product.starred %}{% else %}{% endif %}</a></td>
<td><img src='{{ product.image }}&width=150' class='border rounded p-1' alt='{{ product.name }}'/></td> <td><img src='{{ product.image }}&width=150' class='border rounded p-1' alt='{{ product.name }}'/></td>
<td><a href='{{ path('app_product', {'productId': product.id}) }}' class="text-decoration-none">{{ product.name }}</a></td>
<td>{{ product.subTitle }}</td>
<td> <td>
<ul class='nav'> <a href='{{ path('app_product', {'productId': product.id}) }}' class="text-decoration-none">{{ product.name }}</a>
<span class="badge text-bg-light">{{ product.subTitle }}</span>
</td>
<td>
<nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';">
<ol class="breadcrumb">
{% for category in product.categories %} {% for category in product.categories %}
<li class="nav-item"><a class="nav-link" href="{{ path('app_category', {'category': category}) }}"> {{ category }} </a></li> <li class="breadcrumb-item" aria-current="page"><a class="breadcrumb-item text-decoration-none"
href="{{ path('app_category', {'category': category}) }}">{{ category }}</a></li>
{% endfor %} {% endfor %}
</ul> </ol>
</nav>
</td> </td>
<td><a href='https://pl.ryobitools.eu/{{ product.url }}'>link</a></td> <td><a href='https://pl.ryobitools.eu/{{ product.url }}'>link</a></td>
</tr> </tr>
<tr> <tr>
<td colspan="4"> <td colspan="5">
<div style="width: 800px;"> <div style="width: 800px;">
<canvas id="price"></canvas> <canvas id="price"></canvas>
</div> </div>
</td> </td>
</tr> </tr>
<tr> <tr>
<td colspan="4"> <td colspan="5">
<table class='table table-hover table-sm mb-0'> <table class='table table-hover table-sm mb-0'>
<thead> <thead>
<tr> <tr>
@@ -48,29 +54,36 @@
</td> </td>
</tr> </tr>
</table> </table>
</div>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script> <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script> <script>
const ctx = document.getElementById('price'); const ctx = document.getElementById('price').getContext('2d');
new Chart(ctx, { new Chart(ctx, {
type: 'line', type: 'line',
data: { data: {
labels: ['{{ price_dates|raw }}'], labels: ['{{ price_dates|raw }}'],
datasets: [{ datasets: [
{
label: 'Price (PLN)', label: 'Price (PLN)',
data: [{{ price_list }}], data: {{ price_list|raw }},
yAxisID: 'yPrice',
tension: 0.1,
borderWidth: 1 borderWidth: 1
}] },
{
label: 'Stock (units)',
data: {{ stock_list|raw }},
yAxisID: 'yStock',
tension: 0.1,
borderWidth: 1
}
]
}, },
options: { options: {
responsive: true,
animation: false, animation: false,
plugins: {
title: {
display: true,
text: 'Price in time'
},
},
scales: { scales: {
x: { x: {
title: { title: {
@@ -78,13 +91,40 @@
text: 'Date' text: 'Date'
} }
}, },
y: { yPrice: {
type: 'linear',
position: 'left',
beginAtZero: true, beginAtZero: true,
title: { title: {
display: true, display: true,
text: 'Price' text: 'Price (PLN)'
},
grid: {
drawOnChartArea: false
}
},
yStock: {
type: 'linear',
position: 'right',
beginAtZero: true,
title: {
display: true,
text: 'Stock (units)'
},
grid: {
drawOnChartArea: false
} }
} }
},
plugins: {
legend: {
display: true,
position: 'top'
},
title: {
display: true,
text: 'Price and Stock in time'
},
} }
} }
}); });

View File

@@ -1,36 +1,61 @@
{% extends "template.html.twig" %} {% extends "template.html.twig" %}
{% block content %} {% block content %}
<div class="table-responsive">
{{ app.request.get('order') }}
<table class='table table-hover'> <table class='table table-hover'>
<thead> <thead>
<tr> <tr>
<th></th> <th></th>
<th></th> <th></th>
<th>Name</th> <th><a href="{{ path( app.request.get('_route') , {'order': app.request.get('order') is same as('-name')?'name':'-name'|default('-name')}) }}">Name</a></th>
<th class="d-none d-md-table-cell">Code</th>
<th>Categories</th> <th>Categories</th>
<th></th> <th></th>
<th>Price</th> <th><a href="{{ path( app.request.get('_route') , {'order': app.request.get('order') is same as('-price')?'price':'-price'|default('-price')}) }}">Price</a></th>
<th></th> <th></th>
</tr> </tr>
</thead> </thead>
{% for product in products %} {% for product in products %}
<tr> <tr>
<td class="align-middle font-weight-bold h3"><a class="text-warning text-decoration-none" href="{{ path('app_star', {'productId': product.id}) }}">{% if product.starred == true %}{% else %}{% endif %}</a></td> <td class="align-middle font-weight-bold h3"><a class="text-warning text-decoration-none"
<td class="align-middle" style="width: 120px;"><img src='{{ product.image }}&width=70' class='border rounded p-1' alt='{{ product.name }}'/></td> href="{{ path('app_star', {'productId': product.id}) }}">{% if product.starred == true %}{% else %}{% endif %}</a></td>
<td class="align-middle"><a href='{{ path('app_product', {'productId': product.id}) }}' class="text-decoration-none">{{ product.name }}</a></td> <td class="align-middle" style="width: 120px;"><img src='{{ product.image }}&width=70' class='img-thumbnail' alt='{{ product.name }}'/></td>
<td class="align-middle d-none d-md-table-cell">{{ product.subTitle }}</td>
<td class="align-middle"> <td class="align-middle">
<ul class='nav'> <a href='{{ path('app_product', {'productId': product.id}) }}' class="text-decoration-none">{{ product.name }}</a>
{% if product.currentStock.stock > 0 %}
<span class="badge text-bg-light">stock: {{ product.currentStock.stock }}</span>
{% else %}
<span class="badge text-bg-warning">out of stock</span>
{% endif %}
{% if product.isDiscontinued() %}
<span class="badge text-bg-secondary" data-bs-toggle="tooltip" data-bs-title="Last update: {{ product.updated_at }}">is discontinued</span>
{% endif %}
{% if product.isNew() %}
<span class="badge text-bg-success">is new</span>
{% endif %}
<span class="badge text-bg-light">{{ product.subTitle }}</span>
</td>
<td class="align-middle">
<nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';" >
<ol class="breadcrumb">
{% for category in product.categories %} {% for category in product.categories %}
<li class="nav-item"><a class="nav-link" href="{{ path('app_category', {'category': category}) }}"> {{ category }} </a></li> <li class="breadcrumb-item" aria-current="page"><a class="breadcrumb-item text-decoration-none" href="{{ path('app_category', {'category': category}) }}">{{ category }}</a></li>
{% endfor %} {% endfor %}
</ul> </ol>
</nav>
</td> </td>
<td class="align-middle"><a href='https://pl.ryobitools.eu/{{ product.url }}'>link</a></td> <td class="align-middle"><a href='https://pl.ryobitools.eu/{{ product.url }}'>link</a></td>
<td class="align-middle">{{ product.price.last.price | format_currency('PLN', {}, 'pl') }}</td> <td class="align-middle">{{ product.price.last.price | format_currency('PLN', {}, 'pl') }}</td>
<td class="align-middle">{% if product.price.last.price != product.price.last.productStandardPrice %}<span class="text-decoration-line-through text-warning">{{ product.price.last.productStandardPrice | format_currency('PLN', {}, 'pl') }}</span>&nbsp;<span class="text-success">{{ ((1 - product.price.last.price / product.price.last.productStandardPrice)*100)|number_format(0) }}%</span>{% else %}{% endif %}</td> <td class="align-middle">
<div class="d-flex flex-row">
{% if product.price.last.price != product.price.last.productStandardPrice %}<span
class="badge text-bg-warning text-decoration-line-through flex-fill">{{ product.price.last.productStandardPrice | format_currency('PLN', {}, 'pl') }}</span>&nbsp;<span
class="badge text-bg-success flex-fill">{{ ((1 - product.price.last.price / product.price.last.productStandardPrice)*100)|number_format(0) }}%</span>
{% endif %}
</div>
</td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>
</div>
{% endblock %} {% endblock %}

View File

@@ -5,8 +5,8 @@
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <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"> <meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Ryobi crawler</title> <title>Ryobi crawler</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" <link href="/templates/css/bootstrap.min.css" rel="stylesheet" />
crossorigin="anonymous"/> <script src="/templates/js/script.js" defer></script>
</head> </head>
<body> <body>
<nav class="navbar navbar-expand-lg sticky-top bg-body-tertiary border-bottom border-secondary border-1"> <nav class="navbar navbar-expand-lg sticky-top bg-body-tertiary border-bottom border-secondary border-1">
@@ -19,12 +19,20 @@
<div class="collapse navbar-collapse" id="navbarNav"> <div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav me-auto mb-2 mb-lg-0"> <ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item"> <li class="nav-item">
<a class="nav-link active" aria-current="page" href="{{ path('app_promos') }}">Promos ({{ promosCount() }})</a> <a class="nav-link {% if app.request.pathinfo == path('app_promos') %}active shadow-sm bg-body rounded{% endif %}" aria-current="page" href="{{ path('app_promos') }}">Promos <span class="badge text-bg-secondary">{{ promosCount() }}</span></a>
</li>
<li class="nav-item">
<a class="nav-link {% if app.request.pathinfo == path('app_new') %}active shadow-sm bg-body rounded{% endif %}" aria-current="page" href="{{ path('app_new') }}">New in last 30 days <span class="badge text-bg-secondary">{{ newCount() }}</span></a>
</li>
<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>
</ul> </ul>
<form class="d-flex col-lg-6 col-sm-8" role="search" action="{{ path('app_search') }}">
<input class="form-control me-2" type="search" name="search" placeholder="Search term eg. 36v or RCS18X" value="{{ search|default('') }}" aria-label="Search"> <form class="form-floating d-flex col-lg-6 col-sm-8" role="search" action="{{ path('app_search') }}">
<input class="form-control me-2 form-control-sm" type="search" id="floatingInputValue" name="search" placeholder="Search term eg. 36v or RCS18X" value="{{ search|default('') }}">
<button class="btn btn-outline-success" type="submit">Search</button> <button class="btn btn-outline-success" type="submit">Search</button>
<label for="floatingInputValue">Search term eg. 36v or RCS18X</label>
</form> </form>
</div> </div>
</div> </div>