Interactive interface for browsing global, full-resolution satellite imagery
added alert module #230
Benjamin12a07e0a65a7
diff --git a/deploy/wv.js.json b/deploy/wv.js.jsonindex b94592778..5865a19f4 100644--- a/deploy/wv.js.json+++ b/deploy/wv.js.json@@ -21,6 +21,7 @@"web/js/ui/wv.ui.mouse.js","web/js/ui/wv.ui.indicator.js","web/js/ui/wv.ui.info.js",+ "web/js/map/wv.map.ui.js","web/js/proj/wv.proj.js","web/js/proj/wv.proj.change.js",diff --git a/web/index.html b/web/index.htmlindex b2325b91c..e13e0d542 100644--- a/web/index.html+++ b/web/index.html@@ -189,6 +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/ui/wv.ui.alert.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>@@ -266,6 +267,8 @@</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/ui/wv.ui.alert.js b/web/js/ui/wv.ui.alert.jsnew file mode 100644index 000000000..eced811e2--- /dev/null+++ b/web/js/ui/wv.ui.alert.js@@ -0,0 +1,65 @@+/*+ * NASA Worldview+ *+ * This code was originally developed at NASA/Goddard Space Flight Center for+ * the Earth Science Data and Information System (ESDIS) project.+ *+ * Copyright (C) 2013 - 2017 United States Government as represented by the+ * Administrator of the National Aeronautics and Space Administration.+ * All Rights Reserved.+ *+ * Licensed under the NASA Open Source Agreement, Version 1.3+ * http://opensource.gsfc.nasa.gov/nosa.php+ */+var wv = wv || {};+wv.ui = wv.ui || {};++/*+ * @Class+ */+wv.ui.alert = wv.ui.alert || function(models, url) {+ var self = {};+ var alertReactFactory = React.createFactory(WVC.Alert);+ var mountCase;+ var init = function() {+ var notifications, reactComponent, options, p;+ mountCase = document.getElementById('wv-alert');+ p = wv.util.get(url);+ p.then(function(response) {+ var 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);+ }+ }, 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 renderReactComponent = function(options, mountLocation) {+ console.log(options, mountLocation);+ return ReactDOM.render(alertReactFactory(options), mountLocation);+ };+ var closeAlert = function(e) {+ console.log(e);+ };++ init();+ return self;+};\ No newline at end of filediff --git a/web/js/util/wv.util.js b/web/js/util/wv.util.jsindex 35d5782e5..e68b87eba 100644--- a/web/js/util/wv.util.js+++ b/web/js/util/wv.util.js@@ -629,7 +629,42 @@ wv.util = (function(self) {}};};-+ /**+ * Http request using promises+ * http://www.html5rocks.com/en/tutorials/es6/promises/#toc-promisifying-xmlhttprequest+ *+ * @method get+ * @param {url} func the function to wrap+ * @return {object} Promise+ */+ self.get = function(url) {+ // Return a new promise.+ return new Promise(function(resolve, reject) {+ // Do the usual XHR stuff+ var req = new XMLHttpRequest();+ req.open('GET', url);++ req.onload = function() {+ // This is called even on 404 etc+ // so check the status+ if (req.status == 200) {+ // Resolve the promise with the response text+ resolve(req.response);+ }+ else {+ // Otherwise reject with the status text+ // which will hopefully be a meaningful error+ reject(Error(req.statusText));+ }+ };+ // Handle network errors+ req.onerror = function() {+ reject(Error("Network Error"));+ };+ // Make the request+ req.send();+ });+ };// FIXME: Should be replaced with $.whenself.ajaxJoin = function(calls) {diff --git a/web/js/wv.main.js b/web/js/wv.main.jsindex cb388d76a..a6942bf7d 100644--- a/web/js/wv.main.js+++ b/web/js/wv.main.js@@ -211,6 +211,10 @@ $(function() {ui.link = wv.link.ui(models, config);ui.tour = wv.tour(models, ui, config);ui.info = wv.ui.info(ui, config);+ if(config.features.alert){+ ui.alert = wv.ui.alert(ui, config.features.alert.url);+ }+//FIXME: Old hack$(window).resize(function() {