From 2610d9107fdfd831ce601a26d90f2d18d95dc54d Mon Sep 17 00:00:00 2001 From: "andreas.holzmann" Date: Tue, 9 Feb 2021 20:53:52 +0100 Subject: [PATCH 1/3] add new Feature Admin Panel --- assets/js/app.js | 13 +++- src/Controller/AdminController.php | 41 +++++++++++ src/Service/AdminService.php | 54 ++++++++++++++ templates/admin/index.html.twig | 20 ++++++ templates/admin/modalChart.html.twig | 86 +++++++++++++++++++++++ templates/dashboard/index.html.twig | 2 +- templates/servers/__serverModal.html.twig | 3 + translations/messages+intl-icu.en.xlf | 20 ++++++ translations/messages+intl-icu.fr.xlf | 20 ++++++ 9 files changed, 256 insertions(+), 3 deletions(-) create mode 100644 src/Controller/AdminController.php create mode 100644 src/Service/AdminService.php create mode 100644 templates/admin/index.html.twig create mode 100644 templates/admin/modalChart.html.twig diff --git a/assets/js/app.js b/assets/js/app.js index 2bcd71873..cc3682fa1 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -16,8 +16,10 @@ import flatpickr from 'flatpickr' import {Calendar} from '@fullcalendar/core'; import dayGridPlugin from '@fullcalendar/daygrid'; import bootstrapPlugin from '@fullcalendar/bootstrap'; -import momentPlugin from '@fullcalendar/moment' -import listPlugin from '@fullcalendar/list' +import momentPlugin from '@fullcalendar/moment'; +import listPlugin from '@fullcalendar/list'; +import Chart from 'chart.js'; + $.urlParam = function (name) { var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href); if (results == null) { @@ -129,6 +131,13 @@ $('#loadContentModal').on('shown.bs.modal', function (e) { } }); initSearchUser(); + + var ctx = document.getElementById("lineChart").getContext('2d'); + var myChart = new Chart(ctx, { + type: 'line', + data: data, + options: options + }); }); $(".clickable-row").click(function () { diff --git a/src/Controller/AdminController.php b/src/Controller/AdminController.php new file mode 100644 index 000000000..e1e50e8fb --- /dev/null +++ b/src/Controller/AdminController.php @@ -0,0 +1,41 @@ +getRooms() as $room) { + $countPart = $countPart + count($room->getUser()); + } + + $req = $httpClient->request('GET', 'https://api.github.com/repos/H2-invent/jitsi-admin/tags'); + $tags = json_decode($req->getContent(), true); + $chart = $adminService->createChart($server); + + return $this->render('admin/modalChart.html.twig', [ + 'server' => $server, + 'countPart' => $countPart, + 'chart' => $chart, + 'tags' => $tags + ]); + } +} diff --git a/src/Service/AdminService.php b/src/Service/AdminService.php new file mode 100644 index 000000000..21288a217 --- /dev/null +++ b/src/Service/AdminService.php @@ -0,0 +1,54 @@ +em = $entityManager; + } + + public function createChart(Server $server) + { + $rooms = $this->em->getRepository(Rooms::class)->findBy(['server'=>$server]); + + $chart = array(); + $firstDate = new \DateTime(); + $firstDate = date_modify($firstDate,'-30 days'); + for ($x = 0; $x <= 60; $x++) { + $d = clone $firstDate; + $date = date_modify($d,'+'.$x.'days'); + + $chart[$date->format('Ymd')]['date'] = $date; + $chart[$date->format('Ymd')]['participants'] = 0; + $chart[$date->format('Ymd')]['rooms'] = 0; + foreach ($rooms as $data) { + if ($data->getStart()->format('Ymd') === $date->format('Ymd')) { + $chart[$date->format('Ymd')]['rooms'] = $chart[$date->format('Ymd')]['rooms'] + 1; + $chart[$date->format('Ymd')]['participants'] = $chart[$date->format('Ymd')]['participants'] + count($data->getUser()); + } + } + } + return $chart; + } + +} diff --git a/templates/admin/index.html.twig b/templates/admin/index.html.twig new file mode 100644 index 000000000..6dd4e488b --- /dev/null +++ b/templates/admin/index.html.twig @@ -0,0 +1,20 @@ +{% extends 'base.html.twig' %} + +{% block title %}Hello AdminController!{% endblock %} + +{% block body %} + + +
+

Hello {{ controller_name }}! ✅

+ + This friendly message is coming from: + +
+{% endblock %} diff --git a/templates/admin/modalChart.html.twig b/templates/admin/modalChart.html.twig new file mode 100644 index 000000000..cc15e2f4f --- /dev/null +++ b/templates/admin/modalChart.html.twig @@ -0,0 +1,86 @@ + + \ No newline at end of file diff --git a/templates/dashboard/index.html.twig b/templates/dashboard/index.html.twig index 4b35ae3f8..3a2660faf 100644 --- a/templates/dashboard/index.html.twig +++ b/templates/dashboard/index.html.twig @@ -67,7 +67,7 @@
-
+

