Show first steps on homepage when no parts were created yet.

This commit is contained in:
Jan Böhmer 2023-02-05 21:37:48 +01:00
parent 8447b8b42a
commit b8da4c62d0
3 changed files with 64 additions and 8 deletions

View file

@ -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,
]);
}

View file

@ -17,6 +17,26 @@
{% endif %}
</div>
{% if show_first_steps %}
<div class="card border-info mt-3">
<div class="card-header bg-info ">
<h4><i class="fa fa-circle-play fa-fw " aria-hidden="true"></i> {% trans %}homepage.first_steps.title{% endtrans %}</h4>
</div>
<div class="card-body">
<div>{% trans with {"%url%": "https://github.com/Part-DB/Part-DB-symfony/wiki/Getting-started"} %}homepage.first_steps.introduction{% endtrans %}</div>
<ul>
<li><a href="{{ path("category_new") }}">{{ 'category.labelp'|trans }}</a></li>
<li><a href="{{ path("store_location_new") }}">{{ 'storelocation.labelp'|trans }}</a></li>
<li><a href="{{ path("footprint_new") }}">{{ 'footprint.labelp'|trans }}</a></li>
<li><a href="{{ path("supplier_new") }}">{{ 'supplier.labelp'|trans }}</a></li>
<li><a href="{{ path("manufacturer_new") }}">{{ 'manufacturer.labelp'|trans }}</a></li>
</ul>
<div>{% trans with {"%url%": path('part_new')} %}homepage.first_steps.create_part{% endtrans %}</div>
<div class="text-muted">{% trans %}homepage.first_steps.hide_hint{% endtrans %}</div>
</div>
</div>
{% endif %}
<div class="card border-primary mt-3">
<div class="card-header bg-primary text-white">
<h4><i class="fa fa-book fa-fw" aria-hidden="true"></i> {% trans %}homepage.license{% endtrans %}</h4>

View file

@ -10434,5 +10434,29 @@ Element 3</target>
<target>Save and create new empty part</target>
</segment>
</unit>
<unit id="q2IWd9b" name="homepage.first_steps.title">
<segment>
<source>homepage.first_steps.title</source>
<target>First steps</target>
</segment>
</unit>
<unit id="qoK8lss" name="homepage.first_steps.introduction">
<segment>
<source>homepage.first_steps.introduction</source>
<target><![CDATA[Your database is still empty. You might want to read the <a href="%url%">documentation</a> or start to creating the following data structures:]]></target>
</segment>
</unit>
<unit id="8RkT6ZQ" name="homepage.first_steps.create_part">
<segment>
<source>homepage.first_steps.create_part</source>
<target><![CDATA[Or you can directly <a href="%url%">create a new part</a>.]]></target>
</segment>
</unit>
<unit id="mBSlTrA" name="homepage.first_steps.hide_hint">
<segment>
<source>homepage.first_steps.hide_hint</source>
<target>This box will hide as soon as you have created your first part.</target>
</segment>
</unit>
</file>
</xliff>