Skip to content

Commit 9c69fab

Browse files
64knlkeeama13
andauthored
feat: component filter added (#176) (#188)
* fix: only add column when it doesn't exist (#167) * fix: only add column when it doesn't exist * style: formatting * feat: export cms (#169) * feat: import export * feat: use file instead of database * feat: move import/export to model * fix: export from tableitem * feat: move export to Trait * style: formatting * style: formatting * fix: never use file as source of truth * style: formatting * chore: cleanup * fix: use export to file * feat: comment things that no longer work * feat: add meta data * feat: list filenames * feat: cleaner export * feat: remove UI for import/export * style: formatting * feat: add import command * feat: import from files * feat: remove import UI * feat: prevent editing tables with changes on disk * feat: do not use id's in export for tables * feat: optionally export ids * feat: import ids when available --------- * feat: component filter added * feat: added filterparams * feat: only query if filter exists * feat: WIP * feat: typed editor classes * feat: editor changes * feat: removed code * feat: removed request from editor and overview * feat: added TODO * chore: update dependency * feat: migration for model column in cms_table * fix: retain model on import export cms_table * feat: moved code to component * feat: added guards * style: formatting * feat: parameters now in tableservice * feat: removed parameter * feat: removed request() from editor * fix: return empty array if key not exists * style: formatting * style: formatting --------- Co-authored-by: Xander Schuurman <[email protected]>
1 parent 09bed3e commit 9c69fab

31 files changed

+319
-70
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"spatie/laravel-package-tools": "^1.14.0",
2020
"spatie/laravel-honeypot": "^4.3.2",
2121
"illuminate/contracts": "^10.0",
22-
"notfoundnl/siteboss-layout": "^1.4.3",
22+
"notfoundnl/siteboss-layout": "^1.6",
2323
"notfoundnl/siteboss-static": "^1.13",
2424
"mcamara/laravel-localization": "^1.8",
2525
"xenolope/quahog": "^3.0",
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('cms_table', function (Blueprint $table) {
15+
$table->string('model')->after('table')->nullable();
16+
});
17+
}
18+
19+
/**
20+
* Reverse the migrations.
21+
*/
22+
public function down(): void
23+
{
24+
Schema::table('cms_table', function (Blueprint $table) {
25+
$table->dropColumn('model');
26+
});
27+
}
28+
};

src/Events/AfterSaveEvent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class AfterSaveEvent
1515
/**
1616
* Create a new event instance.
1717
*
18-
* @param $model is an model of Table or Strings that they extends from BaseModel
18+
* @param $model is an model of Table or Strings that they extends from BaseModel
1919
* @return void
2020
*/
2121
public function __construct(BaseModel $model)

src/Events/BeforeSaveEvent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class BeforeSaveEvent
1515
/**
1616
* Create a new event instance.
1717
*
18-
* @param $model is an model of Table or Strings that they implements IAsset
18+
* @param $model is an model of Table or Strings that they implements IAsset
1919
* @return void
2020
*/
2121
public function __construct(BaseModel $model)

src/Helpers/CmsImportHelper.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ private function importTables(string $tableName): object
7070
$table->id = $fileSource->id;
7171
}
7272
$table->name = $fileSource->name;
73+
$table->model = $fileSource->model;
7374
$table->url = $fileSource->url;
7475
$table->rights = $fileSource->rights;
7576

@@ -137,6 +138,7 @@ private function createImportTables(): void
137138
$table->id();
138139
$table->string('name', 128)->nullable();
139140
$table->string('table', 128)->nullable();
141+
$table->string('model', 128)->nullable();
140142
$table->string('url', 128)->nullable();
141143
$table->string('rights', 128)->nullable();
142144
$table->text('comments')->nullable();