{{ 'Eine Konferenz planen'|trans }}

diff --git a/templates/servers/__serverModal.html.twig b/templates/servers/__serverModal.html.twig index a728dbca9..6d0fb4411 100644 --- a/templates/servers/__serverModal.html.twig +++ b/templates/servers/__serverModal.html.twig @@ -29,6 +29,9 @@
{{ 'Organisatoren'|trans }} +
+ {{ 'Statistiken'|trans }} {% else %} {% endif %} diff --git a/translations/messages+intl-icu.en.xlf b/translations/messages+intl-icu.en.xlf index d400cdb4a..1b00cbef1 100644 --- a/translations/messages+intl-icu.en.xlf +++ b/translations/messages+intl-icu.en.xlf @@ -567,6 +567,26 @@ Wollen Sie mit diesem Teilnehmer eine Konferenz starten __Wollen Sie mit diesem Teilnehmer eine Konferenz starten + + Konferenzen + __Konferenzen + + + Neue Version von Jitsi Admin verfügbar + __Neue Version von Jitsi Admin verfügbar + + + Aktuellste Jitsi Admin Version installiert + __Aktuellste Jitsi Admin Version installiert + + + Anzahl Konferenzen + __Anzahl Konferenzen + + + Statistiken + __Statistiken + diff --git a/translations/messages+intl-icu.fr.xlf b/translations/messages+intl-icu.fr.xlf index 05cf4b8bc..8b675711a 100644 --- a/translations/messages+intl-icu.fr.xlf +++ b/translations/messages+intl-icu.fr.xlf @@ -567,6 +567,26 @@ Wollen Sie mit diesem Teilnehmer eine Konferenz starten __Wollen Sie mit diesem Teilnehmer eine Konferenz starten + + Konferenzen + __Konferenzen + + + Neue Version von Jitsi Admin verfügbar + __Neue Version von Jitsi Admin verfügbar + + + Aktuellste Jitsi Admin Version installiert + __Aktuellste Jitsi Admin Version installiert + + + Anzahl Konferenzen + __Anzahl Konferenzen + + + Statistiken + __Statistiken + From 02aaa7cb9786a9273c00b0ec1edd701bd5b34351 Mon Sep 17 00:00:00 2001 From: "andreas.holzmann" Date: Tue, 9 Feb 2021 21:03:10 +0100 Subject: [PATCH 2/3] add security request for admin panel --- src/Controller/AdminController.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Controller/AdminController.php b/src/Controller/AdminController.php index e1e50e8fb..63ded2017 100644 --- a/src/Controller/AdminController.php +++ b/src/Controller/AdminController.php @@ -12,6 +12,7 @@ use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Serializer\SerializerInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; +use Symfony\Contracts\Translation\TranslatorInterface; class AdminController extends AbstractController { @@ -20,13 +21,17 @@ class AdminController extends AbstractController * @Route("/admin/server/{server}", name="admin_server") * @ParamConverter("server", class="App\Entity\Server",options={"mapping": {"server": "id"}}) */ - public function server(Server $server, AdminService $adminService, HttpClientInterface $httpClient) + public function server(Server $server, AdminService $adminService, HttpClientInterface $httpClient, TranslatorInterface $translator) { $countPart = 0; foreach ($server->getRooms() as $room) { $countPart = $countPart + count($room->getUser()); } + if ($this->getUser() !== $server->getAdministrator()) { + return $this->redirectToRoute('dashboard',['snack'=>$translator->trans('Fehler, Der Server wurde nicht gefunden'),'color'=>'danger']); + } + $req = $httpClient->request('GET', 'https://api.github.com/repos/H2-invent/jitsi-admin/tags'); $tags = json_decode($req->getContent(), true); $chart = $adminService->createChart($server); @@ -37,5 +42,6 @@ public function server(Server $server, AdminService $adminService, HttpClientInt 'chart' => $chart, 'tags' => $tags ]); + } } From e9b0c90a0630a3444d2d42b18718d26c533de7f7 Mon Sep 17 00:00:00 2001 From: holema Date: Tue, 9 Feb 2021 21:05:31 +0100 Subject: [PATCH 3/3] Delete index.html.twig --- templates/admin/index.html.twig | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 templates/admin/index.html.twig diff --git a/templates/admin/index.html.twig b/templates/admin/index.html.twig deleted file mode 100644 index 6dd4e488b..000000000 --- a/templates/admin/index.html.twig +++ /dev/null @@ -1,20 +0,0 @@ -{% extends 'base.html.twig' %} - -{% block title %}Hello AdminController!{% endblock %} - -{% block body %} - - -
-

Hello {{ controller_name }}! ✅

- - This friendly message is coming from: - -
-{% endblock %}