Skip to content

Commit

Permalink
Merge pull request #20 from dexterity42/development
Browse files Browse the repository at this point in the history
Update for Release 2.0.0
  • Loading branch information
dexterity42 authored Nov 16, 2021
2 parents cc224e4 + 19c5ad3 commit beb7aca
Show file tree
Hide file tree
Showing 20 changed files with 677 additions and 69 deletions.
6 changes: 6 additions & 0 deletions Controller/ManageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Doctrine\ORM\ORMException;
use KimaiPlugin\SharedProjectTimesheetsBundle\Entity\SharedProjectTimesheet;
use KimaiPlugin\SharedProjectTimesheetsBundle\Form\SharedProjectFormType;
use KimaiPlugin\SharedProjectTimesheetsBundle\Model\RecordMergeMode;
use KimaiPlugin\SharedProjectTimesheetsBundle\Repository\SharedProjectTimesheetRepository;
use KimaiPlugin\SharedProjectTimesheetsBundle\Service\ManageService;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
Expand Down Expand Up @@ -70,6 +71,11 @@ public function index()
'@SharedProjectTimesheets/manage/index.html.twig',
[
'sharedProjects' => $sharedProjects,
'mergeModeNone' => RecordMergeMode::MODE_NONE,
'mergeModeMerge' => RecordMergeMode::MODE_MERGE,
'mergeModeUseFirst' => RecordMergeMode::MODE_MERGE_USE_FIRST_OF_DAY,
'mergeModeUseLast' => RecordMergeMode::MODE_MERGE_USE_LAST_OF_DAY,
'RecordMergeMode' => RecordMergeMode::getModes(),
]
);
}
Expand Down
29 changes: 23 additions & 6 deletions Controller/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ public function __construct(
*/
public function indexAction(string $projectId, string $shareKey, Request $request)
{
// Receive parameters.
$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(
$projectId,
$shareKey
Expand All @@ -69,9 +76,7 @@ public function indexAction(string $projectId, string $shareKey, Request $reques
);
}

// Check password if set.
$givenPassword = $request->get("spt-password", null);

// Check access.
if (!$this->viewService->hasAccess($sharedProject, $givenPassword)) {
return $this->render(
'@SharedProjectTimesheets/view/auth.html.twig',
Expand All @@ -82,24 +87,32 @@ public function indexAction(string $projectId, string $shareKey, Request $reques
);
}

$year = (int)$request->get("year", date('Y'));
$month = (int)$request->get("month", date('m'));

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

// Calculate summary.
$rateSum = 0;
$durationSum = 0;
foreach($timeRecords as $record) {
$rateSum += $record->getRate();
$durationSum += $record->getDuration();
}

// Define currency.
$currency = 'EUR';
$customer = $sharedProject->getProject()->getCustomer();
if ( $customer !== null ) {
$currency = $customer->getCurrency();
}

// Prepare stats for charts.
$annualChartVisible = $sharedProject->isAnnualChartVisible();
$monthlyChartVisible = $sharedProject->isMonthlyChartVisible();

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

return $this->render(
'@SharedProjectTimesheets/view/timesheet.html.twig',
[
Expand All @@ -110,6 +123,10 @@ public function indexAction(string $projectId, string $shareKey, Request $reques
'year' => $year,
'month' => $month,
'currency' => $currency,
'statsPerMonth' => $statsPerMonth,
'monthlyChartVisible' => $monthlyChartVisible,
'statsPerDay' => $statsPerDay,
'detailsMode' => $detailsMode,
]
);
}
Expand Down
54 changes: 53 additions & 1 deletion Entity/SharedProjectTimesheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,21 @@ class SharedProjectTimesheet
* @ORM\Column(name="record_merge_mode", type="string", length=50, nullable=false)
* @Assert\Length(max=50)
*/
protected $recordMergeMode = RecordMergeMode::MODE_MERGE;
protected $recordMergeMode = RecordMergeMode::MODE_NONE;

/**
* @var boolean
*
* @ORM\Column(name="annual_chart_visible", type="boolean", nullable=false)
*/
protected $annualChartVisible = false;

/**
* @var boolean
*
* @ORM\Column(name="monthly_chart_visible", type="boolean", nullable=false)
*/
protected $monthlyChartVisible = false;

/**
* @return Project
Expand Down Expand Up @@ -195,4 +209,42 @@ public function setRecordMergeMode(string $recordMergeMode): SharedProjectTimesh
return $this;
}

/**
* @return bool
*/
public function isAnnualChartVisible(): bool
{
return $this->annualChartVisible;
}

/**
* @param bool $annualChartVisible
* @return SharedProjectTimesheet
*/
public function setAnnualChartVisible(bool $annualChartVisible): SharedProjectTimesheet
{
$this->annualChartVisible = $annualChartVisible;

return $this;
}

/**
* @return bool
*/
public function isMonthlyChartVisible(): bool
{
return $this->monthlyChartVisible;
}

/**
* @param bool $monthlyChartVisible
* @return SharedProjectTimesheet
*/
public function setMonthlyChartVisible(bool $monthlyChartVisible): SharedProjectTimesheet
{
$this->monthlyChartVisible = $monthlyChartVisible;

return $this;
}

}
41 changes: 33 additions & 8 deletions Form/SharedProjectFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
Expand Down Expand Up @@ -46,14 +47,38 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'mapped' => false,
'help' => 'shared_project_timesheets.manage.form.password_hint',
])
->add('entryUserVisible', CheckboxType::class, [
'label' => 'shared_project_timesheets.manage.form.entry_user_visible',
'required' => false,
])
->add('entryRateVisible', CheckboxType::class, [
'label' => 'shared_project_timesheets.manage.form.entry_rate_visible',
'required' => false,
])
->add(
$builder
->create('tableOptions', FormType::class, [
'label' => 'shared_project_timesheets.manage.form.table_options',
'inherit_data' => true,
'required' => false,
])
->add('entryUserVisible', CheckboxType::class, [
'label' => 'shared_project_timesheets.manage.form.entry_user_visible',
'required' => false,
])
->add('entryRateVisible', CheckboxType::class, [
'label' => 'shared_project_timesheets.manage.form.entry_rate_visible',
'required' => false,
])
)
->add(
$builder
->create('chartOptions', FormType::class, [
'label' => 'shared_project_timesheets.manage.form.chart_options',
'inherit_data' => true,
'required' => false,
])
->add('annualChartVisible', CheckboxType::class, [
'label' => 'shared_project_timesheets.manage.form.annual_chart_visible',
'required' => false,
])
->add('monthlyChartVisible', CheckboxType::class, [
'label' => 'shared_project_timesheets.manage.form.monthly_chart_visible',
'required' => false,
])
)
->add('save', SubmitType::class, [
'label' => 'action.save',
]);
Expand Down
45 changes: 45 additions & 0 deletions Migrations/Version2020122010000.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* This file is part of the SharedProjectTimesheetsBundle for Kimai 2.
* All rights reserved by Fabian Vetter (https://vettersolutions.de).
*
* For the full copyright and license information, please view the LICENSE file
* that was distributed with this source code.
*/

declare(strict_types=1);

namespace KimaiPlugin\SharedProjectTimesheetsBundle\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Types;
use Doctrine\Migrations\AbstractMigration;

final class Version2020122010000 extends AbstractMigration
{
public function getDescription(): string
{
return "Add flags to enable charts of shared project timesheets";
}

public function up(Schema $schema): void
{
if ($schema->hasTable(Version2020120600000::SHARED_PROJECT_TIMESHEETS_TABLE_NAME)) {
$table = $schema->getTable(Version2020120600000::SHARED_PROJECT_TIMESHEETS_TABLE_NAME);

$table->addColumn('annual_chart_visible', Types::BOOLEAN, ['default' => false, 'notnull' => true]);
$table->addColumn('monthly_chart_visible', Types::BOOLEAN, ['default' => false, 'notnull' => true]);
}
}

public function down(Schema $schema): void
{
if ($schema->hasTable(Version2020120600000::SHARED_PROJECT_TIMESHEETS_TABLE_NAME)) {
$table = $schema->getTable(Version2020120600000::SHARED_PROJECT_TIMESHEETS_TABLE_NAME);

$table->dropColumn('annual_chart_visible');
$table->dropColumn('monthly_chart_visible');
}
}

}
6 changes: 2 additions & 4 deletions Migrations/shared-project-timesheets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@
# bin/console kimai:bundle:shared-project-timesheets:install
# --------------------------------------------------------------------------------------------------

name: SharedProjectTimesheetsMigrations
table_name: bundle_migration_shared_project_timesheets
migrations_namespace: KimaiPlugin\SharedProjectTimesheetsBundle\Migrations
migrations_directory: var/plugins/SharedProjectTimesheetsBundle/Migrations
migrations_paths:
KimaiPlugin\SharedProjectTimesheetsBundle\Migrations: var/plugins/SharedProjectTimesheetsBundle/Migrations
48 changes: 48 additions & 0 deletions Model/ChartStat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/*
* This file is part of the SharedProjectTimesheetsBundle for Kimai 2.
* All rights reserved by Fabian Vetter (https://vettersolutions.de).
*
* For the full copyright and license information, please view the LICENSE file
* that was distributed with this source code.
*/

namespace KimaiPlugin\SharedProjectTimesheetsBundle\Model;


class ChartStat
{

/**
* @var array
*/
private $duration;

/**
* @var array
*/
private $rate;

public function __construct(?array $resultRow = null)
{
$this->duration = $resultRow !== null && isset($resultRow['duration']) ? $resultRow['duration'] : 0;
$this->rate = $resultRow !== null && isset($resultRow['rate']) ? $resultRow['rate'] : 0;
}

/**
* @return mixed
*/
public function getDuration()
{
return $this->duration;
}

/**
* @return mixed
*/
public function getRate()
{
return $this->rate;
}

}
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ A Kimai 2 plugin that allows you to share your project timesheets with anyone yo
## Features

- Create publicly accessible urls for the project timesheets you want to share
- Manage the view and decide what will be exposed
- Password protection
- Show/hide user of records (name of user)
- Show/hide rates of records (hour rate, total rate)
- Access control feature
- protect the shared project timesheets with a password
- View control feature
- show or hide user of records (name of user)
- show or hide rates of records (hour rate, total rate)
- show or hide chart with day comparison by selected month
- show or hide chart with month comparison by selected year
- View customizations
- define whether and how to merge records of a day (e.g. merge records of one day, use description of last record)

## Installation

Expand Down
19 changes: 16 additions & 3 deletions Resources/translations/messages.de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,29 @@ shared_project_timesheets:
project: Projekt
record_merge_mode: Zeiten eines Tages zusammenführen
password_hint: Feld leer lassen um kein Passwort festzulegen
table_options: Detailtabelle - Optionen
entry_user_visible: Benutzer sichtbar
entry_rate_visible: Kosten sichtbar
chart_options: Diagramme - Optionen
annual_chart_visible: Jahresdiagramm sichtbar
monthly_chart_visible: Monatsdiagramm sichtbar
table:
name: Name des Projekts
password: Passwortgeschützt
url: Link
password: Passwortgeschützt
record_merge_mode: Zeiten zusammenführen
entry_user_visible: Benutzer sichtbar
entry_rate_visible: Kosten sichtbar
annual_chart_visible: Jahresdiagramm sichtbar
monthly_chart_visible: Monatsdiagramm sichtbar
persist:
success: Erfolgreich gespeichert.
error: Speichern fehlgeschlagen. Bitte versuchen Sie es erneut.

view:
title: Zeiten des Projektes
selection_text: Zeige Zeiten von
title: "Projekt:"
subtitle: "- geteilte Projektzeiten"
selection_title: Monat auswählen
month:
1: Januar
2: Februar
Expand All @@ -44,6 +51,7 @@ shared_project_timesheets:
11: November
12: Dezember
table:
title: Details
date: Datum
description: Beschreibung
duration: Dauer
Expand All @@ -60,6 +68,11 @@ shared_project_timesheets:
error:
title: Ein Fehler ist aufgetreten
access_denied: Zugriff verweigert.
chart:
per_month_title: Stunden pro Monat im Jahr %year%
details:
table: Tabelle
chart: Diagramm

model:
merge_record_mode:
Expand Down
Loading

0 comments on commit beb7aca

Please sign in to comment.