Dashboard widgets (#21)

* translated Dashboard widgets #20
* improved phpdoc #20
This commit is contained in:
Kevin Papst
2018-01-05 18:18:09 +01:00
committed by GitHub
parent 8cb76f732c
commit a7bee68b0b
6 changed files with 129 additions and 88 deletions

View File

@@ -527,6 +527,34 @@
<target>Umsatz total</target>
</trans-unit>
<!--
Dashboard
-->
<trans-unit id="stats.userTotal">
<source>stats.userTotal</source>
<target>Anzahl Benutzer</target>
</trans-unit>
<trans-unit id="stats.userActiveThisMoth">
<source>stats.userActiveThisMoth</source>
<target>Aktive Benutzer diesen Monat</target>
</trans-unit>
<trans-unit id="stats.userActiveEver">
<source>stats.userActiveEver</source>
<target>Aktive Benutzer jemals</target>
</trans-unit>
<trans-unit id="stats.userActiveNow">
<source>stats.userActiveNow</source>
<target>Momentan aktiv</target>
</trans-unit>
<trans-unit id="stats.activitiesTotal">
<source>stats.activitiesTotal</source>
<target>Anzahl Aktivitäten</target>
</trans-unit>
<trans-unit id="stats.projectsTotal">
<source>stats.projectsTotal</source>
<target>Anzahl Projekte</target>
</trans-unit>
<!--
Month names
-->

View File

@@ -6,98 +6,23 @@
{% block main %}
{# FIXME Übersetzungen hinzufügen #}
{# blue / yellow / purple / green / black #}
{# bar-chart / line-chart / calendar / clock-o #}
{#
<div class="row">
<div class="col-md-3 col-sm-6 col-xs-12">
{{ widgets.info_box_progress('Bewilligte Stunden', 'Stunden zur Abrechnung bewilligt', 120, 10, 'star-o') }}
</div>
<div class="col-md-3 col-sm-6 col-xs-12">
{{ widgets.info_box_progress('Umsatz / Monat', '70% Increase in 30 Days', 6830, 30, 'credit-card', 'black') }}
</div>
<div class="col-md-3 col-sm-6 col-xs-12">
{{ widgets.info_box_progress('Stunden persönlich', 'Das ist noch nicht genug', 135, 60, 'hourglass-o') }}
</div>
<div class="col-md-3 col-sm-6 col-xs-12">
{{ widgets.info_box_progress('Anzahl Benutzer', 'Mehr ist besser!', 5, 90, 'user') }}
</div>
</div>
#}
{% if is_granted('ROLE_USER') %}
{{ widgets.page_header('dashboard.you') }}
{% for settings in dashboard_widgets %}
{% if settings.header %}
{{ widgets.page_header(settings.header) }}
{% endif %}
{% set columnWidth = 12 / (settings.widgets|length) %}
<div class="row">
<div class="col-md-3 col-sm-6 col-xs-12">
{{ widgets.info_box_counter('stats.durationThisMonth', timesheetUser.durationThisMonth|duration(true), 'hourglass-o', 'green') }}
</div>
<div class="col-md-3 col-sm-6 col-xs-12">
{{ widgets.info_box_counter('stats.amountThisMonth', timesheetUser.amountThisMonth|money, 'money', 'blue') }}
</div>
<div class="col-md-3 col-sm-6 col-xs-12">
{{ widgets.info_box_counter('stats.durationTotal', timesheetUser.durationTotal|duration(true), 'hourglass-o', 'red') }}
</div>
<div class="col-md-3 col-sm-6 col-xs-12">
{{ widgets.info_box_counter('stats.amountTotal', timesheetUser.amountTotal|money, 'money', 'yellow') }}
{% for widgetTemplate in settings.widgets %}
<div class="col-md-{{ columnWidth }} col-sm-{{ columnWidth * 2 }} col-xs-{{ columnWidth * 4 }}">
{% set widgetString = '{% import "macros/widgets.html.twig" as widgets %}' ~ widgetTemplate %}
{{ include(template_from_string(widgetString)) }}
</div>
{% endfor %}
</div>
{% endif %}
{% if is_granted('ROLE_TEAMLEAD') %}
{{ widgets.page_header('dashboard.all') }}
<div class="row">
<div class="col-md-3 col-sm-6 col-xs-12">
{{ widgets.info_box_counter('Arbeitszeit diesen Monat', timesheetGlobal.durationThisMonth|duration(true), 'hourglass-o', 'blue') }}
</div>
<div class="col-md-3 col-sm-6 col-xs-12">
{{ widgets.info_box_counter('Umsatz diesen Monat', timesheetGlobal.amountThisMonth|money, 'money', 'green') }}
</div>
<div class="col-md-3 col-sm-6 col-xs-12">
{{ widgets.info_box_counter('Arbeitszeit total', timesheetGlobal.durationTotal|duration(true), 'hourglass-o', 'yellow') }}
</div>
<div class="col-md-3 col-sm-6 col-xs-12">
{{ widgets.info_box_counter('Umsatz total', timesheetGlobal.amountTotal|money, 'money', 'red') }}
</div>
</div>
{% endif %}
{% if is_granted('ROLE_TEAMLEAD') %}
<div class="row">
<div class="col-md-3 col-sm-6 col-xs-12">
{{ widgets.info_box_counter('Anzahl Benutzer', user.totalAmount, 'users', 'red') }}
</div>
<div class="col-md-3 col-sm-6 col-xs-12">
{{ widgets.info_box_counter('Aktive Benutzer diesen Monat', timesheetGlobal.activeThisMonth, 'users', 'yellow') }}
</div>
<div class="col-md-3 col-sm-6 col-xs-12">
{{ widgets.info_box_counter('Aktive Benutzer jemals', timesheetGlobal.activeTotal, 'users', 'blue') }}
</div>
<div class="col-md-3 col-sm-6 col-xs-12">
{{ widgets.info_box_counter('Momentan aktiv', timesheetGlobal.activeCurrently, 'users', 'green') }}
</div>
</div>
{% endif %}
{% if is_granted('ROLE_ADMIN') %}
{{ widgets.page_header('dashboard.admin') }}
<div class="row">
<div class="col-md-3 col-sm-6 col-xs-12">
{{ widgets.info_box_more('Anzahl Aktivitäten', activity.totalAmount, '', path('admin_activity'), 'tasks', 'purple') }}
</div>
<div class="col-md-3 col-sm-6 col-xs-12">
{{ widgets.info_box_more('Anzahl Projekte', project.totalAmount, '', path('admin_project'), 'book', 'yellow') }}
</div>
<div class="col-md-3 col-sm-6 col-xs-12">
{{ widgets.info_box_more('Anzahl Benutzer', user.totalAmount, ' ', path('admin_user'), 'users') }}
</div>
<div class="col-md-3 col-sm-6 col-xs-12">
{# FIXME #}
{{ widgets.info_box_more('Momentan aktiv', timesheetGlobal.activeCurrently, '', '#', 'hourglass-o', 'red') }}
</div>
</div>
{% endif %}
{% endfor %}
{% endblock %}

View File

@@ -11,6 +11,12 @@ services:
tags:
- { name: twig.extension }
# twig function: template_from_string()
app.twig.loader_extension:
class: Twig_Extension_StringLoader
tags:
- { name: 'twig.extension' }
app.twig.intl_extension:
public: false
class: Twig_Extensions_Extension_Intl

View File

@@ -12,6 +12,7 @@
namespace AppBundle\Controller;
use AppBundle\Entity\User;
use AppBundle\Model\UserStatistic;
use TimesheetBundle\Entity\Activity;
use TimesheetBundle\Entity\Project;
use TimesheetBundle\Entity\Timesheet;
@@ -19,7 +20,10 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
use TimesheetBundle\Model\ActivityStatistic;
use TimesheetBundle\Model\ProjectStatistic;
use TimesheetBundle\Model\TimesheetGlobalStatistic;
use TimesheetBundle\Model\TimesheetStatistic;
/**
* Dashboard controller for the admin area.
@@ -48,6 +52,7 @@ class DashboardController extends Controller
$userStats = $this->getDoctrine()->getRepository(User::class)->getGlobalStatistics();
return $this->render('dashboard/index.html.twig', [
'dashboard_widgets' => $this->getWidgets($timesheetUserStats, $timesheetGlobalStats, $activityStats, $projectStats, $userStats),
'timesheetGlobal' => $timesheetGlobalStats,
'timesheetUser' => $timesheetUserStats,
'activity' => $activityStats,
@@ -55,4 +60,79 @@ class DashboardController extends Controller
'user' => $userStats,
]);
}
protected function getWidgets(
TimesheetStatistic $timesheetUserStats,
TimesheetGlobalStatistic $timesheetGlobalStats,
ActivityStatistic $activityStats,
ProjectStatistic $projectStats,
UserStatistic $userStats
) {
$widgets = [
/*
[
'header' => 'dashboard.you',
'widgets' => [
"{{ widgets.info_box_progress('Bewilligte Stunden', 'Stunden zur Abrechnung bewilligt', 120, 10, 'star-o') }}",
"{{ widgets.info_box_progress('Umsatz / Monat', '70% Increase in 30 Days', 6830, 30, 'credit-card', 'black') }}",
"{{ widgets.info_box_progress('Stunden persönlich', 'Das ist noch nicht genug', 135, 60, 'hourglass-o') }}",
"{{ widgets.info_box_progress('Anzahl Benutzer', 'Mehr ist besser!', 5, 90, 'user') }}",
],
],
*/
[
'id' => 'profile.stats',
'header' => 'dashboard.you',
'widgets' => [
"{{ widgets.info_box_counter('stats.durationThisMonth', timesheetUser.durationThisMonth|duration(true), 'hourglass-o', 'green') }}",
//"{{ widgets.info_box_counter('stats.amountThisMonth', timesheetUser.amountThisMonth|money, 'money', 'blue') }}",
"{{ widgets.info_box_counter('stats.durationTotal', timesheetUser.durationTotal|duration(true), 'hourglass-o', 'red') }}",
//"{{ widgets.info_box_counter('stats.amountTotal', timesheetUser.amountTotal|money, 'money', 'yellow') }}",
],
],
];
if (!$this->isGranted('ROLE_TEAMLEAD', null)) {
return $widgets;
}
$widgets[] = [
'id' => 'alluser.stats',
'header' => 'dashboard.all',
'widgets' => [
"{{ widgets.info_box_counter('stats.durationThisMonth', timesheetGlobal.durationThisMonth|duration(true), 'hourglass-o', 'blue') }}",
//"{{ widgets.info_box_counter('stats.amountThisMonth', timesheetGlobal.amountThisMonth|money, 'money', 'green') }}",
"{{ widgets.info_box_counter('stats.durationTotal', timesheetGlobal.durationTotal|duration(true), 'hourglass-o', 'yellow') }}",
//"{{ widgets.info_box_counter('stats.amountTotal', timesheetGlobal.amountTotal|money, 'money', 'red') }}",
],
];
$widgets[] = [
'id' => 'user.stats',
'header' => '',
'widgets' => [
"{{ widgets.info_box_counter('stats.userTotal', user.totalAmount, 'users', 'red') }}",
"{{ widgets.info_box_counter('stats.userActiveThisMoth', timesheetGlobal.activeThisMonth, 'users', 'yellow') }}",
"{{ widgets.info_box_counter('stats.userActiveEver', timesheetGlobal.activeTotal, 'users', 'blue') }}",
"{{ widgets.info_box_counter('stats.userActiveNow', timesheetGlobal.activeCurrently, 'users', 'green') }}",
],
];
if (!$this->isGranted('ROLE_ADMIN', null)) {
return $widgets;
}
$widgets[] = [
'id' => 'admin.stats',
'header' => 'dashboard.admin',
'widgets' => [
"{{ widgets.info_box_more('stats.activitiesTotal', activity.totalAmount, '', path('admin_activity'), 'tasks', 'purple') }}",
"{{ widgets.info_box_more('stats.projectsTotal', project.totalAmount, '', path('admin_project'), 'book', 'yellow') }}",
"{{ widgets.info_box_more('stats.userTotal', user.totalAmount, ' ', path('admin_user'), 'users') }}",
"{{ widgets.info_box_more('stats.userActiveNow', timesheetGlobal.activeCurrently, '', path('admin_timesheet', {'state': 1}), 'hourglass-o', 'red') }}", // FIXME ???
],
];
return $widgets;
}
}

View File

@@ -29,6 +29,7 @@ class UserRepository extends EntityRepository
* Return statistic data for all user.
*
* @return UserStatistic
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function getGlobalStatistics()
{

View File

@@ -40,6 +40,7 @@ class ProjectRepository extends EntityRepository
* Return statistic data for all user.
*
* @return ProjectStatistic
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function getGlobalStatistics()
{