Skip to content

Commit

Permalink
Adds View::forceShowDate and allows the data provider to customize th…
Browse files Browse the repository at this point in the history
…e data view before outputting to front-end
  • Loading branch information
Willem Vervuurt committed Nov 24, 2023
1 parent d9ddf1b commit 703fdf8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/Contracts/CalendarDataProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

namespace Wdelfuego\NovaCalendar\Contracts;

use Wdelfuego\NovaCalendar\View\AbstractView as View;

interface CalendarDataProviderInterface
{
public function __construct();
Expand All @@ -31,4 +33,7 @@ public function daysOfTheWeek() : array;

// A multi-dimensional array of event styles, see documentation
public function eventStyles() : array;

// Allows the data provider to customize the data view just before sending it to the front-end
public function customizeView(View $view) : View;
}
5 changes: 5 additions & 0 deletions src/DataProvider/AbstractCalendarDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public function initialize(): void

}

public function customizeView(View $view) : View
{
return $view;
}

public function setConfig(array $config)
{
$this->config = $config;
Expand Down
1 change: 1 addition & 0 deletions src/Http/Controllers/CalendarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public function getCalendarData(string $view = 'month')

$view = View::get($view);
$view->initFromRequest($this->request);
$view = $dataProvider->customizeView($this);
return $view->calendarData($this->request, $dataProvider);
}

Expand Down
3 changes: 2 additions & 1 deletion src/View/AbstractView.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public static function get(string $view) : ViewInterface
abstract public function specifier() : string;
abstract public function initFromRequest(NovaRequest $request);
abstract public function viewData(CalendarDataProviderInterface $dataProvider) : array;

abstract public function forceShowDate(Carbon $date);

// The general Range is the date range that the user is interested in.
// The Calendar range is the date range that will be shown in the front-end.
// The Range can be shorter than the Calendar, not the other way around.
Expand Down
5 changes: 5 additions & 0 deletions src/View/Month.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public function viewData(CalendarDataProviderInterface $dataProvider) : array
];
}

public function forceShowDate(Carbon $date)
{
$this->setYearAndMonth($date->year, $date->month);
}

public function setYearAndMonth($year, $month) : self
{
$year = is_null($year) || !is_numeric($year) ? now()->year : intval($year);
Expand Down

0 comments on commit 703fdf8

Please sign in to comment.