-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
platform notifications working closes #1050
- Loading branch information
Showing
12 changed files
with
137 additions
and
57 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,54 @@ | ||
|
||
function notification_get( get_not_url, dismiss_url, forSection ) | ||
{ | ||
$.get( get_not_url, { forSection: forSection }, 'json') | ||
.done(function(data) { | ||
//console.log(data); | ||
|
||
var new_nts_count = data.filter(function(sts) { return sts.status == 'new'; }).length; | ||
|
||
if (new_nts_count > 0) | ||
{ | ||
$('#top-notifications-menu > a').append('<span class="badge badge-notification">'+ new_nts_count +'</span>'); | ||
} | ||
|
||
notifications = ''; | ||
$.each( data, function( i, nstatus ) { | ||
|
||
// TODO: add class="dismissed" to the LIs of notifications that were dismissed | ||
if (nstatus.status == 'new') | ||
$('#top-notifications-menu .drop-content').append('<li><div class="col-md-11">'+ nstatus.notification.text +'<br/><span class="text-muted">'+ nstatus.notification.dateCreated +'</span></div><div class="col-md-1 text-right"><a href="#" class="dismiss" data-id="'+ nstatus.notification.id +'"><i class="fa fa-dot-circle-o"></i></a></div></li>'); | ||
else | ||
$('#top-notifications-menu .drop-content').append('<li class="dismissed"><div class="col-md-11">'+ nstatus.notification.text +'<br/><span class="text-muted">'+ nstatus.notification.dateCreated +'</span></div></li>'); | ||
}); | ||
|
||
|
||
$('.dismiss').on('click', function (evn) { | ||
//console.log('id', $(this).data('id')); | ||
|
||
// dismiss with the new notifications on the menu | ||
var notif_dom = $(this).closest('li'); | ||
|
||
$.get( dismiss_url, { id: $(this).data('id') }, 'json') | ||
.done(function(data) { | ||
console.log(data); | ||
// TODO: update the DOM adding the dismissed class to the LI | ||
console.log(notif_dom); | ||
notif_dom.addClass('dismissed'); | ||
}) | ||
.fail(function() { | ||
//alert( "error" ); | ||
}) | ||
.always(function() { | ||
//alert( "finished" ); | ||
}); | ||
}); | ||
}) | ||
.fail(function() { | ||
//alert( "error" ); | ||
}) | ||
.always(function() { | ||
//alert( "finished" ); | ||
// why are we sending the section if the section is null for remote notifications? | ||
$.get(get_not_url, { forSection: forSection }, 'json') | ||
.done(function(data) { | ||
//console.log(data); | ||
|
||
var new_nts_count = data.filter(function(sts) { return sts.status == 'new'; }).length; | ||
|
||
if (new_nts_count > 0) | ||
{ | ||
$('#top-notifications-menu > a').append('<span class="badge badge-notification">'+ new_nts_count +'</span>'); | ||
} | ||
|
||
notifications = ''; | ||
$.each( data, function( i, nstatus ) { | ||
|
||
// TODO: add class="dismissed" to the LIs of notifications that were dismissed | ||
if (nstatus.status == 'new') | ||
$('#top-notifications-menu .drop-content').append('<li><div class="col-md-11">'+ nstatus.notification.text +'<br/><span class="text-muted">'+ nstatus.notification.timestamp +'</span></div><div class="col-md-1 text-right"><a href="#" class="dismiss" data-id="'+ nstatus.notification.id +'"><i class="fa fa-dot-circle-o"></i></a></div></li>'); | ||
else | ||
$('#top-notifications-menu .drop-content').append('<li class="dismissed"><div class="col-md-11">'+ nstatus.notification.text +'<br/><span class="text-muted">'+ nstatus.notification.timestamp +'</span></div></li>'); | ||
}); | ||
|
||
|
||
$('.dismiss').on('click', function (evn) { | ||
//console.log('id', $(this).data('id')); | ||
|
||
// dismiss with the new notifications on the menu | ||
var notif_dom = $(this).closest('li'); | ||
|
||
$.get( dismiss_url, { id: $(this).data('id') }, 'json') | ||
.done(function(data) { | ||
console.log(data); | ||
// TODO: update the DOM adding the dismissed class to the LI | ||
console.log(notif_dom); | ||
notif_dom.addClass('dismissed'); | ||
}) | ||
.fail(function() { | ||
//alert( "error" ); | ||
}) | ||
.always(function() { | ||
//alert( "finished" ); | ||
}); | ||
}); | ||
}) | ||
.fail(function() { | ||
//alert( "error" ); | ||
}) | ||
.always(function() { | ||
//alert( "finished" ); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
grails-app/jobs/com/cabolabs/ehrserver/notification/NotificationJob.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.cabolabs.ehrserver.notification | ||
|
||
import com.cabolabs.security.User | ||
import com.cabolabs.security.UserRole | ||
|
||
class NotificationJob { | ||
|
||
static concurrent = false | ||
|
||
static triggers = { | ||
simple repeatInterval: 60000l, startDelay: 120000l // execute job once in 5 seconds | ||
} | ||
|
||
def execute() | ||
{ | ||
log.info "Notification Job Executing" | ||
|
||
Notification.findAllBySent(false).each { notificationInstance -> | ||
|
||
//println "send notification "+ notificationInstance.id | ||
|
||
def statuses = [] | ||
if (!notificationInstance.forUser) | ||
{ | ||
def users | ||
if (notificationInstance.forOrganization) | ||
{ | ||
def urs = UserRole.withCriteria { | ||
organization { | ||
eq('uid', notificationInstance.forOrganization) | ||
} | ||
user { | ||
eq('isVirtual', false) | ||
} | ||
} | ||
users = urs.user.unique() // unique avoids the same notif to go to a user that has 2 roles in the same org | ||
} | ||
else | ||
{ | ||
users = User.list() | ||
} | ||
|
||
users.each { user -> | ||
statuses << new NotificationStatus(user:user, notification:notificationInstance) | ||
} | ||
} | ||
else | ||
{ | ||
statuses << new NotificationStatus(user:User.get(notificationInstance.forUser), notification:notificationInstance) | ||
} | ||
|
||
statuses.each { status -> | ||
status.save(failOnError: true) | ||
} | ||
|
||
notificationInstance.sent = true | ||
notificationInstance.save(failOnError: true) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters