| @@ -2,6 +2,7 @@ $(document).ready(function() { | |||||
| addUser(); | addUser(); | ||||
| listing(); | listing(); | ||||
| catalogue(); | catalogue(); | ||||
| onChangeDinAsset(); | |||||
| }); | }); | ||||
| // Message Box for alerts | // 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('<option value="' + i + '">' + data.benchmarkValues[i] + '</option>'); | |||||
| } | |||||
| }, | |||||
| error: function (xhr, msg, three) { | |||||
| messageBox(false, "Fehler bei der Anfrage."); | |||||
| }, | |||||
| dataType: "json" | |||||
| }); | |||||
| }); | |||||
| } | |||||
| let savedCatalogueAnswer, | let savedCatalogueAnswer, | ||||
| savedCatalogueNote; | savedCatalogueNote; | ||||
| $(document).ready(function() { | $(document).ready(function() { | ||||
| @@ -16,8 +16,10 @@ use App\Repository\UserRepository; | |||||
| use App\Utils\Utils; | use App\Utils\Utils; | ||||
| use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; | ||||
| use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||||
| use Symfony\Component\HttpFoundation\JsonResponse; | |||||
| use Symfony\Component\HttpFoundation\Request; | use Symfony\Component\HttpFoundation\Request; | ||||
| use Symfony\Component\Routing\Annotation\Route; | use Symfony\Component\Routing\Annotation\Route; | ||||
| use Symfony\Component\Serializer\SerializerInterface; | |||||
| use Twig\Environment; | use Twig\Environment; | ||||
| /** | /** | ||||
| @@ -25,6 +27,13 @@ use Twig\Environment; | |||||
| */ | */ | ||||
| class UserController extends AbstractController | class UserController extends AbstractController | ||||
| { | { | ||||
| private $serializer; | |||||
| public function __construct(SerializerInterface $serializer) | |||||
| { | |||||
| $this->serializer = $serializer; | |||||
| } | |||||
| /** | /** | ||||
| * @Route("/start", name="start") | * @Route("/start", name="start") | ||||
| */ | */ | ||||
| @@ -73,17 +82,7 @@ class UserController extends AbstractController | |||||
| $benchmarkValues = []; | $benchmarkValues = []; | ||||
| if (count($dinAssets) > 0) { | if (count($dinAssets) > 0) { | ||||
| $initialDinAsset = $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', | 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") | * @Route("/download", name="download") | ||||
| * | * | ||||
| @@ -180,4 +180,21 @@ class DinAsset | |||||
| $this->benchmarks = $benchmarks; | $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; | |||||
| } | |||||
| } | } | ||||
| @@ -46,17 +46,17 @@ | |||||
| </select> | </select> | ||||
| <label for="cycle">Aktueller Zyklus (in Monaten)</label> | <label for="cycle">Aktueller Zyklus (in Monaten)</label> | ||||
| {% if initialDinAsset is not null %} | {% if initialDinAsset is not null %} | ||||
| <input name="cycle" type="number" value="{{ initialDinAsset.cycleMonthsRecommended }}" min="{{ initialDinAsset.cycleMonthsMin }}" max ="{{ initialDinAsset.cycleMonthsMax }}"> | |||||
| <input name="cycle" type="number" id="cycle" value="{{ initialDinAsset.cycleMonthsRecommended }}" min="{{ initialDinAsset.cycleMonthsMin }}" max ="{{ initialDinAsset.cycleMonthsMax }}"> | |||||
| {% else %} | {% else %} | ||||
| <input name="cycle" type="number" disabled> | |||||
| <input name="cycle" type="number" id="cycle" disabled> | |||||
| {% endif %} | {% endif %} | ||||
| <label for="bandwidth">Bandbreite Anlage</label> | <label for="bandwidth">Bandbreite Anlage</label> | ||||
| <select name="bandwidth" id="bandwidth"> | |||||
| {% for key, benchmarkValue in benchmarkValues %} | |||||
| <option value="{{ key }}">{{ benchmarkValue }}</option> | |||||
| {% endfor %} | |||||
| </select> | |||||
| <select name="bandwidth" id="bandwidth"> | |||||
| {% for key, benchmarkValue in benchmarkValues %} | |||||
| <option value="{{ key }}">{{ benchmarkValue }}</option> | |||||
| {% endfor %} | |||||
| </select> | |||||
| </form> | </form> | ||||
| {% endblock %} | {% endblock %} | ||||