Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

feature: custom pages / tools #37

Merged
merged 6 commits into from Oct 9, 2020
Merged

feature: custom pages / tools #37

merged 6 commits into from Oct 9, 2020

Conversation

ryangjchandler
Copy link
Contributor

This PR enables users to build and register custom pages within the Nebula panel.

It introduces a new php artisan nebula:page command that will generate a new class in app/Nebula/Pages, as well as a view under resources/views/nebula/pages.

To register a new page, you follow the same pattern as the dashboards and resources, adding new PageClass under the nebula.pages configuration option.

The idea for these pages is similar to Laravel Nova's custom tools. Have a uniform API that allows developers to build third-party extensions for Nebula.

I've named them pages because using the term Tool felt too similar to Nova, but I'm happy to change this.

It's also worth noting that the developer doesn't need to use the nebula::layouts.shell view in their pages view, since it will automatically be wrapped in it. Instead, they only need to worry about what their page will display.

The page also moves away from the singularName() and pluralName() pattern that the resources & dashboards follow because it didn't make much sense here. Instead the NebulaPage::name() method will be used for displaying the menu item and the page title.

For the URL slug / route binding, a new NebulaPage::slug() method has been introduced which will be used to match the page.

Happy to hear thoughts and ideas on this - this was the simplest implementation after all. 馃

@ryangjchandler
Copy link
Contributor Author

Another idea I had for this was also having permission checks for pages. I'm a big fan of the Nova API for this:

'pages' => [
    (new ExamplePage)->canSee(function (Request $request) {
        return false;
    })
]

Then, inside of Nebula's PageController, simply run that function and pass the current request through. If it returns false, then throw an AuthorizationException.

@ryangjchandler
Copy link
Contributor Author

ryangjchandler commented Oct 9, 2020

I've just added support for NebulaPage::canSee(). It works exactly like the example above, allowing users to check the user, do permission checks, etc. It throws an AuthorizationException when the callback returns false.

@ryangjchandler
Copy link
Contributor Author

The only thing I'm not sure about it having the Pages label in the menu, because the archetype is a page, but the actual usage of them might not be. This would also make it harder for developers to group multiple pages together (perhaps another future feature..)

@Larsklopstra Larsklopstra merged commit 021dac0 into nebulapackage:master Oct 9, 2020
@ryangjchandler ryangjchandler deleted the feature/custom-pages branch October 9, 2020 15:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants