From 9429e49cf829d40a3afc6ef8ee45d7da0bc316f5 Mon Sep 17 00:00:00 2001 From: Henrique Santos Date: Fri, 22 Jan 2016 18:08:39 -0200 Subject: [PATCH] finishing frontend --- .../NotificationsController.coffee | 4 +++ .../Notifications/NotificationsHandler.coffee | 2 +- .../Features/Project/ProjectController.coffee | 4 ++- services/web/app/views/project/list.jade | 3 +- .../app/views/project/list/notifications.jade | 35 ++++++++++--------- .../notifications-controller.coffee | 14 +++++++- .../NotificationsControllerTests.coffee | 4 +++ .../Project/ProjectControllerTests.coffee | 2 ++ 8 files changed, 47 insertions(+), 21 deletions(-) diff --git a/services/web/app/coffee/Features/Notifications/NotificationsController.coffee b/services/web/app/coffee/Features/Notifications/NotificationsController.coffee index 7137dfa986..c4931f5327 100644 --- a/services/web/app/coffee/Features/Notifications/NotificationsController.coffee +++ b/services/web/app/coffee/Features/Notifications/NotificationsController.coffee @@ -1,10 +1,14 @@ NotificationsHandler = require("./NotificationsHandler") logger = require("logger-sharelatex") +_ = require("underscore") module.exports = getAllUnreadNotifications: (req, res)-> NotificationsHandler.getUserNotifications req.session.user._id, (err, unreadNotifications)-> + unreadNotifications = _.map unreadNotifications, (notification)-> + notification.html = req.i18n.translate(notification.templateKey, notification.messageOpts) + return notification res.send(unreadNotifications) markNotificationAsRead: (req, res)-> diff --git a/services/web/app/coffee/Features/Notifications/NotificationsHandler.coffee b/services/web/app/coffee/Features/Notifications/NotificationsHandler.coffee index 1cf11af1f9..b54fd95b3f 100644 --- a/services/web/app/coffee/Features/Notifications/NotificationsHandler.coffee +++ b/services/web/app/coffee/Features/Notifications/NotificationsHandler.coffee @@ -15,7 +15,7 @@ module.exports = if err? or statusCode != 200 e = new Error("something went wrong getting notifications, #{err}, #{statusCode}") logger.err err:err - callback(e, []) + callback(null, []) else if !unreadNotifications? unreadNotifications = [] diff --git a/services/web/app/coffee/Features/Project/ProjectController.coffee b/services/web/app/coffee/Features/Project/ProjectController.coffee index a1b1f9b61d..379cb6ef74 100644 --- a/services/web/app/coffee/Features/Project/ProjectController.coffee +++ b/services/web/app/coffee/Features/Project/ProjectController.coffee @@ -142,7 +142,9 @@ module.exports = ProjectController = return next(err) logger.log results:results, user_id:user_id, "rendering project list" tags = results.tags[0] - notifications = results.notifications + notifications = require("underscore").map results.notifications, (notification)-> + notification.html = req.i18n.translate(notification.templateKey, notification.messageOpts) + return notification projects = ProjectController._buildProjectList results.projects[0], results.projects[1], results.projects[2] user = results.user ProjectController._injectProjectOwners projects, (error, projects) -> diff --git a/services/web/app/views/project/list.jade b/services/web/app/views/project/list.jade index cc8e472dd1..08260219e3 100644 --- a/services/web/app/views/project/list.jade +++ b/services/web/app/views/project/list.jade @@ -20,8 +20,9 @@ block content }; .content.content-alt(ng-controller="ProjectPageController") - include ./list/notifications .container + .row(ng-cloak) + include ./list/notifications .row(ng-cloak) span(ng-show="first_sign_up == 'default' || projects.length > 0") aside.col-md-2.col-xs-3 diff --git a/services/web/app/views/project/list/notifications.jade b/services/web/app/views/project/list/notifications.jade index e68198edb6..531d02328e 100644 --- a/services/web/app/views/project/list/notifications.jade +++ b/services/web/app/views/project/list/notifications.jade @@ -1,18 +1,19 @@ -.notifications(ng-controller="NotificationsController") - .row.row-spaced - .col-xs-12 - ul.list-unstyled.notifications-list.structured-list( - select-all-list, - ng-if="notifications.length > 0", - ng-cloak - ) - li.notification_entry.container-fluid( - ng-repeat="unreadNotification in notifications", +span(ng-controller="NotificationsController") + aside.col-md-2.col-xs-3 + .col-md-10.col-xs-9 + .row + .col-xs-12(ng-cloak) + ul.list-unstyled.notifications-list( + ng-if="notifications.length > 0", + ng-cloak ) - .row - .col-xs-6 - span {{unreadNotification._id}} - .col-xs-2 - span.owner {{unreadNotification.user_id}} - .col-xs-4 - span.last-modified {{unreadNotification.templateKey}} \ No newline at end of file + li.notification_entry( + ng-repeat="unreadNotification in notifications", + ) + .row(ng-hide="unreadNotification.hide") + .col-xs-12 + .alert.alert-info + span {{unreadNotification.html}} + button(ng-click="dismiss(unreadNotification)").close.pull-right + span(aria-hidden="true") × + span.sr-only #{translate("close")} diff --git a/services/web/public/coffee/main/project-list/notifications-controller.coffee b/services/web/public/coffee/main/project-list/notifications-controller.coffee index 31b76dd2b5..36a725f778 100644 --- a/services/web/public/coffee/main/project-list/notifications-controller.coffee +++ b/services/web/public/coffee/main/project-list/notifications-controller.coffee @@ -2,4 +2,16 @@ define [ "base" ], (App) -> - App.controller "NotificationsController", ($scope) -> \ No newline at end of file + App.controller "NotificationsController", ($scope, $http) -> + for notification in $scope.notifications + notification.hide = false + + $scope.dismiss = (notification) -> + $http({ + url: "/notifications/#{notification._id}" + method: "DELETE" + headers: + "X-Csrf-Token": window.csrfToken + }) + .success (data) -> + notification.hide = true diff --git a/services/web/test/UnitTests/coffee/Notifications/NotificationsControllerTests.coffee b/services/web/test/UnitTests/coffee/Notifications/NotificationsControllerTests.coffee index 9069d8c193..083257e62c 100644 --- a/services/web/test/UnitTests/coffee/Notifications/NotificationsControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/Notifications/NotificationsControllerTests.coffee @@ -15,6 +15,8 @@ describe 'NotificationsController', -> markAsRead: sinon.stub().callsArgWith(2) @controller = SandboxedModule.require modulePath, requires: "./NotificationsHandler":@handler + "underscore":@underscore = + map:(arr)-> return arr 'logger-sharelatex': log:-> err:-> @@ -24,6 +26,8 @@ describe 'NotificationsController', -> session: user: _id:user_id + i18n: + translate:-> it 'should ask the handler for all unread notifications', (done)-> allNotifications = [{_id: notification_id, user_id: user_id}] diff --git a/services/web/test/UnitTests/coffee/Project/ProjectControllerTests.coffee b/services/web/test/UnitTests/coffee/Project/ProjectControllerTests.coffee index 050a61f207..3ecb31ba68 100644 --- a/services/web/test/UnitTests/coffee/Project/ProjectControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/Project/ProjectControllerTests.coffee @@ -81,6 +81,8 @@ describe "ProjectController", -> user: @user body: projectName: @projectName + i18n: + translate:-> @res = locals: jsPath:"js path here"