Add collapsible filter state in URL (#6445)

This commit is contained in:
Yuriy Bakhtin 2023-07-19 19:50:29 +04:00 committed by GitHub
parent 9969285398
commit 0dae15c975
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 9 deletions

View File

@ -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

View File

@ -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 = {

View File

@ -345,4 +345,9 @@ class WallStreamFilterNavigation extends FilterNavigation
'class' => 'wallFilterPanel'
];
}
public function isCollapsed(): bool
{
return !Yii::$app->request->get('filters_visible', 0);
}
}

View File

@ -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])
<?= Button::asLink(Yii::t('ContentModule.base', 'Filter') . '<b class="caret"></b>')
->cssClass('wall-stream-filter-toggle')->icon('fa-filter')->sm()->style('pa') ?>
</div>
<div class="wall-stream-filter-body" style="display:none">
<div class="wall-stream-filter-body"<?php if ($isCollapsed) : ?> style="display:none"<?php endif; ?>>
<div class="filter-root">
<div class="row">
<?= FilterPanel::widget(['blocks' => $panelColumn1Blocks, 'span' => count($panels)])?>

View File

@ -377,6 +377,7 @@ humhub.module('ui.filter', function(module, require, $) {
Filter: Filter,
FilterInput: FilterInput,
findFilterByComponent: findFilterByComponent,
addFilterType: addFilterType
addFilterType: addFilterType,
Url: Url
});
});

View File

@ -152,7 +152,8 @@ abstract class FilterNavigation extends JsWidget
{
return $this->render($this->view, [
'panels' => $this->filterOutEmptyPanels(),
'options' => $this->getOptions()
'options' => $this->getOptions(),
'isCollapsed' => $this->isCollapsed()
]);
}
@ -269,4 +270,9 @@ abstract class FilterNavigation extends JsWidget
return array_key_exists($filterId, $this->definition) || in_array($filterId, $this->definition);
}
public function isCollapsed(): bool
{
return true;
}
}