configurable calendar drag and drop behavior (#3537)

This commit is contained in:
Kevin Papst
2022-09-14 23:29:26 +02:00
committed by GitHub
parent d705287510
commit 283ab80fc7
10 changed files with 50 additions and 13 deletions

View File

@@ -67,8 +67,9 @@ final class CalendarService
$entries = []; $entries = [];
$colorHelper = new Color(); $colorHelper = new Color();
$copy = $this->configuration->isCalendarDragAndDropCopyData();
foreach ($recentActivity->getRecentActivities() as $timesheet) { foreach ($recentActivity->getRecentActivities() as $timesheet) {
$entries[] = new TimesheetEntry($timesheet, $colorHelper->getTimesheetColor($timesheet)); $entries[] = new TimesheetEntry($timesheet, $colorHelper->getTimesheetColor($timesheet), $copy);
} }
$event->addSource(new RecentActivitiesSource($entries)); $event->addSource(new RecentActivitiesSource($entries));

View File

@@ -13,6 +13,9 @@ use App\Entity\Activity;
use App\Entity\Project; use App\Entity\Project;
use App\Entity\Timesheet; use App\Entity\Timesheet;
/**
* @internal
*/
final class TimesheetEntry implements DragAndDropEntry final class TimesheetEntry implements DragAndDropEntry
{ {
/** /**
@@ -23,27 +26,31 @@ final class TimesheetEntry implements DragAndDropEntry
* @var string * @var string
*/ */
private $color; private $color;
/**
* @var bool
*/
private $copy;
public function __construct(Timesheet $timesheet, string $color) public function __construct(Timesheet $timesheet, string $color, bool $copy = false)
{ {
$this->timesheet = $timesheet; $this->timesheet = $timesheet;
$this->color = $color; $this->color = $color;
$this->copy = $copy;
} }
public function getData(): array public function getData(): array
{ {
$tags = null; $data = [
if (!empty($this->timesheet->getTagsAsArray())) {
$tags = implode(',', $this->timesheet->getTagsAsArray());
}
return [
// restarting a timesheet should not copy the description - @version 1.21
//'description' => $this->timesheet->getDescription(),
'activity' => $this->timesheet->getActivity() !== null ? $this->timesheet->getActivity()->getId() : null, 'activity' => $this->timesheet->getActivity() !== null ? $this->timesheet->getActivity()->getId() : null,
'project' => $this->timesheet->getProject() !== null ? $this->timesheet->getProject()->getId() : null, 'project' => $this->timesheet->getProject() !== null ? $this->timesheet->getProject()->getId() : null,
'tags' => $tags,
]; ];
if ($this->copy) {
$data['description'] = $this->timesheet->getDescription();
$data['tags'] = implode(',', $this->timesheet->getTagsAsArray());
}
return $data;
} }
public function getTitle(): string public function getTitle(): string

View File

@@ -180,6 +180,11 @@ class SystemConfiguration implements SystemBundleConfiguration
return (int) $this->find('calendar.dragdrop_amount'); return (int) $this->find('calendar.dragdrop_amount');
} }
public function isCalendarDragAndDropCopyData(): bool
{
return (bool) $this->find('calendar.dragdrop_data');
}
// ========== Customer configurations ========== // ========== Customer configurations ==========
public function getCustomerDefaultTimezone(): ?string public function getCustomerDefaultTimezone(): ?string

View File

@@ -650,6 +650,10 @@ final class SystemConfigurationController extends AbstractController
->setTranslationDomain('system-configuration') ->setTranslationDomain('system-configuration')
->setType(IntegerType::class) ->setType(IntegerType::class)
->setConstraints([new Range(['min' => 0, 'max' => 20]), new NotNull()]), ->setConstraints([new Range(['min' => 0, 'max' => 20]), new NotNull()]),
(new Configuration())
->setName('calendar.dragdrop_data')
->setTranslationDomain('system-configuration')
->setType(CheckboxType::class),
(new Configuration()) (new Configuration())
->setName('calendar.title_pattern') ->setName('calendar.title_pattern')
->setTranslationDomain('system-configuration') ->setTranslationDomain('system-configuration')

View File

@@ -438,6 +438,7 @@ class Configuration implements ConfigurationInterface
->thenInvalid('The dragdrop_amount must be between 0 and 20') ->thenInvalid('The dragdrop_amount must be between 0 and 20')
->end() ->end()
->end() ->end()
->booleanNode('dragdrop_data')->defaultFalse()->end()
->enumNode('title_pattern') ->enumNode('title_pattern')
->values(['{activity}', '{project}', '{customer}', '{description}']) ->values(['{activity}', '{project}', '{customer}', '{description}'])
->defaultValue('{activity}') ->defaultValue('{activity}')

View File

@@ -37,7 +37,6 @@ class TimesheetEntryTest extends TestCase
$expectedData = [ $expectedData = [
'activity' => null, 'activity' => null,
'project' => null, 'project' => null,
'tags' => 'bulb,action test',
]; ];
$sut = new TimesheetEntry($timesheet, '#cccccc'); $sut = new TimesheetEntry($timesheet, '#cccccc');
@@ -48,6 +47,17 @@ class TimesheetEntryTest extends TestCase
$this->assertSame($activity, $sut->getActivity()); $this->assertSame($activity, $sut->getActivity());
$this->assertEquals('dd_timesheet', $sut->getBlockName()); $this->assertEquals('dd_timesheet', $sut->getBlockName());
$this->assertEquals($expectedData, $sut->getData()); $this->assertEquals($expectedData, $sut->getData());
$expectedData = [
'activity' => null,
'project' => null,
'tags' => 'bulb,action test',
'description' => 'hello foo bar',
];
$sut = new TimesheetEntry($timesheet, '#cccccc', true);
$this->assertEquals($expectedData, $sut->getData());
} }
public function testEmpty() public function testEmpty()
@@ -57,7 +67,6 @@ class TimesheetEntryTest extends TestCase
$expectedData = [ $expectedData = [
'activity' => null, 'activity' => null,
'project' => null, 'project' => null,
'tags' => null,
]; ];
$sut = new TimesheetEntry($timesheet, '#ddd'); $sut = new TimesheetEntry($timesheet, '#ddd');

