Skip to content

Commit

Permalink
platform notifications working closes #1050
Browse files Browse the repository at this point in the history
  • Loading branch information
ppazos committed Oct 13, 2019
1 parent f94a59b commit 6d21eb4
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 57 deletions.
Binary file modified .gradle/3.5/fileContent/fileContent.lock
Binary file not shown.
Binary file modified .gradle/3.5/taskHistory/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/3.5/taskHistory/fileSnapshots.bin
Binary file not shown.
Binary file modified .gradle/3.5/taskHistory/taskHistory.bin
Binary file not shown.
Binary file modified .gradle/3.5/taskHistory/taskHistory.lock
Binary file not shown.
97 changes: 49 additions & 48 deletions grails-app/assets/javascripts/notification.js
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" );
});
}
1 change: 1 addition & 0 deletions grails-app/conf/logback.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ logger("com.cabolabs.security.stateless", DEBUG)
logger("com.cabolabs.ehrserver.i18n", DEBUG)
logger("com.cabolabs.ehrserver.indexing", INFO)
logger("com.cabolabs.ehrserver.account", INFO)
logger("com.cabolabs.ehrserver.notification", INFO)
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class NotificationController {

// List<NotificationStatus>
def notifications = Notification.lastNotifications(forSection, session.organization.uid, loggedInUser.uid, session.lang)
notifications = notifications.collect{ [status: it.status, notification: [text: it.notification.text, dateCreated: it.notification.dateCreated, id: it.notification.id]] }
notifications = notifications.collect{ [status: it.status, notification: [text: it.notification.text, timestamp: it.notification.timestamp, id: it.notification.id]] }
render (contentType: "application/json", text: notifications as JSON, encoding:"UTF-8")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ class AuthController {
def notifications = remoteNotificationsService.getNotifications('ehrserver', session.lang, from)

notifications.each { notification ->
new Notification(name:'remote', language:session.lang, text:notification.nt, forUser:User.findByEmail(email).id).save()
new Notification(
name: 'remote',
language: session.lang,
text: notification.nt,
forUser: User.findByEmail(email).id,
timestamp: Date.parse("yyyy-MM-dd'T'HH:mm:ss'Z'", notification.ts)
).save()
}

// Mark current read of the remote notifications
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Notification {
String forOrganization
String forUser // user.uid

Date dateCreated
Date timestamp = new Date()

boolean sent = false // used by the job that creates the notification statuses

Expand All @@ -53,8 +53,14 @@ class Notification {
}
if (forUser)
{
user {
eq('uid', forUser)
or
{
user {
eq('uid', forUser)
}
notification {
isNull('forUser')
}
}
}
if (forOrganization) // forOrganization alwas comes, but it should match also when it is null on the notification
Expand All @@ -81,7 +87,7 @@ class Notification {
}
maxResults(last)
notification {
order("dateCreated", "desc")
order("timestamp", "desc")
}
}

Expand All @@ -98,8 +104,14 @@ class Notification {
}
if (forUser)
{
user {
eq('uid', forUser)
or
{
user {
eq('uid', forUser)
}
notification {
isNull('forUser')
}
}
}
if (forOrganization) // forOrganization alwas comes, but it should match also when it is null on the notification
Expand Down
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)
}
}
}
2 changes: 1 addition & 1 deletion grails-app/views/notification/index.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<g:sortableColumn property="forSection" title="${message(code: 'notification.forSection.label', default: 'For Section')}" />
<g:sortableColumn property="forOrganization" title="${message(code: 'notification.forOrganization.label', default: 'For Organization')}" />
<g:sortableColumn property="forUser" title="${message(code: 'notification.forUser.label', default: 'For User')}" />
<g:sortableColumn property="dateCreated" title="${message(code: 'notification.dateCreated.label', default: 'Date Created')}" />
<g:sortableColumn property="timestamp" title="${message(code: 'notification.timestamp.label', default: 'Date')}" />
<g:sortableColumn property="language" title="${message(code: 'notification.language.label', default: 'Language')}" />
</tr>
</thead>
Expand Down

0 comments on commit 6d21eb4

Please sign in to comment.