mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 01:25:55 +02:00
Started work on a build project tool.
This commit is contained in:
parent
fcd8d205d3
commit
3dc9376f40
5 changed files with 76 additions and 10 deletions
|
@ -71,6 +71,27 @@ class ProjectController extends AbstractController
|
|||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{id}/build", name="project_build", requirements={"id"="\d+"})
|
||||
*/
|
||||
public function build(Project $project, Request $request, ProjectBuildHelper $buildHelper): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted('read', $project);
|
||||
|
||||
//If no number of builds is given (or it is invalid), just assume 1
|
||||
$number_of_builds = $request->query->getInt('n', 1);
|
||||
if ($number_of_builds < 1) {
|
||||
$number_of_builds = 1;
|
||||
}
|
||||
|
||||
|
||||
return $this->render('Projects/build/build.html.twig', [
|
||||
'buildHelper' => $buildHelper,
|
||||
'project' => $project,
|
||||
'number_of_builds' => $number_of_builds,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/add_parts", name="project_add_parts_no_id")
|
||||
* @Route("/{id}/add_parts", name="project_add_parts", requirements={"id"="\d+"})
|
||||
|
|
|
@ -72,13 +72,14 @@ class ProjectBuildHelper
|
|||
|
||||
/**
|
||||
* Checks if the given project can be build with the current stock.
|
||||
* This means that the maximum buildable count is greater than 0.
|
||||
* This means that the maximum buildable count is greater or equal than the requested $number_of_projects
|
||||
* @param Project $project
|
||||
* @parm int $number_of_projects
|
||||
* @return bool
|
||||
*/
|
||||
public function isProjectBuildable(Project $project): bool
|
||||
public function isProjectBuildable(Project $project, int $number_of_projects = 1): bool
|
||||
{
|
||||
return $this->getMaximumBuildableCount($project) > 0;
|
||||
return $this->getMaximumBuildableCount($project) >= $number_of_projects;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
36
templates/Projects/build/build.html.twig
Normal file
36
templates/Projects/build/build.html.twig
Normal file
|
@ -0,0 +1,36 @@
|
|||
{% extends "main_card.html.twig" %}
|
||||
|
||||
{% block title %}{% trans %}project.info.builds.label{% endtrans %}: {{ number_of_builds }}x {{ project.name }}{% endblock %}
|
||||
|
||||
{% block card_title %}
|
||||
<i class="fa-solid fa-bolt fa-fw"></i>
|
||||
{% trans %}project.info.builds.label{% endtrans %}: <b>{{ number_of_builds }}x</b> <i>{{ project.name }}</i>
|
||||
{% endblock %}
|
||||
|
||||
{% block card_content %}
|
||||
{% set can_build = buildHelper.projectBuildable(project, number_of_builds) %}
|
||||
{% import "components/projects.macro.html.twig" as project_macros %}
|
||||
|
||||
{% if project.status is not empty and project.status != "in_production" %}
|
||||
<div class="alert alert-warning" role="alert">
|
||||
<i class="fa-solid fa-triangle-exclamation fa-fw"></i> {% trans with {"%project_status%": ('project.status.'~project.status)|trans } %}project.builds.check_project_status{% endtrans %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="alert {% if can_build %}alert-success{% else %}alert-danger{% endif %}" role="alert">
|
||||
{% if not can_build %}
|
||||
<h5><i class="fa-solid fa-circle-exclamation fa-fw"></i> {% trans %}project.builds.build_not_possible{% endtrans %}</h5>
|
||||
<b>{% trans with {"%number_of_builds%": number_of_builds} %}project.builds.following_bom_entries_miss_instock_n{% endtrans %}</b>
|
||||
<ul>
|
||||
{% for bom_entry in buildHelper.nonBuildableProjectBomEntries(project, number_of_builds) %}
|
||||
<li>{{ project_macros.project_bom_entry_with_missing_instock(bom_entry) }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
<h5><i class="fa-solid fa-circle-check fa-fw"></i> {% trans %}project.builds.build_possible{% endtrans %}</h5>
|
||||
<span>{% trans with {"%max_builds%": number_of_builds} %}project.builds.number_of_builds_possible{% endtrans %}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock %}
|
|
@ -23,12 +23,14 @@
|
|||
{% endif %}
|
||||
</div>
|
||||
|
||||
|
||||
<form method="get" action="{{ path('project_build', {"id": project.iD }) }}">
|
||||
<div class="row mt-2">
|
||||
<div class="col-4">
|
||||
<div class="input-group mb-3">
|
||||
<input type="number" min="1" class="form-control" placeholder="Number" aria-describedby="button-addon2" required>
|
||||
<button class="btn btn-outline-secondary" type="button" id="button-addon2">Build</button>
|
||||
<input type="number" min="1" class="form-control" placeholder="Number" name="n" required>
|
||||
<input type="hidden" name="_redirect" value="{{ app.request.requestUri }}">
|
||||
<button class="btn btn-outline-secondary" type="submit" id="button-addon2">Build</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
|
@ -10339,5 +10339,11 @@ Element 3</target>
|
|||
<target><![CDATA[The current project status is <b>"%project_status%"</b>. You should check if you really want to build the project with this status!]]></target>
|
||||
</segment>
|
||||
</unit>
|
||||
<unit id="57BNIbl" name="project.builds.following_bom_entries_miss_instock_n">
|
||||
<segment>
|
||||
<source>project.builds.following_bom_entries_miss_instock_n</source>
|
||||
<target>You do not have enough parts stocked to build this project %number_of_builds% times. The following parts have missing instock:</target>
|
||||
</segment>
|
||||
</unit>
|
||||
</file>
|
||||
</xliff>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue