Skip to content

Commit 377feaf

Browse files
committed
Use yellow alert box for notifying of empty bom on build, show infinite correclty and added translations
Fixes issue #1038
1 parent 05839a5 commit 377feaf

File tree

5 files changed

+47
-10
lines changed

5 files changed

+47
-10
lines changed

src/Services/ProjectSystem/ProjectBuildHelper.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
/**
3232
* @see \App\Tests\Services\ProjectSystem\ProjectBuildHelperTest
3333
*/
34-
class ProjectBuildHelper
34+
final readonly class ProjectBuildHelper
3535
{
36-
public function __construct(private readonly PartLotWithdrawAddHelper $withdraw_add_helper)
36+
public function __construct(private PartLotWithdrawAddHelper $withdraw_add_helper)
3737
{
3838
}
3939

@@ -79,6 +79,21 @@ public function getMaximumBuildableCount(Project $project): int
7979
return $maximum_buildable_count;
8080
}
8181

82+
/**
83+
* Returns the maximum buildable amount of the given project as string, based on the stock of the used parts in the BOM.
84+
* If the maximum buildable count is infinite, the string '∞' is returned.
85+
* @param Project $project
86+
* @return string
87+
*/
88+
public function getMaximumBuildableCountAsString(Project $project): string
89+
{
90+
$max_count = $this->getMaximumBuildableCount($project);
91+
if ($max_count === PHP_INT_MAX) {
92+
return '';
93+
}
94+
return (string) $max_count;
95+
}
96+
8297
/**
8398
* Checks if the given project can be built with the current stock.
8499
* This means that the maximum buildable count is greater or equal than the requested $number_of_projects

templates/projects/build/build.html.twig

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818
</div>
1919
{% endif %}
2020

21-
<div class="alert {% if can_build %}alert-success{% else %}alert-danger{% endif %}" role="alert">
21+
<div class="alert {% if can_build %}alert-success{% elseif bom_empty%}alert-warning{% else %}alert-danger{% endif %}" role="alert">
2222
{% if bom_empty %}
2323
<h5><i class="fa-solid fa-circle-exclamation fa-fw"></i> {% trans %}project.builds.no_bom_entries{% endtrans %}</h5>
24-
<span class="text-muted">{% trans %}project.builds.no_bom_entries_hint{% endtrans %}</span>
2524
{% elseif not can_build %}
2625
<h5><i class="fa-solid fa-circle-exclamation fa-fw"></i> {% trans %}project.builds.build_not_possible{% endtrans %}</h5>
2726
<b>{% trans with {"%number_of_builds%": number_of_builds} %}project.builds.following_bom_entries_miss_instock_n{% endtrans %}</b>
@@ -41,4 +40,4 @@
4140
{% include 'projects/build/_form.html.twig' %}
4241

4342

44-
{% endblock %}
43+
{% endblock %}

templates/projects/info/_builds.html.twig

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
</div>
1010
{% endif %}
1111

12-
<div class="alert mt-2 {% if can_build %}alert-success{% else %}alert-danger{% endif %}" role="alert">
12+
<div class="alert mt-2 {% if can_build %}alert-success{% elseif bom_empty%}alert-warning{% else %}alert-danger{% endif %}" role="alert">
1313
{% if bom_empty %}
1414
<h5><i class="fa-solid fa-circle-exclamation fa-fw"></i> {% trans %}project.builds.no_bom_entries{% endtrans %}</h5>
15-
<span class="text-muted">{% trans %}project.builds.no_bom_entries_hint{% endtrans %}</span>
1615
{% elseif not can_build %}
1716
<h5><i class="fa-solid fa-circle-exclamation fa-fw"></i> {% trans %}project.builds.build_not_possible{% endtrans %}</h5>
1817
<b>{% trans %}project.builds.following_bom_entries_miss_instock{% endtrans %}</b>
@@ -23,7 +22,7 @@
2322
</ul>
2423
{% else %}
2524
<h5><i class="fa-solid fa-circle-check fa-fw"></i> {% trans %}project.builds.build_possible{% endtrans %}</h5>
26-
<span>{% trans with {"%max_builds%": buildHelper.maximumBuildableCount(project)} %}project.builds.number_of_builds_possible{% endtrans %}</span>
25+
<span>{% trans with {"%max_builds%": buildHelper.maximumBuildableCountAsString(project)} %}project.builds.number_of_builds_possible{% endtrans %}</span>
2726
{% endif %}
2827
</div>
2928

@@ -41,4 +40,4 @@
4140

4241
{% if project.buildPart %}
4342
<p><b>{% trans %}project.builds.no_stocked_builds{% endtrans %}:</b> <a href="{{ entity_url(project.buildPart) }}">{{ project.buildPart.amountSum }}</a></p>
44-
{% endif %}
43+
{% endif %}

tests/Services/ProjectSystem/ProjectBuildHelperTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,22 @@ public function testGetMaximumBuildableCount(): void
114114
$this->assertSame(0, $this->service->getMaximumBuildableCount($project));
115115

116116
}
117+
118+
public function testGetMaximumBuildableCountEmpty(): void
119+
{
120+
$project = new Project();
121+
122+
$this->assertSame(0, $this->service->getMaximumBuildableCount($project));
123+
}
124+
125+
public function testGetMaximumBuildableCountAsString(): void
126+
{
127+
$project = new Project();
128+
$bom_entry1 = new ProjectBOMEntry();
129+
$bom_entry1->setName("Test");
130+
$project->addBomEntry($bom_entry1);
131+
132+
$this->assertSame('', $this->service->getMaximumBuildableCountAsString($project));
133+
134+
}
117135
}

translations/messages.en.xlf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14223,7 +14223,13 @@ Please note, that you can not impersonate a disabled user. If you try you will g
1422314223
<unit id="Ej2znKK" name="settings.system.localization.language_menu_entries.description">
1422414224
<segment state="translated">
1422514225
<source>settings.system.localization.language_menu_entries.description</source>
14226-
<target>The languages to show in the language drop-down menu. Order can be changed via drag &amp; drop. Leave empty to show all available languages.</target>
14226+
<target><![CDATA[The languages to show in the language drop-down menu. Order can be changed via drag & drop. Leave empty to show all available languages.]]></target>
14227+
</segment>
14228+
</unit>
14229+
<unit id="xIZ_mEX" name="project.builds.no_bom_entries">
14230+
<segment>
14231+
<source>project.builds.no_bom_entries</source>
14232+
<target>Project has no BOM entries</target>
1422714233
</segment>
1422814234
</unit>
1422914235
</file>

0 commit comments

Comments
 (0)