src/Helpers/LayoutInputDropdownHelper.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ class LayoutInputDropdownHelper
1313
/**
1414
* Easily create a dropdown based on a model
1515
*
16-
* @param $model Model to be queried
17-
* @param $label Label for the dropdown
18-
* @param $internal defaults to $model table name + '_id'
19-
* @param $tableColumnName The column name of site table to get the readable name from
20-
* @param $value default value for the dropdown
16+
* @param $model Model to be queried
17+
* @param $label Label for the dropdown
18+
* @param $internal defaults to $model table name + '_id'
19+
* @param $tableColumnName The column name of site table to get the readable name from
20+
* @param $value default value for the dropdown
2121
*/
2222
public function __construct(
2323
protected BaseModel|LegacyModel $model,

src/Helpers/SitebossHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class SitebossHelper
1515
*
1616
* Returns a value from the cms_config table.
1717
*
18-
* @param mixed $code The internal code for the config value.
19-
* @param mixed $failOnMissing Whether to throw an exception if the config value is missing.
18+
* @param mixed $code The internal code for the config value.
19+
* @param mixed $failOnMissing Whether to throw an exception if the config value is missing.
2020
* @return string|object|null The value of the config.
2121
*/
2222
public static function config(string $code, bool $failOnMissing = true): string|object|null

src/Http/Controllers/Assets/AssetEditorController.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
namespace NotFound\Framework\Http\Controllers\Assets;
44

55
use NotFound\Framework\Http\Controllers\Controller;
6+
use NotFound\Framework\Models\Editor\AbstractEditor;
7+
use NotFound\Framework\Models\Editor\DefaultEditor;
68
use NotFound\Framework\Models\Lang;
9+
use NotFound\Framework\Models\Table;
10+
use NotFound\Framework\Services\Assets\TableService;
711
use NotFound\Layout\Elements\LayoutBar;
812
use NotFound\Layout\Elements\LayoutBarButton;
913
use NotFound\Layout\Elements\LayoutWidget;
@@ -13,9 +17,9 @@ abstract class AssetEditorController extends Controller
1317
/**
1418
* Adds a language bar to the widget
1519
*
16-
* @param LayoutWidget $widget Widget to add to
17-
* @param string $url the url to go to. NOTE: adds the locale to the end
18-
* @param Lang $currentLang Disables routing to the current lang
20+
* @param LayoutWidget $widget Widget to add to
21+
* @param string $url the url to go to. NOTE: adds the locale to the end
22+
* @param Lang $currentLang Disables routing to the current lang
1923
*/
2024
protected function addLanguageBarToWidget(LayoutWidget $widget, string $url, Lang $currentLang): void
2125
{
@@ -39,4 +43,19 @@ protected function addLanguageBarToWidget(LayoutWidget $widget, string $url, Lan
3943

4044
$widget->addBar($bar);
4145
}
46+
47+
protected function customEditor(Table $table, TableService $tableService): AbstractEditor
48+
{
49+
// This only works for models
50+
if ($table->model !== null) {
51+
52+
$editorClass = substr_replace($table->model, '\\Editor', strrpos($table->model, '\\'), 0).'Editor';
53+
54+
if (class_exists($editorClass)) {
55+
return new $editorClass($tableService);
56+
}
57+
}
58+
59+
return new DefaultEditor($tableService);
60+
}
4261
}

src/Http/Controllers/Assets/TableEditorController.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use NotFound\Framework\Services\Assets\TableService;
1515
use NotFound\Layout\Elements\LayoutBar;
1616
use NotFound\Layout\Elements\LayoutBarButton;
17-
use NotFound\Layout\Elements\LayoutBreadcrumb;
1817
use NotFound\Layout\Elements\LayoutButton;
1918
use NotFound\Layout\Elements\LayoutForm;
2019
use NotFound\Layout\Elements\LayoutPage;
@@ -37,9 +36,13 @@ public function index(Request $request, Table $table, int $recordId, string $lan
3736

3837
$tableService = new TableService($table, $lang, $recordId === 0 ? null : $recordId);
3938

39+
$tableService->setRequestParameters($request->query());
40+
41+
$editor = $this->customEditor($table, $tableService);
42+
4043
$params = sprintf('?page=%d&sort=%s&asc=%s', $request->page ?? 1, $request->sort ?? '', $request->asc ?? '');
4144

42-
$formUrl = sprintf('/table/%s/%s/%s/%s', $table->url, $recordId ?? 0, urlencode($langUrl), $params);
45+
$formUrl = sprintf('/table/%s/%s/%s/%s', $table->url, $recordId ?? 0, urlencode($langUrl), $params.$editor->filterToParams());
4346

4447
$form = new LayoutForm($formUrl);
4548

@@ -53,13 +56,9 @@ public function index(Request $request, Table $table, int $recordId, string $lan
5356

5457
$page = new LayoutPage(__('siteboss::ui.page'));
5558
$page->addTitle(new LayoutTitle($table->name));
59+
$page->addBreadCrumb($editor->getBreadCrumbsEdit());
5660

57-
$breadcrumb = new LayoutBreadcrumb();
58-
$breadcrumb->addHome();
59-
$breadcrumb->addItem($table->name, '/table/'.$table->url.'/?'.$params);
6061
$upsertingText = $recordId === 0 ? __('siteboss::ui.new') : __('siteboss::ui.edit');
61-
$breadcrumb->addItem($upsertingText); //TODO: Add better title
62-
$page->addBreadCrumb($breadcrumb);
6362

6463
$saveButton = new LayoutButton(__('siteboss::ui.save'));
6564

@@ -110,6 +109,10 @@ public function update(FormDataRequest $request, Table $table, int $recordId, st
110109

111110
$tableService = new TableService($table, $lang, $recordId);
112111

112+
$tableService->setRequestParameters($request->query());
113+
114+
$editor = $this->customEditor($table, $tableService);
115+
113116
if (! $tableService->validate($request)) {
114117
// TODO: better error
115118
abort(422, 'Error validating');
@@ -135,17 +138,22 @@ public function update(FormDataRequest $request, Table $table, int $recordId, st
135138
isset($request->siteboss_formOptions['send']) &&
136139
$request->siteboss_formOptions['send'] === 'stay_on_page'
137140
) {
141+
138142
// Stay on page
139143
if ($newTableRecord) {
140-
$response->addAction(new Redirect('/table/'.$table->url.'/'.$id.'/'));
144+
$url = '/table/'.$table->url.'/'.$id;
145+
if ($params = $editor->filterToParams()) {
146+
$url .= '?'.ltrim($params, '&');
147+
}
148+
$response->addAction(new Redirect($url));
141149
} else {
142150
$response->addAction(new Reload());
143151
}
144152
} else {
145153
// Redirect
146154

147155
$params = sprintf('?page=%d&sort=%s&asc=%s', $request->page ?? 1, $request->sort ?? '', $request->asc ?? '');
148-
156+
$params .= $editor->filterToParams();
149157
$response->addAction(new Redirect('/table/'.$table->url.'/?'.$params));
150158
}
151159

src/Http/Controllers/Assets/TableOverviewController.php

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44

55
use Illuminate\Http\Request;
66
use Illuminate\Support\Facades\DB;
7-
use NotFound\Framework\Http\Controllers\Controller;
87
use NotFound\Framework\Models\Lang;
98
use NotFound\Framework\Models\Table;
109
use NotFound\Framework\Services\Assets\Components\AbstractComponent;
1110
use NotFound\Framework\Services\Assets\TableQueryService;
1211
use NotFound\Framework\Services\Assets\TableService;
1312
use NotFound\Layout\Elements\LayoutBar;
1413
use NotFound\Layout\Elements\LayoutBarButton;
15-
use NotFound\Layout\Elements\LayoutBreadcrumb;
1614
use NotFound\Layout\Elements\LayoutPage;
1715
use NotFound\Layout\Elements\LayoutPager;
1816
use NotFound\Layout\Elements\LayoutSearchBox;
@@ -24,14 +22,14 @@
2422
use NotFound\Layout\LayoutResponse;
2523
use NotFound\Layout\Responses\Toast;
2624

27-
class TableOverviewController extends Controller
25+
class TableOverviewController extends AssetEditorController
2826
{
2927
/**
3028
* This endpoint returns information about input type that is created data over tg_cms_table and tg_cms_tableitem
3129
* Input types are used on front-end especially Cms form builder
3230
*
33-
* @param string $customer This is an value of tg_cms_table->url column.
34-
* @return array ['headers' => [{'name' => 'name3','properties' => 'sourcename']], 'rows' => [
31+
* @param string $customer This is an value of tg_cms_table->url column.
32+
* @return array ['headers' => [{'name' => 'name3','properties' => 'sourcename']], 'rows' => [
3533
*/
3634
public function index(Request $request, Table $table)
3735
{
@@ -44,8 +42,12 @@ public function index(Request $request, Table $table)
4442
$layoutTable = new LayoutTable(create: $table->allow_create, delete: $table->allow_delete, sort: $table->allow_sort);
4543
$layoutTable->setTotalItems($siteTableRowsPaginator->total());
4644

45+
$tableService->setRequestParameters($request->query());
46+
47+
$editor = $this->customEditor($table, $tableService);
48+
4749
foreach ($siteTableRowsPaginator as $row) {
48-
$link = sprintf('/table/%s/%d/?page=%d&sort=%s&asc=%s', $table->url, $row->id, $request->page ?? 1, $request->sort ?? '', $request->asc ?? '');
50+
$link = sprintf('/table/%s/%d/?page=%d&sort=%s&asc=%s', $table->url, $row->id, $request->page ?? 1, $request->sort ?? '', $request->asc ?? '').$editor->filterToParams();
4951
$layoutRow = new LayoutTableRow($row->id, link: $link);
5052

5153
foreach ($components as $component) {
@@ -72,18 +74,23 @@ public function index(Request $request, Table $table)
7274
$page = new LayoutPage($table->name);
7375
$page->addTitle(new LayoutTitle($table->name));
7476

75-
$breadcrumb = new LayoutBreadcrumb();
76-
$breadcrumb->addHome();
77-
$breadcrumb->addItem($table->name);
78-
$page->addBreadCrumb($breadcrumb);
77+
$page->addBreadCrumb($editor->getBreadCrumbs());
7978

8079
$bar = new LayoutBar();
80+
$bottomBar = new LayoutBar();
81+
$bottomBar->noBackground();
8182

8283
if ($table->allow_create) {
8384
$addNew = new LayoutBarButton('Nieuw');
8485
$addNew->setIcon('plus');
85-
$addNew->setSpecialAction('addNew');
86+
$url = '/table/'.$table->url.'/0';
87+
if ($params = $editor->filterToParams());
88+
89+
$url .= '?'.ltrim($params, '&');
90+
91+
$addNew->setLink($url);
8692
$bar->addBarButton($addNew);
93+
$bottomBar->addBarButton($addNew);
8794
}
8895

8996
$pager = new LayoutPager(totalItems: $siteTableRowsPaginator->total(), itemsPerPage: request()->query('pitems') ?? $table->properties->itemsPerPage ?? 25);
@@ -95,16 +102,6 @@ public function index(Request $request, Table $table)
95102
$widget->noPadding();
96103
$widget->addBar($bar);
97104
$widget->addTable($layoutTable);
98-
99-
$bottomBar = new LayoutBar();
100-
$bottomBar->noBackground();
101-
102-
if ($table->allow_create) {
103-
$addNew = new LayoutBarButton('Nieuw');
104-
$addNew->setIcon('plus');
105-
$addNew->setSpecialAction('addNew');
106-
$bottomBar->addBarButton($addNew);
107-
}
108105
$widget->addBar($bottomBar);
109106

110107
if ($siteTableRowsPaginator->total() == 0) {
@@ -146,7 +143,7 @@ public function updateField(Request $request, Table $table)
146143
* @param int $recordId
147144
* @param int $newPosition
148145
* @param int $oldPosition
149-
* @return jsonResponse
146+
* @return jsonResponse
150147
*/
151148
public function updatePosition(Request $request, Table $table)
152149
{

0 commit comments

Comments
 (0)