mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-12 04:23:19 +00:00
PHRAS-3442_optimize-list-notifications_4.1-bis
WIP mark notif as read fix test
This commit is contained in:
65
Phraseanet-production-client/dist/production.js
vendored
65
Phraseanet-production-client/dist/production.js
vendored
@@ -18905,8 +18905,8 @@ var notifyLayout = function notifyLayout(services) {
|
||||
var $notificationBoxContainer = (0, _jquery2.default)('#notification_box');
|
||||
var $notificationTrigger = (0, _jquery2.default)('.notification_trigger');
|
||||
var $notificationDialog = (0, _jquery2.default)('#notifications-dialog');
|
||||
var $notifications = null;
|
||||
var $navigation = null;
|
||||
var $notifications = (0, _jquery2.default)('.notifications', $notificationDialog);
|
||||
var $navigation = (0, _jquery2.default)('.navigation', $notificationDialog);
|
||||
|
||||
var initialize = function initialize() {
|
||||
/**
|
||||
@@ -19020,15 +19020,6 @@ var notifyLayout = function notifyLayout(services) {
|
||||
$notificationDialog.dialog('close');
|
||||
};
|
||||
|
||||
// create the dlg div if it does not exists
|
||||
//
|
||||
// if ($notificationDialog.length === 0) {
|
||||
// $('body').append('<div id="notifications-dialog"><div class="content"></div><div class="navigation"></div></div>');
|
||||
// $notificationDialog = $('#notifications-dialog');
|
||||
$notifications = (0, _jquery2.default)('.notifications', $notificationDialog);
|
||||
$navigation = (0, _jquery2.default)('.navigation', $notificationDialog);
|
||||
// }
|
||||
|
||||
// open the dlg (even if it is already opened when "load more")
|
||||
//
|
||||
$notificationDialog.dialog({
|
||||
@@ -19076,7 +19067,8 @@ var notifyLayout = function notifyLayout(services) {
|
||||
|
||||
var notifications = data.notifications.notifications;
|
||||
var i = 0;
|
||||
for (i in notifications) {
|
||||
|
||||
var _loop = function _loop() {
|
||||
var notification = notifications[i];
|
||||
|
||||
// group notifs by day
|
||||
@@ -19093,6 +19085,13 @@ var notifyLayout = function notifyLayout(services) {
|
||||
|
||||
// add pre-formatted notif
|
||||
date_cont.append(notification.html);
|
||||
(0, _jquery2.default)('.notification_' + notification.id + '_unread', $notifications).tooltip().click(function () {
|
||||
mark_read(notification.id);
|
||||
});
|
||||
};
|
||||
|
||||
for (i in notifications) {
|
||||
_loop();
|
||||
}
|
||||
|
||||
// handle "show more" button
|
||||
@@ -19109,51 +19108,35 @@ var notifyLayout = function notifyLayout(services) {
|
||||
// no more ? no button
|
||||
$navigation.hide();
|
||||
}
|
||||
/*
|
||||
if (data.notifications.next_page_html) {
|
||||
$navigation
|
||||
.off('click', '.notification__print-action');
|
||||
$navigation.empty().show().append(data.notifications.next_page_html);
|
||||
$navigation
|
||||
.on('click', '.notification__print-action', function (event) {
|
||||
event.preventDefault();
|
||||
let $el = $(event.currentTarget);
|
||||
let offset = $el.data('offset');
|
||||
print_notifications(offset);
|
||||
});
|
||||
}
|
||||
else {
|
||||
$navigation.empty().hide();
|
||||
}
|
||||
*/
|
||||
}
|
||||
});
|
||||
};
|
||||
/* remove in favor of existing /session/ route
|
||||
const read_notifications = () => {
|
||||
var notifications = [];
|
||||
$('#notification_box .unread').each(function () {
|
||||
notifications.push($(this).attr('id').split('_').pop());
|
||||
});
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/user/notifications/read/',
|
||||
|
||||
var mark_read = function mark_read(notification_id) {
|
||||
_jquery2.default.ajax({
|
||||
type: 'PATCH',
|
||||
url: '/user/notifications/' + notification_id + '/',
|
||||
data: {
|
||||
notifications: notifications.join('_')
|
||||
'read': 1
|
||||
},
|
||||
success: function (data) {
|
||||
$('.notification_trigger .counter').css('visibility', 'hidden').empty();
|
||||
success: function success(data) {
|
||||
(0, _jquery2.default)('.notification_' + notification_id + '_unread', $notifications).hide();
|
||||
(0, _jquery2.default)('.notification_' + notification_id + '_read', $notifications).show();
|
||||
}
|
||||
});
|
||||
};
|
||||
/*
|
||||
const clear_notifications = () => {
|
||||
var unread = $('#notification_box .unread');
|
||||
|
||||
if (unread.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
unread.removeClass('unread');
|
||||
$('.notification_trigger .counter').css('visibility', 'hidden').empty();
|
||||
};
|
||||
|
||||
*/
|
||||
|
||||
return {
|
||||
|
@@ -18905,8 +18905,8 @@ var notifyLayout = function notifyLayout(services) {
|
||||
var $notificationBoxContainer = (0, _jquery2.default)('#notification_box');
|
||||
var $notificationTrigger = (0, _jquery2.default)('.notification_trigger');
|
||||
var $notificationDialog = (0, _jquery2.default)('#notifications-dialog');
|
||||
var $notifications = null;
|
||||
var $navigation = null;
|
||||
var $notifications = (0, _jquery2.default)('.notifications', $notificationDialog);
|
||||
var $navigation = (0, _jquery2.default)('.navigation', $notificationDialog);
|
||||
|
||||
var initialize = function initialize() {
|
||||
/**
|
||||
@@ -19020,15 +19020,6 @@ var notifyLayout = function notifyLayout(services) {
|
||||
$notificationDialog.dialog('close');
|
||||
};
|
||||
|
||||
// create the dlg div if it does not exists
|
||||
//
|
||||
// if ($notificationDialog.length === 0) {
|
||||
// $('body').append('<div id="notifications-dialog"><div class="content"></div><div class="navigation"></div></div>');
|
||||
// $notificationDialog = $('#notifications-dialog');
|
||||
$notifications = (0, _jquery2.default)('.notifications', $notificationDialog);
|
||||
$navigation = (0, _jquery2.default)('.navigation', $notificationDialog);
|
||||
// }
|
||||
|
||||
// open the dlg (even if it is already opened when "load more")
|
||||
//
|
||||
$notificationDialog.dialog({
|
||||
@@ -19076,7 +19067,8 @@ var notifyLayout = function notifyLayout(services) {
|
||||
|
||||
var notifications = data.notifications.notifications;
|
||||
var i = 0;
|
||||
for (i in notifications) {
|
||||
|
||||
var _loop = function _loop() {
|
||||
var notification = notifications[i];
|
||||
|
||||
// group notifs by day
|
||||
@@ -19093,6 +19085,13 @@ var notifyLayout = function notifyLayout(services) {
|
||||
|
||||
// add pre-formatted notif
|
||||
date_cont.append(notification.html);
|
||||
(0, _jquery2.default)('.notification_' + notification.id + '_unread', $notifications).tooltip().click(function () {
|
||||
mark_read(notification.id);
|
||||
});
|
||||
};
|
||||
|
||||
for (i in notifications) {
|
||||
_loop();
|
||||
}
|
||||
|
||||
// handle "show more" button
|
||||
@@ -19109,51 +19108,35 @@ var notifyLayout = function notifyLayout(services) {
|
||||
// no more ? no button
|
||||
$navigation.hide();
|
||||
}
|
||||
/*
|
||||
if (data.notifications.next_page_html) {
|
||||
$navigation
|
||||
.off('click', '.notification__print-action');
|
||||
$navigation.empty().show().append(data.notifications.next_page_html);
|
||||
$navigation
|
||||
.on('click', '.notification__print-action', function (event) {
|
||||
event.preventDefault();
|
||||
let $el = $(event.currentTarget);
|
||||
let offset = $el.data('offset');
|
||||
print_notifications(offset);
|
||||
});
|
||||
}
|
||||
else {
|
||||
$navigation.empty().hide();
|
||||
}
|
||||
*/
|
||||
}
|
||||
});
|
||||
};
|
||||
/* remove in favor of existing /session/ route
|
||||
const read_notifications = () => {
|
||||
var notifications = [];
|
||||
$('#notification_box .unread').each(function () {
|
||||
notifications.push($(this).attr('id').split('_').pop());
|
||||
});
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/user/notifications/read/',
|
||||
|
||||
var mark_read = function mark_read(notification_id) {
|
||||
_jquery2.default.ajax({
|
||||
type: 'PATCH',
|
||||
url: '/user/notifications/' + notification_id + '/',
|
||||
data: {
|
||||
notifications: notifications.join('_')
|
||||
'read': 1
|
||||
},
|
||||
success: function (data) {
|
||||
$('.notification_trigger .counter').css('visibility', 'hidden').empty();
|
||||
success: function success(data) {
|
||||
(0, _jquery2.default)('.notification_' + notification_id + '_unread', $notifications).hide();
|
||||
(0, _jquery2.default)('.notification_' + notification_id + '_read', $notifications).show();
|
||||
}
|
||||
});
|
||||
};
|
||||
/*
|
||||
const clear_notifications = () => {
|
||||
var unread = $('#notification_box .unread');
|
||||
|
||||
if (unread.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
unread.removeClass('unread');
|
||||
$('.notification_trigger .counter').css('visibility', 'hidden').empty();
|
||||
};
|
||||
|
||||
*/
|
||||
|
||||
return {
|
||||
|
@@ -194,6 +194,10 @@ const notifyLayout = (services) => {
|
||||
|
||||
// add pre-formatted notif
|
||||
date_cont.append(notification.html);
|
||||
$('.notification_' + notification.id + '_unread', $notifications).tooltip().click(
|
||||
function () {
|
||||
mark_read(notification.id);
|
||||
});
|
||||
}
|
||||
|
||||
// handle "show more" button
|
||||
@@ -216,26 +220,21 @@ const notifyLayout = (services) => {
|
||||
}
|
||||
});
|
||||
};
|
||||
/* remove in favor of existing /session/ route
|
||||
const read_notifications = () => {
|
||||
var notifications = [];
|
||||
|
||||
$('#notification_box .unread').each(function () {
|
||||
notifications.push($(this).attr('id').split('_').pop());
|
||||
});
|
||||
|
||||
const mark_read = (notification_id) => {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/user/notifications/read/',
|
||||
type: 'PATCH',
|
||||
url: '/user/notifications/' + notification_id + '/',
|
||||
data: {
|
||||
notifications: notifications.join('_')
|
||||
'read': 1
|
||||
},
|
||||
success: function (data) {
|
||||
$('.notification_trigger .counter').css('visibility', 'hidden').empty();
|
||||
$('.notification_' + notification_id + '_unread', $notifications).hide();
|
||||
$('.notification_' + notification_id + '_read', $notifications).show();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
const clear_notifications = () => {
|
||||
var unread = $('#notification_box .unread');
|
||||
|
||||
|
@@ -130,37 +130,35 @@ class UserNotificationController extends Controller
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Set notifications as read
|
||||
* patch a notification
|
||||
* for now the only usefull thing is to mark it as "read"
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
/* remove in favor of existing /session/ route
|
||||
public function readNotifications(Request $request)
|
||||
public function patchNotification(Request $request, $notification_id)
|
||||
{
|
||||
if (!$request->isXmlHttpRequest()) {
|
||||
$this->app->abort(400);
|
||||
}
|
||||
|
||||
if($request->get('read', '0') === '1') {
|
||||
// mark as read
|
||||
try {
|
||||
$this->getEventsManager()->read(
|
||||
explode('_', (string) $request->request->get('notifications')),
|
||||
[$notification_id],
|
||||
$this->getAuthenticatedUser()->getId()
|
||||
);
|
||||
|
||||
return $this->app->json(['success' => true, 'message' => '']);
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
return $this->app->json(['success' => false, 'message' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all notifications
|
||||
|
@@ -54,8 +54,11 @@ class Notifications implements ControllerProviderInterface, ServiceProviderInter
|
||||
// ->bind('get_notifications')
|
||||
;
|
||||
|
||||
/* todo : re-implement "read" route
|
||||
*
|
||||
$controllers->patch('/{notification_id}/', 'controller.user.notifications:patchNotification')
|
||||
->assert('notification_id', '\d+')
|
||||
->bind('set_notifications_readed');
|
||||
|
||||
/*
|
||||
/** @uses UserNotificationController::listNotifications * /
|
||||
$controllers->get('/', 'controller.user.notifications:getNotifications')
|
||||
->bind('get_notifications');
|
||||
|
@@ -233,8 +233,16 @@ class eventsmanager_broker
|
||||
// delete old already read notifs (nb: we do this for everybody - not only the current user -)
|
||||
// todo: for now we use "created_on" since there is no timestamp set when reading.
|
||||
//
|
||||
|
||||
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
// do restore : for testing we do not yet delete
|
||||
|
||||
$sql = "DELETE FROM `notifications` WHERE `unread`=0 AND TIMESTAMPDIFF(HOUR, `created_on`, NOW()) > 10";
|
||||
$this->app->getApplicationBox()->get_connection()->exec($sql);
|
||||
// $this->app->getApplicationBox()->get_connection()->exec($sql);
|
||||
|
||||
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
// get count of unread notifications (to be displayed on navbar)
|
||||
//
|
||||
|
@@ -135,8 +135,16 @@ var commonModule = (function ($, p4) {
|
||||
}
|
||||
else {
|
||||
$('.no_notifications', $box).hide();
|
||||
for (n in data.notifications.notifications) {
|
||||
$box_notifications.append(data.notifications.notifications[n].html);
|
||||
for (var n in data.notifications.notifications) {
|
||||
var notification = data.notifications.notifications[n];
|
||||
$box_notifications.append(notification.html);
|
||||
|
||||
$('.notification_' + notification.id + '_read', $box_notifications).click(
|
||||
function (event) {
|
||||
console.log("++++++++++ clicked("+notification.id+")")
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
$('.show_all', $box).show();
|
||||
}
|
||||
|
@@ -64,7 +64,7 @@
|
||||
{#<script type="text/javascript" src="{{ path('minifier', { 'f' : '/assets/requirejs/require.js,/scripts/apps/admin/require.config.js,/scripts/apps/admin/main/main.js' }) }}"></script>#}
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
<div id="admin-app" data-usr="{{ app.getAuthenticatedUser().getId() }}" data-notif-url="{{ path('list_notifications') }}">
|
||||
<div id="admin-app" data-usr="{{ app.getAuthenticatedUser().getId() }}">
|
||||
<div id="left" class="PNB left-view" style="width:250px;right:auto;" data-tree-url="{{ path("admin_display_tree") }}" data-websocket="{{ "ws://" ~ app["conf"].get(["main" ,"websocket-server", "host"]) ~ ":" ~ app["conf"].get(["main" ,"websocket-server", "port"]) ~ "/websockets" }}">
|
||||
<div class="PNB10" style="right:0; top:0px;">
|
||||
<div id="FNDR">
|
||||
|
@@ -1,4 +1,4 @@
|
||||
<div style="position:relative;" id="notification_{{notification['id']}}" class="notification {% if notification['unread'] == '1' %}unread{% endif %}">
|
||||
<div style="position:relative;" class="notification {% if notification['unread'] == '1' %}unread{% endif %}">
|
||||
<table style="width:100%;" cellspacing="0" cellpadding="0" border="0">
|
||||
<tr style="border-top: 1px grey solid">
|
||||
<td style="width:25px; vertical-align: top;">
|
||||
@@ -10,6 +10,10 @@
|
||||
<span class="time">{{notification['created_on']}}</span>
|
||||
</p>
|
||||
</td>
|
||||
<td style="width:25px; vertical-align: bottom;">
|
||||
<span class="notification_{{notification['id']}}_read" title="{{ 'notification::read:tooltip' | trans }}" style="display: {{ notification['unread'] == '1' ? 'none' : 'inherit' }}">✅</span>
|
||||
<span class="notification_{{notification['id']}}_unread" title="{{ 'notification::unread:tooltip' | trans }}" style="cursor: pointer; display: {{ notification['unread'] == '1' ? 'inherit' : 'none' }}">👁</span>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace Alchemy\Tests\Phrasea\Core\Event\Subscriber;
|
||||
|
||||
use Alchemy\Phrasea\Core\Event\Subscriber\SessionManagerSubscriber;
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Core\Event\Subscriber\SessionManagerSubscriber;
|
||||
use Alchemy\Phrasea\Model\Entities\Session;
|
||||
use Symfony\Component\HttpKernel\Client;
|
||||
|
||||
@@ -235,10 +235,6 @@ class SessionManagerSubscriberTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$app['orm.em'] = $this->getMockBuilder('Doctrine\ORM\EntityManager')->disableOriginalConstructor()->getMock();
|
||||
$app['orm.em']->expects($this->never())->method('flush');
|
||||
|
||||
$app->get('/login', function () {
|
||||
return '';
|
||||
})->bind("homepage");
|
||||
|
||||
$app->get($route, function () {
|
||||
return '';
|
||||
});
|
||||
@@ -254,8 +250,43 @@ class SessionManagerSubscriberTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
public function forbiddenRouteProvider()
|
||||
{
|
||||
return [
|
||||
['/admin/databox/17/informations/documents/'],
|
||||
['/'],
|
||||
['/login/'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider notUserActivityRouteProvider
|
||||
*/
|
||||
public function testNotUserActivityRoutes($route)
|
||||
{
|
||||
$app = new Application(Application::ENV_TEST);
|
||||
$app['dispatcher']->addSubscriber(new SessionManagerSubscriber($app));
|
||||
$app['authentication'] = $this->getMockBuilder('Alchemy\Phrasea\Authentication\Authenticator')->disableOriginalConstructor()->getMock();
|
||||
$app['authentication']->expects($this->once())->method('isAuthenticated');
|
||||
|
||||
$app['orm.em'] = $this->getMockBuilder('Doctrine\ORM\EntityManager')->disableOriginalConstructor()->getMock();
|
||||
$app['orm.em']->expects($this->never())->method('flush');
|
||||
|
||||
$app->get($route, function () {
|
||||
return '';
|
||||
});
|
||||
|
||||
$client = new Client($app);
|
||||
$client->request('GET', $route, [], [], [
|
||||
'HTTP_CONTENT-TYPE' => 'application/json',
|
||||
'HTTP_ACCEPT' => 'application/json',
|
||||
'HTTP_X-Requested-With' => 'XMLHttpRequest',
|
||||
]);
|
||||
}
|
||||
|
||||
public function notUserActivityRouteProvider()
|
||||
{
|
||||
return [
|
||||
['/session/'],
|
||||
['/user/'],
|
||||
['/admin/task-manager/tasks/'],
|
||||
['/admin/databox/17/informations/documents/']
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user