Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EMS_ENABLED env variable #516

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,9 @@
});

function showHeatmapCharts(show) {
if(!$scope.ems_enabled){
return;
}
$timeout(function() {
$scope.showHeatmapCharts = show;
if(show === true) {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,21 @@
{% include 'google_analytics.html' %}
</head>

<body class="ct-headroom--fixedTopBar cssAnimate" ng-controller="jurisdictionController" ng-app="fireStation" ng-init="setLevel('all')">
{% if EMS_ENABLED %}
<body
class="ct-headroom--fixedTopBar cssAnimate"
ng-controller="jurisdictionController"
ng-app="fireStation"
ng-init="setLevel('all'); setEmsEnabled(true);"
>
{% else %}
<body
class="ct-headroom--fixedTopBar cssAnimate"
ng-controller="jurisdictionController"
ng-app="fireStation"
ng-init="setLevel('all'); setEmsEnabled(false);"
>
{% endif %}

{% include 'firestation/_mobile_navbar.html' %}
{% include 'firestation/_mobile_search.html' %}
Expand Down
1 change: 1 addition & 0 deletions firecares/firestation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions firecares/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,4 @@
PHONENUMBER_DEFAULT_REGION = 'US'

SPAM_FILTER_ENABLED = True
EMS_ENABLED = os.getenv('EMS_ENABLED', True)