]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Правки и редактор
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 12 Feb 2025 11:03:35 +0000 (14:03 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 12 Feb 2025 11:03:35 +0000 (14:03 +0300)
13 files changed:
erp24/controllers/WikiController.php
erp24/records/WikiArticle.php
erp24/records/WikiArticleSearch.php
erp24/views/wiki-category/index.php
erp24/views/wiki/_form.php
erp24/views/wiki/index.php
erp24/views/wiki/tree.php
erp24/views/wiki/view.php
erp24/web/css/wiki/customWiki.css [new file with mode: 0644]
erp24/web/js/wiki/_form.js [new file with mode: 0644]
erp24/web/js/wiki/tree.js [new file with mode: 0644]
erp24/web/js/wiki/view.js [new file with mode: 0644]
erp24/web/uploads/screen.jpg [new file with mode: 0644]

index cddee509f98c29d523c6fc94e3e3139b8a169531..7a46849f18177fd82fa31554e26274dd468d833f 100644 (file)
@@ -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', [
index 14fb9c992de52ce37828ad66508a6444d8524282..e400429436932f442edd850a66b1b6e82cb75d9b 100644 (file)
@@ -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();
+    }
 }
index c2642d00d4faf2a519452902edc206219f912654..87c7c6613bcc6429ea0c4653ef5b22d1bf5bfd91 100644 (file)
@@ -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
index 99a9c5f33939502e98a73da00e06a1717264ff4b..e52df2ff6adc5ce98ebe98394f74233f08c9be31 100644 (file)
@@ -13,7 +13,7 @@ $this->title = 'Категории документации (wiki)';
 $this->params['breadcrumbs'][] = $this->title;
 ?>
 <div class="wiki-category-index p-4">
-
+    <?= Html::a('К статьям', ['/wiki/index'], ['class' => 'btn btn-secondary mb-4']) ?>
     <h1><?= Html::encode($this->title) ?></h1>
 
     <p>
index 8844bf7ac6ac82d8134908d120ff9bfd05c3e2c0..303306a66af93369743ccb9ec71db5f3169bdb14 100644 (file)
@@ -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' => 'Выберите родительскую категорию']
     ) ?>
 
-    <?= $form->field($model, 'description')->textarea(['rows' => 6]) ?>
+    <?= $form->field($model, 'description')->textarea(['rows' => 3]) ?>
 
-    <?= $form->field($model, 'content')->widget(CKEditor::class, [
-        'options' => ['rows' => 6],
-        'uploadUrl' => '/files/upload'
-    ]) ?>
+    <?= $form->field($model, 'content')->hiddenInput()->label('Содержание') ?>
+    <div id="summernote"><?= $model->content ?></div>
 
 
     <div class="form-group">
index ed28807802144c5da3b3445d2663d624f99cd1dc..0b429f44c932e1db00d75584b84c37f954eb6ed4 100644 (file)
@@ -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;
 ?>
 
 <div class="wiki-category-index p-4">
-    <h1><?= Html::encode($this->title) ?></h1>
-    <?php if ($user->group_id  == 81) : ?>
-    <p>
-        <?= Html::a('Создать категорию', ['wiki-category/create'], ['class' => 'btn btn-success']) ?>
-        <?= Html::a('Создать статью', ['create'], ['class' => 'btn btn-success']) ?>
-    </p>
-    <?php endif; ?>
+    <div class="row mb-4">
+        <div class="col-8"><h1><?= Html::encode($this->title) ?></h1></div>
+        <div class="col-3">
+            <?php if ($user->group_id  == 81) : ?>
+                <p>
+                    <?= Html::a('Создать категорию', ['wiki-category/create'], ['class' => 'btn btn-success']) ?>
+                    <?= Html::a('Создать статью', ['create'], ['class' => 'btn btn-success']) ?>
+                    <?= Html::a('Категории', ['wiki-category/index'], ['class' => 'btn btn-primary']) ?>
+                </p>
+            <?php endif; ?>
+        </div>
+    </div>
+
+
     <!-- Вывод дерева -->
     <div class="row">
         <div class="col-3 tree-container">
             <?= $this->render('tree', ['tree' => $tree]) ?>
         </div>
