From: fomichev Date: Tue, 11 Feb 2025 11:20:29 +0000 (+0300) Subject: Создание правки по вики X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=8fd7421bb42fead033d31b4c09c63c8e7f203fe0;p=erp24_rep%2Fyii-erp24%2F.git Создание правки по вики --- diff --git a/erp24/config/web.php b/erp24/config/web.php index c0b65fee..c6c3a0fc 100644 --- a/erp24/config/web.php +++ b/erp24/config/web.php @@ -41,8 +41,8 @@ $config = [ ], 'queue' => [ 'class' => Queue::class, - // 'dsn' => 'amqp://admin:3qqHK2MRgGgxUdVT61@rabbitmq-yii_erp24:5672', - 'dsn' => 'amqp://admin:3qqHK2MRgGgxUdVT61@localhost:5672', + 'dsn' => 'amqp://admin:3qqHK2MRgGgxUdVT61@rabbitmq-yii_erp24:5672', + // 'dsn' => 'amqp://admin:3qqHK2MRgGgxUdVT61@localhost:5672', 'queueName' => 'telegram-queue', 'as log' => \yii\queue\LogBehavior::class, 'ttr' => 300, // Время для выполнения задания @@ -95,6 +95,7 @@ $config = [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ + 'wiki//' => 'wiki/view', ], ], ], diff --git a/erp24/controllers/WikiController.php b/erp24/controllers/WikiController.php index e48902cb..cddee509 100644 --- a/erp24/controllers/WikiController.php +++ b/erp24/controllers/WikiController.php @@ -76,6 +76,8 @@ class WikiController extends Controller */ public function actionView($parent_cat_slug, $article_slug) { + $categories = WikiCategory::find()->all(); + $tree = $this->buildTree($categories); $category = WikiCategory::findOne(['slug' => $parent_cat_slug]); if (!$category) { throw new NotFoundHttpException('Category not found.'); @@ -86,7 +88,7 @@ class WikiController extends Controller throw new NotFoundHttpException('Article not found.'); } - return $this->render('view', ['model' => $model]); + return $this->render('view', ['model' => $model, 'tree' => $tree]); } /** diff --git a/erp24/records/WikiCategory.php b/erp24/records/WikiCategory.php index 7601035b..3df74747 100644 --- a/erp24/records/WikiCategory.php +++ b/erp24/records/WikiCategory.php @@ -121,4 +121,15 @@ class WikiCategory extends \yii\db\ActiveRecord { return $this->hasMany(WikiCategory::class, ['parent_id' => 'id']); } + public function getParentCategories() + { + $categories = []; + $category = $this; + while ($category !== null) { + array_unshift($categories, $category); + $category = $this->parent; + } + return $categories; + } + } diff --git a/erp24/views/wiki/_form.php b/erp24/views/wiki/_form.php index 15ecddf8..cf965f11 100644 --- a/erp24/views/wiki/_form.php +++ b/erp24/views/wiki/_form.php @@ -47,7 +47,7 @@ $categoryList = getCategoriesWithHierarchy($categories); field($model, 'content')->widget(CKEditor::class, [ 'options' => ['rows' => 6], - 'uploadUrl' => '/uploads', + 'uploadUrl' => Yii::getAlias('@uploads') ]) ?> diff --git a/erp24/views/wiki/index.php b/erp24/views/wiki/index.php index 65bc2d1e..ed288078 100644 --- a/erp24/views/wiki/index.php +++ b/erp24/views/wiki/index.php @@ -14,52 +14,6 @@ use yii\grid\GridView; $this->title = 'Документация'; $this->params['breadcrumbs'][] = $this->title; $user = Yii::$app->user->identity; -function renderTree($tree, $level = 0) -{ - if (empty($tree)) { - return ''; - } - - $html = '
    '; - foreach ($tree as $node) { - $category = $node['category']; - $articles = $node['articles']; - $children = $node['children']; - - // Выводим категорию - $html .= '
  • '; - $html .= Html::tag('div', Html::encode($category->title), ['class' => 'category-title']); - - // Выводим описание категории (если есть) - if (!empty($category->description)) { - $html .= Html::tag('div', Html::encode($category->description), ['class' => 'category-description']); - } - - - if (!empty($articles)) { - $html .= '
      '; - foreach ($articles as $article) { - $articleUrl = Url::to(['view', 'parent_cat_slug' => $category->slug, 'article_slug' => $article->slug], true); - $html .= '
    • '; - $html .= Html::a(Html::encode($article->title), $articleUrl, ['class' => 'article-link']); - - $html .= '
    • '; - } - $html .= '
    '; - } - - if (!empty($children)) { - $html .= '
      '; - $html .= renderTree($children, $level + 1); - $html .= '
    '; - } - - $html .= '
  • '; - } - $html .= '
'; - - return $html; -} ?> @@ -74,10 +28,10 @@ function renderTree($tree, $level = 0)
- + render('tree', ['tree' => $tree]) ?>
- $dataProvider, 'filterModel' => $searchModel, 'columns' => [ @@ -91,103 +45,101 @@ function renderTree($tree, $level = 0) ], ['class' => 'yii\grid\ActionColumn'], ], - ]); ?> + ]) ?>
- - - - + /* Стрелочка */ + .category-title.toggleable svg { + margin-left: 8px; + transition: transform 0.3s ease; + transform: rotate(0deg); + } + .category-title.toggleable.open svg { + transform: rotate(90deg); + } - - - + diff --git a/erp24/views/wiki/tree.php b/erp24/views/wiki/tree.php new file mode 100644 index 00000000..b7b4bcdd --- /dev/null +++ b/erp24/views/wiki/tree.php @@ -0,0 +1,68 @@ + + +
    + + +
  • + +
    + title) ?> + + + + + +
    + + + description)): ?> +
    description) ?>
    + + + +
      + + +
        + +
      • + title), Url::to([ + 'view', + 'parent_cat_slug' => $category->slug, + 'article_slug' => $article->slug + ], true), ['class' => 'article-link']) ?> +
      • + +
      + + + + + render('tree', ['tree' => $children, 'level' => $level + 1]) ?> + +
    + +
  • + +
