Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight searching keywords on view custom page #341

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions assets/HighlightAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/

namespace humhub\modules\custom_pages\assets;

use humhub\components\assets\AssetBundle;
use Yii;

class HighlightAsset extends AssetBundle
{
/**
* @inheritdoc
*/
public $sourcePath = '@custom_pages/resources';

/**
* @inheritdoc
*/
public $js = [
'js/humhub.custom_pages.highlight.js',
];

/**
* @inheritdoc
*/
public static function register($view)
{
$highlight = Yii::$app->request->get('highlight');
if ($highlight !== null && $highlight !== '') {
$view->registerJsConfig('custom_pages.highlight', ['highlight' => $highlight]);
}

return parent::register($view);
}
}
20 changes: 9 additions & 11 deletions controllers/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace humhub\modules\custom_pages\controllers;

use humhub\modules\custom_pages\assets\HighlightAsset;
use humhub\modules\custom_pages\models\CustomContentContainer;
use humhub\modules\custom_pages\models\HtmlType;
use humhub\modules\custom_pages\models\IframeType;
Expand All @@ -16,22 +17,20 @@
use yii\helpers\Html;
use yii\web\HttpException;


/**
* Controller for viewing Pages.
*
* @author buddha
*/
class ViewController extends AbstractCustomContainerController
{

/**
* @inhritdoc
*/
protected function getAccessRules()
{
return [
['strict']
['strict'],
];
}

Expand All @@ -58,15 +57,13 @@ public function actionIndex()
? $page->getTargetModel()->getSubLayout()
: $this->subLayout;

$this->view->pageTitle = Html::encode($page->title);
$this->view->setPageTitle(Html::encode($page->title));

if(!$page->getTargetModel()->isAllowedContentType($page->type)) {
if (!$page->getTargetModel()->isAllowedContentType($page->type)) {
throw new HttpException(404);
}

return $this->renderView($page);


}

/**
Expand All @@ -76,14 +73,15 @@ public function actionIndex()
*/
public function renderView($page)
{
if($this->contentContainer) {
HighlightAsset::register($this->view);

if ($this->contentContainer) {
return $this->renderContainerView($page);
}

return $this->renderGlobalView($page);
}


public function renderContainerView($page)
{
switch ($page->type) {
Expand Down Expand Up @@ -123,7 +121,7 @@ public function renderGlobalView($page)
'page' => $page,
'md' => $page->page_content,
'navigationClass' => $page->getTargetId(),
'title' => $page->title
'title' => $page->title,
]);
case PhpType::ID:
return $this->render('@custom_pages/views/global/php', ['page' => $page]);
Expand Down Expand Up @@ -153,7 +151,7 @@ public function viewTemplatePage(CustomContentContainer $page, $view)
'page' => $page,
'editMode' => $editMode,
'canEdit' => $canEdit,
'html' => $html
'html' => $html,
]);
}

Expand Down
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=========

1.11.0 (Unreleased)
-----------------------
- Enh #341: Highlight searching keywords on view custom page

1.10.6 (August 6, 2024)
-----------------------
- Fix: Add autofocus on item or element edit (for HumHub 1.17 - see https://github.com/humhub/humhub/issues/7136)
Expand Down
18 changes: 12 additions & 6 deletions models/Target.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?php


namespace humhub\modules\custom_pages\models;


use humhub\modules\content\components\ContentContainerActiveRecord;
use humhub\modules\custom_pages\helpers\Url;
use humhub\modules\custom_pages\Module;
use Yii;
use yii\base\Model;

/**
Expand Down Expand Up @@ -78,9 +77,16 @@ class Target extends Model
*/
public function getContentUrl(CustomContentContainer $content)
{
$params = ['id' => $content->id];

$searchKeyword = Yii::$app->request->get('keyword');
if ($searchKeyword !== null) {
$params['highlight'] = $searchKeyword;
}

return $content->content->container
? $content->content->container->createUrl($this->accessRoute, ['id' => $content->id])
: Url::toRoute([$this->accessRoute, 'id' => $content->id]);
? $content->content->container->createUrl($this->accessRoute, $params)
: Url::toRoute(array_merge([$this->accessRoute], $params));
}

/**
Expand All @@ -89,7 +95,7 @@ public function getContentUrl(CustomContentContainer $content)
public function rules()
{
return [
[['id', 'name'], 'required']
[['id', 'name'], 'required'],
];
}

Expand Down Expand Up @@ -139,4 +145,4 @@ public function getSubLayout()
return $this->subLayout;
}

}
}
4 changes: 2 additions & 2 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"name": "Custom Pages",
"description": "Create custom pages and widgets and share them with your users. Take advantage of a wide range of editing options, including HTML and Markdown.",
"keywords": ["pages", "custom", "iframe", "markdown", "link", "navigation", "spaces"],
"version": "1.10.6",
"version": "1.11.0",
"homepage": "https://github.com/humhub/custom-pages",
"humhub": {
"minVersion": "1.14"
"minVersion": "1.16"
}
}
16 changes: 16 additions & 0 deletions resources/js/humhub.custom_pages.highlight.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
humhub.module('custom_pages.highlight', function (module, require, $) {
const highlightWords = require('ui.additions').highlightWords;

const init = function () {
$(document).ready(function () {
if (typeof module.config.highlight === 'string') {
highlightWords('#layout-content', module.config.highlight);
}
});
}

module.export({
init,
initOnPjaxLoad: true,
})
})
8 changes: 5 additions & 3 deletions widgets/views/wallEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
use humhub\widgets\Button;

/* @var $page \humhub\modules\custom_pages\models\Page */

?>
<div class="media">
<div class="media-body">
<div data-ui-show-more>
<?= RichText::output($page->abstract)?>
<?= RichText::output($page->abstract) ?>
</div>

<?= Button::primary(Yii::t('CustomPagesModule.widgets_views_wallentry', 'Open page...'))->link($page->getUrl())->sm() ?>
<?= Button::primary(Yii::t('CustomPagesModule.widgets_views_wallentry', 'Open page...'))
->link($page->getUrl())
->sm()
->loader(false) ?>
</div>
</div>
Loading