Skip to content

Commit

Permalink
feat(download): direct download url
Browse files Browse the repository at this point in the history
Change download button to a simple anchor tag and set href. You get the url by right click and copy
link location.

closes #255
  • Loading branch information
mpfeil committed Jun 5, 2018
1 parent 82260d5 commit f0a4758
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
18 changes: 7 additions & 11 deletions app/scripts/controllers/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
if (boxes instanceof Error) {
$state.go('explore.map.sidebar.error');
}

return OpenSenseMapData.setMarkers(boxes)
.then(function (response) {
vm.mapMarkers = response;
})
.catch(function () {
});
}

function createLegendFromTemplate (templateURI, clickHandler) {
Expand Down Expand Up @@ -123,17 +130,6 @@

////

$scope.$on('layerloaded', function () {
$timeout(function () {
return OpenSenseMapData.setMarkers(boxes)
.then(function (response) {
vm.mapMarkers = response;
})
.catch(function () {
});
});
});

$scope.$on('osemMeasurementMouseOver.map_main', function (e, args) {
vm.hoverlabel = {
left: (args.containerPoint.x + 10) + 'px',
Expand Down
33 changes: 28 additions & 5 deletions app/scripts/controllers/sidebar.download.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
.module('openSenseMapApp')
.controller('SidebarDownloadController', SidebarDownloadController);

SidebarDownloadController.$inject = ['$scope', 'moment', 'OpenSenseMapAPI', 'OpenSenseMapData', 'osemMapData', 'Sidebar'];
SidebarDownloadController.$inject = ['$scope', '$httpParamSerializer', 'moment', 'OpenSenseMapAPI', 'OpenSenseMapData', 'osemMapData', 'Sidebar'];

function SidebarDownloadController ($scope, moment, OpenSenseMapAPI, OpenSenseMapData, osemMapData, Sidebar) {
function SidebarDownloadController ($scope, $httpParamSerializer, moment, OpenSenseMapAPI, OpenSenseMapData, osemMapData, Sidebar) {
var vm = this;
vm.map;
vm.inputFilter = {
Expand Down Expand Up @@ -38,6 +38,7 @@
vm.dataDownload = dataDownload;
vm.closeSidebar = closeSidebar;
vm.changeWindow = changeWindow;
vm.getHref = getHref;

activate();

Expand Down Expand Up @@ -80,8 +81,7 @@
}
}

function dataDownload () {
vm.downloadform.pleaseWait = true;
function getDownloadParameters () {
var boxids = getBoxIdsFromBBox(vm.map);
var columns = [];
for (var key in vm.columns) {
Expand All @@ -102,8 +102,14 @@
download: true
};

return params;
}

function dataDownload () {
vm.downloadform.pleaseWait = true;
var params = getDownloadParameters();

if (vm.inputFilter.window === 'raw') {
params.columns = columns;
OpenSenseMapAPI.getData(params);
} else {
params.window = vm.inputFilter.window;
Expand All @@ -112,6 +118,23 @@
}
}

function getHref () {
if (vm.map && vm.inputFilter.DateTo && vm.inputFilter.DateFrom && vm.inputFilter.Phenomenon) {
var params = getDownloadParameters();
var query = $httpParamSerializer(params);
var endpoint = '';
if (vm.inputFilter.window === 'raw') {
endpoint = '/boxes/data';
} else {
params.window = vm.inputFilter.window;
params.operation = vm.inputFilter.operation;
endpoint = '/statistics/descriptive';
}

return encodeURI(endpoint + '?' + query);
}
}

function getBoxIdsFromBBox (map) {
var boxids = [];
var bbox = map.getBounds();
Expand Down
2 changes: 1 addition & 1 deletion app/views/explore2.sidebar.download.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,5 @@
<div uib-alert class="alert-warning">
<p translate="DOWNLOAD_WARNING" translate-value-count="{{download.count}}"></p>
</div>
<button class="btn btn-lg btn-success" ng-click="download.dataDownload();" ng-disabled="!download.inputFilter.Phenomenon || !download.inputFilter.DateFrom || !download.inputFilter.DateTo "><span class="glyphicon glyphicon-floppy-save"></span> {{ "DOWNLOAD" | translate }}</button>
<a class="btn btn-lg btn-success" ng-click="download.dataDownload();" ng-href="{{download.getHref()}}" ng-disabled="!download.inputFilter.Phenomenon || !download.inputFilter.DateFrom || !download.inputFilter.DateTo"><span class="glyphicon glyphicon-floppy-save"></span> {{ "DOWNLOAD" | translate }}</a>
</div>

0 comments on commit f0a4758

Please sign in to comment.