mark all notification as read

This commit is contained in:
aynsix
2022-02-10 17:23:01 +03:00
parent 974fbf9164
commit 10ef15964f
13 changed files with 104 additions and 6 deletions

View File

@@ -13,5 +13,5 @@ module.exports = {
setupDir: _root + 'tests/setup/node.js',
karmaConf: _root + 'config/karma.conf.js',
// change this version when you change JS file for lazy loading
assetFileVersion: 38
assetFileVersion: 39
};

View File

@@ -96,7 +96,7 @@ return /******/ (function(modules) { // webpackBootstrap
/******/ if (__webpack_require__.nc) {
/******/ script.setAttribute("nonce", __webpack_require__.nc);
/******/ }
/******/ script.src = __webpack_require__.p + "lazy-" + ({}[chunkId]||chunkId) + ".js?v=38";
/******/ script.src = __webpack_require__.p + "lazy-" + ({}[chunkId]||chunkId) + ".js?v=39";
/******/ var timeout = setTimeout(onScriptComplete, 120000);
/******/ script.onerror = script.onload = onScriptComplete;
/******/ function onScriptComplete() {

View File

@@ -96,7 +96,7 @@ return /******/ (function(modules) { // webpackBootstrap
/******/ if (__webpack_require__.nc) {
/******/ script.setAttribute("nonce", __webpack_require__.nc);
/******/ }
/******/ script.src = __webpack_require__.p + "lazy-" + ({}[chunkId]||chunkId) + ".min.js?v=38";
/******/ script.src = __webpack_require__.p + "lazy-" + ({}[chunkId]||chunkId) + ".min.js?v=39";
/******/ var timeout = setTimeout(onScriptComplete, 120000);
/******/ script.onerror = script.onload = onScriptComplete;
/******/ function onScriptComplete() {

View File

@@ -91,7 +91,7 @@
/******/ if (__webpack_require__.nc) {
/******/ script.setAttribute("nonce", __webpack_require__.nc);
/******/ }
/******/ script.src = __webpack_require__.p + "lazy-" + ({}[chunkId]||chunkId) + ".js?v=38";
/******/ script.src = __webpack_require__.p + "lazy-" + ({}[chunkId]||chunkId) + ".js?v=39";
/******/ var timeout = setTimeout(onScriptComplete, 120000);
/******/ script.onerror = script.onload = onScriptComplete;
/******/ function onScriptComplete() {

View File

@@ -91,7 +91,7 @@
/******/ if (__webpack_require__.nc) {
/******/ script.setAttribute("nonce", __webpack_require__.nc);
/******/ }
/******/ script.src = __webpack_require__.p + "lazy-" + ({}[chunkId]||chunkId) + ".min.js?v=38";
/******/ script.src = __webpack_require__.p + "lazy-" + ({}[chunkId]||chunkId) + ".min.js?v=39";
/******/ var timeout = setTimeout(onScriptComplete, 120000);
/******/ script.onerror = script.onload = onScriptComplete;
/******/ function onScriptComplete() {

View File

@@ -19402,6 +19402,19 @@ var notifyLayout = function notifyLayout(services) {
}
}
});
$notificationDialog.on('click', '.mark-all-read', function (event) {
event.preventDefault();
_jquery2.default.ajax({
type: 'POST',
url: '/user/notifications/read-all/',
success: function success(data) {
if (data.success == true) {
print_notifications(0);
}
}
});
});
};
var markNotificationRead = function markNotificationRead(notification_id, $notification) {

View File

@@ -19402,6 +19402,19 @@ var notifyLayout = function notifyLayout(services) {
}
}
});
$notificationDialog.on('click', '.mark-all-read', function (event) {
event.preventDefault();
_jquery2.default.ajax({
type: 'POST',
url: '/user/notifications/read-all/',
success: function success(data) {
if (data.success == true) {
print_notifications(0);
}
}
});
});
};
var markNotificationRead = function markNotificationRead(notification_id, $notification) {

View File

@@ -209,6 +209,20 @@ const notifyLayout = (services) => {
}
}
});
$notificationDialog.on('click', '.mark-all-read', function(event) {
event.preventDefault();
$.ajax({
type: 'POST',
url: '/user/notifications/read-all/',
success: function (data) {
if (data.success == true) {
print_notifications(0);
}
}
});
});
};
const markNotificationRead = (notification_id, $notification) => {

View File

@@ -159,6 +159,27 @@ class UserNotificationController extends Controller
}
}
/**
* mark all notification as read
*
* @param Request $request
* @return JsonResponse
*/
public function readAllNotification(Request $request)
{
if (!$request->isXmlHttpRequest()) {
$this->app->abort(400);
}
try {
$this->getEventsManager()->readAll($this->getAuthenticatedUser()->getId());
return $this->app->json(['success' => true, 'message' => '']);
}
catch (\Exception $e) {
return $this->app->json(['success' => false, 'message' => $e->getMessage()]);
}
}
/**
* Get all notifications

View File

@@ -58,6 +58,10 @@ class Notifications implements ControllerProviderInterface, ServiceProviderInter
->assert('notification_id', '\d+')
->bind('set_notifications_readed');
/** @uses UserNotificationController::readAllNotification() */
$controllers->post('/read-all/', 'controller.user.notifications:readAllNotification')
->bind('set_all_notifications_readed');
/*
/** @uses UserNotificationController::listNotifications * /
$controllers->get('/', 'controller.user.notifications:getNotifications')

View File

@@ -59,7 +59,7 @@ class PhraseanetExtension extends \Twig_Extension
{
return [
// change this version when you change JS file to force the navigation to reload js file
'assetFileVersion' => 38
'assetFileVersion' => 39
];
}

View File

@@ -389,6 +389,36 @@ class eventsmanager_broker
return $this;
}
/**
* mark all user notification as read
* @param $usr_id
* @return $this
*/
public function readAll($usr_id)
{
/** @var Connection $connection */
$connection = $this->app->getApplicationBox()->get_connection();
$builder = $connection->createQueryBuilder();
$builder
->update('notifications')
->set('unread', '0')
->where(
$builder->expr()->eq('usr_id', ':usr_id')
)
->setParameters(
[
'usr_id' => $usr_id,
],
[
'usr_id' => PDO::PARAM_INT,
]
)
->execute()
;
return $this;
}
public function list_notifications_available(User $user)
{
$personal_notifications = [];

View File

@@ -1,5 +1,8 @@
{# css from resources/www/_shared/styles/_notification.scss #}
<div id="notifications-dialog" style="display: none">
<div>
<a href="#" class="mark-all-read" style="cursor: pointer;">{{'notification:: mark all notification as read' | trans}}</a>
</div>
<div class="notifications">
</div>
<div class="navigation">