diff --git a/config/kompass.php b/config/kompass.php index cf5b944..faedfe7 100644 --- a/config/kompass.php +++ b/config/kompass.php @@ -135,6 +135,8 @@ 'adminmenu' => Livewire\Menu::class, 'blocks.blocks-table' => Livewire\BlocksTable::class, 'blocks.blocks-data' => Livewire\BlocksData::class, + 'pages.posts-table' => Livewire\PostsTable::class, + 'pages.posts-show' => Livewire\PostsData::class, 'pages.pages-table' => Livewire\PagesTable::class, 'pages.pages-show' => Livewire\PagesData::class, 'menus.menus-table' => Livewire\MenuTable::class, diff --git a/resources/js/main.js b/resources/js/main.js index 3ecf2f4..a4110fe 100755 --- a/resources/js/main.js +++ b/resources/js/main.js @@ -3,20 +3,28 @@ import '/resources/css/kompass.css' import click_to_edit from './alpine/click_to_edit' -// import * as livewiresortable from './livewire.sortable'; +import * as livewiresortable from './livewire.sortable'; -// import * as editorjs from './editorjs'; +import * as editorjs from './editorjs'; +// const { livewiresortable } = import('./livewire.sortable'); +// const { editorjs } = import('./editorjs'); -document.addEventListener('livewire:initialized', () => { - const { livewiresortable } = import('./livewire.sortable'); +// document.addEventListener('livewire:init', () => { +// livewiresortable(); +// editorjs() +// console.log('go'); - const { editorjs } = import('./editorjs'); -}) +// }) +// Alpine.start(); +// Livewire.start(); +// if (document.getElementsByClassName('kompass-admin-dashboard')) { -// livewiresortable(); -// if (document.getElementById('parent')) { -// const { app } = import('./plugins/lite-yt-embed') -// app(); +// livewiresortable(); +// editorjs() + +// console.log('goss'); +// // const { app } = import('./plugins/lite-yt-embed') +// // app(); // } window.click_to_edit = click_to_edit; \ No newline at end of file diff --git a/resources/views/admin/dashboard.blade.php b/resources/views/admin/dashboard.blade.php index 000f513..310dede 100644 --- a/resources/views/admin/dashboard.blade.php +++ b/resources/views/admin/dashboard.blade.php @@ -28,7 +28,9 @@ - +

+ Whoops, your device has lost connection. The web page you are viewing is offline. +

