Skip to content

Commit 539941e

Browse files
tabacitupxpmStyleCIBot
authored
Demo version with Backpack v7 (#669)
Co-authored-by: pxpm <pxpm88@gmail.com> Co-authored-by: StyleCI Bot <bot@styleci.io> Co-authored-by: Cristian Tabacitu <cristian.tabacitu@digitallyhappy.com>
1 parent 29670e6 commit 539941e

File tree

75 files changed

+2777
-2264
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+2777
-2264
lines changed

.env.example

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ APP_URL=http://localhost
66
BACKPACK_THEME=backpack.theme-tabler
77

88
# MySQL Database Connection
9-
DB_CONNECTION=mysql
10-
DB_HOST=127.0.0.1
11-
DB_PORT=3306
12-
DB_DATABASE=homestead
13-
DB_USERNAME=homestead
14-
DB_PASSWORD=secret
9+
#DB_CONNECTION=mysql
10+
#DB_HOST=127.0.0.1
11+
#DB_PORT=3306
12+
#DB_DATABASE=homestead
13+
#DB_USERNAME=homestead
14+
#DB_PASSWORD=secret
1515

1616
# PostgreSQL Database Connection
1717
#DB_CONNECTION=pgsql
@@ -22,9 +22,9 @@ DB_PASSWORD=secret
2222
#DB_PASSWORD=
2323

2424
# SQLite Database Connection
25-
# You might also need to run 'touch storage/app/database.sqlite` to create the db
26-
#DB_CONNECTION=sqlite
27-
#DB_DATABASE=../storage/app/database.sqlite
25+
# You might also need to run 'touch storage/app/database.sqlite` to create the db if the file does not exist.
26+
DB_CONNECTION=sqlite
27+
DB_DATABASE=./storage/app/database.sqlite
2828

2929
CACHE_DRIVER=file
3030
SESSION_DRIVER=file

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ Homestead.json
1515
/.vscode
1616
/packages
1717
/_volumes
18+
/public/basset

app/Console/Commands/RefreshDb.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ public function __construct()
3939
*/
4040
public function handle()
4141
{
42+
Artisan::call('down');
4243
Log::warning('Cleanup time. Refreshing the database.');
4344
Artisan::call('db:wipe --force');
4445
Artisan::call('migrate --force');
4546
Artisan::call('db:seed --force');
4647
Artisan::call('backup:clean');
48+
Artisan::call('up');
4749
}
4850
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Admin;
4+
5+
class AdminPageController
6+
{
7+
/**
8+
* Show the new in v7 page.
9+
*
10+
* @return \Illuminate\View\View
11+
*/
12+
public function newInV7()
13+
{
14+
return view('admin.new-in-v7', [
15+
'title' => 'New in v7',
16+
'description' => 'Discover the new features and improvements in Backpack v7.',
17+
]);
18+
}
19+
}

app/Http/Controllers/Admin/CaveCrudController.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class CaveCrudController extends CrudController
1818
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
1919
use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
2020
use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;
21+
use \Backpack\Pro\Http\Controllers\Operations\AjaxUploadOperation { ajaxUpload as traitAjaxUpload; }
2122

2223
/**
2324
* Configure the CrudPanel object. Apply settings to all operations.
@@ -147,4 +148,15 @@ public static function getMonsterSubfields()
147148

148149
return $subfields;
149150
}
151+
152+
public function ajaxUpload()
153+
{
154+
if (app('env') === 'production') {
155+
return response()->json(['errors' => [
156+
'message' => 'Uploads are disabled in production.',
157+
]], 500);
158+
}
159+
160+
return $this->traitAjaxUpload();
161+
}
150162
}

app/Http/Controllers/Admin/DummyCrudController.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class DummyCrudController extends CrudController
2121
use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
2222
use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;
2323
use \Backpack\CRUD\app\Http\Controllers\Operations\FetchOperation;
24+
use \Backpack\Pro\Http\Controllers\Operations\AjaxUploadOperation { ajaxUpload as traitAjaxUpload; }
2425

2526
public function setup()
2627
{
@@ -186,4 +187,15 @@ protected function groups()
186187

187188
return $groups;
188189
}
190+
191+
public function ajaxUpload()
192+
{
193+
if (app('env') === 'production') {
194+
return response()->json(['errors' => [
195+
'message' => 'Uploads are disabled in production.',
196+
]], 500);
197+
}
198+
199+
return $this->traitAjaxUpload();
200+
}
189201
}

app/Http/Controllers/Admin/FluentMonsterCrudController.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -443,12 +443,6 @@ protected function setupCreateOperation()
443443
->type('summernote')
444444
->label('Summernote editor')
445445
->tab('Big texts');
446-
447-
CRUD::field('wysiwyg')
448-
->type('ckeditor')
449-
->label('CKEditor - also called the WYSIWYG field')
450-
->tab('Big texts');
451-
452446
CRUD::field('tinymce')
453447
->type('tinymce')
454448
->label('TinyMCE')

app/Http/Controllers/Admin/IconCrudController.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ public function setup()
2525
protected function setupListOperation()
2626
{
2727
$this->crud->addColumns(['name', 'icon']);
28+
29+
$this->crud->addFilter([
30+
'type' => 'date_range',
31+
'name' => 'created_at',
32+
'label' => 'Created At',
33+
], null, function ($value) {
34+
$value = json_decode($value, true);
35+
36+
// if the filter is active
37+
if ($value) {
38+
$this->crud->addClause('where', 'created_at', '>=', $value['from']);
39+
$this->crud->addClause('where', 'created_at', '<=', $value['to']);
40+
}
41+
});
2842
}
2943

3044
protected function setupCreateOperation()

app/Http/Controllers/Admin/MonsterCrudController.php

Lines changed: 64 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@
55
use App\Http\Requests\MonsterRequest as StoreRequest;
66
// VALIDATION: change the requests to match your own file names if you need form validation
77
use Backpack\CRUD\app\Http\Controllers\CrudController;
8+
use Backpack\CRUD\app\Library\Widget;
89
use Illuminate\Support\Collection;
910

1011
class MonsterCrudController extends CrudController
1112
{
1213
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
1314
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
1415
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
16+
use \Backpack\DataformModal\Http\Controllers\Operations\CreateInModalOperation;
17+
use \Backpack\DataformModal\Http\Controllers\Operations\UpdateInModalOperation;
1518
use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
1619
use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;
1720
use \Backpack\CRUD\app\Http\Controllers\Operations\FetchOperation;
18-
use \Backpack\Pro\Http\Controllers\Operations\DropzoneOperation { dropzoneUpload as traitDropzone; }
19-
use \App\Http\Controllers\Admin\Operations\SMSOperation; //Custom Form Operation Example
21+
use \Backpack\Pro\Http\Controllers\Operations\AjaxUploadOperation { ajaxUpload as traitAjaxUpload; }
22+
use Operations\SMSOperation; //Custom Form Operation Example
2023
use \Backpack\ActivityLog\Http\Controllers\Operations\ModelActivityOperation;
2124
use \Backpack\ActivityLog\Http\Controllers\Operations\EntryActivityOperation;
2225

@@ -131,10 +134,10 @@ public function setupListOperation()
131134
'element' => 'span',
132135
'class' => function ($crud, $column, $entry, $related_key) {
133136
if ($column['text'] == 'Yes') {
134-
return 'badge rounded-pill bg-success';
137+
return 'badge rounded-pill bg-success text-white';
135138
}
136139

137-
return 'badge rounded-pill bg-danger';
140+
return 'badge rounded-pill bg-danger text-white';
138141
},
139142
],
140143
],
@@ -279,6 +282,53 @@ public function setupListOperation()
279282

280283
public function setupShowOperation()
281284
{
285+
// add a widget
286+
Widget::add([
287+
'type' => 'datatable',
288+
'controller' => 'App\Http\Controllers\Admin\IconCrudController',
289+
'name' => 'icon_crud',
290+
'section' => 'after_content',
291+
'content' => [
292+
'header' => 'Icons for this monster',
293+
],
294+
'wrapper' => ['class'=> 'mb-3'],
295+
]);
296+
297+
Widget::add([
298+
'type' => 'datatable',
299+
'controller' => 'App\Http\Controllers\Admin\ProductCrudController',
300+
'name' => 'products_datatable',
301+
'section' => 'after_content',
302+
'content' => [
303+
'header' => 'Products for this monster',
304+
],
305+
'wrapper' => ['class'=> 'mb-3'],
306+
'configure' => function ($crud, $entry = null) {
307+
// Customize which columns to show
308+
$crud->removeAllColumns();
309+
$crud->addColumn(['name' => 'name', 'label' => 'Product Name']);
310+
$crud->addColumn(['name' => 'price', 'label' => 'Price']);
311+
312+
// Get the current monster's products
313+
if ($entry) {
314+
$productIds = $entry->products->pluck('id')->toArray();
315+
if (count($productIds) > 0) {
316+
// Configure the controller to only show products related to this monster
317+
$crud->addClause('whereIn', 'id', $productIds);
318+
} else {
319+
// Force an empty result when there are no products
320+
$crud->addClause('where', 'id', 0); // This will match no products
321+
}
322+
323+
// Remove buttons that aren't needed for this embedded view
324+
325+
// Disable features that aren't needed
326+
$crud->denyAccess(['create', 'update', 'delete']);
327+
$crud->disableResponsiveTable();
328+
}
329+
},
330+
]);
331+
282332
$this->crud->setOperationSetting('tabsEnabled', true);
283333
$this->setupListOperation();
284334

@@ -320,13 +370,6 @@ public function setupShowOperation()
320370
'tab' => 'WYSIWYG Editors',
321371
]);
322372

323-
$this->crud->addColumn([
324-
'name' => 'wysiwyg',
325-
'type' => 'wysiwyg',
326-
'label' => 'Wysiwyg'.backpack_pro_badge(),
327-
'tab' => 'WYSIWYG Editors',
328-
]);
329-
330373
$this->crud->addColumn([
331374
'name' => 'features',
332375
'label' => 'Features'.backpack_pro_badge(),
@@ -1703,10 +1746,11 @@ public static function getFieldsArrayForWysiwygEditorsTab()
17031746
'tab' => 'WYSIWYG Editors',
17041747
],
17051748
[ // Summernote
1706-
'name' => 'summernote',
1707-
'label' => 'Summernote editor'.backpack_free_badge(),
1708-
'type' => 'summernote',
1709-
'tab' => 'WYSIWYG Editors',
1749+
'name' => 'summernote',
1750+
'label' => 'Summernote editor'.backpack_free_badge(),
1751+
'type' => 'summernote',
1752+
'tab' => 'WYSIWYG Editors',
1753+
'withFiles' => true,
17101754
],
17111755
[ // CKEditor
17121756
'name' => 'ckeditor',
@@ -1720,12 +1764,6 @@ public static function getFieldsArrayForWysiwygEditorsTab()
17201764
'type' => 'tinymce',
17211765
'tab' => 'WYSIWYG Editors',
17221766
],
1723-
[ // Wysiwyg
1724-
'name' => 'wysiwyg',
1725-
'label' => 'Wysiwyg'.backpack_pro_badge(),
1726-
'type' => 'wysiwyg',
1727-
'tab' => 'WYSIWYG Editors',
1728-
],
17291767
];
17301768
}
17311769

@@ -1837,15 +1875,17 @@ public static function getFieldsArrayForMiscellaneousTab()
18371875
];
18381876
}
18391877

1840-
public function dropzoneUpload()
1878+
public function ajaxUpload()
18411879
{
18421880
if (app('env') === 'production') {
18431881
return response()->json(['errors' => [
1844-
'dropzone' => ['Uploads are disabled in production'],
1882+
'dropzone' => ['Uploads are disabled in production'],
1883+
'easymde' => ['Uploads are disabled in production'],
1884+
'summernote' => ['Uploads are disabled in production'],
18451885
],
18461886
], 500);
18471887
}
18481888

1849-
return $this->traitDropzone();
1889+
return $this->traitAjaxUpload();
18501890
}
18511891
}

app/Http/Controllers/Admin/PetShop/InvoiceCrudController.php

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\Http\Requests\InvoiceRequest;
66
use Backpack\CRUD\app\Http\Controllers\CrudController;
77
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
8+
use Backpack\CRUD\app\Library\Widget;
89

910
/**
1011
* Class InvoiceCrudController.
@@ -14,12 +15,14 @@
1415
class InvoiceCrudController extends CrudController
1516
{
1617
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
17-
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
18-
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
18+
// use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
19+
// use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
1920
use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;
2021
use \Backpack\CRUD\app\Http\Controllers\Operations\FetchOperation;
2122
use \Backpack\Pro\Http\Controllers\Operations\TrashOperation;
2223
use \Backpack\Pro\Http\Controllers\Operations\CustomViewOperation;
24+
use \Backpack\DataformModal\Http\Controllers\Operations\CreateInModalOperation;
25+
use \Backpack\DataformModal\Http\Controllers\Operations\UpdateInModalOperation;
2326

2427
/**
2528
* Configure the CrudPanel object. Apply settings to all operations.
@@ -53,19 +56,32 @@ public function setupLast5YearsView()
5356
protected function setupListOperation()
5457
{
5558
CRUD::addColumn([
56-
'name' => 'owner',
57-
'label' => 'Owner',
58-
'linkTo' => [
59-
'route' => 'owner.show',
60-
'target' => '_blank',
61-
],
59+
'name' => 'info',
60+
'type' => 'view',
61+
'view' => 'crud::chips.invoice',
6262
]);
63-
CRUD::column('series');
64-
CRUD::column('number');
6563
CRUD::column('issuance_date');
6664
CRUD::column('due_date');
6765
CRUD::column('total');
6866

67+
CRUD::filter('series')
68+
->type('dropdown')
69+
->values(\App\Models\PetShop\Invoice::select('series')->distinct()->pluck('series', 'series')->toArray())
70+
->label('Series')
71+
->placeholder('Search by series')
72+
->whenActive(function ($value) {
73+
CRUD::addClause('where', 'series', '=', $value);
74+
});
75+
76+
CRUD::filter('issuance_date')
77+
->type('date_range')
78+
->label('Issuance Date')
79+
->placeholder('Search by issuance date')
80+
->whenActive(function ($value) {
81+
$dates = json_decode($value);
82+
CRUD::addClause('whereBetween', 'issuance_date', [$dates->from, $dates->to]);
83+
});
84+
6985
$this->runCustomViews();
7086
}
7187

@@ -130,6 +146,17 @@ protected function setupShowOperation()
130146
$this->autoSetupShowOperation();
131147

132148
CRUD::column('total');
149+
150+
// get the owner with important relationships
151+
$owner = CRUD::getCurrentEntry()->owner()->with('avatar', 'invoices')->first();
152+
153+
// add a chip widget for the owner
154+
Widget::add()
155+
->to('after_content')
156+
->type('chip')
157+
->view('crud::chips.owner')
158+
->title('Owner')
159+
->entry($owner);
133160
}
134161

135162
public function fetchOwner()

0 commit comments

Comments
 (0)