View File

@@ -131,6 +131,7 @@ class AppExtensionTest extends TestCase
], ],
'weekends' => true, 'weekends' => true,
'dragdrop_amount' => 10, 'dragdrop_amount' => 10,
'dragdrop_data' => false,
'title_pattern' => '{activity}', 'title_pattern' => '{activity}',
], ],
'kimai.dashboard' => [], 'kimai.dashboard' => [],

View File

@@ -361,6 +361,7 @@ class ConfigurationTest extends TestCase
], ],
'weekends' => true, 'weekends' => true,
'dragdrop_amount' => 10, 'dragdrop_amount' => 10,
'dragdrop_data' => false,
'title_pattern' => '{activity}', 'title_pattern' => '{activity}',
], ],
'theme' => [ 'theme' => [

View File

@@ -310,6 +310,10 @@
<source>label.calendar.dragdrop_amount</source> <source>label.calendar.dragdrop_amount</source>
<target>Anzahl an Einträgen für Drag&amp;Drop (0 = deaktiviert)</target> <target>Anzahl an Einträgen für Drag&amp;Drop (0 = deaktiviert)</target>
</trans-unit> </trans-unit>
<trans-unit id="eiQKW2A" resname="label.calendar.dragdrop_data">
<source>label.calendar.dragdrop_data</source>
<target>Kopiert Daten beim Hinzufügen via Drag &amp; Drop</target>
</trans-unit>
<trans-unit id="MXabpD7" resname="label.calendar.title_pattern" approved="yes"> <trans-unit id="MXabpD7" resname="label.calendar.title_pattern" approved="yes">
<source>label.calendar.title_pattern</source> <source>label.calendar.title_pattern</source>
<target>Darstellung der Titel von Kalendereinträgen</target> <target>Darstellung der Titel von Kalendereinträgen</target>

View File

@@ -310,6 +310,10 @@
<source>label.calendar.dragdrop_amount</source> <source>label.calendar.dragdrop_amount</source>
<target>Amount of entries for drag&amp;drop (0 = deactivated)</target> <target>Amount of entries for drag&amp;drop (0 = deactivated)</target>
</trans-unit> </trans-unit>
<trans-unit id="eiQKW2A" resname="label.calendar.dragdrop_data">
<source>label.calendar.dragdrop_data</source>
<target>Copies data when adding via drag &amp; drop</target>
</trans-unit>
<trans-unit id="MXabpD7" resname="label.calendar.title_pattern"> <trans-unit id="MXabpD7" resname="label.calendar.title_pattern">
<source>label.calendar.title_pattern</source> <source>label.calendar.title_pattern</source>
<target>Display of the titles of calendar entries</target> <target>Display of the titles of calendar entries</target>