From: fomichev Date: Wed, 12 Feb 2025 11:03:35 +0000 (+0300) Subject: Правки и редактор X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=0486fca6b5626e2e735f238bc0c555bf0479047c;p=erp24_rep%2Fyii-erp24%2F.git Правки и редактор --- diff --git a/erp24/controllers/WikiController.php b/erp24/controllers/WikiController.php index cddee509..7a46849f 100644 --- a/erp24/controllers/WikiController.php +++ b/erp24/controllers/WikiController.php @@ -44,6 +44,9 @@ class WikiController extends Controller $searchModel = new WikiArticleSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + if (!WikiArticleSearch::hasCategories()) { + Yii::$app->session->setFlash('warning', 'Категории не найдены. Добавьте хотя бы одну категорию.'); + } $categories = WikiCategory::find()->all(); $tree = $this->buildTree($categories); @@ -102,11 +105,8 @@ class WikiController extends Controller if ($this->request->isPost) { if ($model->load($this->request->post()) && $model->save()) { - // Получаем slug категории и slug статьи - $categorySlug = $model->category->slug; // Slug категории из связанной модели - $articleSlug = $model->slug; // Slug созданной статьи - - // Перенаправляем на страницу просмотра с правильными параметрами + $categorySlug = $model->category->slug; + $articleSlug = $model->slug; return $this->redirect(['view', 'parent_cat_slug' => $categorySlug, 'article_slug' => $articleSlug]); } } else { @@ -130,7 +130,9 @@ class WikiController extends Controller $model = $this->findModel($id); if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) { - return $this->redirect(['view', 'id' => $model->id]); + $categorySlug = $model->category->slug; + $articleSlug = $model->slug; + return $this->redirect(['view', 'parent_cat_slug' => $categorySlug, 'article_slug' => $articleSlug]); } return $this->render('update', [ diff --git a/erp24/records/WikiArticle.php b/erp24/records/WikiArticle.php index 14fb9c99..e4004294 100644 --- a/erp24/records/WikiArticle.php +++ b/erp24/records/WikiArticle.php @@ -99,4 +99,14 @@ class WikiArticle extends \yii\db\ActiveRecord { return $this->hasOne(WikiCategory::class, ['id' => 'category_id']); } + + public static function hasCategories(): bool + { + return WikiCategory::find()->exists(); + } + + public function getCreatorName() + { + return $this->hasOne(Admin::class, ['id' => 'created_by'])->select('name')->scalar(); + } } diff --git a/erp24/records/WikiArticleSearch.php b/erp24/records/WikiArticleSearch.php index c2642d00..87c7c661 100644 --- a/erp24/records/WikiArticleSearch.php +++ b/erp24/records/WikiArticleSearch.php @@ -40,6 +40,11 @@ class WikiArticleSearch extends WikiArticle */ public function search($params) { + if (!self::hasCategories()) { + return new ActiveDataProvider([ + 'query' => WikiArticle::find()->where('0=1'), // Возвращает пустой результат + ]); + } $query = WikiArticle::find(); // add conditions that should always apply here diff --git a/erp24/views/wiki-category/index.php b/erp24/views/wiki-category/index.php index 99a9c5f3..e52df2ff 100644 --- a/erp24/views/wiki-category/index.php +++ b/erp24/views/wiki-category/index.php @@ -13,7 +13,7 @@ $this->title = 'Категории документации (wiki)'; $this->params['breadcrumbs'][] = $this->title; ?>
- + 'btn btn-secondary mb-4']) ?>

title) ?>

