editor form

This commit is contained in:
amazuecos
2025-02-25 18:41:59 +01:00
parent eea947e80b
commit 3406fb3005
23 changed files with 503 additions and 145 deletions

View File

@ -9,6 +9,7 @@ use App\Models\Wiki\WikiPageModel;
use App\Models\Wiki\WikiSectionModel; use App\Models\Wiki\WikiSectionModel;
use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\I18n\Time;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
class WikiController extends BaseController class WikiController extends BaseController
@ -70,6 +71,7 @@ class WikiController extends BaseController
$this->wikiContentModel->insert([ $this->wikiContentModel->insert([
"locale" => $this->locale, "locale" => $this->locale,
"page_id" => $wikiPageId, "page_id" => $wikiPageId,
"last_edit_by" => auth()->user()->id,
"editor_data" => json_encode($bodyData) "editor_data" => json_encode($bodyData)
]); ]);
return $this->response->setJSON(["data" => [], "message" => lang("App.global_alert_save_success")]); return $this->response->setJSON(["data" => [], "message" => lang("App.global_alert_save_success")]);
@ -80,11 +82,14 @@ class WikiController extends BaseController
$wikiSectionPage = $this->wikiSectionModel->find($section_id)->page(); $wikiSectionPage = $this->wikiSectionModel->find($section_id)->page();
if ($wikiSectionPage) { if ($wikiSectionPage) {
$wikiPageId = $wikiSectionPage->id; $wikiPageId = $wikiSectionPage->id;
$this->wikiContentModel->update($wikiPageId,[ $wikiContentId = $this->wikiContentModel->where("page_id",$wikiPageId)->where('locale',$this->locale)->first()->id;
"locale" => $this->locale, $this->wikiContentModel->update($wikiContentId,[
"page_id" => $wikiPageId, "published_by" => auth()->user()->id,
"last_edit_by" => auth()->user()->id,
"editor_data" => json_encode($bodyData), "editor_data" => json_encode($bodyData),
"published_data" => json_encode($bodyData) "published_data" => json_encode($bodyData),
"published_at" => Time::now()->format('Y-m-d H:i:s'),
]); ]);
$response = $this->response->setJSON(["data" => [], "message" => lang("App.global_alert_save_success")]); $response = $this->response->setJSON(["data" => [], "message" => lang("App.global_alert_save_success")]);
} else { } else {

View File

@ -31,6 +31,18 @@ class WikiContentsMigration extends Migration
'type' => 'LONGTEXT', 'type' => 'LONGTEXT',
'null' => true, 'null' => true,
], ],
'published_by' => [
'type' => 'INT',
'unsigned' => true,
'null' => true,
'constraint' => 10,
],
'last_edit_by' => [
'type' => 'INT',
'unsigned' => true,
'null' => true,
'constraint' => 10,
],
]; ];
public function up() public function up()
@ -38,6 +50,11 @@ class WikiContentsMigration extends Migration
$this->forge->addField($this->COLUMNS); $this->forge->addField($this->COLUMNS);
$currenttime = new RawSql('CURRENT_TIMESTAMP'); $currenttime = new RawSql('CURRENT_TIMESTAMP');
$this->forge->addField([ $this->forge->addField([
'published_at' => [
'type' => 'TIMESTAMP',
'null' => true,
],
'created_at' => [ 'created_at' => [
'type' => 'TIMESTAMP', 'type' => 'TIMESTAMP',
'default' => $currenttime, 'default' => $currenttime,
@ -54,6 +71,8 @@ class WikiContentsMigration extends Migration
]); ]);
$this->forge->addPrimaryKey('id'); $this->forge->addPrimaryKey('id');
$this->forge->addForeignKey('page_id','wiki_pages','id'); $this->forge->addForeignKey('page_id','wiki_pages','id');
$this->forge->addForeignKey('published_by','users','id');
$this->forge->addForeignKey('last_edit_by','users','id');
$this->forge->createTable("wiki_contents"); $this->forge->createTable("wiki_contents");
} }

View File

@ -8,65 +8,96 @@ use CodeIgniter\Database\Seeder;
class WikiSectionSeeder extends Seeder class WikiSectionSeeder extends Seeder
{ {
protected array $data = [ protected array $dataAdmin = [
[ [
"name" => 'Introducción', "name" => 'Introducción',
"slug" => 'intro', "slug" => 'intro-admin',
"icon" => 'ti ti-home-2' "icon" => 'ti ti-home-2'
], ],
[ [
"name" => 'Presupuesto', "name" => 'Presupuesto',
"slug" => 'presupuesto-administrador', "slug" => 'presupuesto-admin',
"icon" => 'ti ti-currency-dollar'
],
[
"name" => 'Presupuesto cliente',
"slug" => 'presupuesto-cliente',
"role" => 'cliente',
"icon" => 'ti ti-currency-dollar' "icon" => 'ti ti-currency-dollar'
], ],
[ [
"name" => 'Pedidos', "name" => 'Pedidos',
"slug" => 'pedidos', "slug" => 'pedidos-admin',
"icon" => 'ti ti-file-description' "icon" => 'ti ti-file-description'
], ],
[ [
"name" => 'Facturación', "name" => 'Facturación',
"slug" => 'facturacion', "slug" => 'facturacion-admin',
"icon" => 'ti ti-file-dollar' "icon" => 'ti ti-file-dollar'
], ],
[ [
"name" => 'Logística', "name" => 'Logística',
"slug" => 'logistica', "slug" => 'logistica-admin',
"icon" => 'ti ti-truck' "icon" => 'ti ti-truck'
], ],
[ [
"name" => 'Tarifas', "name" => 'Tarifas',
"slug" => 'tarifas', "slug" => 'tarifas-admin',
"icon" => 'ti ti-receipt' "icon" => 'ti ti-receipt'
], ],
[ [
"name" => 'Configuración', "name" => 'Configuración',
"slug" => 'config', "slug" => 'config-admin',
"icon" => 'ti ti-adjustments-horizontal' "icon" => 'ti ti-adjustments-horizontal'
], ],
[ [
"name" => 'Mensajería', "name" => 'Mensajería',
"slug" => 'messages', "slug" => 'messages-admin',
"icon" => 'ti ti-message' "icon" => 'ti ti-message'
] ]
]; ];
protected array $dataCliente = [
[
"name" => 'Presupuesto(Cliente)',
"slug" => 'presupuesto-cliente',
"role" => 'cliente',
"icon" => 'ti ti-currency-dollar',
"role" => 'cliente',
],
[
"name" => 'Pedidos(Cliente)',
"slug" => 'pedidos-cliente',
"icon" => 'ti ti-file-description',
"role" => 'cliente',
],
[
"name" => 'Facturación (Cliente)',
"slug" => 'facturacion-cliente',
"icon" => 'ti ti-file-dollar',
"role" => 'cliente',
],
[
"name" => 'Tarifas (Cliente)',
"slug" => 'tarifas-cliente',
"icon" => 'ti ti-receipt',
"role" => 'cliente',
],
[
"name" => 'Mensajería (Cliente)',
"slug" => 'messages-cliente',
"icon" => 'ti ti-message',
"role" => 'cliente',
]
];
public function run() public function run()
{ {
$wikiSectionModel = model(WikiSectionModel::class); $wikiSectionModel = model(WikiSectionModel::class);
foreach ($this->data as $key => $row) { foreach ($this->dataAdmin as $key => $row) {
# code...
$wikiSectionModel->insert($row);
}
foreach ($this->dataCliente as $key => $row) {
# code... # code...
$wikiSectionModel->insert($row); $wikiSectionModel->insert($row);
} }

View File

@ -1,6 +1,8 @@
<?php <?php
namespace App\Entities\Wiki; namespace App\Entities\Wiki;
use App\Models\Usuarios\UserModel;
use CodeIgniter\Entity\Entity; use CodeIgniter\Entity\Entity;
class WikiContentEntity extends Entity class WikiContentEntity extends Entity
@ -10,12 +12,24 @@ class WikiContentEntity extends Entity
"page_id" => null, "page_id" => null,
"editor_data" => null, "editor_data" => null,
"published_data" => null, "published_data" => null,
"last_edit_by" => null,
"published_by" => null,
"published_at" => null,
]; ];
protected $casts = [ protected $casts = [
"locale" => "string", "locale" => "string",
"page_id" => "int", "page_id" => "int",
"editor_data" => "string", "editor_data" => "string",
"published_data" => "string", "published_data" => "string",
"last_edit_by" => "int",
"published_by" => "int",
"published_at" => "string",
]; ];
public function publish_by() : string
{
$m = model(UserModel::class);
$user = $m->find($this->attributes['published_by']);
return $user->first_name." ".$user->last_name;
}
} }

View File

@ -1,6 +1,7 @@
<?php <?php
namespace App\Entities\Wiki; namespace App\Entities\Wiki;
use App\Models\Usuarios\UserModel;
use CodeIgniter\Entity\Entity; use CodeIgniter\Entity\Entity;
class WikiPageEntity extends Entity class WikiPageEntity extends Entity
@ -12,4 +13,6 @@ class WikiPageEntity extends Entity
"section_id" => "int", "section_id" => "int",
]; ];
} }

View File

@ -58,4 +58,6 @@ class WikiSectionEntity extends Entity
} }
return $content; return $content;
} }
} }

View File

