Skip to content

Commit

Permalink
Merge pull request #8 from DestinationCore/chore/order-date-exceptions
Browse files Browse the repository at this point in the history
Exception Formatting
  • Loading branch information
Matt Banner authored Feb 15, 2023
2 parents 1dcbe38 + 89a84c4 commit 40e7c57
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to this project will be documented in this file.

## 1.5.0 - 2023-02-15
### Added
- CP notice when a date has been added to exceptions.

### Changed
- Date exceptions values ordered before saving.
- Remove duplicates from date exceptions value before saving.

## 1.4.4 - 2022-08-10
### Added
- `nesbot/carbon` package.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "unionco/calendarize",
"description": "A calendar field type providing functionality for recurrence.",
"version": "1.4.4",
"version": "1.5.0",
"type": "craft-plugin",
"keywords": [
"craft",
Expand Down
2 changes: 1 addition & 1 deletion src/assetbundles/cpbundle/dist/js/main.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/assetbundles/cpbundle/src/js/modules/exceptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ class CalendarException {
li.appendChild(p);

this.listing.appendChild(li);

Craft.cp.displayNotice("Added date exception for " + getLocalizedDayName(localizedMoment) + ', ' + localizedMoment.format('L') + ".");
})
}

Expand Down
11 changes: 8 additions & 3 deletions src/services/CalendarizeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,14 @@ public function saveField(CalendarizeField $field, ElementInterface $owner): boo
}

if (isset($value->exceptions)) {
$record->exceptions = Json::encode(array_map(function ($exception) use ($value) {
return Db::prepareDateForDb($exception);
}, $value->exceptions ?? []));
$record->exceptions = collect($value->exceptions)
->unique()
->sort()
->map(function ($exception) {
return Db::prepareDateForDb($exception);
})
->values()
->toJson();
}

if (isset($value->timeChanges)) {
Expand Down

0 comments on commit 40e7c57

Please sign in to comment.