Skip to content

Commit

Permalink
fix dropdown (#5)
Browse files Browse the repository at this point in the history
* fix dropdown
* use global translation for duration
* fix padding
* fix access denied exception
* use month translations from core
  • Loading branch information
kevinpapst authored Jul 23, 2024
1 parent 4121405 commit f44b020
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 53 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 3.2.0

Compatibility: requires minimum Kimai 2.19.0

- Fix dropdowns

## 3.1.0

Compatibility: requires minimum Kimai 2.11.0
Expand Down
31 changes: 18 additions & 13 deletions Controller/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,23 @@
#[Route(path: '/auth/shared-project-timesheets')]
class ViewController extends AbstractController
{
public function __construct(
private ViewService $viewService,
private SharedProjectTimesheetRepository $sharedProjectTimesheetRepository
) {
}

#[Route(path: '/{id}/{shareKey}', name: 'view_shared_project_timesheets', methods: ['GET', 'POST'])]
public function indexAction(Project $project, string $shareKey, Request $request, ProjectStatisticService $statisticsService): Response
public function indexAction(
Project $project,
string $shareKey,
Request $request,
ProjectStatisticService $statisticsService,
ViewService $viewService,
SharedProjectTimesheetRepository $sharedProjectTimesheetRepository
): Response
{
$givenPassword = $request->get('spt-password');
$year = (int) $request->get('year', date('Y'));
$month = (int) $request->get('month', date('m'));
$detailsMode = $request->get('details', 'table');

// Get project.
$sharedProject = $this->sharedProjectTimesheetRepository->findByProjectAndShareKey(
$sharedProject = $sharedProjectTimesheetRepository->findByProjectAndShareKey(
$project->getId(),
$shareKey
);
Expand All @@ -47,15 +48,15 @@ public function indexAction(Project $project, string $shareKey, Request $request
}

// Check access.
if (!$this->viewService->hasAccess($sharedProject, $givenPassword)) {
if (!$viewService->hasAccess($sharedProject, $givenPassword)) {
return $this->render('@SharedProjectTimesheets/view/auth.html.twig', [
'project' => $sharedProject->getProject(),
'invalidPassword' => $request->isMethod('POST') && $givenPassword !== null,
]);
}

// Get time records.
$timeRecords = $this->viewService->getTimeRecords($sharedProject, $year, $month);
$timeRecords = $viewService->getTimeRecords($sharedProject, $year, $month);

// Calculate summary.
$rateSum = 0;
Expand All @@ -76,11 +77,15 @@ public function indexAction(Project $project, string $shareKey, Request $request
$annualChartVisible = $sharedProject->isAnnualChartVisible();
$monthlyChartVisible = $sharedProject->isMonthlyChartVisible();

$statsPerMonth = $annualChartVisible ? $this->viewService->getAnnualStats($sharedProject, $year) : null;
$statsPerMonth = $annualChartVisible ? $viewService->getAnnualStats($sharedProject, $year) : null;
$statsPerDay = ($monthlyChartVisible && $detailsMode === 'chart')
? $this->viewService->getMonthlyStats($sharedProject, $year, $month) : null;
? $viewService->getMonthlyStats($sharedProject, $year, $month) : null;

// we cannot call $this->getDateTimeFactory() as it throws a AccessDeniedException for anonymous users
$timezone = $project->getCustomer()->getTimezone() ?? date_default_timezone_get();
$date = new \DateTimeImmutable('now', new \DateTimeZone($timezone));

$stats = $statisticsService->getBudgetStatisticModel($project, $this->getDateTimeFactory()->createDateTime());
$stats = $statisticsService->getBudgetStatisticModel($project, $date);

return $this->render('@SharedProjectTimesheets/view/timesheet.html.twig', [
'sharedProject' => $sharedProject,
Expand Down
14 changes: 0 additions & 14 deletions Resources/translations/messages.de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,10 @@ shared_project_timesheets:
title: "Projekt:"
subtitle: "- geteilte Projektzeiten"
selection_title: Monat auswählen
month:
1: Januar
2: Februar
3: März
4: April
5: Mai
6: Juni
7: Juli
8: August
9: September
10: Oktober
11: November
12: Dezember
table:
title: Details
date: Datum
description: Beschreibung
duration: Dauer
empty: Keine Einträge verfügbar für diesen Monat
user: Benutzer
rate_hour: Stundenlohn
Expand Down
14 changes: 0 additions & 14 deletions Resources/translations/messages.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,10 @@ shared_project_timesheets:
title: "Project:"
subtitle: "- shared project timesheets"
selection_title: Month selection
month:
1: January
2: February
3: March
4: April
5: May
6: June
7: July
8: August
9: September
10: October
11: November
12: December
table:
title: Details
date: Date
description: Description
duration: Duration
empty: No entries available for this month
user: User
rate_hour: Hour rate
Expand Down
2 changes: 1 addition & 1 deletion Resources/views/view/chart/annual-chart.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
y: {
scaleLabel: {
display: true,
labelString: '{{ 'shared_project_timesheets.view.table.duration' | trans }}',
labelString: '{{ 'duration'|trans }}',
},
ticks: {
beginAtZero: true
Expand Down
4 changes: 2 additions & 2 deletions Resources/views/view/chart/monthly-chart.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{% endfor %}
],
datasets: [{
label: '{{ 'shared_project_timesheets.view.table.duration' | trans }}',
label: '{{ 'duration'|trans }}',
backgroundColor: '{{ backgroundColor }}',
data: [
{% for stats in statsPerDay %}
Expand All @@ -38,7 +38,7 @@
y: {
scaleLabel: {
display: true,
labelString: '{{ 'shared_project_timesheets.view.table.duration' | trans }}',
labelString: '{{ 'duration'|trans }}',
},
ticks: {
beginAtZero: true
Expand Down
20 changes: 13 additions & 7 deletions Resources/views/view/timesheet.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@
{% endblock %}

{% block head %}
{{ parent() }}
{{ encore_entry_script_tags('app') }}
{{ encore_entry_script_tags('chart') }}
{% endblock %}

{% block javascripts %}
{% import "macros/webloader.html.twig" as webloader %}
{{ webloader.init_frontend_loader() }}
{% endblock %}

{% block page_classes %}page{% endblock %}

{% block page_content %}
Expand All @@ -32,11 +36,13 @@
</a>
<div class="btn-group" role="group">
<button type="button" class="btn btn-default dropdown-toggle" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ ('shared_project_timesheets.view.month.' ~ month) | trans }}
{% set tmpMonth = report_date(year, month) %}
{{ tmpMonth|month_name }}
</button>
<ul class="dropdown-menu dropdown-menu-start pre-scrollable">
{% for i in 1..12 %}
<li><a href="{{ app.request.pathinfo }}?year={{ year }}&month={{ i }}{% if detailsMode != 'table' %}&details={{ detailsMode }}{% endif %}" class="dropdown-item {{ i == month ? 'active' : '' }}">{{ ('shared_project_timesheets.view.month.' ~ i) | trans }}</a></li>
{% set tmpMonth = report_date(year, i) %}
<li><a href="{{ app.request.pathinfo }}?year={{ year }}&month={{ i }}{% if detailsMode != 'table' %}&details={{ detailsMode }}{% endif %}" class="dropdown-item {{ i == month ? 'active' : '' }}">{{ tmpMonth|month_name }}</a></li>
{% endfor %}
</ul>
</div>
Expand Down Expand Up @@ -68,7 +74,7 @@
<span class="ps-2">{{ sharedProject.project.name }}</span>
</h2>

{% if statsPerMonth != null %}
{% if statsPerMonth is not null %}
<div class="row mb-3">
<div class="col-md-12">
<div class="card">
Expand Down Expand Up @@ -99,10 +105,10 @@
</div>
{% endif %}
</div>
<div class="card-body{% if timeRecords is not empty%} p-0{% endif %}">
<div class="card-body{% if timeRecords is not empty and statsPerDay is null %} p-0{% endif %}">
{% if timeRecords is empty %}
{{ nothing_found() }}
{% elseif statsPerDay == null %}
{% elseif statsPerDay is null %}
<table class="table table-vcenter table-hover dataTable">
<thead>
<tr>
Expand All @@ -111,7 +117,7 @@
<th>{{ 'shared_project_timesheets.view.table.user' | trans }}</th>
{% endif %}
<th>{{ 'shared_project_timesheets.view.table.description' | trans }}</th>
<th class="w-min">{{ 'shared_project_timesheets.view.table.duration' | trans }}</th>
<th class="w-min">{{ 'duration'|trans }}</th>
{% if sharedProject.entryRateVisible %}
<th class="w-min">{{ 'hourlyRate' | trans }}</th>
<th class="w-min">{{ 'total_rate' | trans }}</th>
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Share project timesheets with anyone",
"homepage": "https://github.com/Keleo/SharedProjectTimesheetsBundle",
"type": "kimai-plugin",
"version": "3.1.0",
"version": "3.2.0",
"keywords": [
"kimai",
"kimai-plugin"
Expand All @@ -22,7 +22,7 @@
],
"extra": {
"kimai": {
"require": 21100,
"require": 21900,
"name": "Shared-Projects"
}
},
Expand Down

0 comments on commit f44b020

Please sign in to comment.