From 3dc9376f4089c9993e842b12efdab3b6cca0ed3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sat, 21 Jan 2023 21:41:08 +0100 Subject: [PATCH] Started work on a build project tool. --- src/Controller/ProjectController.php | 21 +++++++++++ .../ProjectSystem/ProjectBuildHelper.php | 7 ++-- templates/Projects/build/build.html.twig | 36 +++++++++++++++++++ templates/Projects/info/_builds.html.twig | 16 +++++---- translations/messages.en.xlf | 6 ++++ 5 files changed, 76 insertions(+), 10 deletions(-) create mode 100644 templates/Projects/build/build.html.twig diff --git a/src/Controller/ProjectController.php b/src/Controller/ProjectController.php index d831dc3d..3fac4ad9 100644 --- a/src/Controller/ProjectController.php +++ b/src/Controller/ProjectController.php @@ -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+"}) diff --git a/src/Services/ProjectSystem/ProjectBuildHelper.php b/src/Services/ProjectSystem/ProjectBuildHelper.php index 40545834..983313a5 100644 --- a/src/Services/ProjectSystem/ProjectBuildHelper.php +++ b/src/Services/ProjectSystem/ProjectBuildHelper.php @@ -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; } /** diff --git a/templates/Projects/build/build.html.twig b/templates/Projects/build/build.html.twig new file mode 100644 index 00000000..85540293 --- /dev/null +++ b/templates/Projects/build/build.html.twig @@ -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 %} + + {% trans %}project.info.builds.label{% endtrans %}: {{ number_of_builds }}x {{ project.name }} +{% 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" %} + + {% endif %} + + + + +{% endblock %} \ No newline at end of file diff --git a/templates/Projects/info/_builds.html.twig b/templates/Projects/info/_builds.html.twig index 394aecd4..beefd14f 100644 --- a/templates/Projects/info/_builds.html.twig +++ b/templates/Projects/info/_builds.html.twig @@ -23,12 +23,14 @@ {% endif %} - -
-
-
- - +
+
+
+
+ + + +
-
\ No newline at end of file + \ No newline at end of file diff --git a/translations/messages.en.xlf b/translations/messages.en.xlf index fe1e8edf..f75b5b92 100644 --- a/translations/messages.en.xlf +++ b/translations/messages.en.xlf @@ -10339,5 +10339,11 @@ Element 3 "%project_status%". You should check if you really want to build the project with this status!]]> + + + project.builds.following_bom_entries_miss_instock_n + You do not have enough parts stocked to build this project %number_of_builds% times. The following parts have missing instock: + +