diff --git a/erp24/views/wiki/_form.php b/erp24/views/wiki/_form.php index 8844bf7a..303306a6 100644 --- a/erp24/views/wiki/_form.php +++ b/erp24/views/wiki/_form.php @@ -5,12 +5,13 @@ use sangroya\ckeditor5\CKEditor; use yii\helpers\ArrayHelper; use yii\helpers\Html; use yii\widgets\ActiveForm; +use yii_app\helpers\PrintBlockHelper; use yii_app\records\WikiCategory; /** @var yii\web\View $this */ /** @var yii_app\records\WikiArticle $model */ /** @var yii\widgets\ActiveForm $form */ - +$this->registerJsFile('/js/wiki/_form.js', ['position' => \yii\web\View::POS_END]); function getCategoriesWithHierarchy($categories, $parentId = null, $level = 0) { $result = []; @@ -43,12 +44,10 @@ $categoryList = getCategoriesWithHierarchy($categories); ['prompt' => 'Выберите родительскую категорию'] ) ?> - field($model, 'description')->textarea(['rows' => 6]) ?> + field($model, 'description')->textarea(['rows' => 3]) ?> - field($model, 'content')->widget(CKEditor::class, [ - 'options' => ['rows' => 6], - 'uploadUrl' => '/files/upload' - ]) ?> + field($model, 'content')->hiddenInput()->label('Содержание') ?> +

content ?>
diff --git a/erp24/views/wiki/index.php b/erp24/views/wiki/index.php index ed288078..0b429f44 100644 --- a/erp24/views/wiki/index.php +++ b/erp24/views/wiki/index.php @@ -10,7 +10,10 @@ use yii\grid\GridView; /** @var yii_app\records\WikiArticleSearch $searchModel */ /** @var yii\data\ActiveDataProvider $dataProvider */ /** @var array $tree */ +\yii\web\YiiAsset::register($this); +$this->registerCssFile('/css/wiki/customWiki.css'); +$this->registerJsFile('/js/wiki/view.js', ['position' => \yii\web\View::POS_END]); $this->title = 'Документация'; $this->params['breadcrumbs'][] = $this->title; $user = Yii::$app->user->identity; @@ -18,128 +21,36 @@ $user = Yii::$app->user->identity; ?>
-

title) ?>

- group_id == 81) : ?> -

- 'btn btn-success']) ?> - 'btn btn-success']) ?> -

- +
+

title) ?>

+
+ group_id == 81) : ?> +

+ 'btn btn-success']) ?> + 'btn btn-success']) ?> + 'btn btn-primary']) ?> +

+ +
+
+ +
render('tree', ['tree' => $tree]) ?>
-
- $dataProvider, - 'filterModel' => $searchModel, - 'columns' => [ - 'title', - [ - 'attribute' => 'category_id', - 'value' => function ($model) { - return $model->category ? $model->category->title : ''; - }, - 'label' => 'Категория', - ], - ['class' => 'yii\grid\ActionColumn'], - ], - ]) ?> +
+

Справочник ERP

+

для сотрудников

+

В меню слева выберите статью по интересующей вас теме

+ + group_id == 81) : ?> +

Для добавления статей сначала добавьте категорию

+

+ 'btn btn-success']) ?> + 'btn btn-success']) ?> +

