Skip to content

Commit

Permalink
v2.0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
kjmartens committed Dec 28, 2018
1 parent 5e7ac10 commit cb4c34a
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 15 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Solspace Calendar Changelog

## 2.0.12 - 2018-12-28
### Changed
- Updated Demo Templates installer to be compatible with Craft 3.1.
- Updated Live Preview feature to be compatible with Craft 3.1.

### Fixed
- Fixed a bug where pagination was not working reliably for `calendar.events`.
- Fixed a bug where editing events with Select Dates repeat rule via front end could trigger some errors or was showing blank.

## 2.0.11 - 2018-12-13
### Changed
- Updated the Full Calendar JS demo templates to have a limit of 500 events to allow websites with many events to work more reliably by default.
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": "solspace/craft3-calendar",
"description": "The most powerful event management plugin for Craft.",
"version": "2.0.11",
"version": "2.0.12",
"type": "craft-plugin",
"authors": [
{
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/EventsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ private function renderEditForm(Event $event, string $title): Response
'fields' => '#title-field, #fields .calendar-event-wrapper > .field, #fields > .field > .field',
'extraFields' => '#settings',
'previewUrl' => $event->getUrl(),
'previewAction' => 'calendar/events/preview',
'previewAction' => \Craft::$app->getSecurity()->hashData('calendar/events/preview'),
'previewParams' => [
'eventId' => $event->id,
'siteId' => $event->siteId,
Expand Down
3 changes: 2 additions & 1 deletion src/Elements/Db/EventQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,6 @@ public function all($db = null): array
$this->offset = null;

$ids = parent::ids($db);
$this->totalCount = \count($ids);

$this->limit = $limit;
$this->offset = $offset;
Expand Down Expand Up @@ -519,6 +518,8 @@ public function all($db = null): array
shuffle($this->eventCache);
}

$this->totalCount = \count($this->eventCache);

// Remove excess dates based on ::$limit and ::$offset
$this->cutOffExcess($this->eventCache);

Expand Down
48 changes: 41 additions & 7 deletions src/Library/CodePack/Components/RoutesComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use craft\db\Query;
use craft\helpers\Json;
use craft\services\ProjectConfig;

class RoutesComponent extends AbstractJsonComponent
{
Expand All @@ -16,6 +17,13 @@ public function install(string $prefix = null)
{
$routeService = \Craft::$app->routes;

$existingRoutes = [];
if (version_compare(\Craft::$app->getVersion(), '3.1', '>=')) {
/** @var ProjectConfig $config */
$config = \Craft::$app->getProjectConfig();
$existingRoutes = $config->get('routes');
}

$data = $this->getData();
$demoFolder = $prefix . '/';

Expand Down Expand Up @@ -63,13 +71,18 @@ public function install(string $prefix = null)
}
}

$id = (new Query())
->select('id')
->from('{{%routes}}')
->where(['uriParts' => Json::encode($uriParts)])
->scalar();

$routeService->saveRoute($urlParts, $template, null, $id ?: null);
if (version_compare(\Craft::$app->getVersion(), '3.1', '>=')) {
$uuid = $this->findExistingRoute($uriParts, $existingRoutes);
$routeService->saveRoute($urlParts, $template, null, $uuid);
} else {
$id = (new Query())
->select('id')
->from('{{%routes}}')
->where(['uriParts' => Json::encode($uriParts)])
->scalar();

$routeService->saveRoute($urlParts, $template, null, $id ?: null);
}
}
}
}
Expand All @@ -82,4 +95,25 @@ protected function setProperties()
{
$this->fileName = 'routes.json';
}

/**
* @param array $uriParts
* @param array|null $existingRoutes
*
* @return int|string|null
*/
private function findExistingRoute(array $uriParts, array $existingRoutes = null)
{
if (!$existingRoutes) {
return null;
}

foreach ($existingRoutes as $uuid => $route) {
if (Json::encode($route['uriParts']) === Json::encode($uriParts)) {
return $uuid;
}
}

return null;
}
}
2 changes: 1 addition & 1 deletion src/Resources/css/src/event-edit.css

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions src/Services/CalendarsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,11 @@ public function isEventTemplateValid(CalendarModel $calendar, int $siteId): bool
$oldTemplateMode = $view->getTemplateMode();
$view->setTemplateMode($view::TEMPLATE_MODE_SITE);

// Does the template exist?
$templateExists = \Craft::$app->getView()->doesTemplateExist((string) $siteSettings->template);
$templateExists = false;
if ($siteSettings->template) {
// Does the template exist?
$templateExists = \Craft::$app->getView()->doesTemplateExist((string) $siteSettings->template);
}

// Restore the original template mode
$view->setTemplateMode($oldTemplateMode);
Expand Down
4 changes: 2 additions & 2 deletions src/codepack/templates/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -420,13 +420,13 @@ <h1>Event Edit</h1>
<div class="form-group row select-dates-list" data-repeats data-show-for="select_dates">
{% for selectDate in event.selectDatesAsDates %}
<div class="col-12 col-sm-10 offset-sm-2">
<input type="hidden" name="calendarEvent[selectDates][]" value="{{ selectDate.date.toDateTimeString }}" />
<input type="hidden" name="calendarEvent[selectDates][]" value="{{ selectDate.toDateTimeString }}" />
<a href="javascript:;"
class="remove-select-date"
style="color: darkred; text-decoration: none; position: relative; top: 1px;">
<span class="far fa-times-circle"></span>
</a>
{{ selectDate.date.format('l, F j, Y') }}
{{ selectDate.format('l, F j, Y') }}
</div>
{% endfor %}
</div>
Expand Down

0 comments on commit cb4c34a

Please sign in to comment.