Skip to content

Commit

Permalink
Changelog
Browse files Browse the repository at this point in the history
- Added: query filter for crud
- Added: json response for QueryException
- Updated: crud.ts to crud.vue
  • Loading branch information
Blair2004 committed Sep 21, 2021
1 parent d565757 commit 2bfd421
Show file tree
Hide file tree
Showing 15 changed files with 296 additions and 123 deletions.
40 changes: 40 additions & 0 deletions app/Crud/OrderCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use TorMorten\Eventy\Facades\Events as Hook;
use Exception;
use App\Models\Order;
use App\Services\Helper;
use App\Services\OrdersService;
use Illuminate\Support\Facades\DB;

Expand Down Expand Up @@ -42,6 +43,13 @@ class OrderCrud extends CrudService
[ 'nexopos_customers', 'nexopos_customers.id', '=', 'nexopos_orders.customer_id' ],
];

public $pick = [
'nexopos_users' => [ 'username' ],
'nexopos_customers' => [ 'name' ]
];

public $queryFilters = [];

/**
* Define where statement
* @var array
Expand Down Expand Up @@ -75,6 +83,38 @@ public function __construct()
parent::__construct();

Hook::addFilter( $this->namespace . '-crud-actions', [ $this, 'setActions' ], 10, 2 );

/**
* Let's define the query filters
* we would like to apply to the crud
*/
$this->queryFilters = [
[
'type' => 'date',
'name' => 'created_at',
'description' => __( 'Restrict the orders by the creation date.' ),
'label' => __( 'Created At' )
], [
'type' => 'select',
'label' => __( 'Payment Status' ),
'name' => 'payment_status',
'description' => __( 'Restrict the orders by the payment status.' ),
'options' => Helper::kvToJsOptions([
Order::PAYMENT_PAID => __( 'Paid' ),
Order::PAYMENT_PARTIALLY => __( 'Partially Paid' ),
Order::PAYMENT_PARTIALLY_REFUNDED => __( 'Partially Refunded' ),
Order::PAYMENT_REFUNDED => __( 'Refunded' ),
Order::PAYMENT_UNPAID => __( 'Unpaid' ),
Order::PAYMENT_VOID => __( 'Voided' ),
])
], [
'type' => 'select',
'label' => __( 'Author' ),
'name' => 'nexopos_orders.author',
'description' => __( 'Restrict the orders by the author.' ),
'options' => Helper::toJsOptions( User::get(), [ 'id', 'username' ])
]
];
}

/**
Expand Down
6 changes: 6 additions & 0 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ public function render($request, Throwable $exception)
}

if ( $exception instanceof QueryException ) {
if ( $request->expectsJson() ) {
return response()->json([
'message' => $exception->getMessage()
], 404);
}

return ( new ExceptionsQueryException( $exception->getMessage() ) )
->render( $request );
}
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/Dashboard/CrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ public function crudGet( string $namespace, Request $request )

/**
* Let's check it the resource has a method to retreive an item
* @var CrudService
*/
$resource = new $crudClass;

Expand Down Expand Up @@ -462,6 +463,7 @@ public function getConfig( string $namespace )
get_class( $resource ) . '@getColumns',
$resource->getColumns()
),
'queryFilters' => Hook::filter( get_class( $resource ) . '@getQueryFilters', $resource->getQueryFilters() ),
'labels' => Hook::filter( get_class( $resource ) . '@getLabels', $resource->getLabels() ),
'links' => Hook::filter( get_class( $resource ) . '@getLinks', $resource->getLinks() ?? [] ),
'bulkActions' => Hook::filter( get_class( $resource ) . '@getBulkActions', $resource->getBulkActions() ),
Expand Down
34 changes: 34 additions & 0 deletions app/Services/CrudService.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ class CrudService
*/
protected $columns = [];

/**
* Query filters
* @param array
*/
protected $queryFilters = [];

/**
* Link
* @return array
Expand Down Expand Up @@ -129,6 +135,15 @@ public function getBulkActions()
return $this->bulkActions;
}

/**
* Returns the available query filters
* @return array
*/
public function getQueryFilters()
{
return $this->queryFilters;
}

public function __extractTable( $relation )
{
$parts = explode( ' as ', $relation[0] );
Expand Down Expand Up @@ -390,6 +405,25 @@ public function getEntries( $config = [] )
);
}

/**
* @since 4.5.5
* Will filter request using provided
* query filters
*/
if ( $request->query( 'queryFilters' ) ) {
$filters = json_decode( urldecode( $request->query( 'queryFilters' ) ), true );

/**
* @todo we might need to get the filter from the resource
* so that we can parse correctly the provider query filters.
*/
if ( ! empty( $filters ) ) {
foreach( $filters as $key => $value ) {
$query->where( $key, $value );
}
}
}

/**
* let's make the "perPage" value adjustable
*/
Expand Down
2 changes: 1 addition & 1 deletion config/nexopos.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
return [
'version' => '4.5.4',
'version' => '4.5.5',
'languages' => [
'en' => 'English',
'fr' => 'Français',
Expand Down
6 changes: 2 additions & 4 deletions public/css/app.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/app.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/auth.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/manifest.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/js/pos.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/setup.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/vendor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion resources/ts/components/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { nsInput } from './ns-input';
import { nsSelect } from './ns-select';
import { nsSelectAudio } from './ns-select-audio';
import { nsCheckbox } from './ns-checkbox';
import { nsCrud } from './ns-crud';
import { default as nsCrud } from './ns-crud.vue';
import { nsTableRow } from './ns-table-row';
import { nsSpinner } from './ns-spinner';
import { nsCrudForm } from './ns-crud-form';
Expand Down
Loading

0 comments on commit 2bfd421

Please sign in to comment.