Skip to content

Commit

Permalink
Merge pull request #88 from whitecube/nova-4
Browse files Browse the repository at this point in the history
Nova 4 support
  • Loading branch information
toonvandenbos authored Jun 7, 2022
2 parents 23331b4 + 37bd8d1 commit 6a2f06b
Show file tree
Hide file tree
Showing 26 changed files with 5,766 additions and 122 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ In order to assign fields (and even cards!) to a page's edition form, we'll have

#### Creating Templates

```bash
```bash
php artisan make:template About
````

Expand All @@ -54,10 +54,10 @@ class About extends Template
/**
* Get the fields displayed by the resource.
*
* @param \Illuminate\Http\Request $request
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function fields(Request $request)
public function fields(NovaRequest $request)
{
return [
Text::make('Title of the page', 'title')
Expand All @@ -67,10 +67,10 @@ class About extends Template
/**
* Get the cards available for the request.
*
* @param \Illuminate\Http\Request $request
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function cards(Request $request)
public function cards(NovaRequest $request)
{
return [];
}
Expand Down Expand Up @@ -127,7 +127,7 @@ Please note it is also possible to define [Option Templates](https://whitecube.g
<p>{{ Page::option('footer')->copyright }}</p>
```
## 💖 Sponsorships
## 💖 Sponsorships
If you are reliant on this package in your production applications, consider [sponsoring us](https://github.com/sponsors/whitecube)! It is the best way to help us keep doing what we love to do: making great open source software.
Expand All @@ -139,5 +139,5 @@ Thanks!
## Made with ❤️ for open source
At [Whitecube](https://www.whitecube.be) we use a lot of open source software as part of our daily work.
So when we have an opportunity to give something back, we're super excited!
So when we have an opportunity to give something back, we're super excited!
We hope you will enjoy this small contribution from us and would love to [hear from you](https://twitter.com/whitecube_be) if you find it useful in your projects.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
}
],
"require": {
"php": ">=7.1.0",
"laravel/nova": "*"
"php": "^7.3|^8.0",
"laravel/nova": "^4.0",
"orchestra/testbench": "^7.4"
},
"require-dev": {
"phpunit/phpunit": "^8.1",
"orchestra/testbench": "3.8.*"
"phpunit/phpunit": "^9.5"
},
"autoload": {
"psr-4": {
Expand Down
1 change: 1 addition & 0 deletions dist/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
12 changes: 6 additions & 6 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Which will result in:
```php
namespace App\Nova\Templates;

use Illuminate\Http\Request;
use Laravel\Nova\Http\Requests\NovaRequest;
use Whitecube\NovaPage\Pages\Template;

class About extends Template
Expand All @@ -99,21 +99,21 @@ class About extends Template
/**
* Get the fields displayed by the resource.
*
* @param \Illuminate\Http\Request $request
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function fields(Request $request)
public function fields(NovaRequest $request)
{
return [];
}

/**
* Get the cards available for the request.
*
* @param \Illuminate\Http\Request $request
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function cards(Request $request)
public function cards(NovaRequest $request)
{
return [];
}
Expand Down Expand Up @@ -314,7 +314,7 @@ class HomepageController extends Controller

public function show(Template $template, Manager $novapage)
{
// Load other pages or options using
// Load other pages or options using
// Manager::load(string $name, string $type = 'route' | 'option', bool $current = true)
$novapage->load('contact', 'route', false);

Expand Down
27 changes: 15 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
"dev": "mix",
"development": "mix",
"watch": "mix watch",
"watch-poll": "mix watch -- --watch-options-poll=1000",
"hot": "mix watch --hot",
"production": "mix --production"
},
"devDependencies": {
"cross-env": "^5.0.0",
"laravel-mix": "^1.0"
},
"dependencies": {
"vue": "^2.5.0"
"laravel-nova": "^1.0",
"@vue/compiler-sfc": "^3.2.22",
"laravel-mix": "^6.0.41",
"postcss": "^8.2",
"resolve-url-loader": "^3.1.2",
"sass": "^1.32.8",
"sass-loader": "10.*",
"vue-loader": "^16.8.3",
"@vue/babel-plugin-jsx": "^1.1.1"
}
}
6 changes: 3 additions & 3 deletions src/Http/Controllers/Option/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class IndexController extends ResourceIndexController
{
/**
* Resource label callback
*
*
* @return string
*/
protected function resourceLabel() {
Expand All @@ -19,10 +19,10 @@ protected function resourceLabel() {

/**
* Callback to retrieve the resource index items
*
*
* @param \Laravel\Nova\Http\Requests\ResourceIndexRequest $request
* @param \Whitecube\NovaPage\Pages\Manager $manager
* @return \Illuminate\Support\Collection
* @return \Illuminate\Support\Collection
*/
protected function resourceIndexItems(ResourceIndexRequest $request, Manager $manager) {
return $manager->queryIndexResources($request, 'option');
Expand Down
6 changes: 3 additions & 3 deletions src/Http/Controllers/Page/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class IndexController extends ResourceIndexController
{
/**
* Resource label callback
*
*
* @return string
*/
protected function resourceLabel() {
Expand All @@ -19,10 +19,10 @@ protected function resourceLabel() {

/**
* Callback to retrieve the resource index items
*
*
* @param \Laravel\Nova\Http\Requests\ResourceIndexRequest $request
* @param \Whitecube\NovaPage\Pages\Manager $manager
* @return \Illuminate\Support\Collection
* @return \Illuminate\Support\Collection
*/
protected function resourceIndexItems(ResourceIndexRequest $request, Manager $manager) {
return $manager->queryIndexResources($request, 'route');
Expand Down
7 changes: 3 additions & 4 deletions src/Http/Controllers/ResourceIndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ abstract class ResourceIndexController extends Controller
{
/**
* Get the queried resource's plural label
*
*
* @return string
*/
abstract protected function resourceLabel();

/**
* Get the queried resource's index items
*
*
* @param \Laravel\Nova\Http\Requests\ResourceIndexRequest $request
* @param \Whitecube\NovaPage\Pages\Manager $manager
* @return \Illuminate\Support\Collection
* @return \Illuminate\Support\Collection
*/
abstract protected function resourceIndexItems(ResourceIndexRequest $request, Manager $manager);

Expand Down Expand Up @@ -64,5 +64,4 @@ protected function paginator(ResourceIndexRequest $request, Manager $manager)

return new LengthAwarePaginator($items->forPage($page, $perPage), $items->count(), $perPage, $page);
}

}
4 changes: 2 additions & 2 deletions src/Http/Controllers/ResourceUpdateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public function handle(UpdateResourceRequest $request)

$resource = $request->resource();

$resource::validateForUpdate($request);
$resource::validateForUpdate($request, $request->findResourceOrFail());

$template = $request->findModelQuery()->firstOrFail();

if ($this->templateHasBeenUpdatedSinceRetrieval($request, $template)) {
return response('', 409);
}

[$template, $callbacks] = $resource::fillForUpdate($request, $template);

tap($template)->save();
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Middleware/Authorize.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ public function handle(Request $request, Closure $next) : Response
? $next($request)
: abort(403);
}
}

}
2 changes: 1 addition & 1 deletion src/Http/Middleware/LoadPageForCurrentRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ public function handle(Request $request, Closure $next)
return $next($request);
}

}
}
2 changes: 1 addition & 1 deletion src/NovaPageRouteMacros.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ public function template()
};
}

}
}
10 changes: 8 additions & 2 deletions src/NovaPageTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Laravel\Nova\Nova;
use Laravel\Nova\Tool;
use Illuminate\Http\Request;
use Laravel\Nova\Menu\MenuItem;
use Laravel\Nova\Menu\MenuSection;

