From b8da4c62d0e1ed286fd4cef9ca7f2e31b67a9192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sun, 5 Feb 2023 21:37:48 +0100 Subject: [PATCH] Show first steps on homepage when no parts were created yet. --- src/Controller/HomepageController.php | 16 ++++++++++++-- templates/homepage.html.twig | 32 ++++++++++++++++++++++----- translations/messages.en.xlf | 24 ++++++++++++++++++++ 3 files changed, 64 insertions(+), 8 deletions(-) diff --git a/src/Controller/HomepageController.php b/src/Controller/HomepageController.php index 49d2252b..51447c17 100644 --- a/src/Controller/HomepageController.php +++ b/src/Controller/HomepageController.php @@ -23,7 +23,9 @@ declare(strict_types=1); namespace App\Controller; use App\DataTables\LogDataTable; +use App\Entity\Parts\Part; use App\Services\Misc\GitVersionInfo; +use Doctrine\ORM\EntityManagerInterface; use const DIRECTORY_SEPARATOR; use Omines\DataTablesBundle\DataTableFactory; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; @@ -62,7 +64,7 @@ class HomepageController extends AbstractController /** * @Route("/", name="homepage") */ - public function homepage(Request $request, GitVersionInfo $versionInfo): Response + public function homepage(Request $request, GitVersionInfo $versionInfo, EntityManagerInterface $entityManager): Response { if ($this->isGranted('@tools.lastActivity')) { $table = $this->dataTable->createFromType( @@ -81,11 +83,21 @@ class HomepageController extends AbstractController $table = null; } + $show_first_steps = false; + //When the user is allowed to create parts and no parts are in the database, show the first steps + if ($this->isGranted('@parts.create')) { + $repo = $entityManager->getRepository(Part::class); + $number_of_parts = $repo->count([]); + if (0 === $number_of_parts) { + $show_first_steps = true; + } + } + return $this->render('homepage.html.twig', [ 'banner' => $this->getBanner(), 'git_branch' => $versionInfo->getGitBranchName(), 'git_commit' => $versionInfo->getGitCommitHash(), - 'show_first_steps' => true, + 'show_first_steps' => $show_first_steps, 'datatable' => $table, ]); } diff --git a/templates/homepage.html.twig b/templates/homepage.html.twig index 74263e56..3eb79184 100644 --- a/templates/homepage.html.twig +++ b/templates/homepage.html.twig @@ -17,6 +17,26 @@ {% endif %} + {% if show_first_steps %} +
+
+

{% trans %}homepage.first_steps.title{% endtrans %}

+
+
+
{% trans with {"%url%": "https://github.com/Part-DB/Part-DB-symfony/wiki/Getting-started"} %}homepage.first_steps.introduction{% endtrans %}
+ +
{% trans with {"%url%": path('part_new')} %}homepage.first_steps.create_part{% endtrans %}
+
{% trans %}homepage.first_steps.hide_hint{% endtrans %}
+
+
+ {% endif %} +

{% trans %}homepage.license{% endtrans %}

@@ -35,12 +55,12 @@
{% if datatable is not null %} -
-
{% trans %}homepage.last_activity{% endtrans %}
-
- {% import "components/history_log_macros.html.twig" as log %} - {{ log.last_activity_component(datatable) }} +
+
{% trans %}homepage.last_activity{% endtrans %}
+
+ {% import "components/history_log_macros.html.twig" as log %} + {{ log.last_activity_component(datatable) }} +
-
{% endif %} {% endblock %} \ No newline at end of file diff --git a/translations/messages.en.xlf b/translations/messages.en.xlf index 64a3954a..6a9d680d 100644 --- a/translations/messages.en.xlf +++ b/translations/messages.en.xlf @@ -10434,5 +10434,29 @@ Element 3 Save and create new empty part + + + homepage.first_steps.title + First steps + + + + + homepage.first_steps.introduction + documentation or start to creating the following data structures:]]> + + + + + homepage.first_steps.create_part + create a new part.]]> + + + + + homepage.first_steps.hide_hint + This box will hide as soon as you have created your first part. + +