From e1d3886b83f1250247301bef8e4d815cce248ab6 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 22 Jun 2023 16:09:59 +0200 Subject: [PATCH] din selection done --- httpdocs/public/assets/js/my-bim-score.js | 32 ++++++++++++++ httpdocs/src/Controller/UserController.php | 42 ++++++++++++++----- httpdocs/src/Entity/DinAsset.php | 17 ++++++++ .../templates/pages/risk_analysis.html.twig | 14 +++---- 4 files changed, 87 insertions(+), 18 deletions(-) diff --git a/httpdocs/public/assets/js/my-bim-score.js b/httpdocs/public/assets/js/my-bim-score.js index a6f01fb..f29ad49 100644 --- a/httpdocs/public/assets/js/my-bim-score.js +++ b/httpdocs/public/assets/js/my-bim-score.js @@ -2,6 +2,7 @@ $(document).ready(function() { addUser(); listing(); catalogue(); + onChangeDinAsset(); }); // Message Box for alerts @@ -113,6 +114,37 @@ function listing() { }); } +function onChangeDinAsset() { + $("#asset").on("change", function(e) { + console.log($("#asset").val()); + $.ajax({ + url: "/get-benchmark-data", + method: "get", + data: { assetId: $("#asset").val() }, + success: function (data) { + $("#cycle").attr({ + "min" : data.cycleMin, + "max" : data.cycleMax + }).val(data.cycleRecommended); + + $('#bandwidth') + .find('option') + .remove() + .end() + ; + + for (let i in data.benchmarkValues) { + $('#bandwidth').append(''); + } + }, + error: function (xhr, msg, three) { + messageBox(false, "Fehler bei der Anfrage."); + }, + dataType: "json" + }); + }); +} + let savedCatalogueAnswer, savedCatalogueNote; $(document).ready(function() { diff --git a/httpdocs/src/Controller/UserController.php b/httpdocs/src/Controller/UserController.php index b506120..1a6bc88 100644 --- a/httpdocs/src/Controller/UserController.php +++ b/httpdocs/src/Controller/UserController.php @@ -16,8 +16,10 @@ use App\Repository\UserRepository; use App\Utils\Utils; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Serializer\SerializerInterface; use Twig\Environment; /** @@ -25,6 +27,13 @@ use Twig\Environment; */ class UserController extends AbstractController { + private $serializer; + + public function __construct(SerializerInterface $serializer) + { + $this->serializer = $serializer; + } + /** * @Route("/start", name="start") */ @@ -73,17 +82,7 @@ class UserController extends AbstractController $benchmarkValues = []; if (count($dinAssets) > 0) { $initialDinAsset = $dinAssets[0]; - $benchmarks = $initialDinAsset->getBenchmarks(); - /** @var DinAssetBenchmark $benchmark */ - foreach ($benchmarks as $benchmark) { - $value = $benchmark->getComponent() ? $benchmark->getComponent() . " | " : ""; - $value.= $benchmark->getType() ? $benchmark->getType() . " | " : ""; - $value.= $benchmark->getBandwidth() ? $benchmark->getBandwidth() . " | " : ""; - if (substr($value, -3) === " | ") { - $value = rtrim($value, " | "); - } - $benchmarkValues[$benchmark->getId()] = $value; - } + $benchmarkValues = $initialDinAsset->getBenchMarkSelectValues(); } return $this->render('pages/risk_analysis.html.twig', @@ -98,6 +97,27 @@ class UserController extends AbstractController } + /** + * @Route("/get-benchmark-data", name="get_benchmark_data") + */ + public function getAsset(Request $request) + { + $assetId = $request->query->get('assetId'); + /** @var DinAsset $dinAsset */ + $dinAsset = $this->getDoctrine()->getRepository(DinAsset::class)->find($assetId); + + if (null === $dinAsset) { + return new JsonResponse(null, JsonResponse::HTTP_BAD_REQUEST); + } + + $res = []; + $res['cycleRecommended'] = $dinAsset->getCycleMonthsRecommended(); + $res['cycleMin'] = $dinAsset->getCycleMonthsMin(); + $res['cycleMax'] = $dinAsset->getCycleMonthsMax(); + $res['benchmarkValues'] = $dinAsset->getBenchMarkSelectValues(); + return $this->json($res); + } + /** * @Route("/download", name="download") * diff --git a/httpdocs/src/Entity/DinAsset.php b/httpdocs/src/Entity/DinAsset.php index 667901d..a517cf4 100644 --- a/httpdocs/src/Entity/DinAsset.php +++ b/httpdocs/src/Entity/DinAsset.php @@ -180,4 +180,21 @@ class DinAsset $this->benchmarks = $benchmarks; } + public function getBenchMarkSelectValues(): array + { + $benchmarkValues = []; + $benchmarks = $this->getBenchmarks(); + /** @var DinAssetBenchmark $benchmark */ + foreach ($benchmarks as $benchmark) { + $value = $benchmark->getComponent() ? $benchmark->getComponent() . " | " : ""; + $value.= $benchmark->getType() ? $benchmark->getType() . " | " : ""; + $value.= $benchmark->getBandwidth() ? $benchmark->getBandwidth() . " | " : ""; + if (substr($value, -3) === " | ") { + $value = rtrim($value, " | "); + } + $benchmarkValues[$benchmark->getId()] = $value; + } + return $benchmarkValues; + } + } diff --git a/httpdocs/templates/pages/risk_analysis.html.twig b/httpdocs/templates/pages/risk_analysis.html.twig index 179f29c..76380a9 100644 --- a/httpdocs/templates/pages/risk_analysis.html.twig +++ b/httpdocs/templates/pages/risk_analysis.html.twig @@ -46,17 +46,17 @@ {% if initialDinAsset is not null %} - + {% else %} - + {% endif %} - + {% endblock %}