Compare commits
66 Commits
1.1.1
...
feature/or
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2e4c79c87a | ||
| 6246ad8692 | |||
|
|
d18abc6159 | ||
| 5832ac583f | |||
|
|
8f87a6bbf0 | ||
| ef1b7b8a9e | |||
| b0134accfa | |||
|
|
ae0f9b3be7 | ||
|
|
5c2777999a | ||
|
|
71279025ae | ||
| f334ba0232 | |||
|
|
81f9c863c7 | ||
| 7eb7bf3eb2 | |||
|
|
ac1f0af5ae | ||
| 35aea9dd7e | |||
|
|
62239bd052 | ||
|
|
c947e470af | ||
|
|
8eeba225ed | ||
| 22e59a2438 | |||
|
|
585f1336d2 | ||
|
|
9b6bcd22be | ||
| a26ad401df | |||
|
|
3705990be1 | ||
| c65f0fdb3e | |||
| d6bcffc3e1 | |||
| faf9c8a480 | |||
| 14104f61a4 | |||
| 44254ed12a | |||
|
|
d9740a86d0 | ||
|
|
bd62a23854 | ||
| 2dc4dc778d | |||
|
|
85e32554ef | ||
| ebd48cfbf6 | |||
|
|
369bacc38c | ||
| 277257fda2 | |||
|
|
0e5d76313f | ||
| 54488f0b19 | |||
|
|
a6b108cb74 | ||
|
|
0db4bacff4 | ||
| 37680b0c91 | |||
|
|
0e8c312f5e | ||
| 685bff3ffc | |||
|
|
11284e59ea | ||
| 50305d5b5d | |||
|
|
f963dcd4c8 | ||
|
|
48ee68f71a | ||
| f1c0ec6b3a | |||
| 0168290340 | |||
|
|
f451bfca0e | ||
|
|
c280abe484 | ||
|
|
7053716924 | ||
| a911d614e0 | |||
|
|
58562746a3 | ||
|
|
5ee1bba812 | ||
| 3d47726a81 | |||
|
|
fee7495cfe | ||
|
|
53b6d33ab9 | ||
|
|
3cc5d73758 | ||
|
|
d043e8efb1 | ||
|
|
2b595c1403 | ||
|
|
f2e6cba2f5 | ||
|
|
e13a0acce1 | ||
|
|
77732689d8 | ||
|
|
22cc3f699b | ||
|
|
a1b6d65137 | ||
|
|
7ee8df32f9 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,5 @@
|
||||
/vendor/
|
||||
.idea
|
||||
database.sqlite
|
||||
var/cache/
|
||||
.env.local
|
||||
@@ -1,13 +1,15 @@
|
||||
FROM php:8.3-cli
|
||||
|
||||
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 \
|
||||
git \
|
||||
unzip \
|
||||
libicu-dev \
|
||||
libzip-dev
|
||||
|
||||
RUN docker-php-ext-install zip
|
||||
RUN docker-php-ext-install zip intl
|
||||
|
||||
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
|
||||
|
||||
|
||||
26
README.md
26
README.md
@@ -5,6 +5,26 @@
|
||||
1. Clone repository using `git clone https://git.techtube.pl/krzysiej/ryobi-crawler.git`
|
||||
2. Cd into project directory `cd ryobi-crawler`
|
||||
3. Build and start docker container `docker compose up -d`
|
||||
4. Run `docker compose exec php-app php index.php app:migrate` file to create `database.sqlite` and create tables.
|
||||
5. Run `docker compose exec php-app php index.php app:scrape` command to scrape all the products from the ryobi website.
|
||||
6. Access web interface using `localhost:9000` address in web browser.
|
||||
4. Run `docker compose exec php-app php console.php app:migrate` file to create `database.sqlite` and create tables.
|
||||
5. Run `docker compose exec php-app php console.php app:scrape` command to scrape all the products from the ryobi website.
|
||||
6. Access web interface using `localhost:9001` address in web browser.
|
||||
|
||||
|
||||
## Update project
|
||||
|
||||
1. Cd into project directory
|
||||
2. Run `git pull`
|
||||
3. Refresh cache on production by removing cache directory: `rm -rf var/cache`
|
||||
4. Start and build image in one go with command: `docker compose up -d --build --force-recreate`
|
||||
|
||||
## Running Cron
|
||||
|
||||
For now only way of running `app:scrape` command on schedule is to use host crontab.
|
||||
1. Run `crontab -e` command to edit host crontab job file
|
||||
2. Add a new line with e.g. line like this `0 1 * * * cd /var/project/directory/ && docker compose exec php-app php console.php app:scrape`
|
||||
3. Save and exit file editor. Cron will execute `app:scrape` once per day.
|
||||
|
||||
## Screenshots
|
||||
|
||||
### Main screen of the web view
|
||||

|
||||
3
bin/cli
Executable file
3
bin/cli
Executable 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
5
bin/update
Executable 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"
|
||||
42
browser.php
42
browser.php
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
include_once 'vendor/autoload.php';
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
use Krzysiej\RyobiCrawler\Models\Product;
|
||||
use Twig\{Environment, Loader\FilesystemLoader};
|
||||
|
||||
if (!file_exists('database.sqlite')) {
|
||||
exit('Database file <code>database.sqlite</code> missing. Run docker compose <blockquote>docker compose exec php-app php index.php app:migrate</blockquote> to create it.');
|
||||
}
|
||||
|
||||
$capsule = new Capsule;
|
||||
$capsule->addConnection(['driver' => 'sqlite', 'database' => __DIR__ . '/database.sqlite']);
|
||||
$capsule->setAsGlobal();
|
||||
$capsule->bootEloquent();
|
||||
$loader = new FilesystemLoader(__DIR__ . '/src/templates');
|
||||
$twig = new Environment($loader);
|
||||
if (isset($_GET['product_id'])) {
|
||||
$template = 'product.html.twig';
|
||||
$product = Product::with('price')->find($_GET['product_id']);
|
||||
}
|
||||
if (isset($_GET['category'])) {
|
||||
$template = 'productList.html.twig';
|
||||
$products = Product::with('price')->selectRaw('products.*')->fromRaw('products, json_each(products.categories)')->whereRaw('json_each.value = ?', [$_GET['category']])
|
||||
->orderByDesc('starred')->orderByDesc('created_by')->get();
|
||||
}
|
||||
if (isset($_GET['search'])) {
|
||||
$template = 'productList.html.twig';
|
||||
$products = Product::with('price')
|
||||
->orWhere([['name', 'like', "%{$_GET['search']}%"]])
|
||||
->orWhere([['subTitle', 'like', "%{$_GET['search']}%"]])->get();
|
||||
}
|
||||
if (isset($_GET['star'])) {
|
||||
Product::find($_GET['star'])->toggleStarred()->save();
|
||||
header('Location: '.$_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
if (empty($_GET)) {
|
||||
$template = 'productList.html.twig';
|
||||
$products = Product::with('price')->orderByDesc('starred')->orderByDesc('created_by')->get();
|
||||
}
|
||||
$twig->display($template, ['products' => $products ?? [], 'product' => $product ?? [], 'search' => $_GET['search'] ?? '']);
|
||||
@@ -1,15 +1,24 @@
|
||||
{
|
||||
"require": {
|
||||
"guzzlehttp/guzzle": "^7.0",
|
||||
"symfony/var-dumper": "^7.0",
|
||||
"illuminate/database": "11.26.0.0",
|
||||
"ext-json": "*",
|
||||
"twig/twig": "3.14.0.0",
|
||||
"symfony/console": "^7.0"
|
||||
"symfony/console": "^7.0",
|
||||
"symfony/routing": "^7.1",
|
||||
"laravel/serializable-closure": "^1.3",
|
||||
"symfony/http-kernel": "^7.1",
|
||||
"symfony/framework-bundle": "^7.1",
|
||||
"symfony/twig-bundle": "^7.1",
|
||||
"symfony/dotenv": "^7.1",
|
||||
"twig/intl-extra": "^3.13",
|
||||
"twig/extra-bundle": "^3.13"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Krzysiej\\RyobiCrawler\\": "src/"
|
||||
}
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/var-dumper": "^7.1"
|
||||
}
|
||||
}
|
||||
|
||||
1901
composer.lock
generated
1901
composer.lock
generated
File diff suppressed because it is too large
Load Diff
19
console.php
Normal file
19
console.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
include_once 'vendor/autoload.php';
|
||||
|
||||
use Krzysiej\RyobiCrawler\Command\Migrate;
|
||||
use Krzysiej\RyobiCrawler\Command\ScrapeWebsite;
|
||||
|
||||
use Symfony\Component\Console\Application;
|
||||
|
||||
if (php_sapi_name() !== 'cli') {
|
||||
header('Location: browser.php');
|
||||
echo 'Execute this script in cli only';
|
||||
exit;
|
||||
}
|
||||
|
||||
$application = new Application('Ryobi website scraper application', '1.1.1');
|
||||
$application->add(new ScrapeWebsite());
|
||||
$application->add(new Migrate());
|
||||
$application->run();
|
||||
@@ -1,9 +1,10 @@
|
||||
services:
|
||||
php-app:
|
||||
restart: unless-stopped
|
||||
build: .
|
||||
volumes:
|
||||
- .:/usr/src/app
|
||||
command: >
|
||||
sh -c "composer install && php -S 0.0.0.0:8000 -t /usr/src/app"
|
||||
ports:
|
||||
- "9000:8000"
|
||||
- "9001:8000"
|
||||
55
index.php
55
index.php
@@ -1,19 +1,50 @@
|
||||
<?php
|
||||
|
||||
include_once 'vendor/autoload.php';
|
||||
use Krzysiej\RyobiCrawler\Twig\AppExtension;
|
||||
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
use Symfony\Component\Dotenv\Dotenv;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
|
||||
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
|
||||
|
||||
use Krzysiej\RyobiCrawler\Command\Migrate;
|
||||
use Krzysiej\RyobiCrawler\Command\ScrapeWebsite;
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Symfony\Component\Console\Application;
|
||||
class Kernel extends BaseKernel
|
||||
{
|
||||
use MicroKernelTrait;
|
||||
|
||||
if (php_sapi_name() !== 'cli') {
|
||||
header('Location: browser.php');
|
||||
echo 'Execute this script in cli only';
|
||||
exit;
|
||||
public function registerBundles(): iterable
|
||||
{
|
||||
return [
|
||||
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
|
||||
new Symfony\Bundle\TwigBundle\TwigBundle(),
|
||||
new Twig\Extra\TwigExtraBundle\TwigExtraBundle(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function configureContainer(ContainerConfigurator $container): void
|
||||
{
|
||||
$container->extension('framework', [
|
||||
'secret' => 'S0ME_SECRET'
|
||||
]);
|
||||
$container->services()
|
||||
->load('Krzysiej\\RyobiCrawler\\Controller\\', __DIR__.'/src/Controller/*')
|
||||
->autowire()
|
||||
->autoconfigure()
|
||||
;
|
||||
$container->services()->set(AppExtension::class)->tag('twig.extension');
|
||||
}
|
||||
|
||||
protected function configureRoutes(RoutingConfigurator $routes): void
|
||||
{
|
||||
$routes->import(__DIR__.'/src/Controller/', 'attribute');
|
||||
}
|
||||
}
|
||||
(new Dotenv())->bootEnv(__DIR__.'/.env');
|
||||
|
||||
$application = new Application('Ryobi website scraper application', '1.1.1');
|
||||
$application->add(new ScrapeWebsite());
|
||||
$application->add(new Migrate());
|
||||
$application->run();
|
||||
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
|
||||
$request = Request::createFromGlobals();
|
||||
$response = $kernel->handle($request);
|
||||
$response->send();
|
||||
$kernel->terminate($request, $response);
|
||||
BIN
screenshot1.png
Normal file
BIN
screenshot1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 199 KiB |
@@ -9,13 +9,25 @@ use Illuminate\Database\Schema\Blueprint;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
#[AsCommand(name: 'app:migrate', description: 'Create database and rum migrations')]
|
||||
class Migrate extends Command
|
||||
{
|
||||
private const RECREATE_OPTION = 'recreate';
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->addOption(self::RECREATE_OPTION, null, InputOption::VALUE_OPTIONAL, 'Recreate database file event if exist and has data.');
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
if (true === $input->hasOption(self::RECREATE_OPTION)) {
|
||||
unlink(__DIR__ . '/../../database.sqlite');
|
||||
//sleep(5);
|
||||
}
|
||||
touch(__DIR__ . '/../../database.sqlite');
|
||||
$capsule = new Capsule;
|
||||
$capsule->addConnection([
|
||||
@@ -24,10 +36,6 @@ class Migrate extends Command
|
||||
]);
|
||||
$capsule->setAsGlobal();
|
||||
$capsule->bootEloquent();
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$this->createProductsTable();
|
||||
$this->createPricesTable();
|
||||
$this->createStocksTable();
|
||||
@@ -42,9 +50,7 @@ class Migrate extends Command
|
||||
$table->increments('id');
|
||||
$table->string('name');
|
||||
$table->integer('skuID')->unique();
|
||||
$table->integer('agilityID');
|
||||
$table->integer('availableQuantity');
|
||||
$table->integer('stock');
|
||||
$table->json('categories');
|
||||
$table->string('image');
|
||||
$table->string('subTitle');
|
||||
|
||||
@@ -68,7 +68,7 @@ class ScrapeWebsite extends Command
|
||||
$products = array_merge($products, $responseObject->products);
|
||||
$page++;
|
||||
$canLoadMore = $responseObject->canLoadMore;
|
||||
} catch (GuzzleException $e) {
|
||||
} catch (GuzzleException) {
|
||||
return $products;
|
||||
}
|
||||
} while ($canLoadMore);
|
||||
@@ -80,19 +80,21 @@ class ScrapeWebsite extends Command
|
||||
{
|
||||
/** @var Product $productModel */
|
||||
$productModel = Product::firstOrNew(['skuID' => $product->skuID]);
|
||||
|
||||
$productModel->skuID = $product->skuID;
|
||||
$productModel->name = $product->name;
|
||||
$productModel->availableQuantity = $product->availableQuantity;
|
||||
$productModel->stock = $product->stock;
|
||||
$productModel->categories = json_encode($product->categories);
|
||||
$productModel->categories = $product->categories;
|
||||
$productModel->image = $product->image;
|
||||
$productModel->subTitle = $product->subTitle;
|
||||
$productModel->variantCode = $product->variantCode;
|
||||
$productModel->modelCode = $product->modelCode;
|
||||
$productModel->url = $product->url;
|
||||
$productModel->touch('updated_at');
|
||||
$productModel->save();
|
||||
$priceExists = $productModel->price()->whereRaw("strftime('%Y-%m-%d', created_at) = ?", [date('Y-m-d')])->exists();
|
||||
if (!$priceExists) {
|
||||
|
||||
if (false === $priceExists) {
|
||||
$price = new Price();
|
||||
$price->price = $product->productPrice;
|
||||
$price->productStandardPrice = $product->productStandardPrice;
|
||||
@@ -100,7 +102,7 @@ class ScrapeWebsite extends Command
|
||||
$productModel->price()->save($price);
|
||||
}
|
||||
$stockExist = $productModel->stock()->whereRaw("strftime('%Y-%m-%d', created_at) = ?", [date('Y-m-d')])->exists();
|
||||
if (!$stockExist) {
|
||||
if (false === $stockExist) {
|
||||
$stock = new Stock();
|
||||
$stock->availableQuantity = $product->availableQuantity;
|
||||
$stock->stock = $product->stock;
|
||||
|
||||
37
src/Controller/BaseController.php
Normal file
37
src/Controller/BaseController.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Krzysiej\RyobiCrawler\Controller;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Twig\Environment;
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
class BaseController extends AbstractController
|
||||
{
|
||||
protected Environment $twig;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$capsule = new Capsule;
|
||||
$capsule->addConnection(['driver' => 'sqlite', 'database' => __DIR__ . '/../../database.sqlite']);
|
||||
$capsule->setAsGlobal();
|
||||
$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;
|
||||
}
|
||||
}
|
||||
24
src/Controller/CategoryController.php
Normal file
24
src/Controller/CategoryController.php
Normal 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;
|
||||
|
||||
final class CategoryController extends BaseController
|
||||
{
|
||||
#[Route('/category/{category}', name: 'app_category')]
|
||||
public function __invoke(string $category): Response
|
||||
{
|
||||
$products = Product::with('price')
|
||||
->selectRaw('products.*')
|
||||
->distinct('products.id')
|
||||
->fromRaw('products, json_each(products.categories)')
|
||||
->whereRaw('json_each.value = ?', [$category])
|
||||
->orderByDesc('starred')
|
||||
->orderByDesc('created_by')
|
||||
->get();
|
||||
return $this->render('productList.html.twig', ['products' => $products]);
|
||||
}
|
||||
}
|
||||
24
src/Controller/DiscontinuedController.php
Normal file
24
src/Controller/DiscontinuedController.php
Normal 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]);
|
||||
}
|
||||
}
|
||||
19
src/Controller/IndexController.php
Normal file
19
src/Controller/IndexController.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Krzysiej\RyobiCrawler\Controller;
|
||||
|
||||
use Krzysiej\RyobiCrawler\Models\Product;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
final class IndexController extends BaseController
|
||||
{
|
||||
#[Route('/', name: 'app_home')]
|
||||
public function __invoke(Request $request): Response
|
||||
{
|
||||
$products = Product::with(['currentStock', 'price', 'currentPrice']);
|
||||
$products = $this->handleOrderProducts($products, $request)->get();
|
||||
return $this->render('productList.html.twig', ['products' => $products]);
|
||||
}
|
||||
}
|
||||
25
src/Controller/NewController.php
Normal file
25
src/Controller/NewController.php
Normal 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]);
|
||||
}
|
||||
}
|
||||
51
src/Controller/ProductController.php
Normal file
51
src/Controller/ProductController.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Krzysiej\RyobiCrawler\Controller;
|
||||
|
||||
use Krzysiej\RyobiCrawler\Models\Product;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Twig\Error\LoaderError;
|
||||
use Twig\Error\RuntimeError;
|
||||
use Twig\Error\SyntaxError;
|
||||
|
||||
final class ProductController extends BaseController
|
||||
{
|
||||
/**
|
||||
* @throws SyntaxError
|
||||
* @throws RuntimeError
|
||||
* @throws LoaderError
|
||||
*/
|
||||
#[Route('/product/{productId<\d+>}', name: 'app_product')]
|
||||
public function __invoke(int $productId): Response
|
||||
{
|
||||
$product = Product::with([
|
||||
'price' => fn($query) => $query->orderBy('created_at', 'desc'),
|
||||
'stock' => fn($query) => $query->orderBy('created_at', 'desc'),
|
||||
])->find($productId);
|
||||
if (null === $product) {
|
||||
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();
|
||||
|
||||
return $this->render('product.html.twig', [
|
||||
'product' => $product,
|
||||
'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);
|
||||
}
|
||||
}
|
||||
22
src/Controller/PromosController.php
Normal file
22
src/Controller/PromosController.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?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;
|
||||
|
||||
final class PromosController extends BaseController
|
||||
{
|
||||
#[Route('/promos', name: 'app_promos')]
|
||||
public function __invoke(): Response
|
||||
{
|
||||
$products = Product::whereHas('currentPrice', fn(Builder $query) => $query->whereColumn('price', '<', 'productStandardPrice'))
|
||||
->orderByDesc('starred')
|
||||
->orderByDesc('created_by')
|
||||
->with(['currentPrice'])
|
||||
->get();
|
||||
return $this->render('productList.html.twig', ['products' => $products]);
|
||||
}
|
||||
}
|
||||
22
src/Controller/SearchController.php
Normal file
22
src/Controller/SearchController.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Krzysiej\RyobiCrawler\Controller;
|
||||
|
||||
use Krzysiej\RyobiCrawler\Models\Product;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
final class SearchController extends BaseController
|
||||
{
|
||||
#[Route('/search', name: 'app_search')]
|
||||
public function __invoke(Request $request): Response
|
||||
{
|
||||
$search = $request->query->get('search');
|
||||
$products = Product::with('price')
|
||||
->orWhere([['name', 'like', "%$search%"]])
|
||||
->orWhere([['subTitle', 'like', "%$search%"]])->get();
|
||||
|
||||
return $this->render('productList.html.twig', ['products' => $products ?? [], 'search' => $search]);
|
||||
}
|
||||
}
|
||||
18
src/Controller/StarController.php
Normal file
18
src/Controller/StarController.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Krzysiej\RyobiCrawler\Controller;
|
||||
|
||||
use Krzysiej\RyobiCrawler\Models\Product;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
final class StarController extends BaseController
|
||||
{
|
||||
#[Route('/star/{productId<\d+>}', name: 'app_star')]
|
||||
public function __invoke(int $productId, Request $request): Response
|
||||
{
|
||||
Product::find($productId)->toggleStarred()->save();
|
||||
return $this->redirect($request->headers->get('referer'));
|
||||
}
|
||||
}
|
||||
@@ -5,20 +5,21 @@ namespace Krzysiej\RyobiCrawler\Models;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
use function Symfony\Component\Clock\now;
|
||||
|
||||
/**
|
||||
* @property integer $skuID
|
||||
* @property integer $agilityID
|
||||
* @property string $name
|
||||
* @property integer $availableQuantity
|
||||
* @property integer $stock
|
||||
* @property string[] $categories
|
||||
* @property string $image
|
||||
* @property string $subTitle
|
||||
* @property string $variantCode
|
||||
* @property string $modelCode
|
||||
* @property string $url
|
||||
* @property boolean $starred
|
||||
* @property int $starred
|
||||
*/
|
||||
class Product extends Model
|
||||
{
|
||||
@@ -29,21 +30,50 @@ class Product extends Model
|
||||
{
|
||||
return $this->hasMany(Price::class);
|
||||
}
|
||||
|
||||
public function isStarred(): bool
|
||||
{
|
||||
return (bool)$this->starred;
|
||||
}
|
||||
|
||||
public function currentPrice(): HasOne
|
||||
{
|
||||
return $this->hasOne(Price::class)->latestOfMany('created_at');
|
||||
}
|
||||
|
||||
public function stock(): HasMany
|
||||
{
|
||||
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
|
||||
{
|
||||
$this->starred = !$this->starred;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function categories(): Attribute
|
||||
public function categories(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn(string $value) => array_reverse(json_decode($value, 1)),
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
53
src/Twig/AppExtension.php
Normal file
53
src/Twig/AppExtension.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Krzysiej\RyobiCrawler\Twig;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Krzysiej\RyobiCrawler\Models\Price;
|
||||
use Krzysiej\RyobiCrawler\Models\Product;
|
||||
use Krzysiej\RyobiCrawler\Models\Stock;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
use function Symfony\Component\Clock\now;
|
||||
|
||||
class AppExtension extends AbstractExtension
|
||||
{
|
||||
public function getFunctions(): array
|
||||
{
|
||||
return [
|
||||
new TwigFunction('promosCount', [$this, 'promosCount']),
|
||||
new TwigFunction('newCount', [$this, 'newCount']),
|
||||
new TwigFunction('discontinuedCount', [$this, 'discontinuedCount']),
|
||||
];
|
||||
}
|
||||
|
||||
public function getFilters(): array
|
||||
{
|
||||
return [
|
||||
new TwigFilter('findByCreatedAtDate', [$this, 'findByCreatedAtDate']),
|
||||
];
|
||||
}
|
||||
|
||||
public function promosCount(): int
|
||||
{
|
||||
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
|
||||
{
|
||||
return $items->first(fn($item) => str_starts_with($item->created_at, $date));
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
{% extends "template.html.twig" %}
|
||||
|
||||
{% block content %}
|
||||
<table class='table table-hover'>
|
||||
<tr>
|
||||
<td><img src='{{ product.image }}&width=150' class='img-fluid' alt='{{ product.name }}'/></td>
|
||||
<td><a href='?product_id={{ product.id }}'>{{ product.name }}</a></td>
|
||||
<td>{{ product.subTitle }}</td>
|
||||
<td>
|
||||
<ul class='nav'>
|
||||
{% for category in product.categories %}
|
||||
<li class="nav-item"><a class="nav-link" href="?category={{ category }}"> {{ category }} </a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</td>
|
||||
<td><a href='https://pl.ryobitools.eu/{{ product.url }}'>link</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="4">
|
||||
|
||||
<table class='table table-hover table-sm mb-0'>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>price</th>
|
||||
<th>lowest product price in 30 days</th>
|
||||
<th colspan='2'>standard price</th>
|
||||
</tr>
|
||||
</thead>
|
||||
{% for price in product.price %}
|
||||
<tr>
|
||||
<td>{{ price.price }}</td>
|
||||
<td>{{ price.lowestProductPrice30Days }}</td>
|
||||
<td>{{ price.productStandardPrice }}</td>
|
||||
<td>{{ price.created_at }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
{% extends "template.html.twig" %}
|
||||
|
||||
{% block content %}
|
||||
<table class='table table-hover'>
|
||||
{% for product in products %}
|
||||
<tr>
|
||||
<td class="align-middle font-weight-bold h3"><a class="text-warning text-decoration-none" href="?star={{ product.id }}">{% if product.starred %}★{% else %} ☆ {% endif %}</a></td>
|
||||
<td><img src='{{ product.image }}&width=70' class='img-fluid' alt='{{ product.name }}'/></td>
|
||||
<td class="align-middle"><a href='?product_id={{ product.id }}'>{{ product.name }}</a></td>
|
||||
<td class="align-middle">{{ product.subTitle }}</td>
|
||||
<td class="align-middle">
|
||||
<ul class='nav'>
|
||||
{% for category in product.categories %}
|
||||
<li class="nav-item"><a class="nav-link" href="?category={{ category }}"> {{ category }} </a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</td>
|
||||
<td class="align-middle"><a href='https://pl.ryobitools.eu/{{ product.url }}'>link</a></td>
|
||||
<td class="align-middle">{{ product.price.last.price }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% endblock %}
|
||||
@@ -1,24 +0,0 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<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">
|
||||
<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"
|
||||
crossorigin="anonymous"/>
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar sticky-top bg-body-tertiary border-bottom border-secondary border-1">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="/browser.php">Crawler</a>
|
||||
<form class="d-flex w-50" role="search">
|
||||
<input class="form-control me-2" type="search" name="search" placeholder="Search term eg. 36v or RCS18X" value="{{ search }}" aria-label="Search">
|
||||
<button class="btn btn-outline-success" type="submit">Search</button>
|
||||
</form>
|
||||
</div>
|
||||
</nav>
|
||||
{% block content %}{% endblock %}
|
||||
</body>
|
||||
</html>
|
||||
|
||||
6
templates/css/bootstrap.min.css
vendored
Normal file
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
4
templates/js/script.js
Normal file
@@ -0,0 +1,4 @@
|
||||
(function() {
|
||||
const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]')
|
||||
const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl))
|
||||
})();
|
||||
133
templates/product.html.twig
Normal file
133
templates/product.html.twig
Normal file
@@ -0,0 +1,133 @@
|
||||
{% extends "template.html.twig" %}
|
||||
|
||||
{% block content %}
|
||||
<div class="table-responsive">
|
||||
<table class='table table-hover'>
|
||||
<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 %}★{% else %} ☆ {% endif %}</a></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>
|
||||
<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 %}
|
||||
<li class="breadcrumb-item" aria-current="page"><a class="breadcrumb-item text-decoration-none"
|
||||
href="{{ path('app_category', {'category': category}) }}">{{ category }}</a></li>
|
||||
{% endfor %}
|
||||
</ol>
|
||||
</nav>
|
||||
</td>
|
||||
<td><a href='https://pl.ryobitools.eu/{{ product.url }}'>link</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5">
|
||||
<div style="width: 800px;">
|
||||
<canvas id="price"></canvas>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5">
|
||||
<table class='table table-hover table-sm mb-0'>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>price</th>
|
||||
<th>lowest product price in 30 days</th>
|
||||
<th colspan='2'>standard price</th>
|
||||
<th>Stock</th>
|
||||
</tr>
|
||||
</thead>
|
||||
{% for price in product.price %}
|
||||
<tr>
|
||||
<td>{{ price.price | format_currency('PLN', {}, 'pl') }}</td>
|
||||
<td>{{ price.lowestProductPrice30Days | format_currency('PLN', {}, 'pl') }}</td>
|
||||
<td>{{ price.productStandardPrice | format_currency('PLN', {}, 'pl') }}</td>
|
||||
<td>{{ price.created_at }}</td>
|
||||
<td>{{ (product.stock | findByCreatedAtDate(price.created_at | slice(0,10))).stock ?? '' }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||
|
||||
<script>
|
||||
const ctx = document.getElementById('price').getContext('2d');
|
||||
|
||||
new Chart(ctx, {
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: ['{{ price_dates|raw }}'],
|
||||
datasets: [
|
||||
{
|
||||
label: 'Price (PLN)',
|
||||
data: {{ price_list|raw }},
|
||||
yAxisID: 'yPrice',
|
||||
tension: 0.1,
|
||||
borderWidth: 1
|
||||
},
|
||||
{
|
||||
label: 'Stock (units)',
|
||||
data: {{ stock_list|raw }},
|
||||
yAxisID: 'yStock',
|
||||
tension: 0.1,
|
||||
borderWidth: 1
|
||||
}
|
||||
]
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
animation: false,
|
||||
scales: {
|
||||
x: {
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Date'
|
||||
}
|
||||
},
|
||||
yPrice: {
|
||||
type: 'linear',
|
||||
position: 'left',
|
||||
beginAtZero: true,
|
||||
title: {
|
||||
display: true,
|
||||
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'
|
||||
},
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
61
templates/productList.html.twig
Normal file
61
templates/productList.html.twig
Normal file
@@ -0,0 +1,61 @@
|
||||
{% extends "template.html.twig" %}
|
||||
|
||||
{% block content %}
|
||||
<div class="table-responsive">
|
||||
{{ app.request.get('order') }}
|
||||
<table class='table table-hover'>
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th></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>Categories</th>
|
||||
<th></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>
|
||||
</tr>
|
||||
</thead>
|
||||
{% for product in products %}
|
||||
<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" style="width: 120px;"><img src='{{ product.image }}&width=70' class='img-thumbnail' alt='{{ product.name }}'/></td>
|
||||
<td class="align-middle">
|
||||
<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 %}
|
||||
<li class="breadcrumb-item" aria-current="page"><a class="breadcrumb-item text-decoration-none" href="{{ path('app_category', {'category': category}) }}">{{ category }}</a></li>
|
||||
{% endfor %}
|
||||
</ol>
|
||||
</nav>
|
||||
</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">
|
||||
<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> <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>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
{% endblock %}
|
||||
46
templates/template.html.twig
Normal file
46
templates/template.html.twig
Normal file
@@ -0,0 +1,46 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<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">
|
||||
<title>Ryobi crawler</title>
|
||||
<link href="/templates/css/bootstrap.min.css" rel="stylesheet" />
|
||||
<script src="/templates/js/script.js" defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-lg sticky-top bg-body-tertiary border-bottom border-secondary border-1">
|
||||
<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">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
||||
<li class="nav-item">
|
||||
<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>
|
||||
</ul>
|
||||
|
||||
<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>
|
||||
<label for="floatingInputValue">Search term eg. 36v or RCS18X</label>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</nav>
|
||||
{% block content %}{% endblock %}
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user