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 = [];
$colorHelper = new Color();
$copy = $this->configuration->isCalendarDragAndDropCopyData();
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));

View File

@@ -13,6 +13,9 @@ use App\Entity\Activity;
use App\Entity\Project;
use App\Entity\Timesheet;
/**
* @internal
*/
final class TimesheetEntry implements DragAndDropEntry
{
/**
@@ -23,27 +26,31 @@ final class TimesheetEntry implements DragAndDropEntry
* @var string
*/
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->color = $color;
$this->copy = $copy;
}
public function getData(): array
{
$tags = null;
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(),
$data = [
'activity' => $this->timesheet->getActivity() !== null ? $this->timesheet->getActivity()->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

View File

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

View File

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

View File

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