Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support excluding dates and field re-org #83

Merged
merged 11 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
289 changes: 175 additions & 114 deletions resources/fieldsets/event.yaml
Original file line number Diff line number Diff line change
@@ -1,47 +1,30 @@
title: Event
fields:
-
handle: all_day
field:
type: toggle
width: 25
display: 'All Day?'
-
handle: multi_day
field:
type: toggle
width: 25
display: 'Multi-Day?'
-
handle: start_date
field:
type: date
allow_blank: false
allow_time: false
require_time: false
input_format: M/D/YYYY
width: 25
display: 'Start Date'
if:
multi_day: 'equals false'
-
handle: start_time
field:
type: time
width: 25
display: 'Start Time'
if:
multi_day: 'equals false'
all_day: 'equals false'
-
handle: end_time
handle: recurrence
field:
type: time
width: 25
display: 'End Time'
if:
multi_day: 'equals false'
all_day: 'equals false'
type: select
options:
none: None
daily: Daily
weekly: Weekly
monthly: Monthly
every: Every
multi_day: Multi-Day
width: 33
display: Recurrence
default: none
instructions_position: above
listable: hidden
visibility: visible
replicator_preview: true
taggable: false
push_tags: false
multiple: false
clearable: false
searchable: true
cast_booleans: false
hide_display: false
-
handle: timezone
field:
Expand All @@ -53,71 +36,30 @@ fields:
cast_booleans: false
display: Timezone
type: timezones
icon: select
listable: hidden
instructions_position: above
mode: typeahead
width: 50
width: 33
-
handle: days
handle: all_day
field:
type: grid
mode: table
fields:
-
handle: date
field:
type: date
allow_blank: false
allow_time: false
require_time: false
input_format: M/D/YYYY
width: 33
display: Date
-
handle: start_time
field:
type: time
width: 33
display: 'Start Time'
-
handle: end_time
field:
type: time
width: 33
display: 'End Time'
display: Days
add_row: 'Add Day'
type: toggle
width: 33
display: 'All Day?'
instructions_position: above
listable: hidden
reorderable: true
if:
multi_day: 'equals true'
-
handle: recurrence_section
field:
type: section
display: Recurrence
if:
multi_day: 'equals false'
-
handle: recurrence
field:
type: select
options:
0: None
daily: Daily
weekly: Weekly
monthly: Monthly
every: Every
width: 25
display: 'Recurrence Type'
visibility: visible
replicator_preview: true
default: false
if:
multi_day: 'equals false'
hide_display: false
unless:
recurrence: 'equals multi_day'
-
handle: interval
field:
type: integer
width: 25
width: 50
display: Interval
if:
recurrence: 'equals every'
Expand All @@ -130,9 +72,34 @@ fields:
weeks: Weeks
years: Years
display: Period
width: 25
width: 50
if:
recurrence: 'equals every'
-
handle: start_date
field:
type: date
allow_blank: false
allow_time: false
require_time: false
input_format: M/D/YYYY
width: 50
display: 'Start Date'
instructions_position: above
listable: hidden
visibility: visible
replicator_preview: true
mode: single
inline: true
full_width: true
columns: 1
rows: 1
time_enabled: false
time_seconds_enabled: false
hide_display: false
unless_any:
multi_day: 'equals true'
recurrence: 'equals multi_day'
-
handle: end_date
field:
Expand All @@ -142,49 +109,143 @@ fields:
require_time: false
input_format: M/D/YYYY
display: 'End Date'
width: 25
width: 50
listable: hidden
mode: single
time_enabled: false
time_required: false
full_width: false
inline: false
full_width: true
inline: true
columns: 1
rows: 1
instructions_position: above
visibility: visible
replicator_preview: true
time_seconds_enabled: false
hide_display: false
if:
recurrence: 'contains_any daily, weekly, monthly, every'
-
handle: exclude_dates
handle: start_time
field:
type: time
width: 25
display: 'Start Time'
instructions: 'Input in [24-hour format](https://en.wikipedia.org/wiki/24-hour_clock)'
instructions_position: above
listable: hidden
visibility: visible
replicator_preview: true
seconds_enabled: false
hide_display: false
unless_any:
multi_day: 'equals true'
all_day: 'equals true'
recurrence: 'equals multi_day'
-
handle: end_time
field:
type: time
width: 25
display: 'End Time'
instructions: 'Input in [24-hour format](https://en.wikipedia.org/wiki/24-hour_clock)'
instructions_position: above
listable: hidden
visibility: visible
replicator_preview: true
seconds_enabled: false
hide_display: false
unless_any:
multi_day: 'equals true'
all_day: 'equals true'
recurrence: 'equals multi_day'
-
handle: days
field:
type: grid
mode: table
fields:
-
handle: date
field:
mode: single
inline: false
full_width: false
columns: 1
rows: 1
time_enabled: false
time_seconds_enabled: false
type: date
allow_blank: false
allow_time: false
require_time: false
input_format: M/D/YYYY
width: 25
display: Date
-
handle: start_time
field:
type: time
width: 25
display: 'Start Time'
instructions: 'Input in 24-hour format (ie 2:00 PM will be entered as 14:00)'
instructions_position: above
listable: hidden
visibility: visible
replicator_preview: true
seconds_enabled: false
hide_display: false
unless:
all_day: 'equals true'
-
handle: end_time
field:
type: time
width: 25
display: 'End Time'
instructions: 'Input in 24-hour format (ie 2:00 PM will be entered as 14:00)'
instructions_position: above
listable: hidden
visibility: visible
replicator_preview: true
seconds_enabled: false
hide_display: false
mode: table
reorderable: false
fullscreen: false
unless:
all_day: 'equals true'
-
handle: all_day
field: 'events::event.all_day'
config:
width: 25
display: 'Event Days'
add_row: 'Add Day'
listable: hidden
reorderable: true
instructions_position: above
visibility: visible
replicator_preview: true
min_rows: 1
fullscreen: true
hide_display: false
if_any:
multi_day: 'equals true'
recurrence: 'equals multi_day'
-
handle: exclude_dates
field:
type: grid
display: Exclusions
mode: table
fields:
-
handle: date
field:
type: date
allow_blank: false
allow_time: false
require_time: false
input_format: M/D/YYYY
display: Date
display: 'Exclude Days'
add_row: 'Add Day'
listable: hidden
reorderable: true
instructions_position: above
visibility: visible
replicator_preview: true
fullscreen: true
hide_display: false
if:
multi_day: 'equals false'
recurrence: 'contains_any daily, weekly, monthly, every'
add_row: 'Add Excluded Date'
if_any:
recurrence: 'contains_any monthly, daily, weekly, every'
4 changes: 2 additions & 2 deletions src/Day.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(array $data, string $timezone, bool $isAllDay = fals
$this->startTime = Arr::get($data, 'start_time');
$this->endTime = Arr::get($data, 'end_time');

if (! $isAllDay && $this->isAllDay()) {
if (! $isAllDay && (empty($this->startTime) && empty($this->endTime))) {
$this->isAllDay = true;
} else {
$this->isAllDay = $isAllDay;
Expand All @@ -37,7 +37,7 @@ public function hasEndtime(): bool

public function isAllDay(): bool
{
return empty($this->startTime) && empty($this->endTime);
return $this->isAllDay;
}

public function start(): CarbonImmutable
Expand Down
2 changes: 1 addition & 1 deletion src/EventFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class EventFactory
{
public static function createFromEntry(Entry $event, bool $collapseMultiDays = false): Event
{
if ($event->multi_day) {
if ($event->multi_day || $event->recurrence->value() === 'multi_day') {
return new MultiDayEvent($event, $collapseMultiDays);
}

Expand Down
1 change: 1 addition & 0 deletions src/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ private function occurrences(callable $generator): EntryCollection
// take each event and generate the occurences
->flatMap(callback: $generator)
->reject(fn (Entry $occurrence) => collect($occurrence->exclude_dates)
->filter(fn (Values $dateRow) => $dateRow->date)
->contains(fn (Values $dateRow) => $dateRow->date->isSameDay($occurrence->start))
)->sortBy(callback: fn (Entry $occurrence) => $occurrence->start, descending: $this->sort === 'desc')
->values();
Expand Down
Loading
Loading