+
diff --git a/resources/assets/scripts/app/controllers/application.coffee b/resources/assets/scripts/app/controllers/application.coffee
index fc0c3bed..c5e6cf37 100644
--- a/resources/assets/scripts/app/controllers/application.coffee
+++ b/resources/assets/scripts/app/controllers/application.coffee
@@ -36,17 +36,20 @@ module.exports = angular.module('ponyfm').controller "application", [
$scope.menuToggle = () ->
$rootScope.$broadcast('sidebarToggled')
+
+ if $scope.notifActive
+ notifications.markAllAsRead()
+
$scope.notifActive = false
$scope.notifPulloutToggle = () ->
$scope.notifActive = !$scope.notifActive
- # Disabled for now
- # if $scope.notifActive
- # notifications.markAllAsRead()
+ if !$scope.notifActive
+ notifications.markAllAsRead()
$rootScope.$on 'notificationsUpdated', () ->
- $scope.nCount = notifications.getNotificationCount()
+ $scope.nCount = notifications.getUnreadCount()
if $scope.nCount > 99
$scope.nCountFormatted = '99+'
else
@@ -89,6 +92,8 @@ module.exports = angular.module('ponyfm').controller "application", [
statesPreloaded = {}
$scope.$on '$stateChangeStart', (e, newState, newParams, oldState, oldParams) ->
$rootScope.$broadcast('sidebarHide')
+ if $scope.notifActive
+ notifications.markAllAsRead()
$scope.notifActive = false
$scope.isPinnedPlaylistSelected = false
diff --git a/resources/assets/scripts/app/directives/notification-list.coffee b/resources/assets/scripts/app/directives/notification-list.coffee
index 411d774f..63abd0d8 100644
--- a/resources/assets/scripts/app/directives/notification-list.coffee
+++ b/resources/assets/scripts/app/directives/notification-list.coffee
@@ -21,24 +21,28 @@ module.exports = angular.module('ponyfm').directive 'pfmNotificationList', () ->
scope: {}
controller: [
- '$scope', 'notifications', '$timeout'
- ($scope, notifications, $timeout) ->
+ '$scope', 'notifications', '$timeout', '$rootScope'
+ ($scope, notifications, $timeout, $rootScope) ->
$scope.notifications = []
isTimeoutScheduled = false
# TODO: ADD REFRESH BUTTON
+ $rootScope.$on 'shouldUpdateNotifications', () ->
+ refreshNotifications()
+
refreshNotifications = () ->
notifications.getNotifications().done (result) ->
if $scope.notifications.length > 0
- if result[0].text != $scope.notifications[0].text
+ if result[0].id != $scope.notifications[0].id || result[0].is_read != $scope.notifications[0].is_read
$scope.notifications = result
else if result.length > 0
$scope.notifications = result
$scope.nCount = $scope.notifications.length
-
- scheduleTimeout()
+
+ if !isTimeoutScheduled
+ scheduleTimeout()
scheduleTimeout = () ->
isTimeoutScheduled = true
@@ -47,7 +51,5 @@ module.exports = angular.module('ponyfm').directive 'pfmNotificationList', () ->
isTimeoutScheduled = false
, 60000)
-
-
refreshNotifications()
]
diff --git a/resources/assets/scripts/app/services/notifications.coffee b/resources/assets/scripts/app/services/notifications.coffee
index 03704ca0..7fa2ad8b 100644
--- a/resources/assets/scripts/app/services/notifications.coffee
+++ b/resources/assets/scripts/app/services/notifications.coffee
@@ -32,18 +32,34 @@ module.exports = angular.module('ponyfm').factory('notifications', [
getNotificationCount: () ->
return self.notificationList.length
+
+ getUnreadCount: () ->
+ count = 0
+
+ for n, notifObject of self.notificationList
+ if !notifObject.is_read
+ count++
+
+ return count
markAllAsRead: () ->
+ def = new $.Deferred()
unread = []
for n, notifObject of self.notificationList
if !notifObject.is_read
- unread.push notifObject.id.toString()
+ unread.push notifObject.id
- $http.put('/api/web/notifications/mark-as-read', {notification_ids: unread}).success (response) ->
- console.log response
+ if unread.length > 0
+ $http.put('/api/web/notifications/mark-as-read', {notification_ids: unread}).success (response) ->
+ if response.notifications_updated != 0
+ $rootScope.$broadcast 'shouldUpdateNotifications'
- console.log unread
+ def.resolve response.notifications_updated
+
+ def.promise()
+ else
+ return 0
self
])
diff --git a/resources/assets/styles/content.less b/resources/assets/styles/content.less
index e43cdbfd..d0ec0316 100644
--- a/resources/assets/styles/content.less
+++ b/resources/assets/styles/content.less
@@ -567,6 +567,10 @@ html {
border-radius: 20px;
padding: 0 3px;
display: none;
+
+ &.show {
+ display: block;
+ }
}
}
@@ -575,6 +579,7 @@ html {
margin-bottom: 10px;
background: #fff;
box-shadow: 0 1px 2px rgba(0,0,0,.2);
+ border-radius: 2px;
.img-link {
float: left;
@@ -588,6 +593,10 @@ html {
p {
margin: 0;
}
+
+ &.unread {
+ border: 1px solid #b885bd;
+ }
}
.notification-pullout {
diff --git a/resources/views/shared/_app_layout.blade.php b/resources/views/shared/_app_layout.blade.php
index 15cf1ea7..46f6a07c 100644
--- a/resources/views/shared/_app_layout.blade.php
+++ b/resources/views/shared/_app_layout.blade.php
@@ -68,7 +68,7 @@