Update Notification count for each pjax call.

This commit is contained in:
buddh4 2017-02-05 16:24:38 +01:00
parent 338dd40e73
commit a18146928d
7 changed files with 69 additions and 17 deletions

View File

@ -226,6 +226,11 @@ class View extends \yii\web\View
$value = Html::encode(array_values($viewStatus)[0]);
$this->registerJs('humhub.modules.ui.status.' . $type . '("' . $value . '")', View::POS_END, 'viewStatusMessage');
}
if (Yii::$app->request->isPjax) {
echo \humhub\widgets\LayoutAddons::widget();
$this->flushJsConfig();
}
if (Yii::$app->request->isAjax) {
return parent::endBody();

View File

@ -1,4 +1,4 @@
<?php //[STAMP] e93907d5924b39a3cd4134cc6a6ea3a3
<?php //[STAMP] 0468b7e2480518455b63a22d3aa6f7c2
namespace content\_generated;
// This class was automatically generated by build task

View File

@ -8,6 +8,7 @@
namespace humhub\modules\notification;
use Yii;
use humhub\modules\notification\models\Notification;
/**
@ -131,5 +132,12 @@ class Events extends \yii\base\Object
'source_pk' => $event->sender->getPrimaryKey(),
]);
}
public static function onLayoutAddons($event)
{
if(Yii::$app->request->isPjax) {
$event->sender->addWidget(widgets\UpdateNotificationCount::className());
}
}
}

View File

@ -7,6 +7,7 @@ use humhub\modules\space\models\Space;
use humhub\commands\IntegrityController;
use humhub\commands\CronController;
use humhub\components\ActiveRecord;
use humhub\widgets\LayoutAddons;
return [
'id' => 'notification',
@ -17,7 +18,8 @@ return [
array('class' => Space::className(), 'event' => Space::EVENT_BEFORE_DELETE, 'callback' => array(Events::className(), 'onSpaceDelete')),
array('class' => IntegrityController::className(), 'event' => IntegrityController::EVENT_ON_RUN, 'callback' => array(Events::className(), 'onIntegrityCheck')),
array('class' => CronController::className(), 'event' => CronController::EVENT_ON_DAILY_RUN, 'callback' => array(Events::className(), 'onCronDailyRun')),
array('class' => ActiveRecord::className(), 'event' => ActiveRecord::EVENT_BEFORE_DELETE, 'callback' => [Events::className(), 'onActiveRecordDelete'])
array('class' => ActiveRecord::className(), 'event' => ActiveRecord::EVENT_BEFORE_DELETE, 'callback' => [Events::className(), 'onActiveRecordDelete']),
array('class' => LayoutAddons::className(), 'event' => LayoutAddons::EVENT_BEFORE_RUN, 'callback' => [Events::className(), 'onLayoutAddons'])
),
];
?>

View File

@ -219,7 +219,7 @@ humhub.module('notification', function (module, require, $) {
});
}
module.menu = NotificationDropDown.instance('#notification_widget');
};
var initOverviewPage = function () {

View File

@ -0,0 +1,36 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2016 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\notification\widgets;
use Yii;
/**
* UpdateNotificationCount widget is an LayoutAddon widget for updating the notification count
* and is only used if pjax is active.
*
* @author buddha
* @since 1.2
*/
class UpdateNotificationCount extends \yii\base\Widget
{
/**
* @inheritdoc
*/
public function run()
{
if (Yii::$app->user->isGuest) {
return;
}
return $this->render('updateNotificationCount', [
'count' => \humhub\modules\notification\models\Notification::findUnseen()->count()
]);
}
}

View File

@ -24,22 +24,23 @@ class LayoutAddons extends BaseStack
*/
public function init()
{
$this->addWidget(GlobalModal::className());
$this->addWidget(GlobalConfirmModal::className());
if(Yii::$app->params['installed']) {
$this->addWidget(\humhub\modules\tour\widgets\Tour::className());
$this->addWidget(\humhub\modules\admin\widgets\TrackingWidget::className());
}
$this->addWidget(LoaderWidget::className(), ['show' => false, 'id' => "humhub-ui-loader-default"]);
$this->addWidget(StatusBar::className());
$this->addWidget(BlueimpGallery::className());
if(!Yii::$app->request->isPjax) {
$this->addWidget(GlobalModal::className());
$this->addWidget(GlobalConfirmModal::className());
if (Yii::$app->params['enablePjax']) {
$this->addWidget(Pjax::className());
}
if(Yii::$app->params['installed']) {
$this->addWidget(\humhub\modules\tour\widgets\Tour::className());
$this->addWidget(\humhub\modules\admin\widgets\TrackingWidget::className());
}
$this->addWidget(LoaderWidget::className(), ['show' => false, 'id' => "humhub-ui-loader-default"]);
$this->addWidget(StatusBar::className());
$this->addWidget(BlueimpGallery::className());
if (Yii::$app->params['enablePjax']) {
$this->addWidget(Pjax::className());
}
}
parent::init();
}