@ -10,6 +10,11 @@ return [
'tarifas' => "Tariff", 'tarifas' => "Tariff",
'config' => "Configuration", 'config' => "Configuration",
'messages' => "Messages", 'messages' => "Messages",
'save' => "Save",
'release' => "Release",
'preview' => "Preview",
'edit' => "Edit",
'new_section' => "New section",
'errors' => [ 'errors' => [
'publish_before_save' => "You have to save before publish the content" 'publish_before_save' => "You have to save before publish the content"
], ],

View File

@ -1,18 +1,34 @@
<?php <?php
return [ return [
'intro' => "Introducción", 'intro-admin' => "Introducción",
'presupuesto-cliente' => "Presupuesto cliente", 'intro-cliente' => "Introducción",
'presupuesto-administrador' => "Presupuesto admin", 'presupuesto-cliente' => "Presupuesto (Cliente)",
'pedidos' => "Pedidos", 'presupuesto-admin' => "Presupuesto admin",
'facturacion' => "Facturación", 'pedidos-admin' => "Pedidos",
'logistica' => "Logística", 'pedidos-cliente' => "Pedidos (Cliente)",
'tarifas' => "Tarifas", 'facturacion-admin' => "Facturación",
'config' => "Configuración", 'facturacion-cliente' => "Facturación(Cliente)",
'messages' => "Mensajería", 'logistica-admin' => "Logística",
'tarifas-admin' => "Tarifas",
'tarifas-cliente' => "Tarifas (Cliente)",
'config-admin' => "Configuración",
'messages-admin' => "Mensajería",
'messages-cliente' => "Mensajería (Cliente)",
'save' => "Guardar",
'release' => "Publicar",
'preview' => "Vista previa",
'edit' => "Editar",
'name' => "Nombre sección",
'icon' => "Icono sección",
'section_placeholder' => "Introduce el nombre de la sección",
'section_icon_placeholder' => "Introduce el nombre de la sección",
'edit_section' => "Editar sección",
'new_section' => "Nueva sección",
'header-placeholder' => "Escribe un encabezado ...",
'errors' => [ 'errors' => [
'publish_before_save' => "Es necesario guardar antes de publicar" 'publish_before_save' => "Es necesario guardar antes de publicar"
], ],
'published' => 'Publicado', 'published' => 'Publicado',
'not_published' => 'Sin publicar' 'not_published' => 'Sin publicar',
]; ];

View File

@ -17,7 +17,10 @@ class WikiContentModel extends Model
"locale", "locale",
"page_id", "page_id",
"editor_data", "editor_data",
"published_data" "published_data",
"last_edit_by",
"published_by",
"published_at"
]; ];
@ -50,4 +53,6 @@ class WikiContentModel extends Model
protected $afterFind = []; protected $afterFind = [];
protected $beforeDelete = []; protected $beforeDelete = [];
protected $afterDelete = []; protected $afterDelete = [];
} }

View File

@ -58,6 +58,6 @@ class WikiSectionModel extends Model
*/ */
public function sections() : array public function sections() : array
{ {
return $this->where('role','admin')->findAll(); return $this->findAll();
} }
} }

View File

@ -0,0 +1,39 @@
<!-- Modal -->
<div class="modal fade" id="modalSection" tabindex="-1" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel1"><?= lang('Wiki.new_section') ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form id="formSection">
<div class="form-group">
<div class="row">
<div class="col-12 mb-2">
<label for="section-name" class="form-label"><?= lang('Wiki.name') ?></label>
<input type="text" id="section-name" name="title" placeholder="<?= lang('Wiki.section_placeholder') ?>" name="name" class="form-control" required />
</div>
<div class="col-12 mb-2">
<label for="section-icon" class="form-label"><?= lang('Wiki.icon') ?></label>
<input type="text" id="section-icon" name="icon" placeholder="<?= lang('Wiki.section_icon_placeholder') ?>" name="name" class="form-control" required />
</div>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-label-secondary" data-bs-dismiss="modal"><?= lang('App.global_come_back') ?></button>
<?php if (auth()->user()->inGroup('admin')) { ?>
<button type="button" id="submit-new-section" class="btn btn-primary d-none"><?= lang('App.global_save') ?></button>
<button type="button" id="submit-update-section" class="btn btn-primary d-none"><?= lang('App.global_save') ?></button>
<?php } ?>
</div>
</div>
</div>
</div>

View File

@ -1,8 +1,16 @@
<!-- Messages --> <!-- Messages -->
<li class="menu-item"> <li class="menu-item">
<a href="<?= route_to('showWikiPage','intro') ?>" class="menu-link"> <?php if(auth()->user()->inGroup('admin')):?>
<a href="<?= route_to('showWikiPage','intro-admin') ?>" class="menu-link">
<i class="menu-icon tf-icons ti ti-books"></i> <i class="menu-icon tf-icons ti ti-books"></i>
<?= lang("Wiki") ?> <?= lang("Wiki") ?>
</a> </a>
<?php endif;?>
<?php if(auth()->user()->inGroup('cliente-editor')):?>
<a href="<?= route_to('showWikiPage','presupuesto-cliente') ?>" class="menu-link">
<i class="menu-icon tf-icons ti ti-books"></i>
<?= lang("Wiki") ?>
</a>
<?php endif;?>
</li> </li>

View File

