Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Always pass an ID for the event (not only alerts), and keep track of …
Browse files Browse the repository at this point in the history
…the last passed ID: triggers desktop notifications if active and possible.
  • Loading branch information
cdujeu committed Jul 22, 2013
1 parent db11178 commit d17f84d
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 4 deletions.
Expand Up @@ -163,6 +163,7 @@ public function loadUserFeed($actionName, $httpVars, $fileVars){
$node->event_description = ucfirst($notif->getDescriptionBlock()) . " ".$mess["notification.tpl.block.user_link"] ." ". $notif->getAuthor();
$node->event_description_long = $notif->getDescriptionLong(true);
$node->event_date = AJXP_Utils::relativeDate($notif->getDate(), $mess);
$node->event_id = $object->event_id;
if($node->getRepository() != null){
$node->repository_id = ''.$node->getRepository()->getId();
if($node->repository_id != $crtRepId && $node->getRepository()->getDisplay() != null){
Expand Down
46 changes: 42 additions & 4 deletions core/src/plugins/core.notifications/class.NotificationLoader.js
Expand Up @@ -26,6 +26,8 @@ Class.create("NotificationLoader", {
pe : null,
menuItems : null,
hasAlerts : false,
lastEventID:null,
lastAlertID:null,

initialize: function(){

Expand Down Expand Up @@ -84,6 +86,8 @@ Class.create("NotificationLoader", {
var parentAjxpNode = this.ajxpNode;
var alertsCounts = 0;
this.hasAlerts = false;
var newNotifs = $A();
var currentLastAlert = 0, currentLastEvent = 0;

this.ajxpNode.getChildren().each(function(el){

Expand All @@ -105,11 +109,13 @@ Class.create("NotificationLoader", {
alerts = true;
}
var block = '<div class="notif_event_label">'+el.getLabel()+'</div>';
var detail = '';
if(el.getMetadata().get('event_repository_label')){
block += '<div class="notif_event_repository">'+ el.getMetadata().get('event_repository_label') + '</div>';
detail += '<div class="notif_event_repository">'+ el.getMetadata().get('event_repository_label') + '</div>';
}
block += '<div class="notif_event_description">'+ el.getMetadata().get('event_description') + '</div>';
block += '<div class="notif_event_date">'+ el.getMetadata().get('event_date') + '</div>';
detail += '<div class="notif_event_description">'+ el.getMetadata().get('event_description') + '</div>';
detail += '<div class="notif_event_date">'+ el.getMetadata().get('event_date') + '</div>';
block += detail;
block = '<div class="notif_event_container">'+block+'</div><br style="clear:left;"/>';
var moreActions = $A([{
name:MessageHash["notification_center.6"],
Expand All @@ -119,6 +125,7 @@ Class.create("NotificationLoader", {
}
}]);
if(isAlert){
var alertID = parseInt(el.getMetadata().get("alert_id"));
moreActions.push({
name:MessageHash["notification_center.7"],
icon_class:"icon-remove-sign",
Expand All @@ -131,7 +138,7 @@ Class.create("NotificationLoader", {
};
var params = {
get_action:'dismiss_user_alert',
alert_id:el.getMetadata().get("alert_id")
alert_id:alertID
};
if(el.getMetadata().get("event_occurence")){
params.occurrences = el.getMetadata().get("event_occurence");
Expand All @@ -140,7 +147,25 @@ Class.create("NotificationLoader", {
conn.sendAsync();
}
});
if(this.lastAlertID && alertID > this.lastAlertID ){
newNotifs.push({
title:el.getLabel(),
body :detail.stripTags()
});
}
currentLastAlert = Math.max(alertID, currentLastAlert);
}else{
var eventID = parseInt(el.getMetadata().get("event_id"));
if(this.lastEventID && eventID > this.lastEventID ){
newNotifs.push({
title:el.getLabel(),
body :detail.stripTags()
});
}
currentLastEvent = Math.max(eventID, currentLastEvent);
}
this.lastAlertID = currentLastAlert;
this.lastEventID = currentLastEvent;
menuItems.push({
id: "event_" + eventIndex,
name:block,
Expand Down Expand Up @@ -168,6 +193,19 @@ Class.create("NotificationLoader", {
badge.hide();
}
}
if(window.Notification && newNotifs.size()){
newNotifs.each(function(obje){
new Notification(
obje.title,
{
body: obje.body,
icon: 'plugins/gui.ajax/res/themes/vision/images/mimes/64/mime_empty.png',
tag: 'ajaxplorer',
dir: 'auto',
lang: ajaxplorer.currentLanguage
});
});
}
return menuItems;
},

Expand Down
21 changes: 21 additions & 0 deletions core/src/plugins/core.notifications/manifest.xml
Expand Up @@ -14,6 +14,7 @@
</resources>
</client_settings>
<server_settings>
<param name="activate_notifications" scope="user" description="Activate desktop notifications" label="Desktop Notifications" type="button" choices="run_client_action:activateDesktopNotifications" expose="true" editable="true"/>
<global_param description="CONF_MESSAGE[Display a new entry with all events happening on a user workspaces, and alerts. An SQL database must be setup for the FEED_DRIVER configuration.]" label="CONF_MESSAGE[User events and alerts]" name="USER_EVENTS" type="boolean" default="false"/>
<global_param type="plugin_instance:feed" name="UNIQUE_FEED_INSTANCE" group="CONF_MESSAGE[Instance Params]" label="CONF_MESSAGE[Feed Instance]" description="CONF_MESSAGE[Choose the plugin]" mandatory="true" default="feed.sql"/>
</server_settings>
Expand Down Expand Up @@ -48,10 +49,30 @@
<action name="dismiss_user_alert">
<processing><serverCallback methodName="dismissUserAlert"/></processing>
</action>
<action name="activateDesktopNotifications">
<gui src="" iconClass="icon-rss" text="notification_center.1" title="notification_title.2">
<context dir="true" recycle="true" selection="false"/>
</gui>
<processing>
<clientCallback><![CDATA[
if(window.Notification){
alert('Depending on your browser, this will ask for a specific permission. To disable, go through your browser preferences and exceptions. If you have already enabled this feature, probably nothing will hapen.');
window.Notification.requestPermission(function(grant) {
['default', 'granted', 'denied'].indexOf(grant) === true
});
}else{
alert('Your browser does not seem to support Desktop Notifications yet.');
}
]]></clientCallback>
</processing>
</action>
</actions>
<hooks>
<serverCallback methodName="persistChangeHookToFeed" hookName="node.change" defer="true"/>
<serverCallback methodName="persistNotificationToAlerts" hookName="msg.notification"/>
</hooks>
</registry_contributions>
<dependencies>
<activePlugin pluginName="core.conf"/>
</dependencies>
</ajxp_plugin>
1 change: 1 addition & 0 deletions core/src/plugins/feed.sql/class.AJXP_SqlFeedStore.php
Expand Up @@ -95,6 +95,7 @@ public function loadEvents($filterByRepositories, $userId, $userGroup, $offset =
$object->author = $row->user_id;
$object->date = $row->edate;
$object->repository = $row->repository_id;
$object->event_id = $row->id;
$data[] = $object;
}
return $data;
Expand Down

0 comments on commit d17f84d

Please sign in to comment.