Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Notify module development #230

Benjamin8ffbe3586114
diff --git a/web/index.html b/web/index.html
index 116225d28..c903bc733 100644
--- a/web/index.html
+++ b/web/index.html
@@ -189,7 +189,7 @@
<!-- link.dev --> <script type="text/javascript" src="js/ui/wv.ui.mouse.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/ui/wv.ui.indicator.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/ui/wv.ui.info.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/notifications/wv.notification.ui.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/notifications/wv.notifications.ui.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/proj/wv.proj.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/proj/wv.proj.change.js"></script>
@@ -267,7 +267,6 @@
</head>
<body>
- <div class="wv-alert" id="wv-alert">
</div>
<div data-role="page" id="app">
<div data-role="content">
diff --git a/web/js/notifications/wv.notifications.ui.js b/web/js/notifications/wv.notifications.ui.js
index 28e32f47e..55a9f2ce3 100644
--- a/web/js/notifications/wv.notifications.ui.js
+++ b/web/js/notifications/wv.notifications.ui.js
@@ -19,16 +19,14 @@ wv.notifications = wv.notifications || {};
*/
wv.notifications.ui = wv.notifications.ui || function(models, url) {
var self = {};
- var mountCase;
var mainNotification;
- var updateAlert;
var mainIcon;
+ var iconCase;
var secondaryNotification;
- var message;
var sortedNotifications;
- var activeNotifications = [];
- var activeMessage;
+ var activeNotifications = {};
+ var activeMessageId;
self.events = wv.util.events();
self.infoIconActive = false;
@@ -36,14 +34,14 @@ wv.notifications.ui = wv.notifications.ui || function(models, url) {
self.messageIconActive = false;
var classes = {
- alert: 'fa-bolt',
- message: 'fa-gift',
- outage: 'fa-exclamation-circle'
+ alert: 'bolt',
+ message: 'gift',
+ outage: 'exclamation-circle'
};
var init = function() {
var reactComponent, options, p, alertUser;
mainIcon = $('#wv-info-button i')[0];
- console.log(url)
+ iconCase = $('#wv-info-button')[0];
p = wv.util.get(url);
p.then(function(response) {
var obj, notifications, alert;
@@ -52,17 +50,7 @@ wv.notifications.ui = wv.notifications.ui || function(models, url) {
notifications = obj.notifications;
sortedNotifications = separateByType(notifications);
setGlobals(sortedNotifications);
-
-
- // Loop through notifications and create react Alert components
- // for(var i = 0, len = notifications.length, item; i < len; i++) {
- // item = notifications[i];
- // alertUser = objectAlreadySeen(item);
- // if(alertUser) {
- // alert = true;
- // }
- // setNotifications(item);
- // }
+ updateMainIcon();
}, function(error) {
console.warn(error);
});
@@ -70,18 +58,20 @@ wv.notifications.ui = wv.notifications.ui || function(models, url) {
var setGlobals = function(sortedNotifications){
var message, outage, alert;
message = sortedNotifications.messages[0];
- outage = sortedNotifications.outage[0];
- alert = sortedNotifications.alert[0];
+ outage = sortedNotifications.outages[0];
+ alert = sortedNotifications.alerts[0];
if(!objectAlreadySeen(message)) {
- mainNotification = 'message'
- activeMessage = message.id;
- } else if(!objectAlreadySeen(alert)) {
+ mainNotification = 'message';
+ activeMessageId = message.id;
+ }
+ if(!objectAlreadySeen(alert)) {
mainNotification = 'alert';
- activeNotifications.push(alert.id);
- } else if(!objectAlreadySeen(outage)) {
+ activeNotifications.alert = alert.id;
+ }
+ if(!objectAlreadySeen(outage)) {
mainNotification = 'outage';
- activeNotifications.push(outage.id);
+ activeNotifications.outage = outage.id;
}
};
@@ -98,28 +88,7 @@ wv.notifications.ui = wv.notifications.ui || function(models, url) {
}
return fieldValueMatches;
};
- var handleAlertsAndOutages = function(arra) {
- };
- var setNotifications = function(obj) {
- var arraLength, message, alert, outage, type;
-
- type = obj.notification_type;
-
- if(type === 'message') {
- updateAlert = true;
- if(!mainNotification) {
- mainNotification = 'message';
- }
-
- } else if(type === 'alert') {
- if(mainNotification !== 'outage') {
- mainNotification = 'alert';
- }
- } else {
- mainNotification = 'outage';
- }
- };
var separateByType = function(obj) {
var messages = [], alerts = [], outages = [], type, subObj;
for(var i = 0, len = obj.length; i < len; i++) {
@@ -150,41 +119,93 @@ wv.notifications.ui = wv.notifications.ui || function(models, url) {
updateMainIcon();
};
var updateMainIcon = function() {
- mainIcon.class = 'fa fa-2x ' + classes[mainNotification];
+ if(mainNotification) {
+ mainIcon.className = 'fa fa-2x fa-' + classes[mainNotification];
+ iconCase.className = 'wv-toolbar-button ' + classes[mainNotification];
+ } else {
+ mainIcon.className = 'fa fa-2x fa-info-circle';
+ iconCase.className = 'wv-toolbar-button';
+ }
};
- self.getMessage = function() {
- if(classes[mainNotification]) {
- return $("<li><a><i class='ui-icon fa fa-fw " + classes[mainNotification] + "'></i>Notifications</a></li>");
+ self.getMessages = function() {
+ var $message;
+ if(activeMessageId) {
+ $message = $("<li class='gift'><a><i class='ui-icon fa fa-fw fa-gift active'></i>Notifications</a></li>");
+ $message.on('click', deactivateMessage);
+ self.messageIconActive = true;
+ return $message;
} else {
- return null;
+ return $("<li><a><i class='ui-icon fa fa-fw fa-gift'></i>What's New</a></li>");
}
};
- self.getMessage = function() {
- var
- };
+
self.getAlert = function() {
var $notifyMenuItem;
- if(classes[mainNotification]) {
- $notifyMenuItem = $("<li><a><i class='ui-icon fa fa-fw active" + classes[mainNotification] + "'></i>Notifications</a></li>");
+ if(!_.isEmpty(activeNotifications)) {
+ $notifyMenuItem = $("<li class='" + classes[mainNotification] + "'><a><i class='ui-icon fa fa-fw active fa-" + classes[mainNotification] + "'></i>Notifications</a></li>");
self.infoIconActive = true;
self.notifyIconActive = true;
- $notifyMenuItem.on('click', deactivateNotify);
+ $notifyMenuItem.on('click', notify);
return $notifyMenuItem;
} else {
$notifyMenuItem = $("<li><a><i class='ui-icon fa fa-fw fa-bolt'></i>Notifications</a></li>");
+ $notifyMenuItem.on('click', notify);
return $notifyMenuItem;
}
};
- var deactivateNotify = function(e) {
+ var deactivateMessage = function(e) {
+ this.className = 'ui-icon fa fa-fw fa-gift';
+ self.messageIconActive = false;
+ wv.util.localStorage('message', activeMessageId);
+ activeMessageId = null;
+ if(mainNotification === 'message') {
+ mainNotification = null;
+ }
+ updateMainIcon();
+ };
+ var notify = function(e) {
this.className = 'ui-icon fa fa-fw fa-bolt';
- self.infoIconActive = true;
- self.notifyIconActive = true;
+ self.infoIconActive = false;
+ self.notifyIconActive = false;
+ mainNotification = null;
+ createNotifyDialog();
+ if(activeNotifications.outage) {
+ wv.util.localStorage('outage', activeNotifications.outage);
+ }
+ if(activeNotifications.alert) {
+ wv.util.localStorage('alert', activeNotifications.alert);
+ }
+ activeNotifications = {};
if(self.messageIconActive) {
- mainNotification = alert;
+ mainNotification = 'message';
}
updateMainIcon();
};
+ var createNotifyDialog = function() {
+ var $dialog;
+ var $notifyContent = $('<div class="wv-notify-modal"></div>');
+
+ $notifyContent.append(create$block(sortedNotifications.outages, 'Outage'));
+ $notifyContent.append(create$block(sortedNotifications.alerts, 'Alert'));
+ $dialog = wv.ui.getDialog().append($notifyContent);
+ $dialog.dialog({
+ title: "Notifications",
+ width: 625,
+ height: 525,
+ show: { effect: "fade" },
+ hide: { effect: "fade" }
+ });
+ };
+ var create$block = function(arra, title) {
+ var $li, $ul = $('<ul></ul>');
+
+ for(var i = 0, len = arra.length; i < len; i++) {
+ $li = $("<li><div><h2>" + title + "</h2><p>" + arra[i].message +"</p></div></li>");
+ $ul.append($li);
+ }
+ return $ul;
+ };
init();
diff --git a/web/js/ui/wv.ui.info.js b/web/js/ui/wv.ui.info.js
index 23f88d6ac..52262dea6 100644
--- a/web/js/ui/wv.ui.info.js
+++ b/web/js/ui/wv.ui.info.js
@@ -47,13 +47,17 @@ wv.ui.info = wv.ui.info || (function(ui, config) {
var show = function() {
var $menu = wv.ui.getMenu().attr("id", "wv-info-menu");
+ var $alerts;
var $menuItems = $("<ul></ul>");
var $feedback = $("<li><a class='feedback'><i class='ui-icon fa fa-envelope fa-fw'></i>Send Feedback</a></li>");
var $tour = $("<li><a><i class='ui-icon fa fa-truck fa-fw'></i>Start Tour</a></li>");
var $new = $("<li><a><i class='ui-icon fa fa-flag fa-fw'></i>What's New</a></li>");
var $about = $("<li><a><i class='ui-icon fa fa-file fa-fw'></i>About</a></li>");
var $source = $("<li><a><i class='ui-icon fa fa-code fa-fw'></i>Source</a></li>");
- var $alerts = ui.alert.getAlert();
+ if(config.features.alert) {
+ $alerts = ui.alert.getAlert();
+ $new = ui.alert.getMessages();
+ }
if ( config.features.feedback ) {
$menuItems.append($feedback);
}
diff --git a/web/js/wv.main.js b/web/js/wv.main.js
index 37e1532d8..22265116e 100644
--- a/web/js/wv.main.js
+++ b/web/js/wv.main.js
@@ -212,7 +212,7 @@ $(function() {
ui.tour = wv.tour(models, ui, config);
ui.info = wv.ui.info(ui, config);
if(config.features.alert){
- ui.alert = wv.notifications.alert(ui, config.features.alert.url);
+ ui.alert = wv.notifications.ui(ui, config.features.alert.url);
}