+
- - - - - diff --git a/erp24/views/wiki/tree.php b/erp24/views/wiki/tree.php index b7b4bcdd..3c56cdef 100644 --- a/erp24/views/wiki/tree.php +++ b/erp24/views/wiki/tree.php @@ -4,7 +4,7 @@ use yii\helpers\Url; /** @var array $tree */ /** @var int $level */ - +$this->registerJsFile('/js/wiki/tree.js', ['position' => \yii\web\View::POS_END]); if (!isset($level)) { $level = 0; } @@ -26,6 +26,9 @@ if (empty($tree)) {
title) ?> @@ -37,7 +40,7 @@ if (empty($tree)) { description)): ?> -
description) ?>
+description) ?> @@ -51,7 +54,12 @@ if (empty($tree)) { 'view', 'parent_cat_slug' => $category->slug, 'article_slug' => $article->slug - ], true), ['class' => 'article-link']) ?> + ], true), [ + 'class' => 'article-link', + 'title' => Html::encode($article->description), + 'data-toggle' => 'tooltip', + 'data-placement' => 'top' + ]) ?> diff --git a/erp24/views/wiki/view.php b/erp24/views/wiki/view.php index 6f59abed..9f342a13 100644 --- a/erp24/views/wiki/view.php +++ b/erp24/views/wiki/view.php @@ -12,6 +12,8 @@ use yii\bootstrap5\Alert; /** @var yii_app\records\WikiArticle $model */ /** @var array $tree */ +$this->registerCssFile('/css/wiki/customWiki.css'); +$this->registerJsFile('/js/wiki/view.js', ['position' => \yii\web\View::POS_END]); $this->title = $model->title; $this->params['breadcrumbs'][] = ['label' => 'Wiki Articles', 'url' => ['index']]; @@ -47,11 +49,11 @@ YiiAsset::register($this);
- Автор: created_by) ?> | + Автор: creatorName) ?> | Дата создания: created_at)) ?>
-
+
content) ?>
group_id == 81) : ?> @@ -73,96 +75,3 @@ YiiAsset::register($this);
- - - diff --git a/erp24/web/css/wiki/customWiki.css b/erp24/web/css/wiki/customWiki.css new file mode 100644 index 00000000..55e2899a --- /dev/null +++ b/erp24/web/css/wiki/customWiki.css @@ -0,0 +1,66 @@ +.tree-container { + font-family: Roboto, "Helvetica Neue", Helvetica, Arial, sans-serif; + line-height: 1.6; +} +.tree-level-0 { + margin-left: 0; +} +.tree-level-1 { + margin-left: 20px; +} +.tree-level-2 { + margin-left: 40px; +} +/* Категории */ +.category-title { + font-weight: bold; + cursor: pointer; + padding: 8px 12px; + background-color: #f4f4f4; + border-radius: 4px; + transition: background-color 0.3s ease; +} +.category-title:hover { + background-color: #e0e0e0; +} + +/* Стрелочка */ +.category-title.toggleable svg { + margin-left: 8px; + transition: transform 0.3s ease; + transform: rotate(0deg); +} +.category-title.toggleable.open svg { + transform: rotate(90deg); +} + +/* Скрытые подкатегории и статьи */ +.subcategories.hidden { + display: none; +} +.subcategories.visible { + display: block; +} + +/* Статьи */ +.articles-list { + list-style-type: none; + padding-left: 20px; +} +.article-link { + display: block; + padding: 6px 12px; + text-decoration: none; + color: #337ab7; + border-radius: 4px; + transition: background-color 0.3s ease, color 0.3s ease; +} +.article-link:hover { + background-color: #e0e0e0; + color: #23527c; +} +.article-description { + color: #666; + font-size: 0.9em; + margin-top: 4px; +} \ No newline at end of file diff --git a/erp24/web/js/wiki/_form.js b/erp24/web/js/wiki/_form.js new file mode 100644 index 00000000..21cb8035 --- /dev/null +++ b/erp24/web/js/wiki/_form.js @@ -0,0 +1,6 @@ +$(document).ready(() => { + $('#summernote').summernote({maxHeight: 400}); + setInterval(() => { + $('#wikiarticle-content').val($('#summernote').summernote('code')); + }, 1000); +}) \ No newline at end of file diff --git a/erp24/web/js/wiki/tree.js b/erp24/web/js/wiki/tree.js new file mode 100644 index 00000000..a7e89678 --- /dev/null +++ b/erp24/web/js/wiki/tree.js @@ -0,0 +1,3 @@ +$(function () { + $('[data-toggle="tooltip"]').tooltip(); +}); \ No newline at end of file diff --git a/erp24/web/js/wiki/view.js b/erp24/web/js/wiki/view.js new file mode 100644 index 00000000..2124c530 --- /dev/null +++ b/erp24/web/js/wiki/view.js @@ -0,0 +1,22 @@ +function copyToClipboard(text) { + navigator.clipboard.writeText(text).then(function() { + alert('Ссылка скопирована: ' + text); + }, function(err) { + console.error('Ошибка копирования: ', err); + }); +} +document.addEventListener('DOMContentLoaded', function () { + const categoryTitles = document.querySelectorAll('.category-title.toggleable'); + categoryTitles.forEach(title => { + title.addEventListener('click', function () { + const parentLi = this.closest('li'); + const subcategories = parentLi.querySelector('.subcategories'); + + if (subcategories) { + subcategories.classList.toggle('visible'); + subcategories.classList.toggle('hidden'); + this.classList.toggle('open'); + } + }); + }); +}); \ No newline at end of file diff --git a/erp24/web/uploads/screen.jpg b/erp24/web/uploads/screen.jpg new file mode 100644 index 00000000..f86f7689 Binary files /dev/null and b/erp24/web/uploads/screen.jpg differ