Code Monkey home page Code Monkey logo

Comments (5)

wdelfuego avatar wdelfuego commented on May 29, 2024 1

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.

wdelfuego avatar wdelfuego commented on May 29, 2024

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.

vesper8 avatar vesper8 commented on May 29, 2024

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.

wdelfuego avatar wdelfuego commented on May 29, 2024

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.

vesper8 avatar vesper8 commented on May 29, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.