Skip to content

Commit

Permalink
feat: component filter added (#176) (#188)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
64knl and keeama13 authored Jan 26, 2024
1 parent 09bed3e commit 9c69fab
Show file tree
Hide file tree
Showing 31 changed files with 319 additions and 70 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"spatie/laravel-package-tools": "^1.14.0",
"spatie/laravel-honeypot": "^4.3.2",
"illuminate/contracts": "^10.0",
"notfoundnl/siteboss-layout": "^1.4.3",
"notfoundnl/siteboss-layout": "^1.6",
"notfoundnl/siteboss-static": "^1.13",
"mcamara/laravel-localization": "^1.8",
"xenolope/quahog": "^3.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('cms_table', function (Blueprint $table) {
$table->string('model')->after('table')->nullable();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('cms_table', function (Blueprint $table) {
$table->dropColumn('model');
});
}
};
2 changes: 1 addition & 1 deletion src/Events/AfterSaveEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AfterSaveEvent
/**
* Create a new event instance.
*
* @param $model is an model of Table or Strings that they extends from BaseModel
* @param $model is an model of Table or Strings that they extends from BaseModel
* @return void
*/
public function __construct(BaseModel $model)
Expand Down
2 changes: 1 addition & 1 deletion src/Events/BeforeSaveEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class BeforeSaveEvent
/**
* Create a new event instance.
*
* @param $model is an model of Table or Strings that they implements IAsset
* @param $model is an model of Table or Strings that they implements IAsset
* @return void
*/
public function __construct(BaseModel $model)
Expand Down
2 changes: 2 additions & 0 deletions src/Helpers/CmsImportHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ private function importTables(string $tableName): object
$table->id = $fileSource->id;
}
$table->name = $fileSource->name;
$table->model = $fileSource->model;
$table->url = $fileSource->url;
$table->rights = $fileSource->rights;

Expand Down Expand Up @@ -137,6 +138,7 @@ private function createImportTables(): void
$table->id();
$table->string('name', 128)->nullable();
$table->string('table', 128)->nullable();
$table->string('model', 128)->nullable();
$table->string('url', 128)->nullable();
$table->string('rights', 128)->nullable();
$table->text('comments')->nullable();
Expand Down
10 changes: 5 additions & 5 deletions src/Helpers/LayoutInputDropdownHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class LayoutInputDropdownHelper
/**
* Easily create a dropdown based on a model
*
* @param $model Model to be queried
* @param $label Label for the dropdown
* @param $internal defaults to $model table name + '_id'
* @param $tableColumnName The column name of site table to get the readable name from
* @param $value default value for the dropdown
* @param $model Model to be queried
* @param $label Label for the dropdown
* @param $internal defaults to $model table name + '_id'
* @param $tableColumnName The column name of site table to get the readable name from
* @param $value default value for the dropdown
*/
public function __construct(
protected BaseModel|LegacyModel $model,
Expand Down
4 changes: 2 additions & 2 deletions src/Helpers/SitebossHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class SitebossHelper
*
* Returns a value from the cms_config table.
*
* @param mixed $code The internal code for the config value.
* @param mixed $failOnMissing Whether to throw an exception if the config value is missing.
* @param mixed $code The internal code for the config value.
* @param mixed $failOnMissing Whether to throw an exception if the config value is missing.
* @return string|object|null The value of the config.
*/
public static function config(string $code, bool $failOnMissing = true): string|object|null
Expand Down
25 changes: 22 additions & 3 deletions src/Http/Controllers/Assets/AssetEditorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
namespace NotFound\Framework\Http\Controllers\Assets;

use NotFound\Framework\Http\Controllers\Controller;
use NotFound\Framework\Models\Editor\AbstractEditor;
use NotFound\Framework\Models\Editor\DefaultEditor;
use NotFound\Framework\Models\Lang;
use NotFound\Framework\Models\Table;
use NotFound\Framework\Services\Assets\TableService;
use NotFound\Layout\Elements\LayoutBar;
use NotFound\Layout\Elements\LayoutBarButton;
use NotFound\Layout\Elements\LayoutWidget;
Expand All @@ -13,9 +17,9 @@ abstract class AssetEditorController extends Controller
/**
* Adds a language bar to the widget
*
* @param LayoutWidget $widget Widget to add to
* @param string $url the url to go to. NOTE: adds the locale to the end
* @param Lang $currentLang Disables routing to the current lang
* @param LayoutWidget $widget Widget to add to
* @param string $url the url to go to. NOTE: adds the locale to the end
* @param Lang $currentLang Disables routing to the current lang
*/
protected function addLanguageBarToWidget(LayoutWidget $widget, string $url, Lang $currentLang): void
{
Expand All @@ -39,4 +43,19 @@ protected function addLanguageBarToWidget(LayoutWidget $widget, string $url, Lan

$widget->addBar($bar);
}

protected function customEditor(Table $table, TableService $tableService): AbstractEditor
{
// This only works for models
if ($table->model !== null) {

$editorClass = substr_replace($table->model, '\\Editor', strrpos($table->model, '\\'), 0).'Editor';

if (class_exists($editorClass)) {
return new $editorClass($tableService);
}
}

return new DefaultEditor($tableService);
}
}
26 changes: 17 additions & 9 deletions src/Http/Controllers/Assets/TableEditorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use NotFound\Framework\Services\Assets\TableService;
use NotFound\Layout\Elements\LayoutBar;
use NotFound\Layout\Elements\LayoutBarButton;
use NotFound\Layout\Elements\LayoutBreadcrumb;
use NotFound\Layout\Elements\LayoutButton;
use NotFound\Layout\Elements\LayoutForm;
use NotFound\Layout\Elements\LayoutPage;
Expand All @@ -37,9 +36,13 @@ public function index(Request $request, Table $table, int $recordId, string $lan

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

$tableService->setRequestParameters($request->query());

$editor = $this->customEditor($table, $tableService);

$params = sprintf('?page=%d&sort=%s&asc=%s', $request->page ?? 1, $request->sort ?? '', $request->asc ?? '');

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

$form = new LayoutForm($formUrl);

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

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

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

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

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

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

$tableService->setRequestParameters($request->query());

$editor = $this->customEditor($table, $tableService);

if (! $tableService->validate($request)) {
// TODO: better error
abort(422, 'Error validating');
Expand All @@ -135,17 +138,22 @@ public function update(FormDataRequest $request, Table $table, int $recordId, st
isset($request->siteboss_formOptions['send']) &&
$request->siteboss_formOptions['send'] === 'stay_on_page'
) {

// Stay on page
if ($newTableRecord) {
$response->addAction(new Redirect('/table/'.$table->url.'/'.$id.'/'));
$url = '/table/'.$table->url.'/'.$id;
if ($params = $editor->filterToParams()) {
$url .= '?'.ltrim($params, '&');
}
$response->addAction(new Redirect($url));
} else {
$response->addAction(new Reload());
}
} else {
// Redirect

$params = sprintf('?page=%d&sort=%s&asc=%s', $request->page ?? 1, $request->sort ?? '', $request->asc ?? '');

$params .= $editor->filterToParams();
$response->addAction(new Redirect('/table/'.$table->url.'/?'.$params));
}

Expand Down
41 changes: 19 additions & 22 deletions src/Http/Controllers/Assets/TableOverviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use NotFound\Framework\Http\Controllers\Controller;
use NotFound\Framework\Models\Lang;
use NotFound\Framework\Models\Table;
use NotFound\Framework\Services\Assets\Components\AbstractComponent;
use NotFound\Framework\Services\Assets\TableQueryService;
use NotFound\Framework\Services\Assets\TableService;
use NotFound\Layout\Elements\LayoutBar;
use NotFound\Layout\Elements\LayoutBarButton;
use NotFound\Layout\Elements\LayoutBreadcrumb;
use NotFound\Layout\Elements\LayoutPage;
use NotFound\Layout\Elements\LayoutPager;
use NotFound\Layout\Elements\LayoutSearchBox;
Expand All @@ -24,14 +22,14 @@
use NotFound\Layout\LayoutResponse;
use NotFound\Layout\Responses\Toast;

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

$tableService->setRequestParameters($request->query());

$editor = $this->customEditor($table, $tableService);

foreach ($siteTableRowsPaginator as $row) {
$link = sprintf('/table/%s/%d/?page=%d&sort=%s&asc=%s', $table->url, $row->id, $request->page ?? 1, $request->sort ?? '', $request->asc ?? '');
$link = sprintf('/table/%s/%d/?page=%d&sort=%s&asc=%s', $table->url, $row->id, $request->page ?? 1, $request->sort ?? '', $request->asc ?? '').$editor->filterToParams();
$layoutRow = new LayoutTableRow($row->id, link: $link);

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

$breadcrumb = new LayoutBreadcrumb();
$breadcrumb->addHome();
$breadcrumb->addItem($table->name);
$page->addBreadCrumb($breadcrumb);
$page->addBreadCrumb($editor->getBreadCrumbs());

$bar = new LayoutBar();
$bottomBar = new LayoutBar();
$bottomBar->noBackground();

if ($table->allow_create) {
$addNew = new LayoutBarButton('Nieuw');
$addNew->setIcon('plus');
$addNew->setSpecialAction('addNew');
$url = '/table/'.$table->url.'/0';
if ($params = $editor->filterToParams());

$url .= '?'.ltrim($params, '&');

$addNew->setLink($url);
$bar->addBarButton($addNew);
$bottomBar->addBarButton($addNew);
}

$pager = new LayoutPager(totalItems: $siteTableRowsPaginator->total(), itemsPerPage: request()->query('pitems') ?? $table->properties->itemsPerPage ?? 25);
Expand All @@ -95,16 +102,6 @@ public function index(Request $request, Table $table)
$widget->noPadding();
$widget->addBar($bar);
$widget->addTable($layoutTable);

$bottomBar = new LayoutBar();
$bottomBar->noBackground();

if ($table->allow_create) {
$addNew = new LayoutBarButton('Nieuw');
$addNew->setIcon('plus');
$addNew->setSpecialAction('addNew');
$bottomBar->addBarButton($addNew);
}
$widget->addBar($bottomBar);

if ($siteTableRowsPaginator->total() == 0) {
Expand Down Expand Up @@ -146,7 +143,7 @@ public function updateField(Request $request, Table $table)
* @param int $recordId
* @param int $newPosition
* @param int $oldPosition
* @return jsonResponse
* @return jsonResponse
*/
public function updatePosition(Request $request, Table $table)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ContentBlockController
/**
* Get contentBlock template items.
*
* @param $csvTables cms_tables->table in csv format
* @param $csvTables cms_tables->table in csv format
*/
public function get(string $csvTables)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ function db_table_items_change_order(string $tableName, int $recordId, int $repl

if (! function_exists('make_directories')) {
/**
* @param mixed $root The root folder for the path, we'll not go higher than this.
* @param mixed $dir The path from the root folder
* @param mixed $root The root folder for the path, we'll not go higher than this.
* @param mixed $dir The path from the root folder
* @return bool true if the directory was created or already existed.
*/
function make_directories($root, $dir): bool
Expand Down
8 changes: 4 additions & 4 deletions src/Models/CmsUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ public function groups()
* Example: "!admin || user" or "form-data && admin" or "admin"
* check the database which groups exist
*
* @param string $expression The expression to check
* @param bool $default if the rights are not set, returns this
* @param string $expression The expression to check
* @param bool $default if the rights are not set, returns this
* @return bool user is authorized for the expression
*/
public function checkRights($expression, $default = true): bool
Expand Down Expand Up @@ -169,7 +169,7 @@ private function expressionCallBack($matches): string
*
* Checks if the user has explicitly (not inherited) been given the role.
*
* @param string $role The role to check
* @param string $role The role to check
* @return array of roles
*/
public function explicityHasRole($role)
Expand Down Expand Up @@ -204,7 +204,7 @@ public function hasRole($rolesToCheck)
/**
* Checks the database against the roles assigned to the user
*
* @param string $role role to check
* @param string $role role to check
*/
public function hasLocalRole(string $role): bool
{
Expand Down
Loading

0 comments on commit 9c69fab

Please sign in to comment.