Skip to content
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
5 changes: 1 addition & 4 deletions app/Providers/KompassServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,5 @@ public function register()
*
* @return void
*/
public function boot()
{

}
public function boot() {}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"require": {
"php": "^8.2|^8.3|^8.4",
"intervention/image": "^4.0.0",
"laravel/head": "^0.1",
"laravel/head": "^0.1 || ^0.2",
"laravel/passkeys": "^0.1 || ^0.2",
"livewire/livewire": "^4.2.1",
"secondnetwork/blade-tabler-icons": "^3.40.1",
Expand Down
12 changes: 6 additions & 6 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

return RectorConfig::configure()
->withPaths([
__DIR__ . '/app',
__DIR__ . '/config',
__DIR__ . '/public',
__DIR__ . '/resources',
__DIR__ . '/routes',
__DIR__ . '/src',
__DIR__.'/app',
__DIR__.'/config',
__DIR__.'/public',
__DIR__.'/resources',
__DIR__.'/routes',
__DIR__.'/src',
])
// uncomment to reach your current PHP version
// ->withPhpSets()
Expand Down
3 changes: 1 addition & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace Secondnetwork\Kompass;

use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\View;
use Secondnetwork\Kompass\Http\Controllers\KompassController;
use Secondnetwork\Kompass\Livewire\AccountForm;
use Secondnetwork\Kompass\Livewire\Auth\PasskeySetup;
use Secondnetwork\Kompass\Livewire\BlocksData;
use Secondnetwork\Kompass\Livewire\BlocksTable;
use Secondnetwork\Kompass\Livewire\CategoryTable;
Expand All @@ -21,7 +21,6 @@
use Secondnetwork\Kompass\Livewire\Roles;
use Secondnetwork\Kompass\Livewire\Settings;
use Secondnetwork\Kompass\Livewire\Settings\Profile;
use Secondnetwork\Kompass\Livewire\Auth\PasskeySetup;

// Asset Routes
Route::get('assets/{path?}', [KompassController::class, 'assets'])->name('kompass_asset');
Expand Down
3 changes: 2 additions & 1 deletion src/Commands/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Process;

use function Laravel\Prompts\info;
use function Laravel\Prompts\note;
Expand Down Expand Up @@ -98,7 +99,7 @@ protected function rebuildFrontend(string $packageManager): void
if (isset($commands[$packageManager])) {
warning('Running: '.$commands[$packageManager]);

$result = \Illuminate\Support\Facades\Process::forever()->run(
$result = Process::forever()->run(
$commands[$packageManager],
function (string $type, string $output): void {
$this->output->write(' '.$output);
Expand Down
2 changes: 1 addition & 1 deletion src/DataWriter/FileWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class FileWriter
/**
* The filesystem instance.
*
* @var \Illuminate\Filesystem\Filesystem
* @var Filesystem
*/
protected $files;

Expand Down
3 changes: 2 additions & 1 deletion src/KompassFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
namespace Secondnetwork\Kompass;

use Illuminate\Support\Facades\Facade;
use Secondnetwork\Kompass\Skeleton\SkeletonClass;

/**
* @see \Secondnetwork\Kompass\Skeleton\SkeletonClass
* @see SkeletonClass
*/
class KompassFacade extends Facade
{
Expand Down
29 changes: 14 additions & 15 deletions src/Livewire/BlocksData.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private function getIconPath(): string
{
$possiblePaths = [
base_path('vendor/secondnetwork/blade-tabler-icons/resources/svg'),
dirname(base_path()) . '/vendor/secondnetwork/blade-tabler-icons/resources/svg',
dirname(base_path()).'/vendor/secondnetwork/blade-tabler-icons/resources/svg',
public_path('vendor/blade-tabler-icons'),
];

Expand All @@ -132,36 +132,35 @@ public function loadIcons()
$this->filteredIcons = [];

$iconPath = $this->getIconPath();
if (empty($iconPath) || !is_dir($iconPath)) {

if (empty($iconPath) || ! is_dir($iconPath)) {
return;
}

try {
$files = File::files($iconPath);

if (empty($files)) {
return;
}

$icons = collect($files)
->map(fn($file) => str_replace('.svg', '', $file->getFilename()))
->map(fn ($file) => str_replace('.svg', '', $file->getFilename()))
->sort()
->values();

if ($this->iconSearch) {
$search = strtolower(trim($this->iconSearch));
if (!empty($search)) {
$icons = $icons->filter(fn($name) =>
str_contains(strtolower($name), $search)
if (! empty($search)) {
$icons = $icons->filter(fn ($name) => str_contains(strtolower($name), $search)
);
}
}

$this->filteredIcons = $icons->take(100)->map(fn($name) => [
'id' => 'tabler-' . $name,
$this->filteredIcons = $icons->take(100)->map(fn ($name) => [
'id' => 'tabler-'.$name,
'name' => $name,
'full_name' => 'tabler-' . $name,
'full_name' => 'tabler-'.$name,
])->values()->toArray();
} catch (\Exception $e) {
$this->filteredIcons = [];
Expand All @@ -175,8 +174,8 @@ public function updatedIconSearch()

public function selectIcon($name)
{
$this->selectedIcon = 'tabler-' . $name;
$this->iconclass = 'tabler-' . $name;
$this->selectedIcon = 'tabler-'.$name;
$this->iconclass = 'tabler-'.$name;
}

public function resetIcon()
Expand Down Expand Up @@ -343,7 +342,7 @@ public function updateOrder($list)
{

foreach ($list as $item) {
blockfields::whereId($item['value'])->update(['order' => $item['order']]);
Blockfields::whereId($item['value'])->update(['order' => $item['order']]);
// foreach($itemg['items'] as $item){
// block::whereId($item['value'])->update(['order' => $item['order']]);
// }
Expand Down
76 changes: 53 additions & 23 deletions src/Livewire/BlocksTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,37 @@ class BlocksTable extends Component
use WithPagination;

public $headers;

public $data;

public $action;

public $selectedItem;

public $FormDelete = false;

public $FormAdd = false;

public $FormEdit = false;

public $FormRegenerate = false;

public $regenerateId = null;

public $regenerateFileName = '';

public $perPage = 10000;

public $search = '';

public $orderBy = 'order';

public $orderAsc = true;

public $blockarray;

public $name;

public $type;

protected function rules(): array
Expand Down Expand Up @@ -82,8 +98,12 @@ public function render()
public function selectItem($itemId, $action)
{
$this->selectedItem = $itemId;
if ($action == 'add') $this->FormAdd = true;
if ($action == 'delete') $this->FormDelete = true;
if ($action == 'add') {
$this->FormAdd = true;
}
if ($action == 'delete') {
$this->FormDelete = true;
}
}

public function saveBlock()
Expand All @@ -106,18 +126,18 @@ protected function createBlockViewFile(string $type): void

File::ensureDirectoryExists(dirname($path));

$stub = <<<BLADE
$stub = <<<'BLADE'
@props(['item' => ''])

@php
\$cssclassname = get_meta(\$item, 'css-classname', '');
// \$title = get_field('title', \$item->datafield);
// \$image = get_field('image', \$item->datafield);
// \$text = get_field('text', \$item->datafield);
$cssclassname = get_meta($item, 'css-classname', '');
// $title = get_field('title', $item->datafield);
// $image = get_field('image', $item->datafield);
// $text = get_field('text', $item->datafield);
@endphp

<div class="{{ \$cssclassname }}">
{{-- TODO: render fields from \$item->datafield --}}
<div class="{{ $cssclassname }}">
{{-- TODO: render fields from $item->datafield --}}
</div>
BLADE;

Expand Down Expand Up @@ -166,24 +186,24 @@ public function regenerateViewFile(int $templateId): void

return match ($field->type) {
'wysiwyg' => " \$_{$var} = wysiwyg_blocks(\$item, {$raw});",
'link' => " \$_{$var}Raw = {$raw};\n \$_{$var} = is_array(\$_{$var}Raw) ? (object) \$_{$var}Raw : (is_string(\$_{$var}Raw) ? json_decode(\$_{$var}Raw) : null);",
'link' => " \$_{$var}Raw = {$raw};\n \$_{$var} = is_array(\$_{$var}Raw) ? (object) \$_{$var}Raw : (is_string(\$_{$var}Raw) ? json_decode(\$_{$var}Raw) : null);",
'gallery' => " \$_{$var}Raw = {$raw};\n \$_{$var} = is_array(\$_{$var}Raw) ? \$_{$var}Raw : [];",
default => " \$_{$var} = {$raw};",
default => " \$_{$var} = {$raw};",
};
})->implode("\n");

$outputLines = $template->fields->map(function ($field) use ($varMap) {
$var = $varMap[$field->name];

return match ($field->type) {
'wysiwyg' => " {{-- wysiwyg: {$field->name} --}}\n @foreach (\$_{$var} as \$block)\n <p>{!! \$block['content'] ?? '' !!}</p>\n @endforeach",
'image' => " {{-- image: {$field->name} --}}\n @if (\$_{$var})\n <x-image :id=\"\$_{$var}\" class=\"w-full\" />\n @endif",
'gallery' => " {{-- gallery: {$field->name} --}}\n @foreach (\$_{$var} as \$_{$var}Id)\n <x-image :id=\"\$_{$var}Id\" class=\"w-full\" />\n @endforeach",
'link' => " {{-- link: {$field->name} --}}\n @if (\$_{$var})\n <a href=\"{{ \$_{$var}->url ?? '#' }}\" class=\"underline hover:no-underline\">\n {{ \$_{$var}->title ?? '{$field->name}' }}\n </a>\n @endif",
'file' => " {{-- file: {$field->name} --}}\n @if (\$_{$var})\n @php \$_fileModel = \\Secondnetwork\\Kompass\\Models\\File::find(\$_{$var}); @endphp\n @if (\$_fileModel)\n <a href=\"{{ asset('storage/' . \$_fileModel->path . '/' . \$_fileModel->slug . '.' . \$_fileModel->extension) }}\" download>\n {{ \$_fileModel->name }}\n </a>\n @endif\n @endif",
'wysiwyg' => " {{-- wysiwyg: {$field->name} --}}\n @foreach (\$_{$var} as \$block)\n <p>{!! \$block['content'] ?? '' !!}</p>\n @endforeach",
'image' => " {{-- image: {$field->name} --}}\n @if (\$_{$var})\n <x-image :id=\"\$_{$var}\" class=\"w-full\" />\n @endif",
'gallery' => " {{-- gallery: {$field->name} --}}\n @foreach (\$_{$var} as \$_{$var}Id)\n <x-image :id=\"\$_{$var}Id\" class=\"w-full\" />\n @endforeach",
'link' => " {{-- link: {$field->name} --}}\n @if (\$_{$var})\n <a href=\"{{ \$_{$var}->url ?? '#' }}\" class=\"underline hover:no-underline\">\n {{ \$_{$var}->title ?? '{$field->name}' }}\n </a>\n @endif",
'file' => " {{-- file: {$field->name} --}}\n @if (\$_{$var})\n @php \$_fileModel = \\Secondnetwork\\Kompass\\Models\\File::find(\$_{$var}); @endphp\n @if (\$_fileModel)\n <a href=\"{{ asset('storage/' . \$_fileModel->path . '/' . \$_fileModel->slug . '.' . \$_fileModel->extension) }}\" download>\n {{ \$_fileModel->name }}\n </a>\n @endif\n @endif",
'true_false' => " {{-- true_false: {$field->name} --}}\n @if (\$_{$var})\n {{-- visible when active --}}\n @endif",
'color' => " {{-- color: {$field->name} --}}\n @if (\$_{$var})\n <div class=\"w-8 h-8 rounded-full border border-base-300\" style=\"background-color: {{ \$_{$var} }}\"></div>\n @endif",
default => " {{-- {$field->type}: {$field->name} --}}\n @if (\$_{$var})<p>{{ \$_{$var} }}</p>@endif",
'color' => " {{-- color: {$field->name} --}}\n @if (\$_{$var})\n <div class=\"w-8 h-8 rounded-full border border-base-300\" style=\"background-color: {{ \$_{$var} }}\"></div>\n @endif",
default => " {{-- {$field->type}: {$field->name} --}}\n @if (\$_{$var})<p>{{ \$_{$var} }}</p>@endif",
};
})->implode("\n\n");

Expand All @@ -198,7 +218,10 @@ public function regenerateViewFile(int $templateId): void
}
}

public function updatedName($value) { $this->type = Str::slug($value); }
public function updatedName($value)
{
$this->type = Str::slug($value);
}

public function delete()
{
Expand All @@ -210,24 +233,31 @@ public function handleSort($item, $position)
{
$blocks = Blocktemplates::orderBy('order', 'ASC')->get();
$movedItemIndex = $blocks->search(fn ($block) => $block->id == $item);
if ($movedItemIndex === false) return;
if ($movedItemIndex === false) {
return;
}
$movedItem = $blocks->pull($movedItemIndex);
$blocks->splice($position, 0, [$movedItem]);
foreach ($blocks->values() as $index => $block) {
if ($block->order !== $index) $block->update(['order' => $index]);
if ($block->order !== $index) {
$block->update(['order' => $index]);
}
}
$this->call_emit_reset();
}

public function sortBy($field)
{
if ($this->orderBy === $field) {
$this->orderAsc = !$this->orderAsc;
$this->orderAsc = ! $this->orderAsc;
} else {
$this->orderBy = $field;
$this->orderAsc = true;
}
}

public function toJSON(): string { return '{}'; }
public function toJSON(): string
{
return '{}';
}
}
Loading