Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added novaPageIndexQuery to StaticResource to mimic indexQuery #46

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

GarethSomers
Copy link
Contributor

I've added a method novaPageIndexQuery to Whitecube\NovaPage\Pages\StaticResource which allows someone to manipulate the Whitecube\NovaPage\Pages\Query on the nova index page. It's intended to mimic the indexQuery method.

I've also added the methodWhitecube\NovaPage\Pages\Query::sortBy to allow simple sorting.

It might work better just having a generic callback (e.g. $query->setCallback(...)) which gets applied to the Collection in Whitecube\NovaPage\Pages\Query::get.

Should merge in conjunction with #45 merged

Closes

#44 (sorta)

Usage

Configure your own config novapage.default_page_resource in config/novapage.php

    'default_page_resource' => \App\Nova\Page::class,
<?php

namespace App\Nova;

use Whitecube\NovaPage\Pages\PageResource;
use Whitecube\NovaPage\Pages\Query;

class Page extends PageResource
{
    public static function novaPageIndexQuery(Query $query)
    {
        return $query->orderBy(function ($item) {
            return $item->getTitle();
        }, 'ASC');
    }
}

GarethSomers and others added 3 commits September 26, 2019 15:35
…the QueriesResource Concern to mimic the core indexQuery method.

Added a orderBy method to the Query to allow control ordering.
Merge whitecube/nova-page#master into rapidz/nova-page#resource-index-query
Copy link
Member

@toonvandenbos toonvandenbos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @GarethSomers,

Thanks for the PR. It seems good to me, I just found two little points I'd love to see enhanced :

  • Could you add & document the 2 new configuration keys into src/config.php ?
  • As shown in my previous review comment, the configuration values could not exist when upgrading an existing Nova project, meaning we should provide default values on lines 58 & 59 of src/Pages/Concerns/QueriesResources.php.

Thanks !


protected function applyIndexQueryForType($type, Query $query) {
$page_resource_class = config('novapage.default_page_resource');
$option_resource_class = config('novapage.default_option_resource');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both config() calls should default to the provided Resource classes in case the config file does not (yet) contain the default_page_resource or default_option_resource keys in order to ensure update compatibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Nyratas I've added documentation docs/README.md and I've set the default values in src/Pages/Concerns/QueriesResources.php .

Let me know if there's anything I've missed. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants