Skip to content

Commit 4b00697

Browse files
committed
Allow to customize which items get shown on the homepage and in which order
This fixes issue #470 and #894
1 parent 617ae03 commit 4b00697

File tree

4 files changed

+117
-17
lines changed

4 files changed

+117
-17
lines changed

src/Settings/SystemSettings/CustomizationSettings.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@
2828
use App\Settings\SettingsIcon;
2929
use App\Validator\Constraints\ValidTheme;
3030
use Jbtronics\SettingsBundle\Metadata\EnvVarMode;
31+
use Jbtronics\SettingsBundle\ParameterTypes\ArrayType;
32+
use Jbtronics\SettingsBundle\ParameterTypes\EnumType;
3133
use Jbtronics\SettingsBundle\Settings\Settings;
3234
use Jbtronics\SettingsBundle\Settings\SettingsParameter;
3335
use Jbtronics\SettingsBundle\Settings\SettingsTrait;
3436
use Symfony\Component\Translation\TranslatableMessage as TM;
37+
use Symfony\Component\Validator\Constraints as Assert;
3538

3639
#[Settings(name: "customization", label: new TM("settings.system.customization"))]
3740
#[SettingsIcon("fa-paint-roller")]
@@ -46,17 +49,31 @@ class CustomizationSettings
4649
)]
4750
public string $instanceName = "Part-DB";
4851

52+
#[SettingsParameter(
53+
label: new TM("settings.system.customization.theme"),
54+
formType: ThemeChoiceType::class, formOptions: ['placeholder' => false]
55+
)]
56+
#[ValidTheme]
57+
public string $theme = 'bootstrap';
58+
4959
#[SettingsParameter(
5060
label: new TM("settings.system.customization.banner"),
5161
formType: RichTextEditorType::class, formOptions: ['mode' => 'markdown-full'],
5262
envVar: "BANNER", envVarMode: EnvVarMode::OVERWRITE,
5363
)]
5464
public ?string $banner = null;
5565

56-
#[SettingsParameter(
57-
label: new TM("settings.system.customization.theme"),
58-
formType: ThemeChoiceType::class, formOptions: ['placeholder' => false]
66+
/**
67+
* @var HomepageItems[] The items to show in the sidebar.
68+
*/
69+
#[SettingsParameter(ArrayType::class,
70+
label: new TM("settings.behavior.hompepage.items"),
71+
description: new TM("settings.behavior.homepage.items.help"),
72+
options: ['type' => EnumType::class, 'options' => ['class' => HomepageItems::class]],
73+
formType: \Symfony\Component\Form\Extension\Core\Type\EnumType::class,
74+
formOptions: ['class' => HomepageItems::class, 'multiple' => true, 'ordered' => true]
5975
)]
60-
#[ValidTheme]
61-
public string $theme = 'bootstrap';
76+
#[Assert\NotBlank()]
77+
#[Assert\Unique()]
78+
public array $homepageitems = [HomepageItems::SEARCH, HomepageItems::BANNER, HomepageItems::FIRST_STEPS, HomepageItems::LICENSE, HomepageItems::LAST_ACTIVITY];
6279
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/*
3+
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
4+
*
5+
* Copyright (C) 2019 - 2025 Jan Böhmer (https://github.com/jbtronics)
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Affero General Public License as published
9+
* by the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Affero General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public License
18+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
declare(strict_types=1);
22+
23+
24+
namespace App\Settings\SystemSettings;
25+
26+
use Symfony\Contracts\Translation\TranslatableInterface;
27+
use Symfony\Contracts\Translation\TranslatorInterface;
28+
29+
use function Symfony\Component\Translation\t;
30+
31+
enum HomepageItems: string implements TranslatableInterface
32+
{
33+
case SEARCH = 'search';
34+
case BANNER = 'banner';
35+
case LICENSE = 'license';
36+
case FIRST_STEPS = 'first_steps';
37+
case LAST_ACTIVITY = 'last_activity';
38+
39+
public function trans(TranslatorInterface $translator, ?string $locale = null): string
40+
{
41+
$key = match($this) {
42+
self::SEARCH => 'search.placeholder',
43+
self::BANNER => 'settings.system.customization.banner',
44+
self::LICENSE => 'homepage.license',
45+
self::FIRST_STEPS => 'homepage.first_steps.title',
46+
self::LAST_ACTIVITY => 'homepage.last_activity',
47+
};
48+
49+
return $translator->trans($key, locale: $locale);
50+
}
51+
}

templates/homepage.html.twig

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,13 @@
44
{% import "components/search.macro.html.twig" as search %}
55
{% import "vars.macro.twig" as vars %}
66

7-
{% block content %}
8-
9-
{% if is_granted('@system.show_updates') %}
10-
{{ nv.new_version_alert(new_version_available, new_version, new_version_url) }}
11-
{% endif %}
12-
7+
{% block item_search %}
138
{% if is_granted('@parts.read') %}
149
{{ search.search_form("standalone") }}
15-
<div class="mb-2"></div>
1610
{% endif %}
11+
{% endblock %}
1712

18-
13+
{% block item_banner %}
1914
<div class="rounded p-4 bg-body-secondary">
2015
<h1 class="display-3">{{ vars.partdb_title() }}</h1>
2116
<h4>
@@ -31,9 +26,11 @@
3126
</div>
3227
{% endif %}
3328
</div>
29+
{% endblock %}
3430

31+
{% block item_first_steps %}
3532
{% if show_first_steps %}
36-
<div class="card border-info mt-3">
33+
<div class="card border-info">
3734
<div class="card-header bg-info ">
3835
<h4><i class="fa fa-circle-play fa-fw " aria-hidden="true"></i> {% trans %}homepage.first_steps.title{% endtrans %}</h4>
3936
</div>
@@ -51,8 +48,10 @@
5148
</div>
5249
</div>
5350
{% endif %}
51+
{% endblock %}
5452

55-
<div class="card border-primary mt-3">
53+
{% block item_license %}
54+
<div class="card border-primary">
5655
<div class="card-header bg-primary text-white">
5756
<h4><i class="fa fa-book fa-fw" aria-hidden="true"></i> {% trans %}homepage.license{% endtrans %}</h4>
5857
</div>
@@ -68,14 +67,35 @@
6867
<strong><i class="fas fa-comments fa-fw"></i> {% trans %}homepage.forum.caption{% endtrans %}:</strong> {% trans with {'%href%': 'https://github.com/Part-DB/Part-DB-server/discussions'}%}homepage.forum.text{% endtrans %}<br>
6968
</div>
7069
</div>
70+
{% endblock %}
7171

72+
{% block item_last_activity %}
7273
{% if datatable is not null %}
73-
<div class="card mt-3">
74+
<div class="card">
7475
<div class="card-header"><i class="fas fa-fw fa-history"></i> {% trans %}homepage.last_activity{% endtrans %}</div>
7576
<div class="card-body">
7677
{% import "components/history_log_macros.html.twig" as log %}
7778
{{ log.last_activity_component(datatable) }}
7879
</div>
7980
</div>
8081
{% endif %}
81-
{% endblock %}
82+
{% endblock %}
83+
84+
{% block content %}
85+
86+
{% if is_granted('@system.show_updates') %}
87+
{{ nv.new_version_alert(new_version_available, new_version, new_version_url) }}
88+
{% endif %}
89+
90+
{% for item in settings_instance('customization').homepageitems %}
91+
{% if block('item_' ~ item.value) is defined %}
92+
{{ block('item_' ~ item.value) }}
93+
<div class="mb-2"></div>
94+
{% else %}
95+
<div class="alert alert-warning mt-3" role="alert">
96+
Alert: The homepage item "{{ item.value }}" is not defined!
97+
</div>
98+
{% endif %}
99+
{% endfor %}
100+
101+
{% endblock %}

translations/messages.en.xlf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13441,5 +13441,17 @@ Please note, that you can not impersonate a disabled user. If you try you will g
1344113441
<target>Label profile updated successfully.</target>
1344213442
</segment>
1344313443
</unit>
13444+
<unit id="7lgFa7I" name="settings.behavior.hompepage.items">
13445+
<segment>
13446+
<source>settings.behavior.hompepage.items</source>
13447+
<target>Homepage items</target>
13448+
</segment>
13449+
</unit>
13450+
<unit id="FsrRdkp" name="settings.behavior.homepage.items.help">
13451+
<segment>
13452+
<source>settings.behavior.homepage.items.help</source>
13453+
<target><![CDATA[The items to show at the homepage. Order can be changed via drag & drop.]]></target>
13454+
</segment>
13455+
</unit>
1344413456
</file>
1344513457
</xliff>

0 commit comments

Comments
 (0)