Skip to content

Commit

Permalink
feat: Version 0.17.0 (#195)
Browse files Browse the repository at this point in the history
* feat: component filter added (#176)

* 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

---------

Co-authored-by: Rene <rene@64k.nl>

* 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: René <rene@64k.nl>

* fix: exceptions handling (#189)

* fix: exception handling

* style: formatting

* fix: return type

* feat: date helper (#191)

* feat: moved layoutbar to editor (#193)

* feat: moved layoutbar to editor

* style: formatting

* chore: remove unused methods

---------

Co-authored-by: Rene <rene@64k.nl>

* feat: CMS editor import/export (#197)

* feat: move to service

* style: formatting

* feat: template import

* fix: edit tables

* feat: moved bar items to editor (#196)

* feat: moved bar items to editor

* feat: abstract class

* style: formatting

* feat: updated default editor

---------

Co-authored-by: Rene <rene@64k.nl>

---------

Co-authored-by: Xander Schuurman <44030544+keeama13@users.noreply.github.com>
  • Loading branch information
64knl and keeama13 committed Feb 2, 2024
1 parent 1248eae commit 6cc299e
Show file tree
Hide file tree
Showing 16 changed files with 497 additions and 172 deletions.
2 changes: 1 addition & 1 deletion routes/cms/editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

// import/export
Route::post('table-export', [CmsEditorImportExportController::class, 'exportAllTables']);

Route::post('template-export', [CmsEditorImportExportController::class, 'exportAllTemplates']);
// table
Route::prefix('table')->group(function () {
Route::get('', [CmsEditorTableController::class, 'index']);
Expand Down
4 changes: 2 additions & 2 deletions routes/console.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
use NotFound\Framework\Helpers\CmsImportHelper;
use NotFound\Framework\Services\CmsExchange\ExchangeConsoleService;
use NotFound\Framework\Services\Indexer\IndexBuilderService;

Artisan::command('siteboss:index-site {--debug : Whether debug messages should be displayed} {--clean : Truncate search table}', function ($debug, $clean) {
Expand All @@ -15,7 +15,7 @@

Artisan::command('siteboss:cms-import {--debug : Whether debug messages should be displayed} {--dry : Dry Run}', function ($debug, $dry) {

$indexer = new CmsImportHelper($debug, $dry);
$indexer = new ExchangeConsoleService($debug, $dry);
$indexer->import();

return Command::SUCCESS;
Expand Down
8 changes: 2 additions & 6 deletions src/Http/Controllers/Assets/TableOverviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use NotFound\Layout\Elements\LayoutBar;
use NotFound\Layout\Elements\LayoutPage;
use NotFound\Layout\Elements\LayoutPager;
use NotFound\Layout\Elements\LayoutSearchBox;
use NotFound\Layout\Elements\LayoutText;
use NotFound\Layout\Elements\LayoutTitle;
use NotFound\Layout\Elements\LayoutWidget;
Expand Down Expand Up @@ -75,13 +74,10 @@ public function index(Request $request, Table $table)

$page->addBreadCrumb($editor->getBreadCrumbs());

$bar = $editor->getBar();
$bottomBar = $editor->getBottomBar();

$pager = new LayoutPager(totalItems: $siteTableRowsPaginator->total(), itemsPerPage: request()->query('pitems') ?? $table->properties->itemsPerPage ?? 25);
$bar->addPager($pager);

$bar->addSearchBox(new LayoutSearchBox(''));
$bar = $editor->getTopBar($pager);
$bottomBar = $editor->getBottomBar();

$widget = new LayoutWidget(__('siteboss::ui.overview'));
$widget->noPadding();
Expand Down
18 changes: 18 additions & 0 deletions src/Http/Controllers/CmsEditor/CmsEditorImportExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use NotFound\Framework\Http\Controllers\Controller;
use NotFound\Framework\Models\Table;
use NotFound\Framework\Models\Template;
use NotFound\Layout\LayoutResponse;
use NotFound\Layout\Responses\Toast;

Expand All @@ -25,4 +26,21 @@ public function exportAllTables()

return $response->build();
}

public function exportAllTemplates()
{
$response = new LayoutResponse();
$templates = Template::all();

foreach ($templates as $template) {
// TODO: catch exceptions
$template->exportToFile();
}

$response->addAction(
new Toast($templates->count().' templates exported successfully')
);

return $response->build();
}
}
6 changes: 3 additions & 3 deletions src/Http/Controllers/CmsEditor/CmsEditorTableController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
use Illuminate\Http\Request as HttpRequest;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use NotFound\Framework\Helpers\CmsImportHelper;
use NotFound\Framework\Http\Requests\FormDataRequest;
use NotFound\Framework\Models\Table;
use NotFound\Framework\Services\CmsExchange\TableExchangeService;
use NotFound\Framework\Services\Editor\FieldsProperties;
use NotFound\Layout\Elements\LayoutBreadcrumb;
use NotFound\Layout\Elements\LayoutButton;
Expand Down Expand Up @@ -121,8 +121,8 @@ public function readOne(Table $table)
$breadcrumbs->addItem($table->name ?? 'New table');
$page->addBreadCrumb($breadcrumbs);

$importHelper = new CmsImportHelper();
$hasChanges = $importHelper->hasChanges($table);
$tableExchangeService = new TableExchangeService();
$hasChanges = $tableExchangeService->hasChanges($table);

$widget1 = new LayoutWidget($table->name ?? 'New table', $hasChanges ? 12 : 6);

Expand Down
10 changes: 7 additions & 3 deletions src/Http/Controllers/CmsEditor/CmsEditorTemplateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ public function index()
$form->addButton(new LayoutButton('Add new template'));
$widget2->addForm($form);

$form = new LayoutForm('/app/editor/template-export/');

$form->addInput((new LayoutInputCheckbox('name', 'I know this will overwrite the template files from my database'))->setRequired());

$form->addButton(new LayoutButton('Export all templates to files'));
$widget2->addForm($form);

$page->addWidget($widget2);

$response->addUIElement($page);
Expand Down Expand Up @@ -170,9 +177,6 @@ public function readOne(Template $table)

$page->addWidget($widget2);

$page->addWidget(CmsEditorImportExportController::getExport($tables));
$page->addWidget(CmsEditorImportExportController::getImport($table->id, 'page'));

$response->addUIElement($page);

return $response->build();
Expand Down
79 changes: 31 additions & 48 deletions src/Models/Editor/AbstractEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,49 @@
use NotFound\Layout\Elements\LayoutBar;
use NotFound\Layout\Elements\LayoutBarButton;
use NotFound\Layout\Elements\LayoutBreadcrumb;
use NotFound\Layout\Elements\LayoutPager;
use NotFound\Layout\Elements\LayoutSearchBox;

abstract class AbstractEditor
{
public function __construct(protected TableService $ts)
{

}

public function getBar(): LayoutBar
{
$bar = new LayoutBar();
abstract public function getTopBar(LayoutPager $pager): LayoutBar;

$table = $this->ts->getAssetModel();
abstract public function getBottomBar(): LayoutBar;

if ($table->allow_create) {
$addNew = $this->getNewButton();
$bar->addBarButton($addNew);
}
abstract public function getBreadCrumbs(): LayoutBreadCrumb;

abstract public function getBreadCrumbsEdit(): LayoutBreadCrumb;

return $bar;
public function filters(): array
{
return $this->ts->getRequestParameters('filter') ?? [];
}

public function getBottomBar(): LayoutBar
public function filterToParams(): string
{
$bottomBar = $this->getBar();
$bottomBar->noBackground();
if (empty($this->filters())) {
return '';
}
$filterParams = '';
foreach ($this->filters() as $key => $value) {
$filterParams .= '&filter['.$key.']='.$value;
}

return $bottomBar;
return $filterParams;
}

public function getNewButton(): LayoutBarButton
protected function addNewButton(LayoutBar $bar): LayoutBar
{
$table = $this->ts->getAssetModel();

if (! $table->allow_create) {
return $bar;
}

$addNew = new LayoutBarButton('Nieuw');
$table = $this->ts->getAssetModel();
$addNew->setIcon('plus');
Expand All @@ -47,44 +58,16 @@ public function getNewButton(): LayoutBarButton
}
$addNew->setLink($url);

return $addNew;
return $bar->addBarButton($addNew);
}

public function getBreadCrumbs(): LayoutBreadCrumb
protected function addPager(LayoutBar $bar, LayoutPager $pager): LayoutBar
{
$table = $this->ts->getAssetModel();
$breadcrumb = new LayoutBreadcrumb();
$breadcrumb->addHome();
$breadcrumb->addItem($table->name);

return $breadcrumb;
return $bar->addPager($pager);
}

public function getBreadCrumbsEdit(): LayoutBreadCrumb
protected function addSearchBox(LayoutBar $bar): LayoutBar
{
$table = $this->ts->getAssetModel();
$breadcrumb = $this->getBreadCrumbs();
end($breadcrumb->properties->items)->link = '/table/'.$table->url.'/?'.$this->filterToParams();
$breadcrumb->addItem('edit');

return $breadcrumb;
}

public function filters(): array
{
return $this->ts->getRequestParameters('filter') ?? [];
}

public function filterToParams(): string
{
if (empty($this->filters())) {
return '';
}
$filterParams = '';
foreach ($this->filters() as $key => $value) {
$filterParams .= '&filter['.$key.']='.$value;
}

return $filterParams;
return $bar->addSearchBox(new LayoutSearchBox(''));
}
}
69 changes: 69 additions & 0 deletions src/Models/Editor/DefaultEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,75 @@

namespace NotFound\Framework\Models\Editor;

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\LayoutPager;
use NotFound\Layout\Elements\LayoutSearchBox;

class DefaultEditor extends AbstractEditor
{
public function __construct(protected TableService $ts)
{
}

public function getTopBar(LayoutPager $pager): LayoutBar
{
$bar = $this->addNewButton(new LayoutBar);

$bar->addPager($pager);
$bar->addSearchBox(new LayoutSearchBox(''));

return $bar;
}

public function getBottomBar(): LayoutBar
{
$bar = $this->addNewButton(new LayoutBar);

$bar->noBackground();

return $bar;
}

protected function addNewButton(LayoutBar $bar): LayoutBar
{
$table = $this->ts->getAssetModel();

if (! $table->allow_create) {
return $bar;
}

$addNew = new LayoutBarButton('Nieuw');
$table = $this->ts->getAssetModel();
$addNew->setIcon('plus');
$url = '/table/'.$table->url.'/0';
if ($params = $this->filterToParams()) {
$url .= '?'.ltrim($params, '&');
}
$addNew->setLink($url);

return $bar->addBarButton($addNew);
}

public function getBreadCrumbs(): LayoutBreadCrumb
{
$table = $this->ts->getAssetModel();
$breadcrumb = new LayoutBreadcrumb();
$breadcrumb->addHome();
$breadcrumb->addItem($table->name);

return $breadcrumb;
}

public function getBreadCrumbsEdit(): LayoutBreadCrumb
{
$table = $this->ts->getAssetModel();
$breadcrumb = $this->getBreadCrumbs();
end($breadcrumb->properties->items)->link = '/table/'.$table->url.'/?'.$this->filterToParams();
$breadcrumb->addItem('edit');

return $breadcrumb;
}
}
4 changes: 2 additions & 2 deletions src/Models/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Schema;
use NotFound\Framework\Services\Legacy\StatusColumn;
use NotFound\Framework\Traits\Exportable;
use NotFound\Framework\Traits\Exchangeable;

/**
* NotFound\Framework\Models\Table
Expand Down Expand Up @@ -56,7 +56,7 @@
*/
class Table extends AssetModel
{
use Exportable;
use Exchangeable;
use SoftDeletes;

protected $table = 'cms_table';
Expand Down
10 changes: 9 additions & 1 deletion src/Models/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
use NotFound\Framework\Traits\Exchangeable;

/**
* NotFound\Framework\Models\Template
Expand Down Expand Up @@ -50,7 +51,9 @@
*/
class Template extends AssetModel
{
use HasFactory, SoftDeletes;
use HasFactory;
use SoftDeletes;
use Exchangeable;

protected $table = 'cms_template';

Expand Down Expand Up @@ -79,4 +82,9 @@ public function getIdentifier()
{
return strtolower($this->attributes['filename']);
}

private function getSiteTableName()
{
return strtolower($this->filename);
}
}
Loading

0 comments on commit 6cc299e

Please sign in to comment.