@ -109,16 +109,16 @@ $picture = "/assets/img/default-user.png";
<!-- Iterate throught sections --> <!-- Iterate throught sections -->
<?php foreach ($wiki_sections as $key => $value) : ?> <?php foreach ($wiki_sections as $key => $value) : ?>
<li class="menu-item <?= $value->slug == $slug ? 'active' : "" ?>"> <?php if (auth()->user()->inGroup($value->role) || auth()->user()->inGroup('admin')): ?>
<!-- Check if user can view the section link --> <li class="menu-item <?= $value->slug == $slug ? 'active' : "" ?>">
<?php if (auth()->user()->inGroup($value->role) || auth()->user()->inGroup('admin') ): ?> <!-- Check if user can view the section link -->
<a href="<?= site_url("wiki/view/".$value->slug) ?>" class="menu-link" > <a href="<?= site_url("wiki/view/" . $value->slug) ?>" class="menu-link">
<i class="menu-icon tf-icons <?= $value->icon ?>"></i> <i class="menu-icon tf-icons <?= $value->icon ?>"></i>
<?= lang("Wiki.".$value->slug) ?> <?= lang("Wiki." . $value->slug) ?>
</a> </a>
<?php endif; ?> </li>
</li> <?php endif; ?>
<?php endforeach; ?> <?php endforeach; ?>
</ul> </ul>
</aside> </aside>
@ -135,9 +135,20 @@ $picture = "/assets/img/default-user.png";
<i class="ti ti-menu-2 ti-sm"></i> <i class="ti ti-menu-2 ti-sm"></i>
</a> </a>
</div> </div>
<div class="navbar-nav-left d-flex align-items-center" id="navbar-collapse">
<ul class="navbar-nav flex-row justify-content-start align-items-center ms-auto">
<div>
<a class="nav-link" href="<?= route_to("home") ?>">
<i class="ti ti-home rounded-circle me-1 fs-3"></i>
</a>
</div>
</ul>
</div>
<div class="navbar-nav-right d-flex align-items-center" id="navbar-collapse"> <div class="navbar-nav-right d-flex align-items-center" id="navbar-collapse">
<ul class="navbar-nav flex-row align-items-center ms-auto"> <ul class="navbar-nav flex-row justify-content-start align-items-center ms-auto">
<!-- Language --> <!-- Language -->
<li class="nav-item dropdown-language dropdown me-2 me-xl-0"> <li class="nav-item dropdown-language dropdown me-2 me-xl-0">
@ -145,6 +156,7 @@ $picture = "/assets/img/default-user.png";
data-bs-toggle="dropdown"> data-bs-toggle="dropdown">
<i class="fi <?= getCurrentLanguageFlag(); ?> fis rounded-circle me-1 fs-3"></i> <i class="fi <?= getCurrentLanguageFlag(); ?> fis rounded-circle me-1 fs-3"></i>
</a> </a>
<ul class="dropdown-menu dropdown-menu-end"> <ul class="dropdown-menu dropdown-menu-end">
<li> <li>
<a class="dropdown-item" href="<?= site_url('lang/es'); ?>" data-language="es"> <a class="dropdown-item" href="<?= site_url('lang/es'); ?>" data-language="es">

View File

