Comments (5)
Thanks a lot for your input! I'll be exploring something analogous to this, hope to launch the feature with version 2.0 in January or February.
from nova-calendar.
This is currently not possible, since the CalendarDataProvider is provided to the CalendarController through dependency injection. I agree that it would be a valuable feature to have so I'd be happy to help you implement this. I won't work on this myself on short notice since there are other features that are higher on my own list of priorities (event filtering & week view).
There is already an issue for this feature request so I'll close this one.
Let me know if you're interested in developing this feature and we'll get in touch to make sure you're successful :).
from nova-calendar.
Thanks, it would be nice if it was added in a future release. In the meantime I was able to get multiple calendars working and I explain how I did it here: [[link removed by @wdelfuego, see next comment]]
from nova-calendar.
Nice, glad you got this to work and thanks for sharing your solution!
If the package is going to support multiple calendar instances, I will require a different calendar data provider per calendar view since the calendar data provider is already at risk of growing to a god object, let alone when you need to detect the requested view in every of its methods. I have hidden your comment from issue #3 since it is not relevant to that specific issue (supplying a different calendar data provider to the CalendarController) and am reproducing it here because it is relevant to people who are interested in using your solution for implementing multiple calendar views in the meantime:
Well with very little effort I was able to hack something together that allows for this. Here's how I did it.
First I needed to add multiple new routes that would all lead to the same calendar. So inside my
NovaServiceProvider.php
boot method I added$this->app->booted(function () { Nova::router(['nova', \Wdelfuego\NovaCalendar\Http\Middleware\Authorize::class], 'bookings-calendar') ->group(base_path('vendor/wdelfuego/nova-calendar/routes/inertia.php')); Nova::router(['nova', \Wdelfuego\NovaCalendar\Http\Middleware\Authorize::class], 'lessons-calendar') ->group(base_path('vendor/wdelfuego/nova-calendar/routes/inertia.php')); });
So now I have two routes that lead to my calendar
/nova/bookings-calendar
and/nova/lessons-calendar
Then, inside my CalendarDataProvider I simply need to know which route I'm on and based on this I'll use different resources.
Here's how I did that:
public function novaResources(): array { switch(basename(request()->server('HTTP_REFERER'))) { case 'bookings-calendar': $resources = [ \App\Nova\Resources\Bookings\Booking::class => ['starts_at', 'ends_at'], ]; break; case 'lessons-calendar': $resources = [ \App\Nova\Resources\Bookings\BookingLesson::class => 'created_at', ]; break; } return $resources; }
And voila! Easy-peasy ;-)
from nova-calendar.
I thought about the "god object" case and quickly came up with something that would work to prevent that.
Basically inside the config file you could have an associative array of route paths and resourceProvider classes. And then inside the data provider you could use that mapping to essentially abstract the data provider.
So something like this in the config file:
'calendars' => [
'bookings-calendar' => BookingCalendarDataProvider::class,
'lessons-calendar' => LessonCalendarDataProvider::class,
],
And then inside the novaResources function
$resources = (new config('nova-calendar.calendars')[basename(request()->server('HTTP_REFERER'))])->getResources();
Proof of concept but it would allow for some abstraction and would work with the way you're currently doing things.
You could loop over these calendars from the config as well when setting up the extra routes.
from nova-calendar.
Related Issues (20)
- Consider PHP8.0 HOT 2
- str_contains(): Argument #1 ($haystack) must be of type string, Closure given HOT 8
- Version 2.0 HOT 11
- Event filtering HOT 4
- Applying styles to calendar cells (for example to highlight current day and fade-out days in the past) HOT 3
- Allow us to include html inside the event notes HOT 2
- Please allow CMD/Meta/Ctrl click to open in a new tab when clicking on an event HOT 3
- Customizing Event properties in custom event generator HOT 3
- Poor performance - eager loading breaks in Custom Event Generators HOT 1
- recommendation: calendar backend library vkurko/calendar
- ERROR There are no commands defined in the "nova-calendar" namespace. HOT 2
- calendar does not load - missing slash in api url HOT 7
- Week View Update? HOT 1
- [Bug] Method Laravel\Nova\Http\Requests\NovaRequest::schemeAndHttpHost does not exist HOT 7
- When searching, events are still clickable HOT 7
- month and year pickers disappear on press HOT 3
- BindingResolutionException: Target class [] does not exist. when caching routes HOT 4
- Ability to use url parameters for optionally filtering down HOT 11
- It is possible to change the URL by clicking the event to access a custom tool instead of using the resource? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nova-calendar.