Skip to content

Commit

Permalink
Merge pull request #62 from H2-invent/feature/admin_dashboard
Browse files Browse the repository at this point in the history
Feature/admin dashboard
  • Loading branch information
holema authored Feb 9, 2021
2 parents 3bfb2d2 + e9b0c90 commit d761072
Show file tree
Hide file tree
Showing 8 changed files with 242 additions and 3 deletions.
13 changes: 11 additions & 2 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 () {
Expand Down
47 changes: 47 additions & 0 deletions src/Controller/AdminController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace App\Controller;

use App\Entity\Rooms;
use App\Entity\Server;
use App\Service\AdminService;
use Doctrine\DBAL\Types\DateType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
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
{

/**
* @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, 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);

return $this->render('admin/modalChart.html.twig', [
'server' => $server,
'countPart' => $countPart,
'chart' => $chart,
'tags' => $tags
]);

}
}
54 changes: 54 additions & 0 deletions src/Service/AdminService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* Created by PhpStorm.
* User: Emanuel
* Date: 03.10.2019
* Time: 19:01
*/

namespace App\Service;

use App\Entity\Rooms;
use App\Entity\Server;
use App\Entity\User;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;


class AdminService
{
private $em;

public function __construct(EntityManagerInterface $entityManager)
{
$this->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;
}

}
86 changes: 86 additions & 0 deletions templates/admin/modalChart.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<div class="modal-dialog modal-xl modal-dialog-centered">
<div class="modal-content">

<div class="modal-header light-blue darken-3 white-text">
<h5 class="modal-title">{{ server.url }}</h5>

</div>
<div class="modal-body ">
<div class="row">
<div class="col-md-6 col-sm-6 col-lg-3 mb-2">
<div class="card border-info text-center">
<div class="card-body">
{{ 'Konferenzen'|trans }}
<hr>
{{ server.rooms | length }}
</div>
</div>
</div>
<div class="col-md-6 col-sm-6 col-lg-3 mb-2">
<div class="card border-info text-center">
<div class="card-body">
{{ 'Teilnehmer'|trans }}
<hr>
{{ countPart }}
</div>
</div>
</div>
<div class="col-md-6 col-sm-6 col-lg-3 mb-2">
<div class="card border-info text-center">
<div class="card-body">
{{ 'Organisatoren'|trans }}
<hr>
{{ server.user | length }}
</div>
</div>
</div>
<div class="col-md-6 col-sm-6 col-lg-3 mb-2">
<a href="https://github.com/H2-invent/jitsi-admin/releases/tag/{{ tags[0].name }}" referrerpolicy="no-referrer " target="_blank" rel="noreferrer noopener">
<div class="card {% if laf_version != tags[0].name %}border-danger{% else %}border-info{% endif %} text-center">
<div class="card-body">
{% if laf_version != tags[0].name %}{{ 'Neue Version von Jitsi Admin verfügbar'|trans }}{% else %}{{ 'Aktuellste Jitsi Admin Version installiert'|trans }}{% endif %}
</div>
</div>
</a>
</div>
</div>
<hr>
<h3 class="h3-responsive">
{{ 'Konferenzen'|trans }}
</h3>
<canvas id="lineChart"></canvas>
</div>
</div>
</div>
<script>
data = {
labels: [{% for date in chart %}"{{ date['date']|date('d.m.Y') }}",{% endfor %}],
datasets: [{
label: "{{ 'Anzahl Konferenzen'|trans }}",
data: [{% for date in chart %}"{{ date['rooms'] }}",{% endfor %}],
backgroundColor: [
'rgba(105, 0, 132, .2)',
],
borderColor: [
'rgba(200, 99, 132, .7)',
],
borderWidth: 2
},
{
label: "{{ 'Anzahl Teilnehmer'|trans }}",
data: [{% for date in chart %}"{{ date['participants'] }}",{% endfor %}],
backgroundColor: [
'rgba(0, 137, 132, .2)',
],
borderColor: [
'rgba(0, 10, 130, .7)',
],
borderWidth: 2
}
]
};
options = {
responsive: true
};
</script>
2 changes: 1 addition & 1 deletion templates/dashboard/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<div class="row">
<div class="col-md-6 mb-3">
<a href="{{ path('room_new') }}" class="loadContent">
<div class="card card-body bg-success btn rounded-pill">
<div class="card card-body bg-success btn">
<p class="mt-2 mb-2 text-center">
{{ 'Eine Konferenz planen'|trans }}
</p>
Expand Down
3 changes: 3 additions & 0 deletions templates/servers/__serverModal.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
<br>
<a href="{{ path('server_add_user',{'id':server.id}) }}" data-dismiss="modal"
class="loadContent">{{ 'Organisatoren'|trans }}</a>
<br>
<a href="{{ path('admin_server',{'server':server.id}) }}" data-dismiss="modal"
class="loadContent">{{ 'Statistiken'|trans }}</a>
{% else %}
<a class="confirmHref" href="{{ path('server_user_remove',{'id':server.id,'user':app.user.id}) }}"><i class="fa fa-trash"></i></a>
{% endif %}
Expand Down
20 changes: 20 additions & 0 deletions translations/messages+intl-icu.en.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,26 @@
<source>Wollen Sie mit diesem Teilnehmer eine Konferenz starten</source>
<target>__Wollen Sie mit diesem Teilnehmer eine Konferenz starten</target>
</trans-unit>
<trans-unit id="zPVs_1Q" resname="Konferenzen">
<source>Konferenzen</source>
<target>__Konferenzen</target>
</trans-unit>
<trans-unit id="N32k9a1" resname="Neue Version von Jitsi Admin verfügbar">
<source>Neue Version von Jitsi Admin verfügbar</source>
<target>__Neue Version von Jitsi Admin verfügbar</target>
</trans-unit>
<trans-unit id="6EwrsHz" resname="Aktuellste Jitsi Admin Version installiert">
<source>Aktuellste Jitsi Admin Version installiert</source>
<target>__Aktuellste Jitsi Admin Version installiert</target>
</trans-unit>
<trans-unit id="MhTMC2j" resname="Anzahl Konferenzen">
<source>Anzahl Konferenzen</source>
<target>__Anzahl Konferenzen</target>
</trans-unit>
<trans-unit id="wMIPplV" resname="Statistiken">
<source>Statistiken</source>
<target>__Statistiken</target>
</trans-unit>
</body>
</file>
</xliff>
20 changes: 20 additions & 0 deletions translations/messages+intl-icu.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,26 @@
<source>Wollen Sie mit diesem Teilnehmer eine Konferenz starten</source>
<target>__Wollen Sie mit diesem Teilnehmer eine Konferenz starten</target>
</trans-unit>
<trans-unit id="zPVs_1Q" resname="Konferenzen">
<source>Konferenzen</source>
<target>__Konferenzen</target>
</trans-unit>
<trans-unit id="N32k9a1" resname="Neue Version von Jitsi Admin verfügbar">
<source>Neue Version von Jitsi Admin verfügbar</source>
<target>__Neue Version von Jitsi Admin verfügbar</target>
</trans-unit>
<trans-unit id="6EwrsHz" resname="Aktuellste Jitsi Admin Version installiert">
<source>Aktuellste Jitsi Admin Version installiert</source>
<target>__Aktuellste Jitsi Admin Version installiert</target>
</trans-unit>
<trans-unit id="MhTMC2j" resname="Anzahl Konferenzen">
<source>Anzahl Konferenzen</source>
<target>__Anzahl Konferenzen</target>
</trans-unit>
<trans-unit id="wMIPplV" resname="Statistiken">
<source>Statistiken</source>
<target>__Statistiken</target>
</trans-unit>
</body>
</file>
</xliff>

0 comments on commit d761072

Please sign in to comment.