@ -3,15 +3,44 @@
<?= $this->include('themes/_commonPartialsBs/_confirm2delete') ?> <?= $this->include('themes/_commonPartialsBs/_confirm2delete') ?>
<?= $this->include("themes/_commonPartialsBs/sweetalert") ?> <?= $this->include("themes/_commonPartialsBs/sweetalert") ?>
<?= $this->extend('themes/vuexy/wiki/layout') ?> <?= $this->extend('themes/vuexy/wiki/layout') ?>
<?php
use CodeIgniter\I18n\Time;
?>
<?= $this->section('content'); ?> <?= $this->section('content'); ?>
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
<div class="card card-info"> <div class="card card-info">
<div class="card-header"> <div class="card-header">
<div class="row">
<div class="col-md-6 d-flex flex-row flex-wrap justify-content-start align-items-center pb-2 gap-2">
<?php if ($section->content()?->published_data): ?>
<span class="badge badge-center rounded-pill text-bg-success"><i class="ti ti-check"></i></span>
<strong><?= lang('Wiki.published') ?></strong>
<strong><?= $section->content()->published_at ? Time::createFromFormat('Y-m-d H:i:s', $section->content()->published_at)->format('d/m/Y H:i') : "" ?></strong>
<strong class="text-secondary"><?= $section->content()->publish_by() ?></strong>
<?php else: ?>
<span class="badge badge-center rounded-pill text-bg-danger"><i class="ti ti-alert-circle"></i></span>
<strong><?= lang('Wiki.not_published') ?></strong>
<?php endif; ?>
</div>
<div class="col-md-6 d-flex flex-row flex-wrap justify-content-end align-items-stretch pb-2 gap-2">
<?php if (auth()->user()->inGroup('admin')): ?>
<button type="button" class="btn btn-success btn-xs col-xs-12 " id="new-section"><i class="icon-base ti ti-plus icon-xs me-2"></i><?= lang('Wiki.new_section') ?></button>
<button type="button" class="btn btn-warning btn-xs col-auto " id="edit-section"><i class="icon-base ti ti-pencil icon-xs me-2"></i><?= lang('Wiki.edit_section') ?></button>
<button type="button" class="btn btn-primary btn-xs col-auto " id="save-editor"><i class="icon-base ti ti-device-floppy icon-xs me-2"></i><?= lang('App.global_save') ?></button>
<button type="button" class="btn btn-danger btn-xs col-auto " id="release-editor"><i class="icon-base ti ti-upload icon-xs me-2"></i>Publicar</button>
<button type="button" class="btn btn-secondary btn-xs d-none col-auto " id="preview-editor"><i class="icon-base ti ti-eye icon-xs me-2"></i>Vista previa</button>
<button type="button" class="btn btn-warning btn-xs col-auto " id="edit-editor"><i class="icon-base ti ti-pencil icon-xs me-2"></i>Editar</button>
</div>
<?php endif; ?>
</div>
</div><!--//.card-header --> </div><!--//.card-header -->
<div class="card-body"> <div class="card-body">
<div class="row"> <div class="row">
<form action="POST" id="form-wiki"> <form action="POST" id="form-wiki">
@ -20,37 +49,9 @@
<input type="hidden" name="wiki_page_id" id="wiki-page-id"> <input type="hidden" name="wiki_page_id" id="wiki-page-id">
<input type="hidden" name="wiki_page_id" id="wiki-content-id"> <input type="hidden" name="wiki_page_id" id="wiki-content-id">
</form> </form>
<?php if (auth()->user()->inGroup('admin')): ?> <div class="col-md-12">
<div id="editorjs"></div>
<div class="col-md-12 d-flex flex-row justify-content-between align-items-center pb-2"> </div>
<div class="d-flex flex-row gap-2 justify-content-start align-items-center">
<?php if ($section->content()?->published_data): ?>
<span class="badge badge-center rounded-pill text-bg-success"><i class="ti ti-check"></i></span>
<strong><?= lang('Wiki.published') ?></strong>
<?php else: ?>
<span class="badge badge-center rounded-pill text-bg-danger"><i class="ti ti-alert-circle"></i></span>
<strong><?= lang('Wiki.not_published') ?></strong>
<?php endif; ?>
</div>
<div class="btn-group btn-group-sm" role="group">
<button type="button" class="btn btn-primary" id="save-editor"><i class="icon-base ti ti-device-floppy icon-xs me-2"></i><?= lang('App.global_save') ?></button>
<button type="button" class="btn btn-danger" id="release-editor"><i class="icon-base ti ti-upload icon-xs me-2"></i>Publicar</button>
<button type="button" class="btn btn-secondary d-none" id="preview-editor"><i class="icon-base ti ti-eye icon-xs me-2"></i>Vista previa</button>
<button type="button" class="btn btn-warning" id="edit-editor"><i class="icon-base ti ti-pencil icon-xs me-2"></i>Editar</button>
</div>
</div>
<div class="col-md-12">
<div id="editorjs"></div>
</div>
<?php else : ?>
<div class="col-md-12">
<div id="editorjs"></div>
</div>
<?php endif; ?>
</div> </div>
</div><!--//.card-body --> </div><!--//.card-body -->
<div class="card-footer"> <div class="card-footer">
@ -59,6 +60,8 @@
</div><!--//.card --> </div><!--//.card -->
</div><!--//.col --> </div><!--//.col -->
</div><!--//.row --> </div><!--//.row -->
<?= view("themes/vuexy/components/modals/modalSection") ?>
<?= $this->endSection() ?> <?= $this->endSection() ?>
<?= $this->section('css') ?> <?= $this->section('css') ?>
@ -68,6 +71,10 @@
<?= $this->section("additionalExternalJs") ?> <?= $this->section("additionalExternalJs") ?>
<script src="<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.js') ?>"></script> <script src="<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.js') ?>"></script>
<script type="module" src="<?= site_url('assets/js/safekat/pages/wiki/home.js') ?>"></script> <?php if (auth()->user()->inGroup('admin')) : ?>
<script type="module" src="<?= site_url('assets/js/safekat/pages/wiki/home.js') ?>"></script>
<?php else : ?>
<script type="module" src="<?= site_url('assets/js/safekat/pages/wiki/viewOnly.js') ?>"></script>
<?php endif; ?>
<?= $this->endSection() ?> <?= $this->endSection() ?>

View File

@ -0,0 +1,41 @@
import Ajax from "../components/ajax.js";
class TranslationHelper {
constructor() {
this.locale = "es"
this.lang = {}
}
async get_translations(translationFile) {
return new Promise(async (resolve,reject) => {
this.locale = $("meta[name='locale']").attr("content");
this.translationFile = translationFile
const ajax = new Ajax('/translate/getTranslation',
{
locale: this.locale,
translationFile: this.translationFile
},
null,
(response) => {
this.lang = JSON.parse(response)
resolve(this.lang)
},
(error) => {
reject(error)
}
);
ajax.post()
})
}
get_lang(key) {
if (key in this.lang) {
return this.lang[key]
}else{
return key
}
}
}
export default TranslationHelper;

View File

@ -83,8 +83,7 @@ export const alertSuccess = (value, target = 'body') => {
return Swal.mixin({ return Swal.mixin({
toast: true, toast: true,
position: 'bottom-end', position: 'bottom-end',
html: ` html: `<span class="text-sm-left text-wrap">${value}</span>`,
<span class="badge badge-label-primary fs-big">${value}</span>`,
customClass: { customClass: {
popup: 'bg-success text-white', popup: 'bg-success text-white',
}, },
@ -100,9 +99,9 @@ export const alertError = (value, target = 'body') => {
return Swal.mixin({ return Swal.mixin({
toast: true, toast: true,
position: 'bottom-end', position: 'bottom-end',
html: `<span class="badge badge-label-error fs-big">${value}</span>`, html: `<span class="text-sm-left text-wrap">${value}</span>`,
customClass: { customClass: {
popup: 'bg-error text-white', popup: 'bg-danger text-white',
}, },
icon : 'error', icon : 'error',
iconColor: 'white', iconColor: 'white',
@ -116,8 +115,7 @@ export const alertWarning = (value, target = 'body') => {
return Swal.mixin({ return Swal.mixin({
toast: true, toast: true,
position: 'bottom-end', position: 'bottom-end',
html: ` html: `<span class="text-sm-left text-wrap">${value}</span>`,
<span class="badge badge-label-warning fs-big">${value}</span>`,
customClass: { customClass: {
popup: 'bg-warning text-white', popup: 'bg-warning text-white',
}, },

View File

@ -1,26 +1,50 @@
import { es } from './lang/es.js';
import EditorJS from '../../../../../themes/vuexy/js/editorjs.mjs';
import '../../../../../../themes/vuexy/js/editorjs/header.js';
import '../../../../../themes/vuexy/js/editorjs/list.js';
import '../../../../../../themes/vuexy/js/editorjs/alert.js';
import '../../../../../../themes/vuexy/js/editorjs/drag-drop.js';
import '../../../../../../themes/vuexy/js/editorjs/image.js';
import '../../../../../themes/vuexy/js/editorjs/table.js';
import '../../../../../themes/vuexy/js/editorjs/tune.js';
import Ajax from '../ajax.js' import Ajax from '../ajax.js'
import { es } from './lang/es.js';
import '../../../../../themes/vuexy/js/editorjs/toc.js';
import '../../../../../themes/vuexy/js/editorjs/list.js';
import '../../../../../themes/vuexy/js/editorjs/tune.js';
import '../../../../../themes/vuexy/js/editorjs/table.js';
import '../../../../../../themes/vuexy/js/editorjs/image.js';
import '../../../../../../themes/vuexy/js/editorjs/alert.js';
import '../../../../../../themes/vuexy/js/editorjs/header.js';
import '../../../../../../themes/vuexy/js/editorjs/drag-drop.js';
import EditorJS from '../../../../../themes/vuexy/js/editorjs.mjs';
import TranslationHelper from '../../common/TranslationHelper.js';
import { alertConfirmAction, alertError, alertSuccess, alertWarning } from '../alerts/sweetAlert.js'; import { alertConfirmAction, alertError, alertSuccess, alertWarning } from '../alerts/sweetAlert.js';
class WikiEditor { import Modal from '../modal.js'
import WikiSectionForm from '../forms/WikiSectionForm.js'
class WikiEditor extends TranslationHelper{
constructor() { constructor() {
super();
this.sectionId = $("#wiki-section-id").val(); this.sectionId = $("#wiki-section-id").val();
this.modalSection = $("#modalSection")
this.newSectionBtn = $("#new-section")
this.editSectionBtn = $("#edit-section")
this.modal = new Modal(this.modalSection)
this.wikiFormSection = new WikiSectionForm()
}
async initEditor()
{
this.wikiFormSection
this.newSectionBtn.on('click',() => {
this.modal.toggle()
this.wikiFormSection.initPost()
})
this.editSectionBtn.on('click',() => {
this.modal.toggle()
this.wikiFormSection.initUpdate()
})
await this.get_translations("Wiki")
this.editor = new EditorJS({ this.editor = new EditorJS({
holder: 'editorjs', holder: 'editorjs',
i18n: es, i18n: this.locale == "es" ? es : null,
autofocus: true, autofocus: true,
placeholder: 'Empieza a diseñar aquí', placeholder: this.get_lang('header-placeholder'),
readOnly: true, readOnly: true,
tunes: { tunes: {
alignment: { alignment: {
@ -28,26 +52,26 @@ class WikiEditor {
}, },
}, },
tools: { tools: {
toc: TOC,
header: { header: {
class: Header, class: Header,
tunes : ['alignment'], tunes: ['alignment'],
config: { config: {
placeholder: 'Introduce un encabezado ...', placeholder: "",
levels: [1, 2, 3, 4], levels: [1, 2, 3, 4],
defaultLevel: 3 defaultLevel: 1
}, },
}, },
nestedchecklist: { nestedchecklist: {
class: editorjsNestedChecklist , class: editorjsNestedChecklist,
config : { config: {
maxLevel : 1, maxLevel: 1,
} }
}, },
alert: { alert: {
class: Alert, class: Alert,
inlineToolbar: true, inlineToolbar: true,
tunes : ['alignment'], tunes: ['alignment'],
config: { config: {
alertTypes: ['primary', 'secondary', 'info', 'success', 'warning', 'danger', 'light', 'dark'], alertTypes: ['primary', 'secondary', 'info', 'success', 'warning', 'danger', 'light', 'dark'],
defaultType: 'primary', defaultType: 'primary',
@ -56,10 +80,9 @@ class WikiEditor {
}, },
image: { image: {
class: ImageTool, class: ImageTool,
tunes : ['alignment'],
config: { config: {
features: { features: {
border: false, border: true,
caption: 'optional', caption: 'optional',
stretch: false stretch: false
}, },
@ -71,7 +94,7 @@ class WikiEditor {
}, },
table: { table: {
class: Table, class: Table,
tunes : ['alignment'], tunes: ['alignment'],
inlineToolbar: true, inlineToolbar: true,
config: { config: {
rows: 2, rows: 2,
@ -81,13 +104,13 @@ class WikiEditor {
}, },
}, },
alignment: { alignment: {
class:AlignmentBlockTune, class: AlignmentBlockTune,
config:{ config: {
default: "left", default: "left",
blocks: { blocks: {
header: 'left', header: 'left',
list: 'left' list: 'left'
} }
} }
}, },
@ -95,47 +118,58 @@ class WikiEditor {
}, },
}) })
} }
async initViewOnly()
{
try {
await this.editor.isReady;
this.handleGetDataPublished();
} catch (reason) {
console.log(`Editor.js initialization failed because of ${reason}`)
}
}
async init() { async init() {
try { try {
await this.initEditor()
await this.editor.isReady; await this.editor.isReady;
new DragDrop(this.editor); new DragDrop(this.editor);
/** Do anything you need after editor initialization */ /** Do anything you need after editor initialization */
$('#save-editor').on('click', () => { $('#save-editor').on('click', () => {
this.editor.save().then(outputData => {
alertConfirmAction('Guardar contenido').then(result => {
if (result.isConfirmed) {
this.handleSaveContent(outputData)
}
});
})
this.editor.save().then(outputData => {
this.editor.readOnly.toggle()
console.log("Data saved", outputData)
alertConfirmAction('Guardar contenido').then(result => {
if(result.isConfirmed){
this.handleSaveContent(outputData)
}
});
})
}) })
$('#release-editor').on('click', () => { $('#release-editor').on('click', () => {
this.editor.save().then(outputData => { this.editor.save().then(outputData => {
this.editor.readOnly.toggle() alertConfirmAction('Publicar contenido').then(result => {
console.log("Data published", outputData) if (result.isConfirmed) {
alertConfirmAction('Publicar contenido').then(result => { this.handlePublishContent(outputData)
if(result.isConfirmed){ }
this.handlePublishContent(outputData) console.log(result)
} });
}); }).catch((error) => {
}) alertError('Tienes que estar en modo editar para publicar').fire()
})
}) })
$('#preview-editor').on('click', () => { $('#preview-editor').on('click', () => {
this.editor.readOnly.toggle() this.editor.readOnly.toggle()
$('#edit-editor').removeClass('d-none') $('#edit-editor').removeClass('d-none')
$('#preview-editor').addClass('d-none') $('#preview-editor').addClass('d-none')
$('#release-editor').attr('disabled',null) $('#release-editor').attr('disabled', 'disabled')
$('#save-editor').attr('disabled',null) $('#save-editor').attr('disabled', 'disabled')
}) })
$('#edit-editor').on('click', () => { $('#edit-editor').on('click', () => {
$('#edit-editor').addClass('d-none') $('#edit-editor').addClass('d-none')
$('#preview-editor').removeClass('d-none') $('#preview-editor').removeClass('d-none')
$('#release-editor').attr('disabled','disabled')
$('#save-editor').attr('disabled','disabled') $('#release-editor').attr('disabled', null)
$('#save-editor').attr('disabled', null)
this.editor.readOnly.toggle() this.editor.readOnly.toggle()
}) })
this.handleGetData(); this.handleGetData();
@ -175,7 +209,7 @@ class WikiEditor {
handleGetDataPublishedSuccess(response) { handleGetDataPublishedSuccess(response) {
if (response.data.contents) { if (response.data.contents) {
alertSuccess(response.message).fire() alertSuccess(response.message).fire()
this.renderContent(response.data.contents.editor_data) this.renderContent(response.data.contents.published_data)
} else { } else {
alertWarning('No hay contenido').fire() alertWarning('No hay contenido').fire()
} }
@ -188,6 +222,7 @@ class WikiEditor {
try { try {
let parsedContent = JSON.parse(content) let parsedContent = JSON.parse(content)
this.editor.render(parsedContent) this.editor.render(parsedContent)
this.centerImages()
} catch (error) { } catch (error) {
console.log(error) console.log(error)
} }
@ -217,6 +252,14 @@ class WikiEditor {
this.handleGetData() this.handleGetData()
} }
handleSaveContentError(response) { } handleSaveContentError(response) { }
centerImages(){
setInterval(() => {
$(".image-tool img").css('margin','0 auto')
$(".image-tool__caption").css('margin','0 auto').css('border','none').css('text-align','center').css('box-shadow','none')
},500)
}
} }
export default WikiEditor export default WikiEditor

View File

@ -45,6 +45,7 @@ export const es = {
"Checklist": "Checklist", "Checklist": "Checklist",
"Quote": "Cita", "Quote": "Cita",
"Code": "Codigo", "Code": "Codigo",
"Nested Checklist": "Lista anidada",
"Delimiter": "Delimitador", "Delimiter": "Delimitador",
"Raw HTML": "Raw HTML", "Raw HTML": "Raw HTML",
"Table": "Tabla", "Table": "Tabla",
@ -55,7 +56,8 @@ export const es = {
"InlineCode": "Código", "InlineCode": "Código",
"Image" : "Imagen", "Image" : "Imagen",
"Alert" : "Alerta", "Alert" : "Alerta",
"Convert to" : "Convertir a" "Convert to" : "Convertir a",
"TOC" : "Tabla de contenidos"
}, },
@ -76,7 +78,22 @@ export const es = {
"Unordered": "Sin orden", "Unordered": "Sin orden",
"Ordered" : "Ordenada", "Ordered" : "Ordenada",
"Counter type" : "Contador", "Counter type" : "Contador",
"Convert to" : "Convertir a" "Convert to" : "Convertir a",
},
"toc" : {
'Refresh' : "Actualizar",
},
"table" : {
"Add column to left" : "Añadir columna a la izquierda",
"Add column to right" : "Añadir columna a la derecha",
"Delete column" : "Eliminar columna",
"Delete row" : "Eliminar fila",
"Without headings" : "Sin encabezados",
"With headings" : "Con encabezados",
"Stretch" : "Ampliar",
"Add row above" : "Añadir fila arriba",
"Add row below" : "Añadir fila abajo",
}, },
/** /**
* Link is the internal Inline Tool * Link is the internal Inline Tool
@ -107,6 +124,8 @@ export const es = {
"With border" : "Con borde", "With border" : "Con borde",
"Stretch image" : "Estirar imagen", "Stretch image" : "Estirar imagen",
"With background" : "Añadir fondo", "With background" : "Añadir fondo",
"Select an Image" : "Seleccione una imagen",
"With caption" : "Con título"
} }
}, },

View File

@ -0,0 +1,76 @@
import Ajax from "../ajax.js";
import { alertError, alertSuccess } from "../alerts/sweetAlert.js";
class WikiSectionForm
{
constructor() {
this.item = $("#formSection")
this.btnNew = $("#submit-new-section")
this.btnUpdate = $("#submit-update-section")
this.name = this.item.find('#section-name')
this.icon = this.item.find('#section-icon')
}
initPost()
{
this.showPost()
this.btnNew.on('click',this.post.bind(this))
this.btnUpdate.off('click')
}
initUpdate()
{
this.showUpdate()
this.btnUpdate.on('click',this.update.bind(this))
this.btnNew.off('click')
}
getFormData()
{
return {
name : this.name.val(),
icon : this.icon.val()
}
}
post(){
const ajax = new Ajax('/wiki/section',
this.getFormData(),
null,
this.success.bind(this),
this.error.bind(this)
)
ajax.post()
}
update(){
const ajax = new Ajax('/wiki/update/section',
this.getFormData(),
null,
this.success.bind(this),
this.error.bind(this)
)
ajax.post()
}
success(response)
{
alertSuccess(response.message).fire()
}
error(error)
{
alertError(error?.message).fire()
}
showPost(){
this.btnNew.removeClass('d-none')
this.btnUpdate.addClass('d-none')
}
showUpdate(){
this.btnUpdate.removeClass('d-none')
this.btnNew.addClass('d-none')
}
}
export default WikiSectionForm

View File

@ -1,9 +1,8 @@
import WikiEditor from "../../components/editorjs/WikiEditor.js" import WikiEditor from "../../components/editorjs/WikiEditor.js"
import Ajax from "../../components/ajax.js"
$(async () => {
$(async() => {
try { try {
const editor = new WikiEditor() const editor = new WikiEditor()
await editor.init() await editor.init()

View File

@ -0,0 +1,13 @@
import WikiEditor from "../../components/editorjs/WikiEditor.js"
$(async() => {
try {
const editor = new WikiEditor()
await editor.init()
} catch (error) {
}
})

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long