Skip to content

Commit

Permalink
Merge branch 'enh/526-display-select-space-prompt' into fix/523-my-pr…
Browse files Browse the repository at this point in the history
…ofile-filter
  • Loading branch information
marc-farre committed Jan 23, 2025
2 parents 0a1582d + 92ce780 commit 1c3d84b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
6 changes: 4 additions & 2 deletions controllers/GlobalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ private function getFilterSettings()
public function actionSelect($start = null, $end = null)
{
/* @var $user User */
$contentContainerSelection = [];
$user = Yii::$app->user->getIdentity();
$canSelectProfileCalendar = $user->moduleManager->isEnabled('calendar') || $user->moduleManager->canEnable('calendar');

if ($user->moduleManager->isEnabled('calendar') || $user->moduleManager->canEnable('calendar')) {
$contentContainerSelection = [];
if ($canSelectProfileCalendar) {
$contentContainerSelection[$user->contentcontainer_id] = Yii::t('CalendarModule.base', 'Profile Calendar');
}

Expand All @@ -157,6 +158,7 @@ public function actionSelect($start = null, $end = null)

return $this->renderAjax('selectContainerModal', [
'contentContainerSelection' => $contentContainerSelection,
'canSelectProfileCalendar' => $canSelectProfileCalendar,
'submitUrl' => Url::to(['/calendar/global/select-submit', 'start' => $start, 'end' => $end]),
]);
}
Expand Down
2 changes: 2 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Changelog
------------------------
- Fix #523: Global calendar: display the "My profile" filter only when the module is enabled in for the User account
- Fix #525: Fix Space calendar header
- Enh #526: New event from the global calendar: display "Select space..." or "Select calendar..." prompt instead of first Space
- Enh: Show the "Filter by types" filter only if a list a type is available

1.7.1 (January 17, 2025)
------------------------
Expand Down
2 changes: 2 additions & 0 deletions tests/codeception/acceptance/GlobalCalendarCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public function testGlobalCalendarCreateEntry(AcceptanceTester $I)
$I->click('.fc-today');
$I->expectTo('see the choose calendar modal');
$I->waitForText('Choose target calendar');
$I->click('.select2-selection--single');
$I->click('.select2-results__option:nth-child(2)');
$I->click('Next', '#globalModal');


Expand Down
9 changes: 8 additions & 1 deletion views/global/selectContainerModal.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use humhub\widgets\ModalDialog;

/* @var $contentContainerSelection array */
/* @var $canSelectProfileCalendar bool */
/* @var $submitUrl array */

?>
Expand All @@ -20,7 +21,13 @@
<?php if ($contentContainerSelection): ?>
<?php $form = ActiveForm::begin() ?>
<div class="modal-body">
<?= Html::dropDownList('contentContainerId', null, $contentContainerSelection, ['class' => 'form-control', 'data-ui-select2' => '']) ?>
<?= Html::dropDownList('contentContainerId', null, $contentContainerSelection, [
'class' => 'form-control',
'data-ui-select2' => '',
'prompt' => $canSelectProfileCalendar ?
Yii::t('CalendarModule.base', 'Select calendar...') :
Yii::t('CalendarModule.base', 'Select space...'),
]) ?>
</div>
<div class="modal-footer">
<?= ModalButton::submitModal($submitUrl, Yii::t('CalendarModule.base', 'Next')) ?>
Expand Down
10 changes: 10 additions & 0 deletions widgets/CalendarFilterBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
namespace humhub\modules\calendar\widgets;

use humhub\components\Widget;
use humhub\modules\calendar\models\CalendarEntryType;
use humhub\modules\content\helpers\ContentContainerHelper;
use humhub\modules\content\models\ContentTag;
use Yii;

/**
Expand All @@ -34,6 +37,13 @@ public function run()
return '';
}

$currentContentContainer = ContentContainerHelper::getCurrent();
$typesQuery = ContentTag::find()->where(['type' => CalendarEntryType::class]);
if ($currentContentContainer) {
$typesQuery->andWhere(['contentcontainer_id' => $currentContentContainer->contentcontainer_id]);
}
$this->showTypes = $this->showTypes && $typesQuery->exists();

return $this->render('calendarFilterBar', [
'filters' => $this->filters,
'canConfigure' => $this->canConfigure,
Expand Down

0 comments on commit 1c3d84b

Please sign in to comment.