diff --git a/resources/views/admin/layouts/app.blade.php b/resources/views/admin/layouts/app.blade.php index 256c52c..f934b47 100644 --- a/resources/views/admin/layouts/app.blade.php +++ b/resources/views/admin/layouts/app.blade.php @@ -37,7 +37,7 @@ @if(isset($seo->description)) @endif - + @livewireStyles @kompassCss @@ -82,33 +82,24 @@
  • Dashboard
  • - {{--
  • {{ __('Posts') }}
  • --}} +
  • {{ __('Posts') }}
  • {{ __('Pages') }}
  • {{-- --}} -
  • {{ __('Media library') }}
  • +
  • {{ __('Media library') }}
  • {{ __('Theme') }}
  • {{ __('Block') }}
  • {{ __('Menu') }}
  • {{ __('Settings') }}
  • - - @canany(['admin','user']) - - @endcanany + @role('admin')
    {{ __('Permissions') }}
  • {{ __('User account') }}
  • {{ __('Manage Role') }}
  • - - - {{-- @canany(['update', 'view', 'delete']) - // This user can update, view, or delete - @elsecanany(['admin', 'user']) - // This user can create - @endcanany --}} + @endrole
  • {{ __('About') }}
  • @@ -147,8 +138,7 @@ - {{-- --}} - {{-- @wireUiScripts --}} + @livewireScripts @kompassJs @stack('scripts') diff --git a/resources/views/components/blocks.blade.php b/resources/views/components/blocks.blade.php index fca09f2..17e7f96 100644 --- a/resources/views/components/blocks.blade.php +++ b/resources/views/components/blocks.blade.php @@ -60,14 +60,14 @@
    logo + src="{{ asset('storage/' . $file->path . '/' . $file->slug . '.' . $file->extension) }}">
    {{ $file->name }}
    - +
    @@ -77,14 +77,10 @@
    @endif - @else - - - + @endif @else - @@ -104,36 +100,24 @@ class="cursor-pointer grid place-content-center border-2 border-dashed border-gr
    logo + src="{{ asset('storage/' . $file->path . '/' . $file->slug . '.' . $file->extension) }}">
    {{ $file->name }}
    - + +
    - - -
    - - @endif - @else - - - + @endif @endif - @else - - - + @endif @endif diff --git a/resources/views/components/blocksgroup.blade.php b/resources/views/components/blocksgroup.blade.php index 01c9803..a778bad 100644 --- a/resources/views/components/blocksgroup.blade.php +++ b/resources/views/components/blocksgroup.blade.php @@ -73,7 +73,7 @@ class="flex items-center select-none cursor-text" x-on:keydown.escape="isEditing
    @if ($type == 'group') - + @if ($itemblocks->status == 'published') @@ -85,7 +85,7 @@ class="flex items-center select-none cursor-text" x-on:keydown.escape="isEditing @endif - + @endif @@ -104,7 +104,7 @@ class="flex items-center select-none cursor-text" x-on:keydown.escape="isEditing - +
    @@ -140,7 +140,8 @@ class="transform transition-transform duration-500"> @endif @endforeach - diff --git a/resources/views/components/rich-text/quill.blade.php b/resources/views/components/rich-text/quill.blade.php deleted file mode 100644 index 01c8fbb..0000000 --- a/resources/views/components/rich-text/quill.blade.php +++ /dev/null @@ -1,23 +0,0 @@ -
    $hasErrorsAndShow($name)])> - -
    -
    -
    -
    - -@push('scripts') - - -@endpush diff --git a/resources/views/livewire/pages/pages-show.blade.php b/resources/views/livewire/pages/pages-show.blade.php index d7880cd..bfd4aca 100644 --- a/resources/views/livewire/pages/pages-show.blade.php +++ b/resources/views/livewire/pages/pages-show.blade.php @@ -182,7 +182,7 @@ class="grid place-content-center border-2 border-dashed border-gray-300 rounded- @endforelse
    + wire:click="selectitem('addBlock',{{ $page->id }})">{{ __('Add') }}
    @@ -211,7 +211,7 @@ class="grid place-content-center border-2 border-dashed border-gray-300 rounded-
    @foreach ($blocktemplates as $itemblock)
    + wire:click.defer="addBlock({{ $itemblock['id'] }},'{{ $itemblock['name'] }}','{{ $itemblock['slug'] }}',{{ $itemblock['grid'] }})"> @if ($itemblock['icon_img_path']) @@ -220,25 +220,25 @@ class="grid place-content-center border-2 border-dashed border-gray-300 rounded-
    @endforeach
    + wire:click.defer="addBlock('','Textblock','wysiwyg','1','wysiwyg')"> Textblock
    + wire:click.defer="addBlock('','Gallery','gallery','1','gallery')"> Gallery
    + wire:click.defer="addBlock('','Group','group','1','group')"> Layout Block
    + wire:click.defer="addBlock('','Accordion Group','group','1','accordiongroup')"> Accordion Group
    diff --git a/resources/views/livewire/posts/posts-show.blade.php b/resources/views/livewire/posts/posts-show.blade.php new file mode 100644 index 0000000..3a8f69c --- /dev/null +++ b/resources/views/livewire/posts/posts-show.blade.php @@ -0,0 +1,279 @@ +
    + + +
    + + + + + + + +
    + {{ __('Page Attributes') }}
    + Letztes Update: {{ $post->updated_at }}
    + + + + +
    + + @if ($post->status == 'draft') + + @endif + + Autor: Max Mustermann
    + + SEO: + + Thumbnails + {{-- --}} + @if (!empty($post->thumbnails)) + @php + $file = Secondnetwork\Kompass\Models\File::find($post->thumbnails); + @endphp + + @if ($file) + @if (Storage::disk('local')->exists('/public/' . $file->path . '/' . $file->slug . '.' . + $file->extension)) +
    + + logo + +
    {{ $file->name }}
    +
    + + + + + + +
    +
    + +
    + @endif + @endif + @else + + + + + + @endif +
    +
    +
    + + + + +
    + +
    + +
    + {{ __('Page title') }} + + + +
    + +
    + @if ($post->layout == 'is_front_post' || $post->layout == 'is_front_post') + Permalink: {{ url('/') }} + @else + Permalink: {{ url('/' . $post->slug) }} + @endif +
    + + +
    +
    + + + + + + @switch($post->status) + @case('published') + + + + + + + Live + + @break + + @case('password') + + + + + + Passwort + + @break + + @default + + + + + + + {{ __('draft') }} + + @endswitch + + + + + + + + + +
    + +
    +
    + +
    + @if ($errors->any()) +
    +
      + @foreach ($errors->all() as $error) +
    • {{ $error }}
    • + @endforeach +
    +
    + @endif + +
    + + Block Builder + + @forelse ($blocks as $itemblocks) + + + @empty +
    + {{ __('Click "Add" to create the layout') }}
    + @endforelse +
    + +
    + + +
    + +
    +
    + + +
    + + + @livewire('medialibrary', ['fieldId' => $getIdField]) + + +
    + + + + + + +
    + + +
    + @foreach ($blocktemplates as $itemblock) +
    + @if ($itemblock['icon_img_path']) + + @endif + {{ $itemblock['name'] }} +
    + @endforeach +
    + + Textblock +
    + +
    + + Gallery +
    + +
    + + Layout Block +
    + +
    + + Accordion Group +
    +
    +
    +
    +
    + +
    diff --git a/resources/views/livewire/posts/posts-table.blade.php b/resources/views/livewire/posts/posts-table.blade.php new file mode 100644 index 0000000..28bdda6 --- /dev/null +++ b/resources/views/livewire/posts/posts-table.blade.php @@ -0,0 +1,148 @@ +
    + +
    + + + + + + + + + + + +
    + + + + +
    +
    +
    + + +
    +
    + +
    +
    + + + + @if ($posts->count()) + + + @foreach ($headers as $key => $value) + + @endforeach + + + + + @foreach ($posts as $key => $post) + + @foreach ($data as $key => $value) + + @endforeach + + + @endforeach + + + + +
    + {{ __($value) }} +
    + @if ($key == 0) + + @endif + @if ($key == 1) + @switch($post->$value) + @case('published') + + + + + + @break + + @case('password') + + + + + + @break + + @default + + + + + + @endswitch + @endif + {{ __($post->$value) }} + @if ($key == 0) + + @endif + @if ($key == 1) + + @endif + +
    + + + + + + @if ($post->status == 'published') + + + + @else + + + + @endif + + + + + + + + + + + + +
    +
    + @else +
    {{ __('No Data') }}
    + + @endif + + +
    +
    + +
    + +
    diff --git a/resources/views/livewire/settings.blade.php b/resources/views/livewire/settings.blade.php index 973ba7d..5cf684d 100644 --- a/resources/views/livewire/settings.blade.php +++ b/resources/views/livewire/settings.blade.php @@ -207,43 +207,36 @@ class="flex justify-center"> @switch($type) @case('image') + @if (!empty($setting->$value)) @php $file = Secondnetwork\Kompass\Models\File::find($setting->$value); @endphp - @if ($file) - @if (Storage::disk('local')->exists('/public/' . $file->path . '/' . $file->slug . '.' . - $file->extension)) -
    - - logo - -
    {{ $file->name }}
    -
    - - - - - - -
    -
    + @if ($file) + @if (Storage::disk('local')->exists('/public/' . $file->path . '/' . $file->slug . '.' . + $file->extension)) +
    + + logo + +
    {{ $file->name }}
    +
    + + + + + + +
    +
    -
    - @endif - @else - - - - - - @endif +
    + @endif + @endif @else - @@ -251,6 +244,7 @@ class="cursor-pointer grid place-content-center border-2 border-dashed border-gr @endif + @break @case('text_area') @@ -315,6 +309,4 @@ class="cursor-pointer grid place-content-center border-2 border-dashed border-gr
    -
    @push('qscripts') - -@endpush \ No newline at end of file +
    diff --git a/routes/web.php b/routes/web.php index a2f80ff..bf9deec 100644 --- a/routes/web.php +++ b/routes/web.php @@ -14,6 +14,8 @@ use Secondnetwork\Kompass\Livewire\MenuTable; use Secondnetwork\Kompass\Livewire\PagesData; use Secondnetwork\Kompass\Livewire\PagesTable; +use Secondnetwork\Kompass\Livewire\PostsData; +use Secondnetwork\Kompass\Livewire\PostsTable; use Secondnetwork\Kompass\Livewire\Redirection; use Secondnetwork\Kompass\Livewire\Roles; use Secondnetwork\Kompass\Livewire\Settings; @@ -40,6 +42,9 @@ Route::view('/', 'kompass::admin.dashboard')->name('dashboard-root'); Route::view('dashboard', 'kompass::admin.dashboard')->name('dashboard'); + Route::get('posts', PostsTable::class)->name('posts'); + Route::get('posts/{action}/{id}', PostsData::class)->name('posts.show'); + Route::get('pages', PagesTable::class)->name('pages'); Route::get('pages/{action}/{id}', PagesData::class)->name('pages.show'); diff --git a/src/KompassServiceProvider.php b/src/KompassServiceProvider.php index d6211af..b7b6114 100644 --- a/src/KompassServiceProvider.php +++ b/src/KompassServiceProvider.php @@ -2,11 +2,13 @@ namespace Secondnetwork\Kompass; +use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Foundation\Http\Kernel; use Illuminate\Routing\Router; use Illuminate\Support\Facades\Blade; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Config; +use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\View; use Illuminate\Support\ServiceProvider; @@ -15,6 +17,8 @@ use Livewire\Livewire; use Secondnetwork\Kompass\Commands\KompassCommand; use Secondnetwork\Kompass\Http\Middleware\RoleMiddleware; +use Secondnetwork\Kompass\Models\Page; +use Secondnetwork\Kompass\Models\Post; use Secondnetwork\Kompass\Models\Setting; class KompassServiceProvider extends ServiceProvider @@ -68,7 +72,24 @@ public function boot(): void KompassCommand::class, ]); } + Gate::define('role', function ($user, ...$roles) { + return $user->hasRole($roles); + }); + + Blade::if('role', function (...$roles) { + if (auth()->check()) { + return auth()->user()->hasRole($roles); + } + return false; + }); + + Relation::morphMap( + [ + 'post' => Post::class, + 'page' => Page::class, + ] + ); // View::composer('*', function ($view) { // $view_name = str_replace('.', ' ', $view->getName()); // View::share('view_name', $view_name); diff --git a/src/Livewire/Medialibrary.php b/src/Livewire/Medialibrary.php index d4c33d5..a0d117c 100644 --- a/src/Livewire/Medialibrary.php +++ b/src/Livewire/Medialibrary.php @@ -10,6 +10,7 @@ use Livewire\WithPagination; use Secondnetwork\Kompass\Models\Datafields; use Secondnetwork\Kompass\Models\File; +use Secondnetwork\Kompass\Models\Post; use Secondnetwork\Kompass\Models\Setting; class Medialibrary extends Component @@ -97,8 +98,10 @@ class Medialibrary extends Component public function getIdField($id_field, $page) { + $this->field_id = $id_field; $this->page = $page; + } public function getIdBlock($id_field) @@ -365,9 +368,9 @@ public function createThumbnail($type, $path, $width, $height, $position, $quali } } - public function selectField($media_id, $page) + public function selectField($media_id, $fieldOrPageName) { - if ($page == 'page') { + if ($fieldOrPageName == 'gallery') { if ($this->field_id == '0') { Datafields::updateOrCreate(['id' => $this->field_id], [ 'name' => 'Gallery', @@ -383,12 +386,25 @@ public function selectField($media_id, $page) ); } - $this->dispatch('refreshmedia'); } - if ($page == 'setting') { + if ($fieldOrPageName == 'image') { + Datafields::updateOrCreate( + ['id' => $this->field_id], + ['data' => $media_id] + ); + } + if ($fieldOrPageName == 'thumbnails') { + Post::updateOrCreate( + ['id' => $this->field_id], + ['thumbnails' => $media_id] + ); + } + if ($fieldOrPageName == 'setting') { Setting::updateOrCreate(['id' => $this->field_id], ['data' => $media_id]); $this->dispatch('refreshmedia'); } + + $this->dispatch('refreshmedia'); } public function update() diff --git a/src/Livewire/PagesData.php b/src/Livewire/PagesData.php index 0b15d3f..1a6142d 100644 --- a/src/Livewire/PagesData.php +++ b/src/Livewire/PagesData.php @@ -18,15 +18,12 @@ #[Layout('kompass::admin.layouts.app')] class PagesData extends Component { - // use WithPagination; + use WithPagination; /** * The component's listeners. * * @var array */ - #[Locked] - public $page_id; - #[Locked] public $selectedItem; @@ -88,8 +85,7 @@ class PagesData extends Component protected $listeners = [ 'editorjssave' => 'saveEditorState', - 'refreshComponent' => '$refresh', - 'refreshmedia' => 'call_emit_reset', + 'refreshmedia' => 'resetPageComponent', ]; @@ -106,20 +102,18 @@ public function saveEditorState($editorJsonData, $id) } - // $this->call_emit_reset(); + // $this->resetPageComponent(); } public function mount($id) { - - $this->page_id = $id; $this->page = Page::findOrFail($id); - $blocks = Block::where('page_id', $id)->orderBy('order', 'asc')->where('subgroup', null)->with('children')->get(); + $blocks = Block::where('blockable_type', 'page')->where('blockable_id', $id)->orderBy('order', 'asc')->where('subgroup', null)->with('children')->get(); if ($blocks->isNotEmpty()) { $this->blocks = $blocks; - $blocks_id = Block::where('page_id', $id)->orderBy('order', 'asc')->pluck('id'); + $blocks_id = Block::where('blockable_id', $id)->orderBy('order', 'asc')->pluck('id'); Arr::collapse($blocks_id); @@ -131,14 +125,10 @@ public function mount($id) // $this->blockfields = Blockfields::where('blocktemplate_id',$id)->orderBy('order')->get(); } - public function selectitem($itemId, $action, $groupId = null) + public function selectitem($action, $itemId, $fieldOrPageName = null, $blockgroupId = null) { - - $this->selectedItem = $itemId; - $this->blockgroupId = $groupId; - if ($action == 'addBlock') { - + $this->blockgroupId = $blockgroupId; $this->FormBlocks = true; } if ($action == 'update') { @@ -146,23 +136,22 @@ public function selectitem($itemId, $action, $groupId = null) if ($action == 'addMedia') { $this->getIdField = $itemId; $this->FormMedia = true; - $this->dispatch('getIdField_changnd', $this->getIdField, 'page'); - $this->dispatch('getIdBlock', $this->blockgroupId); + $this->dispatch('getIdField_changnd', $this->getIdField, $fieldOrPageName); + $this->dispatch('getIdBlock', $blockgroupId); } if ($action == 'deleteblock') { $this->FormDelete = true; } } - public function addBlock($pageID, $blocktemplatesID, $name, $slug, $grid, $blockType = null) + public function addBlock($blocktemplatesID, $name, $slug, $grid, $blockType = null) { // Layout *popout or full *** alignment* left or right $blockTypeData = ['layout' => 'popout', 'alignment' => 'left', 'slider' => '', 'type' => $blockType]; $tempBlock = Blocktemplates::where('id', $blocktemplatesID)->first(); - $block = Block::create([ - 'page_id' => $pageID, + $block = $this->page->blocks()->create([ 'name' => $name, 'subgroup' => $this->blockgroupId, 'set' => $blockTypeData, @@ -198,21 +187,20 @@ public function addBlock($pageID, $blocktemplatesID, $name, $slug, $grid, $block } } $this->FormBlocks = false; - $this->call_emit_reset(); + + $this->resetPageComponent(); } public function refreshmedia() { - $this->dispatch('refreshComponent'); $this->dispatch('status'); } - public function call_emit_reset() + public function resetPageComponent() { - $this->mount($this->page_id); + $this->mount($this->page->id); $this->FormMedia = false; - $this->dispatch('refreshComponent'); $this->dispatch('status'); // return redirect()->to('admin'); @@ -235,7 +223,7 @@ public function clone($id) $copyitem->save(); }, ); - $this->call_emit_reset(); + $this->resetPageComponent(); } public function selected($id) @@ -251,7 +239,7 @@ public function selected($id) 'data' => '0', ]); } - $this->call_emit_reset(); + $this->resetPageComponent(); } public function savename($id) @@ -260,14 +248,14 @@ public function savename($id) $block = block::findOrFail($id); $block->update(['name' => $this->newName]); } - $this->call_emit_reset(); + $this->resetPageComponent(); } public function updateGrid($id, $grid) { $setblock = Block::findOrFail($id); $setblock->update(['grid' => $grid]); - $this->call_emit_reset(); + $this->resetPageComponent(); } public function saveset($id, $set, $status) @@ -285,7 +273,7 @@ public function saveset($id, $set, $status) $setblock->update(['set->slider' => $status]); } - $this->call_emit_reset(); + $this->resetPageComponent(); } public function status($id, $status) @@ -298,7 +286,7 @@ public function status($id, $status) Block::where('id', $id)->update(['status' => 'published']); $this->dispatch('status'); } - $this->call_emit_reset(); + $this->resetPageComponent(); } public function statusPage($id, $status) @@ -310,7 +298,7 @@ public function statusPage($id, $status) Page::where('id', $id)->update(['status' => 'published']); } - $this->call_emit_reset(); + $this->resetPageComponent(); } public function update($id, $publisheded = null) @@ -384,19 +372,19 @@ public function update($id, $publisheded = null) } } - $this->call_emit_reset(); + $this->resetPageComponent(); } public function removemedia($id) { Datafields::whereId($id)->update(['data' => null]); - $this->call_emit_reset(); + $this->resetPageComponent(); } public function removemediaIngallery($id) { Datafields::whereId($id)->delete(); - $this->call_emit_reset(); + $this->resetPageComponent(); } public function delete() //delete block @@ -405,7 +393,7 @@ public function delete() //delete block block::destroy($this->selectedItem); $this->FormDelete = false; // $this->mount($this->selectedItem); - $this->call_emit_reset(); + $this->resetPageComponent(); } public function updateOrder($list) @@ -418,7 +406,7 @@ public function updateOrder($list) } } - $this->call_emit_reset(); + $this->resetPageComponent(); $this->dispatch('status'); // Page::whereId($list['value'])->update(['order' => $list['order']]); } @@ -436,7 +424,7 @@ public function updateItemsOrder($list) } } } - $this->call_emit_reset(); + $this->resetPageComponent(); } public function updateBlocksOrder($list) @@ -448,7 +436,7 @@ public function updateBlocksOrder($list) // } } - $this->call_emit_reset(); + $this->resetPageComponent(); $this->dispatch('status'); // Page::whereId($list['value'])->update(['order' => $list['order']]); } diff --git a/src/Livewire/PagesTable.php b/src/Livewire/PagesTable.php index 3e23533..90281db 100644 --- a/src/Livewire/PagesTable.php +++ b/src/Livewire/PagesTable.php @@ -92,11 +92,6 @@ public function mount() // $this->form->fill(); } - public function resetpage() - { - $this->mount($this->page_id); - } - private function resultDate() { return Page::where('title', 'like', '%'.$this->search.'%') diff --git a/src/Livewire/PostsData.php b/src/Livewire/PostsData.php new file mode 100644 index 0000000..9a1cd6e --- /dev/null +++ b/src/Livewire/PostsData.php @@ -0,0 +1,456 @@ + 'required|string|min:3', + 'post.meta_description' => '', + 'post.slug' => '', + 'post.layout' => '', + 'post.status' => '', + 'post.password' => '', + 'post.begin_at' => '', + 'post.end_at' => '', + 'blocks.*.id' => '', + 'blocks.*.name' => '', + 'fields.*.id' => '', + 'fields.*.data' => '', + + ]; + + protected $listeners = [ + 'editorjssave' => 'saveEditorState', + 'refreshmedia' => 'resetPageComponent', + ]; + + public function saveEditorState($editorJsonData, $id) + { + + if (! empty($editorJsonData)) { + + Datafields::whereId($id)->update(['data' => $editorJsonData]); + // foreach($itemg['items'] as $item){ + // block::whereId($item['value'])->update(['order' => $item['order']]); + // } + // dump($itemg); + + } + + // $this->resetPageComponent(); + } + + public function mount($id) + { + $this->post = Post::findOrFail($id); + + $blocks = Block::where('blockable_type', 'post')->where('blockable_id', $id)->orderBy('order', 'asc')->where('subgroup', null)->with('children')->get(); + + if ($blocks->isNotEmpty()) { + $this->blocks = $blocks; + $blocks_id = Block::where('blockable_id', $id)->orderBy('order', 'asc')->pluck('id'); + + Arr::collapse($blocks_id); + + $this->fields = Datafields::whereIn('block_id', $blocks_id)->get(); + + } + + $this->blocktemplates = Blocktemplates::orderBy('order', 'asc')->get()->all(); + } + + public function selectitem($action, $itemId, $fieldOrPageName = null, $blockgroupId = null) + { + + if ($action == 'addBlock') { + + $this->FormBlocks = true; + } + if ($action == 'update') { + } + if ($action == 'addMedia') { + $this->getIdField = $itemId; + $this->FormMedia = true; + $this->dispatch('getIdField_changnd', $this->getIdField, $fieldOrPageName); + $this->dispatch('getIdBlock', $blockgroupId); + } + if ($action == 'deleteblock') { + $this->FormDelete = true; + } + } + + public function addBlock($blocktemplatesID, $name, $slug, $grid, $blockType = null) + { + // Layout *popout or full *** alignment* left or right + + $blockTypeData = ['layout' => 'popout', 'alignment' => 'left', 'slider' => '', 'type' => $blockType]; + $tempBlock = Blocktemplates::where('id', $blocktemplatesID)->first(); + $block = $this->post->blocks()->create([ + 'name' => $name, + 'subgroup' => $this->blockgroupId, + 'set' => $blockTypeData, + 'status' => 'published', + 'iconclass' => $tempBlock->iconclass ?? null, + 'slug' => $slug, + 'grid' => $grid, + 'order' => '999', + ]); + if ($blockType == 'wysiwyg') { + Datafields::create([ + 'block_id' => $block->id, + 'name' => 'wysiwyg', + 'slug' => 'wysiwyg', + 'type' => 'wysiwyg', + 'grid' => '1', + 'order' => '1', + ]); + } + + if ($blocktemplatesID != null) { + $get_blocks = Blockfields::where('blocktemplate_id', $blocktemplatesID)->get(); + + foreach ($get_blocks as $value) { + Datafields::create([ + 'block_id' => $block->id, + 'name' => $value->name, + 'slug' => $value->slug, + 'type' => $value->type, + 'grid' => $value->grid, + 'order' => $value->order, + ]); + } + } + $this->FormBlocks = false; + $this->resetPageComponent(); + } + + public function refreshmedia() + { + $this->dispatch('refreshComponent'); + $this->dispatch('status'); + } + + public function resetPageComponent() + { + $this->mount($this->post->id); + + $this->FormMedia = false; + $this->dispatch('refreshComponent'); + $this->dispatch('status'); + + // return redirect()->to('admin'); + } + + public function clone($id) + { + $block = block::find($id); + $newblock = $block->replicate(); + + $newblock->created_at = Carbon::now(); + + $newblock->push(); + + $fields = Datafields::where('block_id', $id)->get(); + + $fields->each(function ($item, $key) use ($newblock) { + $copyitem = $item->replicate(); + $copyitem->block_id = $newblock->id; + $copyitem->save(); + }, ); + + $this->resetPageComponent(); + } + + public function selected($id) + { + $data = Datafields::findOrFail($id); + + if ($data->data == 0) { + $data->update([ + 'data' => '1', + ]); + } else { + $data->update([ + 'data' => '0', + ]); + } + $this->resetPageComponent(); + } + + public function savename($id) + { + if ($this->newName != null) { + $block = block::findOrFail($id); + $block->update(['name' => $this->newName]); + } + $this->resetPageComponent(); + } + + public function updateGrid($id, $grid) + { + $setblock = Block::findOrFail($id); + $setblock->update(['grid' => $grid]); + $this->resetPageComponent(); + } + + public function saveset($id, $set, $status) + { + + $setblock = Block::findOrFail($id); + + if ($set == 'layout') { + $setblock->update(['set->layout' => $status]); + } + if ($set == 'alignment') { + $setblock->update(['set->alignment' => $status]); + } + if ($set == 'slider') { + $setblock->update(['set->slider' => $status]); + } + + $this->resetPageComponent(); + } + + public function status($id, $status) + { + if ($status == 'draft') { + Block::where('id', $id)->update(['status' => 'draft']); + $this->dispatch('status'); + } + if ($status == 'published') { + Block::where('id', $id)->update(['status' => 'published']); + $this->dispatch('status'); + } + $this->resetPageComponent(); + } + + public function statusPost($id, $status) + { + if ($status == 'draft') { + Post::where('id', $id)->update(['status' => 'draft']); + } + if ($status == 'published') { + Post::where('id', $id)->update(['status' => 'published']); + } + + $this->resetPageComponent(); + } + + public function update($id, $publisheded = null) + { + + $post = Post::findOrFail($id); + + // $this->getDynamicSEOData(); + // $post->addSEO(); + $this->dispatch('savedatajs'); + + $validateData = $this->validate(); + + $titlePostDB = Str::slug($post->title, '-', 'de'); + $slugPostDB = $post->slug; + $titlePost = Str::slug($validateData['post']['title'], '-', 'de'); + $slugPost = $validateData['post']['slug']; + + $placeObj = new Post; + + if ($titlePost != $titlePostDB) { + $numericalPrefix = 1; + while (1) { + $newSlug = $titlePost.'-'.$numericalPrefix++; + $newSlug = Str::slug($newSlug, '-', 'de'); + $checkSlug = $placeObj->whereSlug($newSlug)->exists(); + if (! $checkSlug) { + $slugNameURL = $newSlug; //New Slug + break; + } + } + } else { + //Slug do not exists. Just use the selected Slug. + $slugNameURL = $titlePost; + } + + if ($publisheded == true) { + Post::where('id', $id)->update(['status' => 'published']); + $this->dispatch('status'); + } + + $post->update([ + 'title' => $validateData['post']['title'], + 'meta_description' => $validateData['post']['meta_description'], + // 'layout' => $validateData['post']['layout'], + // 'status' => $validateData['post']['status'], + // 'password' => $validateData['post']['password'], + // 'begin_at' => $validateData['post']['begin_at'], + // 'end_at' => $validateData['post']['end_at'], + ]); + + $post->update([ + 'slug' => $slugNameURL, + 'updated_at' => Carbon::now(), + ]); + + if (! empty($validateData['blocks'])) { + foreach ($validateData['blocks'] as $itemg) { + Block::whereId($itemg['id'])->update($itemg); + } + } + + if (! empty($validateData['fields'])) { + + foreach ($validateData['fields'] as $itemg) { + Datafields::whereId($itemg['id'])->update($itemg); + // foreach($itemg['items'] as $item){ + // block::whereId($item['value'])->update(['order' => $item['order']]); + // } + // dump($itemg); + } + } + + $this->resetPageComponent(); + } + + public function removemediaThumbnails($id) + { + Post::whereId($id)->update(['thumbnails' => null]); + $this->resetPageComponent(); + } + + public function removemedia($id) + { + Datafields::whereId($id)->update(['data' => null]); + $this->resetPageComponent(); + } + + public function removemediaIngallery($id) + { + Datafields::whereId($id)->delete(); + $this->resetPageComponent(); + } + + public function delete() //delete block + { + Datafields::where('block_id', $this->selectedItem)->delete(); + block::destroy($this->selectedItem); + $this->FormDelete = false; + // $this->mount($this->selectedItem); + $this->resetPageComponent(); + } + + public function updateOrder($list) + { + + foreach ($list as $items) { + // $boardgroub = $itemg['value']; + foreach ($items['items'] as $item) { + Block::whereId($item['value'])->update(['order' => $item['order']]); + } + } + + $this->resetPageComponent(); + $this->dispatch('status'); + // Post::whereId($list['value'])->update(['order' => $list['order']]); + } + + public function updateItemsOrder($list) + { + foreach ($list as $itemgroup) { + Block::whereId($itemgroup['value'])->update(['order' => $itemgroup['order']]); + + if ($itemgroup['items']) { + foreach ($itemgroup['items'] as $item) { + if ($item['value'] != $itemgroup['value']) { + Block::whereId($item['value'])->update(['order' => $item['order'], 'subgroup' => $itemgroup['value']]); + } + } + } + } + $this->resetPageComponent(); + } + + public function updateBlocksOrder($list) + { + foreach ($list as $item) { + Block::whereId($item['value'])->update(['order' => $item['order']]); + // foreach($itemg['items'] as $item){ + // Post::whereId($item['value'])->update(['order' => $item['order']]); + // } + } + + $this->resetPageComponent(); + $this->dispatch('status'); + // Post::whereId($list['value'])->update(['order' => $list['order']]); + } + + // + public function render() + { + + return view('kompass::livewire.posts.posts-show') + ->layout('kompass::admin.layouts.app'); + } +} diff --git a/src/Livewire/PostsTable.php b/src/Livewire/PostsTable.php new file mode 100644 index 0000000..f9ce5ed --- /dev/null +++ b/src/Livewire/PostsTable.php @@ -0,0 +1,268 @@ + 'unique:posts|required|string|min:3', + 'meta_description' => '', + + ]; + + protected function headerTable(): array + { + return [ + + 'title', + // 'thumbnails', + // 'description', + + 'status', + 'Updated', + + '', + ]; + } + + protected function dataTable(): array + { + return [ + 'title', + // 'thumbnails', + // 'meta_description', + + 'status', + 'updated_at', + + ]; + } + + public function mount() + { + $this->headers = $this->headerTable(); + $this->data = $this->dataTable(); + // $this->form->fill(); + } + + public function resetpost() + { + $this->mount($this->post_id); + } + + private function resultDate() + { + + $results = Post::query(); + + if ($results->count() > 0) { + return $results->orderBy('created_at', 'DESC')->get(); + } + + return $results; + } + + public function selectItem($itemId, $action) + { + $this->selectedItem = $itemId; + if ($action == 'add') { + // This will show the modal on the frontend + // $this->reset(['name', 'email', 'password', 'role']); + $this->FormAdd = true; + } + if ($action == 'update') { + } + + if ($action == 'delete') { + $this->FormDelete = true; + } + } + + public function status($id, $status) + { + if ($status == 'draft') { + Post::where('id', $id)->update(['status' => 'draft']); + } + if ($status == 'published') { + Post::where('id', $id)->update(['status' => 'published']); + } + + // $this->resetpost(); + } + + public function addPost() + { + $this->validate(); + + $slugNameURL = Str::slug($this->title, '-', 'de'); //Convert Input to Str Slug + + $placeObj = new Post; + + $checkSlug = $placeObj->whereSlug($slugNameURL)->exists(); + + if ($checkSlug) { + $numericalPrefix = 1; + while (1) { + $newSlug = $slugNameURL.'-'.$numericalPrefix++; + $newSlug = Str::slug($newSlug, '-', 'de'); + $checkSlug = $placeObj->whereSlug($newSlug)->exists(); + if (! $checkSlug) { + $newpostslug = $newSlug; //New Slug + break; + } + } + } else { + //Slug do not exists. Just use the selected Slug. + $newpostslug = $slugNameURL; + } + + $post = Post::create([ + + 'title' => $this->title, + 'status' => 'draft', + 'meta_description' => $this->meta_description, + 'slug' => $newpostslug, + // 'slug' => generateSlug($this->title) + + ]); + $this->FormAdd = false; + + return redirect()->to('/admin/posts/show/'.$post->id); + } + + public function clone($id) + { + $post = Post::find($id); + + $newpost = $post->replicate(); + + $slugNameURL = Str::slug($newpost['title'], '-', 'de'); //Convert Input to Str Slug + + $placeObj = new Post; + + $checkSlug = $placeObj->whereSlug($slugNameURL)->exists(); + + if ($checkSlug) { + $numericalPrefix = 1; + while (1) { + $newSlug = $slugNameURL.'-'.$numericalPrefix++; + $newSlug = Str::slug($newSlug, '-', 'de'); + $checkSlug = $placeObj->whereSlug($newSlug)->exists(); + if (! $checkSlug) { + $newpost->slug = $newSlug; //New Slug + break; + } + } + } else { + //Slug do not exists. Just use the selected Slug. + $newpost->slug = $slugNameURL; + } + $newpost->status = 'draft'; + $newpost->created_at = Carbon::now(); + + $newpost->push(); + + $blocksclone = Block::where('post_id', $id)->orderBy('order', 'asc')->where('subgroup', null)->with('children')->get(); + + $blocksclone->each(function ($item, $key) use ($newpost) { + $altID = $item->id; + + $copy = $item->replicate(); + + $copy->post_id = $newpost->id; + $copy->save(); + if ($copy->children) { + foreach ($copy->children as $subgroup) { + $copygroup = $subgroup->replicate(); + $copygroup->post_id = $newpost->id; + $copygroup->subgroup = $copy->id; + $copygroup->save(); + } + } + + $fields = Datafields::where('block_id', $altID)->get(); + $fields->each(function ($item, $key) use ($copy) { + $copyitem = $item->replicate(); + $copyitem->block_id = $copy->id; + $copyitem->save(); + }, ); + }, ); + } + + public function delete() + { + + Post::find($this->selectedItem)->delete(); + + $blocks_id = Block::where('post_id', $this->selectedItem)->orderBy('order', 'asc')->pluck('id'); + + Arr::collapse($blocks_id); + + Block::where('post_id', $this->selectedItem)->delete(); + + $this->fields = Datafields::whereIn('block_id', $blocks_id)->delete(); + + $this->FormDelete = false; + } + + public function addate() + { + // dd($this->form->getState()); post::create + post::create($this->form->getState()); + Post::where('deleted_at'); + } + + public function render() + { + return view('kompass::livewire.posts.posts-table', [ + 'posts' => $this->resultDate(), + ])->layout('kompass::admin.layouts.app'); + } +} diff --git a/src/Models/Block.php b/src/Models/Block.php index 0659565..dac0c41 100644 --- a/src/Models/Block.php +++ b/src/Models/Block.php @@ -28,6 +28,11 @@ public static function boot() }); } + public function blockable() + { + return $this->morphTo(); + } + public function children() { return $this->hasMany(Block::class, 'subgroup')->with('children'); diff --git a/src/Models/Page.php b/src/Models/Page.php index f33cf75..9088c42 100644 --- a/src/Models/Page.php +++ b/src/Models/Page.php @@ -43,9 +43,9 @@ public static function boot() public $timestamps = false; - public function block() + public function blocks() { - return $this->belongsToMany('Secondnetwork\Kompass\Models\Block'); + return $this->morphMany(Block::class, 'blockable'); // return $this->hasOne('Rote'); } diff --git a/src/Models/Post.php b/src/Models/Post.php new file mode 100644 index 0000000..17a1795 --- /dev/null +++ b/src/Models/Post.php @@ -0,0 +1,64 @@ + 'array', + 'begin_at' => 'datetime:Y-m-d H:i:s', + 'end_at' => 'datetime:Y-m-d H:i:s', + ]; + + protected $guarded = []; + + protected $dates = [ + 'created_at', + 'updated_at', + 'deleted_at', + ]; + + public static function boot() + { + parent::boot(); + + static::creating(function () { + cache()->flush(); + }); + static::updating(function () { + cache()->flush(); + }); + static::deleting(function () { + cache()->flush(); + }); + } + + public function blocks() + { + return $this->morphMany(Block::class, 'blockable'); + // return $this->belongsToMany('Secondnetwork\Kompass\Models\Block'); + // return $this->hasOne('Rote'); + } + + public function getCreatedAtAttribute($date) + { + $timezone = config('app.timezone'); + + return Carbon::parse($date)->tz($timezone)->format('d.m.Y H:i'); + } + + public function getUpdatedAtAttribute($date) + { + $timezone = config('app.timezone'); + + return Carbon::parse($date)->tz($timezone)->format('d.m.Y H:i'); + } +} diff --git a/src/database/migrations/2021_10_01_100000_create_blocks_table.php b/src/database/migrations/2021_10_01_100000_create_blocks_table.php index 65e0b61..5a37e74 100644 --- a/src/database/migrations/2021_10_01_100000_create_blocks_table.php +++ b/src/database/migrations/2021_10_01_100000_create_blocks_table.php @@ -15,8 +15,8 @@ public function up() { Schema::create('blocks', function (Blueprint $table) { $table->id(); - - $table->foreignId('page_id')->constrained()->onDelete('cascade'); + $table->string('blockable_id'); + $table->string('blockable_type'); $table->string('subgroup')->nullable(); $table->text('set')->nullable(); $table->string('name'); diff --git a/src/database/seeders/DatabaseSeeder.php b/src/database/seeders/DatabaseSeeder.php index 15b3ffc..f17ac27 100644 --- a/src/database/seeders/DatabaseSeeder.php +++ b/src/database/seeders/DatabaseSeeder.php @@ -14,6 +14,6 @@ class DatabaseSeeder extends Seeder public function run() { $this->call(RoleSeeder::class); - $this->call(PageSeeder::class); + // $this->call(PageSeeder::class); } }