Use MicroKernelTrait to bootstrap application. Rewrote routes, controllers and structure of application a bit. Including use of twig.

This commit is contained in:
Krzysztof Płaczek
2024-10-19 16:01:54 +02:00
parent 3d47726a81
commit 5ee1bba812
16 changed files with 1593 additions and 73 deletions

View File

@@ -0,0 +1,91 @@
{% extends "template.html.twig" %}
{% block content %}
<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_home') }}/product/{{ product.id }}' class="text-decoration-none">{{ 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="{{ path('app_category', {'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">
<div style="width: 800px;">
<canvas id="price"></canvas>
</div>
</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>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
const ctx = document.getElementById('price');
new Chart(ctx, {
type: 'line',
data: {
labels: ['{{ price_dates|raw }}'],
datasets: [{
label: 'Price (PLN)',
data: [{{ price_list }}],
borderWidth: 1
}]
},
options: {
animation: false,
plugins: {
title: {
display: true,
text: 'Price in time'
},
},
scales: {
x: {
title: {
display: true,
text: 'Date'
}
},
y: {
beginAtZero: true,
title: {
display: true,
text: 'Price'
}
}
}
}
});
</script>
{% endblock %}

View File

@@ -0,0 +1,35 @@
{% extends "template.html.twig" %}
{% block content %}
<table class='table table-hover'>
<thead>
<tr>
<th></th>
<th></th>
<th>Name</th>
<th>Code</th>
<th>Categories</th>
<th></th>
<th>Price</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='border rounded p-1' alt='{{ product.name }}'/></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">{{ product.subTitle }}</td>
<td class="align-middle">
<ul class='nav'>
{% for category in product.categories %}
<li class="nav-item"><a class="nav-link" href="{{ path('app_category', {'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>
<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 }}</span> <span class="text-success">{{ ((1 - product.price.last.price / product.price.last.productStandardPrice)*100)|number_format(0) }}%</span>{% else %}{% endif %}</td>
</tr>
{% endfor %}
</table>
{% endblock %}

View File

@@ -0,0 +1,36 @@
<!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 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">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="{{ path('app_promos') }}">Promos</a>
</li>
</ul>
</div>
</div>
<form class="d-flex w-50" 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">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
</nav>
{% block content %}{% endblock %}
</body>
</html>