From 6b149919736edf25616423447cfa6eef2a02d793 Mon Sep 17 00:00:00 2001 From: Goutte Date: Fri, 4 Aug 2017 10:48:27 +0200 Subject: [PATCH] Add a Download button. --- CHANGELOG.md | 4 +++- README.md | 15 ++++++--------- web/static/js/swapp.js | 18 ++++++++++++++++++ web/static/js/swapp.ls | 9 +++++++++ web/view/home.html.jinja2 | 32 +++++++++++++++++++++++++++++--- 5 files changed, 65 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ff853e..0ba55cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - [ ] Optimize CSV generation (with some vectorization using numpy) - [ ] Credit the author of the pixel art planets - [ ] Set the log level to _error_ in production (see `web/run.py`) +- [ ] Add a README to the download tarball ## 1.0.0 @@ -21,8 +22,9 @@ - [ ] Cache cleanup - [x] API at /cache/clear - [ ] CRON statement to call it -- [ ] Download raw data (tarball of CSV) for current time interval and targets +- [x] Download raw data (tarball of CSV) for current time interval and targets - [ ] Same via SAMP +- [ ] Add a warning for users with javascript disabled ## 0.0.0 diff --git a/README.md b/README.md index 3b44006..b0c8302 100644 --- a/README.md +++ b/README.md @@ -6,19 +6,15 @@ The sources of the website available at https://spaceweatheronline.cdpp.eu ## Web Server -Build and serve the space weather visualization webpages. -A flask webserver, serving d3.js visualizations. - - -## Bridge - -Gather NetCDF data from AMDA, and serve it as CSV to the javascript plotter. +Build and serve heliopropa's visualizations. +It's a `flask` webserver, serving `d3.js` plots written in `livescript`. +It also gathers NetCDF data from AMDA, and serves it as CSV to the plotter. ### Rationale -- Reading NetCDF from javascript is doable, but still very hacky. -- The bridge can handle pagination, collecting multiple NetCDF into one CSV. +- Reading NetCDF from javascript is doable, but still *very* hacky. +- The bridge can handle pagination and collecting multiple NetCDF into one CSV. # How @@ -27,6 +23,7 @@ Gather NetCDF data from AMDA, and serve it as CSV to the javascript plotter. - `config.yml` : the main configuration file. - `web/run.py` : the front controller, holding most of the code. +- `web/view/home.html.jinja2` : the HTML template. ## Install diff --git a/web/static/js/swapp.js b/web/static/js/swapp.js index 7ad2ac0..52c1548 100644 --- a/web/static/js/swapp.js +++ b/web/static/js/swapp.js @@ -58,6 +58,24 @@ url = url.replace('', stopped_at); return url; }; + SpaceWeather.prototype.buildDownloadUrl = function(){ + var ref$, started_at, stopped_at, targets, t, url; + ref$ = this.getDomain(), started_at = ref$[0], stopped_at = ref$[1]; + targets = (function(){ + var results$ = []; + for (t in this.targets) { + if (this.targets[t].active) { + results$.push(t); + } + } + return results$; + }.call(this)).sort().join('-'); + url = this.configuration['api']['download']; + url = url.replace('', targets); + url = url.replace('', started_at.format(API_TIME_FORMAT)); + url = url.replace('', stopped_at.format(API_TIME_FORMAT)); + return url; + }; SpaceWeather.prototype.addTarget = function(target){ this.targets[target.slug] = target; return this; diff --git a/web/static/js/swapp.ls b/web/static/js/swapp.ls index bd7a611..07039d2 100644 --- a/web/static/js/swapp.ls +++ b/web/static/js/swapp.ls @@ -88,6 +88,15 @@ https://gitlab.irap.omp.eu/CDPP/SPACEWEATHERONLINE url = url.replace('', stopped_at) url + buildDownloadUrl: -> + [started_at, stopped_at] = @getDomain() + targets = [t for t of @targets when @targets[t].active].sort().join('-') + url = @configuration['api']['download'] + url = url.replace('', targets) + url = url.replace('', started_at.format(API_TIME_FORMAT)) + url = url.replace('', stopped_at.format(API_TIME_FORMAT)) + url + addTarget: (target) -> @targets[target.slug] = target this diff --git a/web/view/home.html.jinja2 b/web/view/home.html.jinja2 index 21f4932..fe18cee 100755 --- a/web/view/home.html.jinja2 +++ b/web/view/home.html.jinja2 @@ -88,6 +88,10 @@
+
@@ -117,7 +121,7 @@ {# position: relative;#} } #plots_loader { - position: absolute; + position: fixed; top: 0; left: 0; bottom: 0; right: 0; height: 100%; width: 100%; @@ -199,6 +203,11 @@ animation-delay: .8s; } + #download { + display: block; + margin: 3em auto; + } + #time_series .help { position: absolute; text-align: center; @@ -329,7 +338,8 @@ var configuration = { time_series_container: '#time_series', orbits_container: '#orbits', api : { - 'data_for_interval': "{{ request.url_root }}__.csv" + 'data_for_interval': "{{ request.url_root }}__.csv", + 'download': "{{ request.url_root }}__.tar.gz" }, sun: { img: '{{ static('img/sun_128.png') }}' @@ -440,7 +450,23 @@ jQuery().ready(function($){ var stopped_at = moment($("#stopped_at").val()); sw.resizeDomain(started_at, stopped_at); return false; - }) + }); + $('#download').on("click", function(e){ + var url = sw.buildDownloadUrl(); + $.ajax({ + type: 'GET', + url: url, + processData: false, + success: function (data) { + window.location = url; + }, + error: function (xhr) { + console.error('Cannot download.', xhr); + alert("Our apologies, there was an error while downloading."); + } + }); + return false; + }); }); -- libgit2 0.21.2