-        <div class="col-9">
-            <?= GridView::widget([
-                'dataProvider' => $dataProvider,
-                'filterModel' => $searchModel,
-                'columns' => [
-                    'title',
-                    [
-                        'attribute' => 'category_id',
-                        'value' => function ($model) {
-                            return $model->category ? $model->category->title : '';
-                        },
-                        'label' => 'Категория',
-                    ],
-                    ['class' => 'yii\grid\ActionColumn'],
-                ],
-            ]) ?>
+        <div class="col-9 d-flex align-items-center flex-column">
+                <h2 class="mb-1 ">Справочник ERP</h2>
+                <h3 class="mb-2 text-muted">для сотрудников</h3>
+                <p class="lead">В меню слева выберите статью по интересующей вас теме</p>
+                <img class="my-3" src="/web/uploads/screen.jpg" alt="">
+            <?php if ($user->group_id  == 81) : ?>
+                <p class="lead">Для добавления статей сначала добавьте категорию</p>
+                <p>
+                    <?= Html::a('Создать категорию', ['wiki-category/create'], ['class' => 'btn btn-success']) ?>
+                    <?= Html::a('Создать статью', ['create'], ['class' => 'btn btn-success']) ?>
+                </p>
+            <?php endif; ?>
         </div>
     </div>
-
-
-    <style>
-        .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;
-        }
-    </style>
-    <script>
-        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');
-                    }
-                });
-            });
-        });
-    </script>
-
index b7b4bcddd5398620e49573d134f507a7b92e06f4..3c56cdefb6ab2db6beeb17a45d86e1bd4321ca60 100644 (file)
@@ -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)) {
             <div
                     class="category-title open <?= $hasContent ? 'toggleable' : '' ?>"
                     data-has-content="<?= $hasContent ? 'true' : 'false' ?>"
+                    title="<?= $category->description ?>"
+                    data-toggle="tooltip"
+                    data-placement="top"
             >
                 <?= Html::encode($category->title) ?>
                 <?php if ($hasContent): ?>
@@ -37,7 +40,7 @@ if (empty($tree)) {
 
 
             <?php if (!empty($category->description)): ?>
-                <div class="category-description"><?= Html::encode($category->description) ?></div>
+<!--                <div class="category-description">--><?php //= Html::encode($category->description) ?><!--</div>-->
             <?php endif; ?>
 
             <?php if ($hasContent): ?>
@@ -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'
+                                    ]) ?>
                                 </li>
                             <?php endforeach; ?>
                         </ul>
index 6f59abeddbd99147c78bb5d874570c41829e2105..9f342a13433ec7b36f30cac03a4bc06fe354c705 100644 (file)
@@ -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);
             </div>
 
             <div class="text-muted mb-3">
-                <strong>Автор:</strong> <?= Html::encode($model->created_by) ?> |
+                <strong>Автор:</strong> <?= Html::encode($model->creatorName) ?> |
                 <strong>Дата создания:</strong> <?= date('d.m.Y H:i', strtotime($model->created_at)) ?>
             </div>
 
-            <div class="article-content border p-3 rounded bg-light">
+            <div class="article-content border p-3 rounded bg-white">
                 <?= nl2br($model->content) ?>
             </div>
             <?php if ($user->group_id  == 81) : ?>
@@ -73,96 +75,3 @@ YiiAsset::register($this);
 
 
 </div>
-
-<style>
-    .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;
-    }
-</style>
-<script>
-    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');
-                }
-            });
-        });
-    });
-</script>
diff --git a/erp24/web/css/wiki/customWiki.css b/erp24/web/css/wiki/customWiki.css
new file mode 100644 (file)
index 0000000..55e2899
--- /dev/null
@@ -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 (file)
index 0000000..21cb803
--- /dev/null
@@ -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 (file)
index 0000000..a7e8967
--- /dev/null
@@ -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 (file)
index 0000000..2124c53
--- /dev/null
@@ -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 (file)
index 0000000..f86f768
Binary files /dev/null and b/erp24/web/uploads/screen.jpg differ