Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: packaged cmseditor #2

Merged
merged 6 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.idea
.phpunit.result.cache
build
composer.lock
coverage
docs
phpunit.xml
phpstan.neon
testbench.yaml
vendor
node_modules
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Changelog

- Initial version `siteboss-framework`.
660 changes: 660 additions & 0 deletions LICENSE.md

Large diffs are not rendered by default.

70 changes: 70 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"name": "notfoundnl/siteboss-framework",
"description": "This is my package siteboss-framework",
"keywords": [
"NotFoundNL",
"laravel",
"siteboss-framework"
],
"homepage": "https://github.com/notfoundnl/siteboss-framework",
"license": "MIT",
"authors": [
{
"name": "NotFound Digital Creativity",
"email": "support@siteboss.nl",
"role": "Developer"
}
],
"require": {
"php": "^8.1",
"spatie/laravel-package-tools": "^1.14.0",
"illuminate/contracts": "^10.0",
"notfoundnl/siteboss-layout": "^1.3.0"
},
"require-dev": {
"laravel/pint": "^1.0",
"nunomaduro/collision": "^6.0",
"nunomaduro/larastan": "^2.0.1",
"orchestra/testbench": "^7.0",
"pestphp/pest": "^1.21",
"pestphp/pest-plugin-laravel": "^1.1",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^9.5"
},
"autoload": {
"psr-4": {
"NotFound\\Framework\\": "src",
"NotFound\\Framework\\Database\\Factories\\": "database/factories"
}
},
"autoload-dev": {
"psr-4": {
"NotFound\\Framework\\Tests\\": "tests"
}
},
"scripts": {
"post-autoload-dump": "@php ./vendor/bin/testbench package:discover --ansi",
"analyse": "vendor/bin/phpstan analyse",
"test": "vendor/bin/pest",
"test-coverage": "vendor/bin/pest --coverage",
"format": "vendor/bin/pint"
},
"config": {
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true,
"phpstan/extension-installer": true
}
},
"extra": {
"laravel": {
"aliases": {
"Framework": "NotFound\\Framework\\Facades\\Framework"
}
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
40 changes: 40 additions & 0 deletions src/CmsEditor/CmsEditorController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace NotFound\Framework\CmsEditor;

use NotFound\Layout\Elements\Table\LayoutTable;
use NotFound\Layout\Elements\Table\LayoutTableColumn;
use NotFound\Layout\Elements\Table\LayoutTableHeader;
use NotFound\Layout\Elements\Table\LayoutTableRow;
use NotFound\Layout\Helpers\LayoutWidgetHelper;

class CmsEditorController extends \App\Http\Controllers\Controller
{
public function index()
{
$widgetPage = new LayoutWidgetHelper(pageTitle: 'CMS Editor', widgetTitle: 'CMS Editor');
$widgetPage->widget->noPadding();

$table = new LayoutTable(delete: false, edit: true, create: false);
$table->addHeader(new LayoutTableHeader('Main menu', 'table'));

$row = new LayoutTableRow(1, '/app/editor/table/');
$row->addColumn(new LayoutTableColumn('Tables'));
$table->addRow($row);

$row = new LayoutTableRow(2, '/app/editor/page/');
$row->addColumn(new LayoutTableColumn('Page Templates'));
$table->addRow($row);

$row = new LayoutTableRow(3, '/app/editor/menu/');
$row->addColumn(new LayoutTableColumn('CMS Menu'));
$table->addRow($row);

$row = new LayoutTableRow(4, '/app/editor/lang/');
$row->addColumn(new LayoutTableColumn('Language'));
$table->addRow($row);
$widgetPage->widget->addTable($table);

return $widgetPage->response();
}
}
184 changes: 184 additions & 0 deletions src/CmsEditor/CmsEditorLangController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
<?php

namespace NotFound\Framework\CmsEditor;

use App\Http\Controllers\Controller;
use App\Http\Requests\FormDataRequest;
use App\Models\Lang;
use Illuminate\Http\Request as HttpRequest;
use Illuminate\Support\Facades\Log;
use NotFound\Layout\Elements\LayoutBreadcrumb;
use NotFound\Layout\Elements\LayoutButton;
use NotFound\Layout\Elements\LayoutForm;
use NotFound\Layout\Elements\LayoutPage;
use NotFound\Layout\Elements\LayoutWidget;
use NotFound\Layout\Elements\Table\LayoutTable;
use NotFound\Layout\Elements\Table\LayoutTableColumn;
use NotFound\Layout\Elements\Table\LayoutTableHeader;
use NotFound\Layout\Elements\Table\LayoutTableRow;
use NotFound\Layout\Helpers\LayoutWidgetHelper;
use NotFound\Layout\Inputs\LayoutInputCheckbox;
use NotFound\Layout\Inputs\LayoutInputText;
use NotFound\Layout\LayoutResponse;
use NotFound\Layout\Responses\Redirect;
use NotFound\Layout\Responses\Toast;

class CmsEditorLangController extends Controller
{
public function index()
{
$response = new LayoutResponse();

$page = new LayoutPage('Language');

$breadcrumbs = new LayoutBreadcrumb();
$breadcrumbs->addHome();
$breadcrumbs->addItem('CMS Editor', '/app/editor/');
$breadcrumbs->addItem('Language');
$page->addBreadCrumb($breadcrumbs);

$widget1 = new LayoutWidget('Language', 6);

$table = new LayoutTable(delete: false, edit: true, create: true, sort: true);
$table->addHeader(new LayoutTableHeader('Language', 'language'));
$table->addHeader(new LayoutTableHeader('Url', 'url'));
$table->addHeader(new LayoutTableHeader('Flag', 'flag'));
$table->addHeader(new LayoutTableHeader('Enabled', 'enabled'));
$table->addHeader(new LayoutTableHeader('Default', 'default'));
$tables = Lang::orderBy('order')->get();

foreach ($tables as $langTable) {
$row = new LayoutTableRow($langTable->id, '/app/editor/lang/'.$langTable->id);
$row->addColumn(new LayoutTableColumn($langTable->language, 'text'));
$row->addColumn(new LayoutTableColumn($langTable->url, 'text'));
$row->addColumn(new LayoutTableColumn($langTable->flag ?? '', 'text'));
$row->addColumn(new LayoutTableColumn($langTable->enabled, 'checkbox'));
$row->addColumn(new LayoutTableColumn($langTable->default, 'checkbox'));
$table->addRow($row);
}
$widget1->addTable($table);
$widget1->noPadding();

$page->addWidget($widget1);

$widget2 = new LayoutWidget('Add new language', 6);

$newFieldForm = new LayoutForm('/app/editor/lang/');

$newFieldForm->addInput((new LayoutInputText('language', 'Language display name'))->setRequired());
$newFieldForm->addInput((new LayoutInputText('url', 'Url'))->setRequired());
$newFieldForm->addInput((new LayoutInputText('flag', 'Flag'))->setRequired());
$newFieldForm->addButton(new LayoutButton('Add language'));

$widget2->addForm($newFieldForm);

$page->addWidget($widget2);

$response->addUIElement($page);

return $response->build();
}

public function create(FormDataRequest $request)
{
$request->validate([
'language' => 'string|required',
'url' => 'string|required',
'flag' => 'string|required',
]);

$response = new LayoutResponse();
$response->addAction(new Toast('Language added'));

$max = Lang::max('order') + 1;
$newLang = Lang::insertGetId([
'language' => $request->language,
'url' => $request->url,
'flag' => $request->flag,
'enabled' => false,
'order' => $max,
]);
$response->addAction(new Redirect('/app/editor/lang/'.$newLang));

return $response->build();
}

public function readOne(Lang $lang)
{
$widgetPage = new LayoutWidgetHelper(pageTitle: 'Language', widgetTitle: $lang->language);
$widgetPage->addBreadcrumb('CMS Editor', '/app/editor/');
$widgetPage->addBreadcrumb('Language', '/app/editor/lang/');

$form = new LayoutForm('/app/editor/lang/'.$lang->id);

$input = new LayoutInputText('language', 'Language');
$input->setValue($lang->language);
$input->setRequired();
$form->addInput($input);

$input = new LayoutInputText('url', 'Url');
$input->setValue($lang->url);
$input->setRequired();
$form->addInput($input);

$input = new LayoutInputText('flag', 'Flag');
$input->setValue($lang->flag);
$input->setRequired();
$form->addInput($input);

$input = new LayoutInputCheckbox('enabled', 'Enabled');
$input->setValue($lang->enabled == 1 ?? false);
$form->addInput($input);

$form->addButton(new LayoutButton(__('save')));

$widgetPage->widget->addForm($form);

return $widgetPage->response();
}

public function update(FormDataRequest $request, Lang $lang)
{
$lang->update($request->validate([
'language' => 'string|required',
'url' => 'string|required',
'flag' => 'string|required',
'enabled' => 'boolean',
]), ['timestamps' => false]);
$response = new LayoutResponse();
$response->addAction(new Toast('Field properties updated'));

return $response->build();
}

public function updatePosition(HttpRequest $request)
{
$request->validate([
'recordId' => 'required|int',
'replacedRecordId' => 'required|int',
]);

$response = new LayoutResponse();
try {
db_table_items_change_order('lang', $request->recordId, $request->replacedRecordId);
} catch (\Exception $e) {
$response->addAction(new Toast($e->getMessage(), 'error'));

return $response->build();
}

return response()->json(['status' => 'ok']);
}

public function deleteRecord(int $id)
{
// $this->authorize('delete', Lang::class);
Log::withContext(['record-id' => $id])->notice('Language deleted');

if (Lang::where('id', $id)->delete()) {
return response()->json(['status' => 'ok']);
}

abort(404, __('response.table.delete'));
}
}
Loading