class NovaPageTool extends Tool
{
Expand All @@ -25,8 +28,11 @@ public function boot()
*
* @return \Illuminate\View\View
*/
public function renderNavigation()
public function menu(Request $request)
{
return view('nova-page::navigation');
return MenuSection::make('Nova Page', [
MenuItem::make('Pages')->path('resources/nova-page'),
MenuItem::make('Options')->path('resources/nova-option'),
])->collapsable()->icon('document');
}
}
23 changes: 7 additions & 16 deletions src/NovaPageToolServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@

namespace Whitecube\NovaPage;

use Laravel\Nova\Nova;
use Laravel\Nova\Events\ServingNova;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Gate;
use Whitecube\NovaPage\Pages\Manager;
use Whitecube\NovaPage\Pages\Template;
use Whitecube\NovaPage\Http\Middleware\Authorize;

class NovaPageToolServiceProvider extends ServiceProvider
Expand All @@ -21,8 +16,6 @@ class NovaPageToolServiceProvider extends ServiceProvider
*/
public function boot()
{
$this->loadViewsFrom(__DIR__.'/../resources/views', 'nova-page');

$this->app->booted(function () {
$this->routes();
});
Expand All @@ -38,18 +31,16 @@ protected function routes()
if ($this->app->routesAreCached()) {
return;
}

Route::middleware(['nova', Authorize::class])
->group(__DIR__.'/../routes/api.php');
}

/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
$this->registerRoutes();
}

protected function registerRoutes()
{
Route::middleware(['nova', Authorize::class])
->group(__DIR__.'/../routes/api.php');
}
}
2 changes: 1 addition & 1 deletion src/Pages/Concerns/ResolvesResourceFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ protected function isDisplayingIndexFields(NovaRequest $request)
$indexActions
);
}
}
}
8 changes: 4 additions & 4 deletions src/Pages/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function load($name, $type = 'route', $current = true, $throwOnMissing =
public function loadForRoute(Route $route, $current = true, $throwOnMissing = false)
{
if(!$route->template()) return;

$this->load($route->getName(), 'route', $current, $throwOnMissing);
}

Expand All @@ -130,7 +130,7 @@ public function find($name = null, $type = 'route')

/**
* Get an option template by its name
*
*
* @param string $name
* @param bool $throwOnMissing
* @return mixed
Expand Down Expand Up @@ -190,5 +190,5 @@ public function getRepository()
{
return $this->repository;
}
}

}
7 changes: 4 additions & 3 deletions src/Pages/OptionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class OptionResource extends StaticResource
* @var string
*/
public static $model = 'nova-option';

/**
* Get the URI key for the resource.
*
Expand Down Expand Up @@ -71,8 +71,9 @@ protected function getIndexTableFields()

DateTime::make(__('Last updated on'), 'last_updated_on', function () {
$updated_at = $this->getDate('updated_at');
return $updated_at ? $updated_at->toDateTimeString() : null;
})->format(config('novapage.date_format'))->sortable(),
return $updated_at ? $updated_at : null;
})
->sortable(),
];
}

Expand Down
Loading

0 comments on commit 6a2f06b

Please sign in to comment.