Skip to content

Commit

Permalink
fix(download): just use filtered boxes
Browse files Browse the repository at this point in the history
If a filter is active just use filtered boxes in download
  • Loading branch information
mpfeil committed Dec 20, 2018
1 parent fdbc8dd commit 908a3c5
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 69 deletions.
11 changes: 6 additions & 5 deletions app/scripts/controllers/sidebar.download.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
'app',
'OpenSenseMapAPI',
'OpenSenseMapData',
'FilterActiveService',
'osemMapData',
'Sidebar',
'boxes'
Expand All @@ -22,16 +23,14 @@
app,
OpenSenseMapAPI,
OpenSenseMapData,
FilterActiveService,
osemMapData,
Sidebar,
boxes
) {
var vm = this;
vm.map;
vm.inputFilter = {
window: 'raw',
operation: 'arithmeticMean'
};
vm.inputFilter = { window: 'raw', operation: 'arithmeticMean' };
vm.downloadform = {
format: 'csv',
pleaseWait: false,
Expand Down Expand Up @@ -64,7 +63,9 @@

function activate () {
Sidebar.setTitle('Download');
OpenSenseMapData.setMarkers(boxes); // retrieved through state.resolve in app.js (because we need the full metadata for filtering)
if (!FilterActiveService.active) {
OpenSenseMapData.setMarkers(boxes);
}
vm.markersFiltered = OpenSenseMapData.getMarkers();
vm.downloadMarkers = vm.markersFiltered;
vm.count = Object.keys(vm.markersFiltered).length;
Expand Down
132 changes: 79 additions & 53 deletions app/scripts/controllers/sidebar.filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,29 @@
.module('openSenseMapApp')
.controller('SidebarFilterController', SidebarFilterController);

SidebarFilterController.$inject = ['$scope', '$timeout', 'boxFilter', 'phenomenonFilter', 'OpenSenseMapData', 'OpenSenseMapAPI', 'FilterActiveService', 'Sidebar', 'boxes'];
SidebarFilterController.$inject = [
'$scope',
'$timeout',
'boxFilter',
'phenomenonFilter',
'OpenSenseMapData',
'OpenSenseMapAPI',
'FilterActiveService',
'Sidebar',
'boxes'
];

function SidebarFilterController ($scope, $timeout, boxFilter, phenomenonFilter, OpenSenseMapData, OpenSenseMapAPI, FilterActiveService, Sidebar, boxes) {
function SidebarFilterController (
$scope,
$timeout,
boxFilter,
phenomenonFilter,
OpenSenseMapData,
OpenSenseMapAPI,
FilterActiveService,
Sidebar,
boxes
) {
var vm = this;
vm.inputFilter = {};
vm.filteredMarkers = {};
Expand Down Expand Up @@ -79,42 +99,50 @@
};

if (useLiveFilteredMarkers) {
return boxFilter(markers, nameexpr)
.then(function (response) {
setMarkersLive(response);
});
}

return boxFilter(vm.filteredMarkers, nameexpr)
.then(function (response) {
if (vm.inputFilter.Phenomenon) {
return performLiveFilter('phenomenon', true, response);
}
return boxFilter(markers, nameexpr).then(function (response) {
setMarkersLive(response);
});
}

return boxFilter(vm.filteredMarkers, nameexpr).then(function (
response
) {
if (vm.inputFilter.Phenomenon) {
return performLiveFilter('phenomenon', true, response);
}
setMarkersLive(response);
});
case 'phenomenon':
if (useLiveFilteredMarkers) {
return phenomenonFilter(markers, vm.inputFilter.Phenomenon)
.then(function (response) {
return phenomenonFilter(markers, vm.inputFilter.Phenomenon).then(
function (response) {
setMarkersLive(response);
});
}
);
}

return phenomenonFilter(vm.filteredMarkers, vm.inputFilter.Phenomenon)
.then(function (response) {
if (vm.inputFilter.Exposure !== undefined ||
vm.inputFilter.Name !== undefined ||
vm.inputFilter.vendor !== undefined ||
vm.inputFilter.Grouptag !== undefined) {
return performLiveFilter('box', true, response);
}
setMarkersLive(response);
});
return phenomenonFilter(
vm.filteredMarkers,
vm.inputFilter.Phenomenon
).then(function (response) {
if (
vm.inputFilter.Exposure !== undefined ||
vm.inputFilter.Name !== undefined ||
vm.inputFilter.vendor !== undefined ||
vm.inputFilter.Grouptag !== undefined
) {
return performLiveFilter('box', true, response);
}
setMarkersLive(response);
});
}
}

function performTimeFilter () {
var date = [vm.inputFilter.DateFrom.toISOString(), vm.inputFilter.DateTo.toISOString()];
var date = [
vm.inputFilter.DateFrom.toISOString(),
vm.inputFilter.DateTo.toISOString()
];
if (date !== '' && Array.isArray(date)) {
date = date.join(',');
}
Expand All @@ -125,10 +153,9 @@
}
};

return getBoxes(data)
.then(function () {
FilterActiveService.active = true;
});
return getBoxes(data).then(function () {
FilterActiveService.active = true;
});
}

function resetFilter () {
Expand All @@ -138,19 +165,18 @@
}
};

return getBoxes(data)
.then(function () {
vm.inputFilter.Name = undefined;
vm.inputFilter.Grouptag = undefined;
vm.inputFilter.DateFrom = undefined;
vm.inputFilter.DateTo = undefined;
vm.inputFilter.Exposure = undefined;
vm.inputFilter.Phenomenon = undefined;
vm.inputFilter.vendor = undefined;
FilterActiveService.active = false;
FilterActiveService.query = {};
vm.needsRefresh = false;
});
return getBoxes(data).then(function () {
vm.inputFilter.Name = undefined;
vm.inputFilter.Grouptag = undefined;
vm.inputFilter.DateFrom = undefined;
vm.inputFilter.DateTo = undefined;
vm.inputFilter.Exposure = undefined;
vm.inputFilter.Phenomenon = undefined;
vm.inputFilter.vendor = undefined;
FilterActiveService.active = false;
FilterActiveService.query = {};
vm.needsRefresh = false;
});
}

function reset (filter) {
Expand Down Expand Up @@ -183,8 +209,7 @@
.then(function (response) {
setMarkers(response);
})
.catch(function () {
})
.catch(function () {})
.finally(function () {
vm.loading = false;
});
Expand All @@ -196,17 +221,18 @@
vm.filteredMarkers = response;
vm.results = Object.keys(vm.filteredMarkers).length;
$scope.$emit('markersChanged', {});
if (vm.inputFilter.Exposure !== undefined ||
vm.inputFilter.Name !== undefined ||
vm.inputFilter.vendor !== undefined ||
vm.inputFilter.Phenomenon !== undefined ||
vm.inputFilter.Grouptag !== undefined) {
if (
vm.inputFilter.Exposure !== undefined ||
vm.inputFilter.Name !== undefined ||
vm.inputFilter.vendor !== undefined ||
vm.inputFilter.Phenomenon !== undefined ||
vm.inputFilter.Grouptag !== undefined
) {
vm.needsRefresh = true;
}
FilterActiveService.query = vm.inputFilter;
})
.catch(function () {
})
.catch(function () {})
.finally(function () {
vm.loading = false;
});
Expand Down
21 changes: 10 additions & 11 deletions app/scripts/services/boxesService.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
* - allows to fetch boxes with minimal metadata
*/

angular
.module('app.services')
.factory('BoxesService', BoxesService);
angular.module('app.services').factory('BoxesService', BoxesService);

BoxesService.$inject = ['OpenSenseMapAPI', 'ngProgressFactory'];

Expand All @@ -22,35 +20,36 @@

return {
getBoxesMinimal: getBoxesMinimal,
getBoxesFullMetadata: getBoxesFullMetadata,
getBoxesFullMetadata: getBoxesFullMetadata
};

function getBoxesMinimal () {
if (!boxes) {
return getBoxesWithProgress({ minimal: true, classify: true })
.then(function (response) {
return getBoxesWithProgress({ minimal: true, classify: true }).then(
function (response) {
boxes = response;

return boxes;
});
}
);
}

return Promise.resolve(boxes);
}

function getBoxesFullMetadata () {
if (!fullMetadataLoaded) {
return getBoxesWithProgress({ minimal: false, classify: true })
.then(function (response) {
return getBoxesWithProgress({ minimal: false, classify: true }).then(
function (response) {
fullMetadataLoaded = true;
boxes = response;

return boxes;
});
}
);
}

return Promise.resolve(boxes);

}

function getBoxesWithProgress (params) {
Expand Down

0 comments on commit 908a3c5

Please sign in to comment.