Henrique Santos 10 лет назад
Родитель
Сommit
9429e49cf8

+ 4 - 0
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)->

+ 1 - 1
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 = []

+ 3 - 1
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) ->

+ 2 - 1
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

+ 18 - 17
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}}
+					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")}

+ 13 - 1
services/web/public/coffee/main/project-list/notifications-controller.coffee

@@ -2,4 +2,16 @@ define [
 	"base"
 ], (App) ->
 
-	App.controller "NotificationsController", ($scope) ->
+	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

+ 4 - 0
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}]

+ 2 - 0
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"