Interactive interface for browsing global, full-resolution satellite imagery
building alerts module
Benjamina59051308603
diff --git a/web/js/ui/wv.ui.alert.js b/web/js/ui/wv.ui.alert.jsindex eced811e2..4784958d8 100644--- a/web/js/ui/wv.ui.alert.js+++ b/web/js/ui/wv.ui.alert.js@@ -19,45 +19,106 @@ wv.ui = wv.ui || {};*/wv.ui.alert = wv.ui.alert || function(models, url) {var self = {};- var alertReactFactory = React.createFactory(WVC.Alert);- var mountCase;+ var mountCase;+ var mainNotification;+ var updateAlert;+ var mainIcon;+ var secondaryNotification;+ var message;++ var classes = {+ alert: 'fa-bolt',+ message: 'fa-gift',+ outage: 'fa-exclamation-circle'+ };var init = function() {- var notifications, reactComponent, options, p;- mountCase = document.getElementById('wv-alert');+ var reactComponent, options, p, alertUser;+ $mainIcon = $('#wv-info-button i')[0];p = wv.util.get(url);p.then(function(response) {- var obj = JSON.parse(response);+ var obj, notifications, alert;++ alert = false;+ obj = JSON.parse(response);notifications = obj.notifications;// Loop through notifications and create react Alert components- for(var i = 0, len = notifications.length; i < len; i++) {- var mountDiv = createAlertDiv(mountCase, 'wv-alert-case', i);- options = initReactComponent(notifications[i]);- reactComponent = renderReactComponent(options, mountDiv);+ for(var i = 0, len = notifications.length, item; i < len; i++) {+ item = notifications[i];+ alertUser = objectAlreadySeen(item);+ if(alertUser) {+ alert = true;+ }+ setNotifications(item);}}, function(error) {console.warn(error);});- };- var initReactComponent = function(response) {- return {- header: response.notification_type,- content: response.message,- onclose: closeAlert- };};- var createAlertDiv = function(parent, id, index) {- var div = document.createElement('div');- div.id = id + '_' + index;- div.className = id;- parent.appendChild(div);- return div;+ var objectAlreadySeen = function(obj) {+ var fieldExists, fieldValueMatches, type, idString;++ type = obj.notification_type;+ idString = obj.id.toString();+ fieldExists = wv.util.isInLocalStorage(type);+ fieldValueMatches = false;++ if(fieldExists) {+ fieldValueMatches = wv.util.localStorageValueMatches(type, idString);+ }+ return fieldValueMatches;+ };++ 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 setSecondaryIcons = function(obj) {+ var type;++ type = obj.notification_type;++ if(type === 'message') {+ updateAlert = true;+ if(!mainNotification) {+ mainNotification = 'message';+ }++ } else if(type === 'alert') {+ alertUser(obj);+ if(mainNotification !== 'outage') {+ mainNotification = 'alert';+ }+ } else {+ mainNotification = 'outage';+ }+ };+ var initViewAdjusts = function() {+ updateMainIcon();};- var renderReactComponent = function(options, mountLocation) {- console.log(options, mountLocation);- return ReactDOM.render(alertReactFactory(options), mountLocation);+ var updateMainIcon = function() {+ mainIcon.class = 'fa fa-2x ' + classes[mainNotification];};- var closeAlert = function(e) {- console.log(e);+ self.getAlert = function() {+ if(classes[mainNotification]) {+ return $("<li><a><i class='ui-icon fa fa-fw " + classes[mainNotification] + "'></i>Notifications</a></li>");+ } else {+ return null;+ }};init();diff --git a/web/js/ui/wv.ui.info.js b/web/js/ui/wv.ui.info.jsindex 356e1c88b..23f88d6ac 100644--- a/web/js/ui/wv.ui.info.js+++ b/web/js/ui/wv.ui.info.js@@ -53,7 +53,7 @@ wv.ui.info = wv.ui.info || (function(ui, config) {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.feedback ) {$menuItems.append($feedback);}@@ -65,6 +65,10 @@ wv.ui.info = wv.ui.info || (function(ui, config) {}$menuItems.append($source);$menuItems.append($about);+ if($alerts) {+ $menuItems.append($alerts);+ }+ $menuItems.append($about);$menu.append($menuItems);$menuItems.menu();diff --git a/web/js/util/wv.util.js b/web/js/util/wv.util.jsindex e68b87eba..9555f64c4 100644--- a/web/js/util/wv.util.js+++ b/web/js/util/wv.util.js@@ -612,7 +612,13 @@ wv.util = (function(self) {localStorage.setItem(property, value);}};-+ self.isInLocalStorage = function(property) {+ return localStorage.getItem(property);+ };+ self.localStorageValueMatches = function(property, value) {+ var oldValue = localStorage.getItem(property);+ return oldValue === value;+ };/*** Wraps a function in a try/catch block that invokes wv.util.error* if an exception is thrown.