diff --git a/erp24/views/wiki/view.php b/erp24/views/wiki/view.php index 844b23b0..6f59abed 100644 --- a/erp24/views/wiki/view.php +++ b/erp24/views/wiki/view.php @@ -3,13 +3,15 @@ use yii\helpers\Html; use yii\helpers\Url; use yii\web\YiiAsset; -use yii\widgets\DetailView; + use yii\web\View; use yii\bootstrap5\Button; use yii\bootstrap5\Alert; /** @var View $this */ /** @var yii_app\records\WikiArticle $model */ +/** @var array $tree */ + $this->title = $model->title; $this->params['breadcrumbs'][] = ['label' => 'Wiki Articles', 'url' => ['index']]; @@ -19,47 +21,127 @@ $articleUrl = Url::to(['view', 'parent_cat_slug' => $model->category->slug, 'art YiiAsset::register($this); ?> -
-
-

- title) ?> - -

- 'btn btn-secondary']) ?> -
+ + + -
- Автор: created_by) ?> | - Дата создания: created_at)) ?> -
+
+ +
+ Автор: created_by) ?> | + Дата создания: created_at)) ?> +
+ +
+ content) ?> +
+ group_id == 81) : ?> +
+ $model->id], ['class' => 'btn btn-primary']) ?> + $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Вы уверены, что хотите удалить статью?', + 'method' => 'post', + ], + ]) ?> +
+ + + -
- content) ?> -
- group_id == 81) : ?> -
- $model->id], ['class' => 'btn btn-primary']) ?> - $model->id], [ - 'class' => 'btn btn-danger', - 'data' => [ - 'confirm' => 'Вы уверены, что хотите удалить статью?', - 'method' => 'post', - ], - ]) ?>
- + + +