From 0dae15c975ff3f8f56ec0266c29c9d84db822653 Mon Sep 17 00:00:00 2001 From: Yuriy Bakhtin Date: Wed, 19 Jul 2023 19:50:29 +0400 Subject: [PATCH] Add collapsible filter state in URL (#6445) --- CHANGELOG-DEV.md | 1 + .../modules/stream/resources/js/humhub.stream.wall.js | 10 ++++------ .../stream/widgets/WallStreamFilterNavigation.php | 5 +++++ .../widgets/views/wallStreamFilterNavigation.php | 3 ++- .../modules/ui/filter/resources/js/humhub.ui.filter.js | 3 ++- .../modules/ui/filter/widgets/FilterNavigation.php | 8 +++++++- 6 files changed, 21 insertions(+), 9 deletions(-) diff --git a/CHANGELOG-DEV.md b/CHANGELOG-DEV.md index e709382b75..c546b0ae34 100644 --- a/CHANGELOG-DEV.md +++ b/CHANGELOG-DEV.md @@ -81,3 +81,4 @@ HumHub Changelog - Fix #6428: Translation for custom profile field is served from wrong file - Fix #6429: Fix Marketplace view - Fix #6383: Remove permission verifying from archive methods +- Enh #6439: Add collapsible filter state in URL diff --git a/protected/humhub/modules/stream/resources/js/humhub.stream.wall.js b/protected/humhub/modules/stream/resources/js/humhub.stream.wall.js index 5e6fab2107..c0f3b8cd67 100644 --- a/protected/humhub/modules/stream/resources/js/humhub.stream.wall.js +++ b/protected/humhub/modules/stream/resources/js/humhub.stream.wall.js @@ -18,6 +18,7 @@ humhub.module('stream.wall', function (module, require, $) { var Widget = require('ui.widget').Widget; var event = require('event'); var Filter = require('ui.filter').Filter; + var Url = require('ui.filter').Url; var string = require('util').string; var topic = require('topic'); var view = require('ui.view'); @@ -382,11 +383,6 @@ humhub.module('stream.wall', function (module, require, $) { WallStreamFilter.prototype.initFilterCount = function () { this.updateFilterCount(); - - var activeFiltersCount = parseInt(this.$.find('.filterCount').text().replace(/^.+?(\d+).+?$/, '$1')); - if (activeFiltersCount > 0 && this.$.find('.wall-stream-filter-body').is(':hidden')) { - this.toggleFilterPanel(); - } } WallStreamFilter.prototype.updateFilterCount = function () { @@ -414,7 +410,9 @@ humhub.module('stream.wall', function (module, require, $) { }; WallStreamFilter.prototype.toggleFilterPanel = function() { - this.$.find('.wall-stream-filter-body').slideToggle(); + const filters = this.$.find('.wall-stream-filter-body'); + Url.updateParam('filters_visible', filters.is(':visible') ? 0 : 1); + filters.slideToggle(); }; WallStreamFilter.template = { diff --git a/protected/humhub/modules/stream/widgets/WallStreamFilterNavigation.php b/protected/humhub/modules/stream/widgets/WallStreamFilterNavigation.php index 93ceb226c2..b751e1f2f8 100644 --- a/protected/humhub/modules/stream/widgets/WallStreamFilterNavigation.php +++ b/protected/humhub/modules/stream/widgets/WallStreamFilterNavigation.php @@ -345,4 +345,9 @@ class WallStreamFilterNavigation extends FilterNavigation 'class' => 'wallFilterPanel' ]; } + + public function isCollapsed(): bool + { + return !Yii::$app->request->get('filters_visible', 0); + } } diff --git a/protected/humhub/modules/stream/widgets/views/wallStreamFilterNavigation.php b/protected/humhub/modules/stream/widgets/views/wallStreamFilterNavigation.php index 96ad9b2bc8..8bf50ce817 100644 --- a/protected/humhub/modules/stream/widgets/views/wallStreamFilterNavigation.php +++ b/protected/humhub/modules/stream/widgets/views/wallStreamFilterNavigation.php @@ -14,6 +14,7 @@ use yii\helpers\Html; /* @var $this \humhub\modules\ui\view\components\View */ /* @var $panels [] */ /* @var $options [] */ +/* @var $isCollapsed bool */ $panelColumn1Blocks = isset($panels[WallStreamFilterNavigation::PANEL_COLUMN_1]) ? $panels[WallStreamFilterNavigation::PANEL_COLUMN_1] : null; $panelColumn2Blocks = isset($panels[WallStreamFilterNavigation::PANEL_COLUMN_2]) ? $panels[WallStreamFilterNavigation::PANEL_COLUMN_2] : null; @@ -30,7 +31,7 @@ $panelColumn4Blocks = isset($panels[WallStreamFilterNavigation::PANEL_COLUMN_4]) ') ->cssClass('wall-stream-filter-toggle')->icon('fa-filter')->sm()->style('pa') ?> -