Skip to content

Commit 05839a5

Browse files
mknejbtronics
authored andcommitted
Fix Wrong default number of project builds if BOM is empty #1038
1 parent 7a1a458 commit 05839a5

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

src/Services/ProjectSystem/ProjectBuildHelper.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,19 @@ public function getMaximumBuildableCountForBOMEntry(ProjectBOMEntry $projectBOME
6363
*/
6464
public function getMaximumBuildableCount(Project $project): int
6565
{
66+
$bom_entries = $project->getBomEntries();
67+
if ($bom_entries->isEmpty()) {
68+
return 0;
69+
}
6670
$maximum_buildable_count = PHP_INT_MAX;
67-
foreach ($project->getBomEntries() as $bom_entry) {
71+
foreach ($bom_entries as $bom_entry) {
6872
//Skip BOM entries without a part (as we can not determine that)
6973
if (!$bom_entry->isPartBomEntry()) {
7074
continue;
7175
}
72-
7376
//The maximum buildable count for the whole project is the minimum of all BOM entries
7477
$maximum_buildable_count = min($maximum_buildable_count, $this->getMaximumBuildableCountForBOMEntry($bom_entry));
7578
}
76-
7779
return $maximum_buildable_count;
7880
}
7981

templates/projects/build/build.html.twig

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
{% endblock %}
99

1010
{% block card_content %}
11-
{% set can_build = buildHelper.projectBuildable(project, number_of_builds) %}
11+
{% set bom_empty = project.bomEntries | length == 0 %}
12+
{% set can_build = not bom_empty and buildHelper.projectBuildable(project, number_of_builds) %}
1213
{% import "components/projects.macro.html.twig" as project_macros %}
1314

1415
{% if project.status is not empty and project.status != "in_production" %}
@@ -18,7 +19,10 @@
1819
{% endif %}
1920

2021
<div class="alert {% if can_build %}alert-success{% else %}alert-danger{% endif %}" role="alert">
21-
{% if not can_build %}
22+
{% if bom_empty %}
23+
<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>
25+
{% elseif not can_build %}
2226
<h5><i class="fa-solid fa-circle-exclamation fa-fw"></i> {% trans %}project.builds.build_not_possible{% endtrans %}</h5>
2327
<b>{% trans with {"%number_of_builds%": number_of_builds} %}project.builds.following_bom_entries_miss_instock_n{% endtrans %}</b>
2428
<ul>

templates/projects/info/_builds.html.twig

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
{% set can_build = buildHelper.projectBuildable(project) %}
1+
{% set bom_empty = project.bomEntries | length == 0 %}
2+
{% set can_build = not bom_empty and buildHelper.projectBuildable(project) %}
23

34
{% import "components/projects.macro.html.twig" as project_macros %}
45

@@ -9,7 +10,10 @@
910
{% endif %}
1011

1112
<div class="alert mt-2 {% if can_build %}alert-success{% else %}alert-danger{% endif %}" role="alert">
12-
{% if not can_build %}
13+
{% if bom_empty %}
14+
<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>
16+
{% elseif not can_build %}
1317
<h5><i class="fa-solid fa-circle-exclamation fa-fw"></i> {% trans %}project.builds.build_not_possible{% endtrans %}</h5>
1418
<b>{% trans %}project.builds.following_bom_entries_miss_instock{% endtrans %}</b>
1519
<ul>
@@ -27,7 +31,7 @@
2731
<div class="row mt-2">
2832
<div class="col-4">
2933
<div class="input-group mb-3">
30-
<input type="number" min="1" class="form-control" placeholder="{% trans %}project.builds.number_of_builds{% endtrans %}" name="n" required>
34+
<input type="number" min="1" class="form-control" placeholder="{% trans %}project.builds.number_of_builds{% endtrans %}" name="n" required value="1">
3135
<input type="hidden" name="_redirect" value="{{ uri_without_host(app.request) }}">
3236
<button class="btn btn-outline-secondary" type="submit" id="button-addon2">{% trans %}project.build.btn_build{% endtrans %}</button>
3337
</div>

0 commit comments

Comments
 (0)