added drag and drop for new records via calendar (#1962)

This commit is contained in:
Kevin Papst
2020-09-17 01:13:48 +02:00
committed by GitHub
parent 14b3de4300
commit 9ef32e75c5
82 changed files with 2808 additions and 385 deletions

View File

@@ -0,0 +1,41 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Calendar;
interface DragAndDropEntry
{
/**
* Data to be passed to the API call.
*
* @return array<string, mixed>
*/
public function getData(): array;
/**
* Returns the title for this entry.
*
* @return string
*/
public function getTitle(): string;
/**
* Returns the color for this entry.
*
* @return string
*/
public function getColor(): string;
/**
* The block to use for rendering the entry.
*
* @return string|null
*/
public function getBlockName(): ?string;
}

View File

@@ -0,0 +1,50 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Calendar;
interface DragAndDropSource
{
/**
* @return string
*/
public function getTitle(): string;
/**
* @return string
*/
public function getRoute(): string;
/**
* @return array<string, string>
*/
public function getRouteParams(): array;
/**
* @return array<string, string>
*/
public function getRouteReplacer(): array;
/**
* @return string
*/
public function getMethod(): string;
/**
* @return DragAndDropEntry[]
*/
public function getEntries(): array;
/**
* If you want to customize the item rendering, you have to return a path to your include here.
*
* @return string|null
*/
public function getBlockInclude(): ?string;
}

View File

@@ -9,39 +9,36 @@
namespace App\Calendar;
class Google
final class Google
{
/**
* @var Source[]
* @var GoogleSource[]
*/
protected $sources = [];
private $sources;
/**
* @var string
*/
protected $apiKey = null;
private $apiKey;
/**
* @param string $apiKey
* @param Source[] $sources
* @param GoogleSource[] $sources
*/
public function __construct($apiKey, $sources = [])
public function __construct(string $apiKey, array $sources = [])
{
$this->apiKey = $apiKey;
$this->sources = $sources;
}
/**
* @return Source[]
* @return GoogleSource[]
*/
public function getSources()
public function getSources(): array
{
return $this->sources;
}
/**
* @return string
*/
public function getApiKey()
public function getApiKey(): string
{
return $this->apiKey;
}

View File

@@ -0,0 +1,48 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Calendar;
final class GoogleSource
{
/**
* @var string
*/
private $id;
/**
* @var string
*/
private $uri;
/**
* @var string|null
*/
private $color;
public function __construct(string $id, string $uri, ?string $color = null)
{
$this->id = $id;
$this->uri = $uri;
$this->color = $color;
}
public function getId(): string
{
return $this->id;
}
public function getUri(): string
{
return $this->uri;
}
public function getColor(): ?string
{
return $this->color;
}
}

View File

@@ -0,0 +1,70 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Calendar;
class RecentActivitiesSource implements DragAndDropSource
{
/**
* @var DragAndDropEntry[]
*/
private $entries;
/**
* @param DragAndDropEntry[] $entries
*/
public function __construct(array $entries)
{
$this->entries = $entries;
}
public function getTitle(): string
{
return 'recent.activities';
}
public function getRoute(): string
{
return 'post_timesheet';
}
public function getMethod(): string
{
return 'POST';
}
/**
* @return array<string, string>
*/
public function getRouteParams(): array
{
return ['full' => 'true'];
}
/**
* @return array<string, string>
*/
public function getRouteReplacer(): array
{
return [];
}
/**
* @return DragAndDropEntry[]
*/
public function getEntries(): array
{
return $this->entries;
}
public function getBlockInclude(): ?string
{
return 'calendar/drag-drop.html.twig';
}
}

View File

@@ -1,83 +0,0 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Calendar;
class Source
{
/**
* @var string
*/
protected $id;
/**
* @var string
*/
protected $uri;
/**
* @var string
*/
protected $color;
/**
* @return string
*/
public function getId(): ?string
{
return $this->id;
}
/**
* @param string $id
* @return Source
*/
public function setId(string $id)
{
$this->id = $id;
return $this;
}
/**
* @return string
*/
public function getUri(): ?string
{
return $this->uri;
}
/**
* @param string $uri
* @return Source
*/
public function setUri(string $uri)
{
$this->uri = $uri;
return $this;
}
/**
* @return string
*/
public function getColor(): ?string
{
return $this->color;
}
/**
* @param string $color
* @return Source
*/
public function setColor(string $color)
{
$this->color = $color;
return $this;
}
}

View File

@@ -0,0 +1,75 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Calendar;
use App\Entity\Activity;
use App\Entity\Project;
use App\Entity\Timesheet;
final class TimesheetEntry implements DragAndDropEntry
{
/**
* @var Timesheet
*/
private $timesheet;
/**
* @var string
*/
private $color;
public function __construct(Timesheet $timesheet, string $color)
{
$this->timesheet = $timesheet;
$this->color = $color;
}
public function getData(): array
{
return [
'description' => $this->timesheet->getDescription(),
'activity' => $this->timesheet->getActivity() !== null ? $this->timesheet->getActivity()->getId() : null,
'project' => $this->timesheet->getProject() !== null ? $this->timesheet->getProject()->getId() : null,
'tags' => implode(',', $this->timesheet->getTagsAsArray()),
];
}
public function getTitle(): string
{
if ($this->timesheet->getActivity() !== null && $this->timesheet->getActivity()->getName() !== null) {
return $this->timesheet->getActivity()->getName();
}
if (null !== $this->timesheet->getProject() && $this->timesheet->getProject()->getName() !== null) {
return $this->timesheet->getProject()->getName();
}
return $this->timesheet->getDescription() ?? '';
}
public function getColor(): string
{
return $this->color;
}
public function getBlockName(): ?string
{
return 'dd_timesheet';
}
public function getActivity(): ?Activity
{
return $this->timesheet->getActivity();
}
public function getProject(): ?Project
{
return $this->timesheet->getProject();
}
}