diff --git a/firecares/firestation/static/firestation/js/controllers/departmentDetail.js b/firecares/firestation/static/firestation/js/controllers/departmentDetail.js index b8adc2d3..da5d1dfa 100644 --- a/firecares/firestation/static/firestation/js/controllers/departmentDetail.js +++ b/firecares/firestation/static/firestation/js/controllers/departmentDetail.js @@ -379,6 +379,9 @@ }); function showHeatmapCharts(show) { + if(!$scope.ems_enabled){ + return; + } $timeout(function() { $scope.showHeatmapCharts = show; if(show === true) { @@ -396,76 +399,85 @@ // // EMS Heatmap // - var emsHeatmapDataUrl = 'https://s3.amazonaws.com/firecares-test/' + config.id + '-ems-incidents.csv'; - $http.head(emsHeatmapDataUrl) - .then(function(response) { - var contentLength = Number(response.headers('Content-Length')); - - // Don't show the ems heatmap layer option for a department with no ems heatmap data. - // HACK: A department with no ems heatmap data will still return the table header for the empty data, which - // has a length of 59 bytes. Remember to change this value if the columns ever change in any way. - if (contentLength <= 59) { - return; - } - - emsHeatmap.init(departmentMap); - $scope.emsHeatmap = emsHeatmap; - $scope.showEMSHeatmapCharts = false; - - layersControl.addOverlay(emsHeatmap.layer, 'EMS Heatmap'); - departmentMap.on('overlayadd', function(layer) { - if(layer.layer.id === 'weather'){ - $('.weather-messages').fadeIn('slow'); - $scope.showDetails = false; + $scope.setEmsEnabled = function(enabled) { + $scope.ems_enabled = enabled; + + // Call this once we have been initialized: + if($scope.ems_enabled){ + var emsHeatmapDataUrl = 'https://s3.amazonaws.com/firecares-test/' + config.id + '-ems-incidents.csv'; + $http.head(emsHeatmapDataUrl) + .then(function(response) { + var contentLength = Number(response.headers('Content-Length')); + + // Don't show the ems heatmap layer option for a department with no ems heatmap data. + // HACK: A department with no ems heatmap data will still return the table header for the empty data, which + // has a length of 59 bytes. Remember to change this value if the columns ever change in any way. + if (contentLength <= 59) { + return; } - else if (layer.layer._leaflet_id === emsHeatmap.layer._leaflet_id) { - if (emsHeatmap.heat) { - showEMSHeatmapCharts(true); - } else { - departmentMap.spin(true); - emsHeatmap.download(emsHeatmapDataUrl) - .then(function() { - showEMSHeatmapCharts(true); - }, function(err) { - alert(err.message); - layersControl.removeLayer(emsHeatmap.layer); - }) - .finally(function() { - departmentMap.spin(false); - }) - ; + + emsHeatmap.init(departmentMap); + $scope.emsHeatmap = emsHeatmap; + $scope.showEMSHeatmapCharts = false; + + layersControl.addOverlay(emsHeatmap.layer, 'EMS Heatmap'); + departmentMap.on('overlayadd', function(layer) { + if(layer.layer.id === 'weather'){ + $('.weather-messages').fadeIn('slow'); + $scope.showDetails = false; } - } - }); - - departmentMap.on('overlayremove', function(layer) { - if(layer.layer.id === 'weather'){ - $('.weather-messages').fadeOut('slow'); - } - else if (layer.layer._leaflet_id === emsHeatmap.layer._leaflet_id) { - showEMSHeatmapCharts(false); - } - if(layer.layer._leaflet_id === activeFires._leaflet_id){ - departmentMap.removeControl(activeFirelegend); - } - }); - - function showEMSHeatmapCharts(show) { - $timeout(function() { - $scope.showEMSHeatmapCharts = show; - - if(show === true) { - // Remove Fires heatmap if its on - $scope.showHeatmapCharts = false; // Hides filters - // Removes the heatmap and unchecks the control. - if(departmentMap.hasLayer(heatmap.layer)) { - departmentMap.removeLayer(heatmap.layer); - layersControl.update(); + else if (layer.layer._leaflet_id === emsHeatmap.layer._leaflet_id) { + if (emsHeatmap.heat) { + showEMSHeatmapCharts(true); + } else { + departmentMap.spin(true); + emsHeatmap.download(emsHeatmapDataUrl) + .then(function() { + showEMSHeatmapCharts(true); + }, function(err) { + alert(err.message); + layersControl.removeLayer(emsHeatmap.layer); + }) + .finally(function() { + departmentMap.spin(false); + }) + ; } } }); - } - }); + + departmentMap.on('overlayremove', function(layer) { + if(layer.layer.id === 'weather'){ + $('.weather-messages').fadeOut('slow'); + } + else if (layer.layer._leaflet_id === emsHeatmap.layer._leaflet_id) { + showEMSHeatmapCharts(false); + } + if(layer.layer._leaflet_id === activeFires._leaflet_id){ + departmentMap.removeControl(activeFirelegend); + } + }); + + function showEMSHeatmapCharts(show) { + $timeout(function() { + $scope.showEMSHeatmapCharts = show; + + if(show === true) { + // Remove Fires heatmap if its on + $scope.showHeatmapCharts = false; // Hides filters + // Removes the heatmap and unchecks the control. + if(departmentMap.hasLayer(heatmap.layer)) { + departmentMap.removeLayer(heatmap.layer); + layersControl.update(); + } + } + }); + } + }); + } + } + + // // Parcels diff --git a/firecares/firestation/templates/firestation/department_detail.html b/firecares/firestation/templates/firestation/department_detail.html index d94bb26d..2745229f 100644 --- a/firecares/firestation/templates/firestation/department_detail.html +++ b/firecares/firestation/templates/firestation/department_detail.html @@ -72,7 +72,21 @@ {% include 'google_analytics.html' %} - +{% if EMS_ENABLED %} + +{% else %} + +{% endif %} {% include 'firestation/_mobile_navbar.html' %} {% include 'firestation/_mobile_search.html' %} diff --git a/firecares/firestation/views.py b/firecares/firestation/views.py index 67230946..8350a280 100644 --- a/firecares/firestation/views.py +++ b/firecares/firestation/views.py @@ -115,6 +115,7 @@ def get_context_data(self, **kwargs): # population stats provide summary statistics for fields within the current objects population class context['population_stats'] = self.object.metrics.population_class_stats + context['EMS_ENABLED'] = settings.EMS_ENABLED return context diff --git a/firecares/settings/base.py b/firecares/settings/base.py index 1d8091f7..319284fe 100644 --- a/firecares/settings/base.py +++ b/firecares/settings/base.py @@ -358,3 +358,4 @@ PHONENUMBER_DEFAULT_REGION = 'US' SPAM_FILTER_ENABLED = True +EMS_ENABLED = os.getenv('EMS_ENABLED', True)