finishing frontend

This commit is contained in:
Henrique Santos 2016-01-22 18:08:39 -02:00
parent 25f9bd30b6
commit 9429e49cf8
8 changed files with 47 additions and 21 deletions

View file

@ -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)->

View file

@ -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 = []

View file

@ -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) ->

View file

@ -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

View file

@ -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")}

View file

@ -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

View file

@ -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}]

View file

@ -81,6 +81,8 @@ describe "ProjectController", ->
user: @user
body:
projectName: @projectName
i18n:
translate:->
@res =
locals:
jsPath:"js path here"