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

Fix: pick laravel old #24

Merged
merged 38 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
27e7511
fix: slug trim (#309)
keeama13 May 9, 2023
ddadb72
fix: date not required (#312)
keeama13 May 9, 2023
d6fd2c4
fix: perserve params in table editor
64knl May 10, 2023
92cc67e
fix: use params in breadcrumb
64knl May 10, 2023
44d3d49
feat: title search
64knl May 10, 2023
428dd3c
fix: Moved overview setting to correct properties (#314)
nfmerijn May 11, 2023
5bdfa9b
chore: rename sample configuration
64knl May 11, 2023
b12ca63
fix: ordering
64knl May 12, 2023
6bd237b
fix: date localized display
64knl May 15, 2023
6e09427
feat: check database (#315)
64knl May 15, 2023
965bf84
feat: timepicker (#313)
keeama13 May 15, 2023
efcb6e8
fix: date can be empty in overview
64knl May 15, 2023
d96f5ae
fix: paging
64knl May 19, 2023
70c714a
fix: columntype for button
64knl May 25, 2023
ce2e14b
feat: add Laravel's email verification middleware (#311)
JasperWelsing May 26, 2023
bd3e2ab
fix: cms editor problem
64knl May 31, 2023
b710f65
feat: show forms in UI
64knl Mar 24, 2023
67342d6
fix: array
64knl Mar 24, 2023
a1c4152
feat: add form locales (#287)
MAPCMC Apr 3, 2023
0f363b6
feat: locale support
64knl Apr 3, 2023
34f9db9
chore: add todo
64knl Apr 5, 2023
a662e2a
feat: send (sample) autolayout fields
64knl Apr 5, 2023
95ca94d
feat: better names
64knl Apr 5, 2023
c766f96
fix: categories
64knl Apr 5, 2023
6daadcf
feat: add Slider AutoLayout field
64knl Apr 6, 2023
4f00710
feat: update formbuilder option creation
64knl Apr 6, 2023
4475af5
feat: update layout package
64knl Apr 6, 2023
4d705bc
feat: update layout package
64knl Apr 7, 2023
6c7672c
fix: fixed form fields with repeatable options and added migration th…
nfmerijn May 24, 2023
4982919
fix: use correct object to get option name
nfmerijn Jun 13, 2023
5c017ee
fix: linting error
MAPCMC Jun 15, 2023
e11393f
fix: remove aliases
64knl Jun 15, 2023
13e3808
fix: remove site specific packages
64knl Jun 15, 2023
4d83666
fix: remove .env file
64knl Jun 15, 2023
4536351
fix: re-add packages
64knl Jun 15, 2023
0d6bbdc
fix: remove default middleware
64knl Jun 15, 2023
d74e642
fix: update namespace
64knl Jun 15, 2023
271d53f
style: formatting
64knl Jun 15, 2023
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"illuminate/contracts": "^10.0",
"notfoundnl/siteboss-layout": "^1.3.0",
"mcamara/laravel-localization": "^1.8",
"firebase/php-jwt": "^6.3",
"xenolope/quahog": "^3.0",
"firebase/php-jwt": "^6.3",
"intervention/image": "^2.7",
"php": "^8.1"
},
Expand Down
57 changes: 57 additions & 0 deletions database/migrations/2023_05_18_133000_check_cms_form_tables.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

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

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$this->fix('cms_form');
$this->fix('cms_form_categories');
$this->fix('cms_form_fields');
$this->fix('cms_form_properties');
$this->fix('cms_form_data');

Schema::table('cms_form', function (Blueprint $table) {
$table->string('locales')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('cms_form', function (Blueprint $table) {
$table->dropColumn('locales');
});
}

private function fix($tableName)
{
if (! Schema::hasColumn($tableName, 'created_at')) {
Schema::table($tableName, function (Blueprint $table) {
$table->timestamp('created_at')->nullable();
});
}
if (! Schema::hasColumn($tableName, 'updated_at')) {
Schema::table($tableName, function (Blueprint $table) {
$table->timestamp('updated_at')->nullable();
});
}
if (! Schema::hasColumn($tableName, 'deleted_at')) {
Schema::table($tableName, function (Blueprint $table) {
$table->softDeletes();
});
}
}
};
2 changes: 1 addition & 1 deletion resources/views/siteboss/forms/fields/checkbox.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
type="checkbox"
name="{{ $id }}[]"
id="radio{{ $id }}{{ $optionString }}"
value="{{ $option->id }}"
value="{{ $option->index }}"
{{$required}}
>
<label class="form-check-label" for="radio{{ $id }}{{ $optionString }}">
Expand Down
2 changes: 1 addition & 1 deletion resources/views/siteboss/forms/fields/dropdown.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@foreach ($optionList as $option)
@php($optionString = $getByLanguage($option))
<option value="{{ $option->id }}">{{ $optionString }}</option>
<option value="{{ $option->index }}">{{ $optionString }}</option>
@endforeach
</select>
<label for="{{ $id }}" generated="true" class="error invalid-feedback" style="display: none;"></label>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/siteboss/forms/fields/radio.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class="error invalid-feedback"
type="radio"
name="{{ $id }}[]"
id="radio{{ $id }}$optionString"
value="{{ $option->id }}"
value="{{ $option->index }}"
{{$required}}
>
<label class="form-check-label" for="radio{{ $id }}{{$optionString}}">
Expand Down
14 changes: 10 additions & 4 deletions src/Http/Controllers/Assets/TableEditorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace NotFound\Framework\Http\Controllers\Assets;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
use NotFound\Framework\Events\AfterSaveEvent;
Expand All @@ -28,14 +29,16 @@
*/
class TableEditorController extends AssetEditorController
{
public function index(Table $table, int $recordId, string $langUrl)
public function index(Request $request, Table $table, int $recordId, string $langUrl)
{
$this->authorize('view', $table);
$lang = Lang::whereUrl($langUrl)->firstOrFail();

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

$formUrl = sprintf('/table/%s/%s/%s/', $table->url, $recordId ?? 0, urlencode($langUrl));
$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);

$form = new LayoutForm($formUrl);

Expand All @@ -52,7 +55,7 @@ public function index(Table $table, int $recordId, string $langUrl)

$breadcrumb = new LayoutBreadcrumb();
$breadcrumb->addHome();
$breadcrumb->addItem($table->name, '/table/'.$table->url.'/');
$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);
Expand Down Expand Up @@ -139,7 +142,10 @@ public function update(FormDataRequest $request, Table $table, int $recordId, st
}
} else {
// Redirect
$response->addAction(new Redirect('/table/'.$table->url.'/'));

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

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

return $response->build();
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/Assets/TableOverviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function index(Request $request, Table $table)
$layoutTable->setTotalItems($siteTableRowsPaginator->total());

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

foreach ($components as $component) {
Expand Down
27 changes: 26 additions & 1 deletion src/Http/Controllers/CmsEditor/CmsEditorTableController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace NotFound\Framework\Http\Controllers\CmsEditor;

use Illuminate\Http\Request as HttpRequest;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use NotFound\Framework\Http\Requests\FormDataRequest;
use NotFound\Framework\Models\Table;
use NotFound\Framework\Services\Editor\FieldsProperties;
Expand All @@ -22,6 +24,7 @@
use NotFound\Layout\LayoutResponse;
use NotFound\Layout\Responses\Redirect;
use NotFound\Layout\Responses\Toast;
use stdClass;

class CmsEditorTableController extends \NotFound\Framework\Http\Controllers\Controller
{
Expand Down Expand Up @@ -157,14 +160,22 @@ public function readOne(Table $table)

$UItable->addHeader(new LayoutTableHeader('Element', 'table'));
$UItable->addHeader(new LayoutTableHeader('Type', 'type'));
$UItable->addHeader(new LayoutTableHeader('Internal name', 'internal'));
$UItable->addHeader(new LayoutTableHeader('Error', 'error'));
$UItable->addHeader(new LayoutTableHeader('Enabled', 'enabled'));
$tables = $table->items()->orderBy('order', 'asc')->get();

foreach ($tables as $cmsTable) {
$row = new LayoutTableRow($cmsTable->id, '/app/editor/table/'.$table->id.'/'.$cmsTable->id);
$row->addColumn(new LayoutTableColumn($cmsTable->name, 'text'));
$row->addColumn(new LayoutTableColumn($cmsTable->type, 'text'));

if (isset($cmsTable->properties->localize) && $cmsTable->properties->localize == 1) {
$tableName = $table->table.'_tr';
} else {
$tableName = $table->table;
}
$row->addColumn(new LayoutTableColumn($cmsTable->enabled ? $this->checkColumn($tableName, $cmsTable) : '-', 'text'));

$row->addColumn(new LayoutTableColumn($cmsTable->internal, 'text'));
$row->addColumn(new LayoutTableColumn($cmsTable->enabled, 'checkbox'));
$UItable->addRow($row);
Expand Down Expand Up @@ -265,4 +276,18 @@ public function updatePosition(HttpRequest $request, Table $table)

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

private function checkColumn(string $table, object $field): string
{
$className = '\\NotFound\\Framework\\Services\\Editor\\Fields\\'.$field->type;

$fieldClass = new $className(new stdClass());

if (Schema::hasColumn($table, $field->internal)) {
return $fieldClass->checkColumnType(DB::getDoctrineColumn(set_database_prefix($table), $field->internal)->getType());

} else {
return $fieldClass->checkColumnType(null);
}
}
}
1 change: 1 addition & 0 deletions src/Http/Controllers/Forms/FieldController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function readOne($formId)
$response->category_slug = $form->category?->slug;
$response->name = $form->name;
$response->category_properties = $form->category?->properties;
$response->locales = $form->locales;

$propC = new Property();
$response->available_fields = $propC->getWithCustomCombinations();
Expand Down
16 changes: 9 additions & 7 deletions src/Http/Controllers/Forms/FormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ public function readAllCombinations(Form $form)
{
return $form
->whereTypeCombination()
->where('archived', 0)
->orWhere('archived', null)
->where('archived', false)
->orderBy('name', 'ASC')
->get();
}
Expand All @@ -28,12 +27,11 @@ public function readAllArchive(Form $form)
->get();
}

public function readAllBasedOnCategory(Form $form, Category $category)
public function readAllBasedOnCategory(Category $category)
{
$this->authorize('view', $category);

//TODO: show number of applications
return $form->getByCategory($category->slug);
return $category->forms->where('archived', false)->where('type', 'form')->values();
}

public function updateText(Request $request, Form $form)
Expand Down Expand Up @@ -83,6 +81,7 @@ public function create(Request $request)
$form->category_id = $category->id;

$form->notification_address = $request->mail ?? '';
$form->locales = $request->locales ?? '';
}

try {
Expand All @@ -101,15 +100,18 @@ public function create(Request $request)

public function update(Request $request, Form $form)
{
$this->authorize('update', $form->category);
$this->authorize('view', $form->category);

$request->validate([
'name' => 'required',
'archived' => 'boolean',
'notification_address' => 'string',
]);

$form->name = $request->name;
$form->locales = $request->locales ?? null;
$form->notification_address = $request->mail ?? '';
$form->archived = $request->archived ?? $form->archived;
$form->archived = $request->archived;

return $form->save();
}
Expand Down
5 changes: 5 additions & 0 deletions src/Models/Forms/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,9 @@ public function getCategoriesByRights()

return $filteredCategories->values();
}

public function forms()
{
return $this->hasMany(Form::class, 'category_id', 'id');
}
}
4 changes: 3 additions & 1 deletion src/Models/Forms/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class Form extends BaseModel
'id',
'name',
'type',
'locales',
'success_text',
'notification_address',
'confirmation_mail',
Expand All @@ -67,6 +68,7 @@ class Form extends BaseModel
protected $casts = [
'success_text' => 'object',
'confirmation_mail' => 'object',
'archived' => 'boolean',
];

public function category()
Expand Down Expand Up @@ -99,7 +101,7 @@ public function getByCategory($categorySlug)
->where('archived', 0)
->orWhere('archived', null)
->orderBy('name', 'ASC')
->get(['id', 'name', 'type', 'notification_address', 'archived']);
->get(['id', 'name', 'type', 'notification_address', 'locales', 'archived']);
}

public function getNotificationAddresses(): array
Expand Down
67 changes: 66 additions & 1 deletion src/Models/Forms/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
use Illuminate\Database\Eloquent\SoftDeletes;
use NotFound\Framework\Models\BaseModel;
use NotFound\Framework\Services\Forms\Fields\FactoryType;
use NotFound\Layout\Inputs\LayoutInputCheckbox;
use NotFound\Layout\Inputs\LayoutInputDropdown;
use NotFound\Layout\Inputs\LayoutInputRepeatable;
use NotFound\Layout\Inputs\LayoutInputSlider;
use NotFound\Layout\Inputs\LayoutInputText;
use NotFound\Layout\Inputs\LayoutInputTextArea;

/**
* NotFound\Framework\Models\Forms\Property
Expand Down Expand Up @@ -61,7 +67,7 @@ public function getWithCustomCombinations()
$properties = [];
foreach ($this->get() as $property) {
$type = $typeFactory->getByType($property->type, $property->options, 4);
$property->{'options'} = $type->getOptions($property->options);
$property->{'options'} = $this->makeAutoLayout($type->getOptions($property->options));

$properties[] = $property;
}
Expand All @@ -83,4 +89,63 @@ public function getWithCustomCombinations()

return $properties;
}

private function makeAutoLayout($options)
{
$autoLayoutOptions = [];
foreach ($options as $option) {
switch ($option->type) {
case 'checkbox':
$checkbox = new LayoutInputCheckbox($option->internal, $option->label);
$autoLayoutOptions[] = $checkbox->build();
break;
case 'textarea':
$textArea = new LayoutInputTextArea('textarea'.$option->internal, $option->label);
$autoLayoutOptions[] = $textArea->build();
break;
case 'number':
$slider = new LayoutInputSlider($option->internal, $option->label);
$slider->setMin(1);
$slider->setMax(12);
$autoLayoutOptions[] = $slider->build();
break;
case 'list':
$optionList = new LayoutInputRepeatable($option->internal, $option->label);
$optionList->setRequired();
$optionList->showDeleted();

$form = new \NotFound\Layout\Elements\LayoutForm('form');
// $form->addInput((new LayoutInputHidden('id')));
$form->addInput((new LayoutInputText('option', 'Optie'))->setLocalize()->setRequired());

$optionList->setForm($form);
$autoLayoutOptions[] = $optionList->build();
break;
case 'optionlist':
$optionList = new LayoutInputDropdown($option->internal, $option->label);
$optionList->setRequired();
foreach ($option->options as $item) {
$optionList->addOption($item->value, $item->label);
}
if (isset($option->required) && $option->required === true) {
$optionList->setRequired();
}
$autoLayoutOptions[] = $optionList->build();
break;
case 'input':
$textInput = new LayoutInputText($option->internal, $option->label);
if (isset($option->localize) && $option->localize === true) {
$textInput->setLocalize();
}
if (isset($option->required) && $option->required === true) {
$textInput->setRequired();
}
$textInput->setLocalize();
$autoLayoutOptions[] = $textInput->build();
break;
}
}

return $autoLayoutOptions;
}
}
Loading