Skip to content

Commit 22e0f0b

Browse files
authored
Rewrite / Nova4 Support (#89)
* add nova4 support * clean up * update readme * update readme * update screenshot * update readme * update readme * ecs
1 parent a92842f commit 22e0f0b

34 files changed

+5930
-8365
lines changed

README.md

Lines changed: 34 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -4,195 +4,80 @@
44
[![Total Downloads](https://img.shields.io/packagist/dt/digital-creative/nova-mega-filter)](https://packagist.org/packages/digital-creative/nova-mega-filter)
55
[![License](https://img.shields.io/packagist/l/digital-creative/nova-mega-filter)](https://github.com/dcasia/nova-mega-filter/blob/master/LICENSE)
66

7-
This package allows you to control the columns and filters shown on your nova resources.
7+
Display all your filters in a card instead of a tiny dropdown!
8+
9+
<picture>
10+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/dcasia/nova-mega-filter/nova4/screenshots/dark.png">
11+
<img alt="Nova Mega Filter in Action" src="https://raw.githubusercontent.com/dcasia/nova-mega-filter/nova4/screenshots/light.png">
12+
</picture>
813

914
# Installation
1015

1116
You can install the package via composer:
1217

13-
```
18+
```shell
1419
composer require digital-creative/nova-mega-filter
1520
```
1621

1722
## Basic Usage
1823

19-
Basic demo showing the power of this field:
24+
Basic demo showing the power of this package:
2025

2126
```php
2227

2328
use DigitalCreative\MegaFilter\MegaFilter;
24-
use DigitalCreative\MegaFilter\HasMegaFilterTrait;
25-
use DigitalCreative\MegaFilter\Column;
29+
use DigitalCreative\MegaFilter\MegaFilterTrait;
2630

2731
class ExampleNovaResource extends Resource {
2832

29-
use HasMegaFilterTrait; // Important!!
33+
use MegaFilterTrait;
3034

31-
public function cards(Request $request)
35+
public function filters(RequestRequest $request): array
3236
{
3337
return [
3438
MegaFilter::make([
35-
'filters' => [
36-
new DateOfBirthFilter(),
37-
new UserTypeFilter()
38-
],
39-
'columns' => [
40-
Column::make('Customer Name', 'name')->addFilter(new ActiveFilter()),
41-
Column::make('Assets'),
42-
Column::make('Payments')
43-
]
44-
])
39+
DateOfBirthFilter::make(),
40+
UserTypeFilter::make(),
41+
]),
4542
];
4643
}
4744

4845
}
4946
```
5047

51-
### Columns
52-
53-
Columns reflects every column that is normally shown on your table resource, however you are free to give your user the
54-
ability to toggle it on/off:
55-
56-
![Columns in Action](https://raw.githubusercontent.com/dcasia/nova-mega-filter/master/screenshots/columns-demo.png)
57-
58-
```php
59-
use DigitalCreative\MegaFilter\Column;
60-
use DigitalCreative\MegaFilter\HasMegaFilterTrait;
61-
use DigitalCreative\MegaFilter\MegaFilter;
62-
63-
MegaFilter::make([
64-
'columns' => [
65-
Column::make($label),
66-
Column::make($label, $attribute),
67-
Column::make($label, $attribute, $filters),
68-
new Column($label, $attribute, $filters),
69-
],
70-
])
71-
```
72-
73-
You can add additional filters that only appears when the desired column is enabled:
74-
75-
```php
76-
MegaFilter::make([
77-
'columns' => [
78-
Column::make('Gender')->addFilter(new GenderFilter())
79-
],
80-
])
81-
```
82-
83-
![Columns in Action](https://raw.githubusercontent.com/dcasia/nova-mega-filter/master/screenshots/columns-gender-filter-demo.png)
48+
And you are done!
8449

85-
> If you want to have filters that are always shown, use the 'filters' option bellow
50+
Previously this package also had the ability to toggle columns, but since the nova 4 upgrade this functionality has been
51+
moved away to its own package: https://github.com/dcasia/column-toggler
8652

87-
You can also define columns that can not be toggled by the user and will be always present on the table resource:
88-
89-
```php
90-
MegaFilter::make([
91-
'columns' => [
92-
Column::make('Name')->permanent()
93-
],
94-
])
95-
```
53+
---
9654

97-
When using `->permanent()` every filter that the column may define will be also present
98-
99-
Other column methods include the ability to have a column default checked
55+
You can also add other fields alongside your Mega Filters, they will be rendered as usual:
10056

10157
```php
102-
MegaFilter::make([
103-
'columns' => [
104-
Column::make('Name')->checked() // Checked by default
105-
],
106-
])
107-
```
108-
109-
### Filters
11058

111-
The `filters` key accepts an array of any instance of the default Nova filter class or third party.
112-
113-
```php
114-
MegaFilter::make([
115-
'filters' => [
116-
new BirthdayFilter(),
117-
new UserTypeFilter(),
118-
new GenderFilter(),
119-
],
120-
])
121-
```
122-
123-
### Actions
124-
125-
Actions will use the same Nova action mechanism
126-
127-
```php
128-
MegaFilter::make([
129-
'actions' => [
130-
new ExportClientAsExcell(),
131-
],
132-
])
133-
```
134-
135-
![Columns in Action](https://raw.githubusercontent.com/dcasia/nova-mega-filter/master/screenshots/action-demo.png)
136-
137-
If you have multiple actions defined, a dropdown will be shown:
138-
139-
![Columns in Action](https://raw.githubusercontent.com/dcasia/nova-mega-filter/master/screenshots/action-demo-2.png)
140-
141-
The columns selected will also be given to your action, you can access them directly from the request:
59+
use DigitalCreative\MegaFilter\MegaFilter;
60+
use DigitalCreative\MegaFilter\MegaFilterTrait;
14261

143-
```php
144-
public function handle(ActionFields $fields, Collection $models)
145-
{
62+
class ExampleNovaResource extends Resource {
14663

147-
$columns = json_decode(request()->input('columns'));
64+
use MegaFilterTrait;
14865

149-
dd($columns);
66+
public function filters(RequestRequest $request): array
67+
{
68+
return [
69+
MegaFilter::make([ ... ]),
70+
71+
// These will be rendered as normal on the usual tiny filter dropdown
72+
DateOfBirthFilter::make(),
73+
UserTypeFilter::make(),
74+
];
75+
}
15076

15177
}
15278
```
15379

154-
### Settings
155-
156-
The settings key is optional as it comes with some good defaults, but feel free to override it to suit your needs.
157-
158-
```php
159-
MegaFilter::make([
160-
'settings' => [
161-
162-
/**
163-
* Tailwind width classes: w-full w-1/2 w-1/3 w-1/4 etc.
164-
*/
165-
'columnsWidth' => 'w-1/4',
166-
'filtersWidth' => 'w-1/2',
167-
168-
/**
169-
* The default state of the main toggle buttons
170-
*/
171-
'columnsActive' => false,
172-
'filtersActive' => true,
173-
'actionsActive' => true,
174-
175-
/**
176-
* Show/Hide elements
177-
*/
178-
'showHeader' => true,
179-
180-
/**
181-
* Labels
182-
*/
183-
'headerLabel' => 'Menu',
184-
'columnsLabel' => 'Columns',
185-
'filtersLabel' => 'Filters',
186-
'actionsLabel' => 'Actions',
187-
'columnsSectionTitle' => 'Additional Columns',
188-
'filtersSectionTitle' => 'Filters',
189-
'actionsSectionTitle' => 'Actions',
190-
'columnsResetLinkTitle' => 'Reset Columns',
191-
'filtersResetLinkTitle' => 'Reset Filters',
192-
193-
],
194-
])
195-
```
80+
> Note: At the moment this package only works with a single Mega Filter per resource, adding multiple on the same resource may result in unexpected behavior.
19681
19782
## License
19883

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
],
1616
"license": "MIT",
1717
"require": {
18-
"php": ">=7.1.0",
19-
"laravel/nova": "^3.17.0"
18+
"php": ">=8.0",
19+
"laravel/nova": "^4.0"
2020
},
2121
"autoload": {
2222
"psr-4": {

dist/css/card.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/card.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/card.js.LICENSE.txt

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
/*!
2-
* Determine if an object is a Buffer
3-
*
4-
* @author Feross Aboukhadijeh <https://feross.org>
5-
* @license MIT
2+
* vuex v4.1.0
3+
* (c) 2022 Evan You
4+
* @license MIT
65
*/
76

8-
/**
9-
* @license
10-
* Lodash <https://lodash.com/>
11-
* Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
12-
* Released under MIT license <https://lodash.com/license>
13-
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
14-
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
15-
*/
7+
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */

dist/mix-manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"/js/card.js": "/js/card.js"
2+
"/js/card.js": "/js/card.js",
3+
"/css/card.css": "/css/card.css"
34
}

nova.mix.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const mix = require('laravel-mix')
2+
const webpack = require('webpack')
3+
const path = require('path')
4+
5+
class NovaExtension {
6+
name() {
7+
return 'nova-extension'
8+
}
9+
10+
register(name) {
11+
this.name = name
12+
}
13+
14+
webpackConfig(webpackConfig) {
15+
webpackConfig.externals = {
16+
vue: 'Vue',
17+
}
18+
19+
webpackConfig.resolve.alias = {
20+
...(webpackConfig.resolve.alias || {}),
21+
'laravel-nova': path.join(__dirname, '../../vendor/laravel/nova/resources/js/mixins/packages.js'),
22+
'@': path.resolve(__dirname, '../../vendor/laravel/nova/resources/js/'),
23+
}
24+
25+
webpackConfig.output = {
26+
uniqueName: this.name,
27+
}
28+
}
29+
}
30+
31+
mix.extend('nova', new NovaExtension())

0 commit comments

Comments
 (0)