From eea947e80b02326be77941b929d718e77e13d021 Mon Sep 17 00:00:00 2001 From: amazuecos Date: Sun, 23 Feb 2025 00:14:07 +0100 Subject: [PATCH] wiki features --- ci4/app/Controllers/Wiki/WikiController.php | 22 +++++- ...025-02-22-074400_WikiSectionsMigration.php | 5 ++ ci4/app/Database/Seeds/WikiSectionSeeder.php | 74 +++++++++++++++++++ ci4/app/Entities/Wiki/WikiSectionEntity.php | 2 + ci4/app/Language/en/Wiki.php | 18 +++++ ci4/app/Language/es/Wiki.php | 18 +++++ ci4/app/Models/Wiki/WikiSectionModel.php | 1 + .../themes/vuexy/main/menus/wiki_menu.php | 2 +- ci4/app/Views/themes/vuexy/wiki/layout.php | 16 ++-- .../Views/themes/vuexy/wiki/pages/render.php | 46 +++++++----- ci4/app/Views/themes/vuexy/wiki/sidebar.php | 2 +- .../safekat/components/alerts/sweetAlert.js | 18 ++++- .../safekat/components/editorjs/WikiEditor.js | 60 ++++++++++++++- 13 files changed, 251 insertions(+), 33 deletions(-) create mode 100644 ci4/app/Database/Seeds/WikiSectionSeeder.php create mode 100644 ci4/app/Language/en/Wiki.php create mode 100644 ci4/app/Language/es/Wiki.php diff --git a/ci4/app/Controllers/Wiki/WikiController.php b/ci4/app/Controllers/Wiki/WikiController.php index ba6faf18..77651af3 100644 --- a/ci4/app/Controllers/Wiki/WikiController.php +++ b/ci4/app/Controllers/Wiki/WikiController.php @@ -43,7 +43,9 @@ class WikiController extends BaseController $section = $this->wikiSectionModel->where('slug', $slug)->first(); $this->viewData['slug'] = $slug; $this->viewData['section'] = $section->withAll($this->locale); - + $this->viewData['breadcrumb'] = [ + ['title' => lang("Wiki.".$section->slug), 'route' => route_to('showWikiPage',$slug), 'active' => true], + ]; return view('themes/vuexy/wiki/pages/render', $this->viewData); } public function get_section(int $section_id) @@ -72,6 +74,24 @@ class WikiController extends BaseController ]); return $this->response->setJSON(["data" => [], "message" => lang("App.global_alert_save_success")]); } + public function store_publish_page(int $section_id) + { + $bodyData = $this->request->getPost(); + $wikiSectionPage = $this->wikiSectionModel->find($section_id)->page(); + if ($wikiSectionPage) { + $wikiPageId = $wikiSectionPage->id; + $this->wikiContentModel->update($wikiPageId,[ + "locale" => $this->locale, + "page_id" => $wikiPageId, + "editor_data" => json_encode($bodyData), + "published_data" => json_encode($bodyData) + ]); + $response = $this->response->setJSON(["data" => [], "message" => lang("App.global_alert_save_success")]); + } else { + $response = $this->response->setStatusCode(400)->setJSON(["data" => [], "error" => lang('Wiki.errors.publish_before_save')]); + } + return $response; + } public function wiki_file_upload(int $section_id) { try { diff --git a/ci4/app/Database/Migrations/2025-02-22-074400_WikiSectionsMigration.php b/ci4/app/Database/Migrations/2025-02-22-074400_WikiSectionsMigration.php index f43eb033..b450d8f1 100644 --- a/ci4/app/Database/Migrations/2025-02-22-074400_WikiSectionsMigration.php +++ b/ci4/app/Database/Migrations/2025-02-22-074400_WikiSectionsMigration.php @@ -27,6 +27,11 @@ class WikiSectionsMigration extends Migration 'constraint' => 255, 'default' => 'admin' ], + 'icon' => [ + 'type' => 'VARCHAR', + 'constraint' => 255, + 'null' => true, + ], 'parent_section_id' => [ 'type' => 'INT', 'unsigned' => true, diff --git a/ci4/app/Database/Seeds/WikiSectionSeeder.php b/ci4/app/Database/Seeds/WikiSectionSeeder.php new file mode 100644 index 00000000..ef1df474 --- /dev/null +++ b/ci4/app/Database/Seeds/WikiSectionSeeder.php @@ -0,0 +1,74 @@ + 'Introducción', + "slug" => 'intro', + "icon" => 'ti ti-home-2' + ], + [ + "name" => 'Presupuesto', + "slug" => 'presupuesto-administrador', + "icon" => 'ti ti-currency-dollar' + ], + [ + "name" => 'Presupuesto cliente', + "slug" => 'presupuesto-cliente', + "role" => 'cliente', + "icon" => 'ti ti-currency-dollar' + ], + [ + "name" => 'Pedidos', + "slug" => 'pedidos', + "icon" => 'ti ti-file-description' + + ], + [ + "name" => 'Facturación', + "slug" => 'facturacion', + "icon" => 'ti ti-file-dollar' + + ], + [ + "name" => 'Logística', + "slug" => 'logistica', + "icon" => 'ti ti-truck' + + ], + [ + "name" => 'Tarifas', + "slug" => 'tarifas', + "icon" => 'ti ti-receipt' + + ], + [ + "name" => 'Configuración', + "slug" => 'config', + "icon" => 'ti ti-adjustments-horizontal' + + ], + [ + "name" => 'Mensajería', + "slug" => 'messages', + "icon" => 'ti ti-message' + + ] + ]; + public function run() + { + + $wikiSectionModel = model(WikiSectionModel::class); + foreach ($this->data as $key => $row) { + # code... + $wikiSectionModel->insert($row); + } + } +} diff --git a/ci4/app/Entities/Wiki/WikiSectionEntity.php b/ci4/app/Entities/Wiki/WikiSectionEntity.php index 420b07fb..15dd3591 100644 --- a/ci4/app/Entities/Wiki/WikiSectionEntity.php +++ b/ci4/app/Entities/Wiki/WikiSectionEntity.php @@ -11,12 +11,14 @@ class WikiSectionEntity extends Entity "name" => null, "slug" => null, "role" => null, + "icon" => null, "parent_id" => null ]; protected $casts = [ "name" => "string", "slug" => "string", "role" => "string", + "icon" => "string", "parent_id" => "int" ]; diff --git a/ci4/app/Language/en/Wiki.php b/ci4/app/Language/en/Wiki.php new file mode 100644 index 00000000..b10a7071 --- /dev/null +++ b/ci4/app/Language/en/Wiki.php @@ -0,0 +1,18 @@ + "Introduction", + 'presupuesto-cliente' => "Cliente budget", + 'presupuesto-administrador' => "Admin budget", + 'pedidos' => "Orders", + 'facturacion' => "Invoice", + 'logistica' => "Logistic", + 'tarifas' => "Tariff", + 'config' => "Configuration", + 'messages' => "Messages", + 'errors' => [ + 'publish_before_save' => "You have to save before publish the content" + ], + 'published' => 'Released', + 'not_published' => 'Not released' +]; \ No newline at end of file diff --git a/ci4/app/Language/es/Wiki.php b/ci4/app/Language/es/Wiki.php new file mode 100644 index 00000000..9761b6f0 --- /dev/null +++ b/ci4/app/Language/es/Wiki.php @@ -0,0 +1,18 @@ + "Introducción", + 'presupuesto-cliente' => "Presupuesto cliente", + 'presupuesto-administrador' => "Presupuesto admin", + 'pedidos' => "Pedidos", + 'facturacion' => "Facturación", + 'logistica' => "Logística", + 'tarifas' => "Tarifas", + 'config' => "Configuración", + 'messages' => "Mensajería", + 'errors' => [ + 'publish_before_save' => "Es necesario guardar antes de publicar" + ], + 'published' => 'Publicado', + 'not_published' => 'Sin publicar' +]; diff --git a/ci4/app/Models/Wiki/WikiSectionModel.php b/ci4/app/Models/Wiki/WikiSectionModel.php index 942976f5..f163d309 100644 --- a/ci4/app/Models/Wiki/WikiSectionModel.php +++ b/ci4/app/Models/Wiki/WikiSectionModel.php @@ -17,6 +17,7 @@ class WikiSectionModel extends Model "name", "slug", "role", + "icon", "parent_id" ]; diff --git a/ci4/app/Views/themes/vuexy/main/menus/wiki_menu.php b/ci4/app/Views/themes/vuexy/main/menus/wiki_menu.php index bd766aba..6341ff1f 100644 --- a/ci4/app/Views/themes/vuexy/main/menus/wiki_menu.php +++ b/ci4/app/Views/themes/vuexy/main/menus/wiki_menu.php @@ -1,7 +1,7 @@