Commit 2bf51c07 authored by Alan Mitchell's avatar Alan Mitchell

Progress on BMON Essential Coffeescript.

parent 76e60449
...@@ -47,6 +47,11 @@ BMSAPP_NAV_LINKS = (('Map', 'map'), ...@@ -47,6 +47,11 @@ BMSAPP_NAV_LINKS = (('Map', 'map'),
# The number of hours before a sensor is considered to be inactive (not posting data). # The number of hours before a sensor is considered to be inactive (not posting data).
BMSAPP_SENSOR_INACTIVITY = 2.0 # Hours BMSAPP_SENSOR_INACTIVITY = 2.0 # Hours
# This is the base URL where BMON Essential Energy Reports are located.
# If Energy Reports are not being geneerated for this system, assign None
# to this variable.
ENERGY_REPORTS_URL = 'https://bmonreporter-data.energytools.com/reports/bms.ahfc.us/'
# If you are using the Pushover notification service for alerts generated by the BMON # If you are using the Pushover notification service for alerts generated by the BMON
# application, you need to register an Application with Pushover and enter the API # application, you need to register an Application with Pushover and enter the API
# Token/Key below. It is a 30 character string. See 'https://pushover.net'. # Token/Key below. It is a 30 character string. See 'https://pushover.net'.
......
# Coffee Script file that provides the functionality for the Energy Reports
# page. The Javascript version of this is included in the 'energy-reports.html'
# template.
# Variables needed for identifying availabe reports
# An object mapping organization ID to a list of buildings associated with
# that organization.
_org_to_bldgs = {}
# An object mapping building ID to a list of building reports
_bldg_reports = {}
# An object mapping organization ID to a list of organization reports
_org_reports = {}
# ---------------------------------------------------------------
# function that runs when the document is ready.
$ ->
# Get the data files from the Report server, first getting the base URL from
# the hidden span element on this page.
base_url = $("#energy-reports-url").text()
# only acquire data if there is a Base URL.
if base_url.length > 0
$.getJSON(base_url + "org_to_bldgs.json").done((results) ->
_org_to_bldgs = results
).fail (jqxhr, textStatus, error) ->
$("body").css "cursor", "default" # remove hourglass cursor
err = textStatus + ", " + error
alert "Error Occurred: " + err
$.getJSON(base_url + "building.json").done((results) ->
_bldg_reports = results
).fail (jqxhr, textStatus, error) ->
$("body").css "cursor", "default" # remove hourglass cursor
err = textStatus + ", " + error
alert "Error Occurred: " + err
$.getJSON(base_url + "organization.json").done((results) ->
_org_reports = results
$("#debug-out").text JSON.stringify(_org_reports)
).fail (jqxhr, textStatus, error) ->
$("body").css "cursor", "default" # remove hourglass cursor
err = textStatus + ", " + error
alert "Error Occurred: " + err
// Generated by CoffeeScript 1.12.7
(function() {
var _bldg_reports, _org_reports, _org_to_bldgs;
_org_to_bldgs = {};
_bldg_reports = {};
_org_reports = {};
$(function() {
var base_url;
base_url = $("#energy-reports-url").text();
if (base_url.length > 0) {
$.getJSON(base_url + "org_to_bldgs.json").done(function(results) {
return _org_to_bldgs = results;
}).fail(function(jqxhr, textStatus, error) {
var err;
$("body").css("cursor", "default");
err = textStatus + ", " + error;
return alert("Error Occurred: " + err);
});
$.getJSON(base_url + "building.json").done(function(results) {
return _bldg_reports = results;
}).fail(function(jqxhr, textStatus, error) {
var err;
$("body").css("cursor", "default");
err = textStatus + ", " + error;
return alert("Error Occurred: " + err);
});
return $.getJSON(base_url + "organization.json").done(function(results) {
_org_reports = results;
return $("#debug-out").text(JSON.stringify(_org_reports));
}).fail(function(jqxhr, textStatus, error) {
var err;
$("body").css("cursor", "default");
err = textStatus + ", " + error;
return alert("Error Occurred: " + err);
});
}
});
}).call(this);
{% extends "bmsapp/base.html" %} {% extends "bmsapp/base.html" %}
{% load staticfiles %}
{% block pagetitle %}Energy Reports{% endblock %} {% block pagetitle %}Energy Reports{% endblock %}
{% block head %} {% block head %}
<style> <style>
</style> </style>
<script src="{% static 'bmsapp/scripts/energy-reports.js' %}"></script>
{% endblock %} {% endblock %}
{% block this_nav_link %}link_energy-reports{% endblock %} {% block this_nav_link %}link_energy-reports{% endblock %}
{% block content %} {% block content %}
<span id="energy-reports-url" style="display:none">{{ energy_reports_url }}</span>
<h2>Energy Reports</h2> <h2>Energy Reports</h2>
<h5><i>{{ error_message }}</i></h5>
<div id="debug-out"></div>
{% endblock %} {% endblock %}
{% block scripts %} {% block scripts %}
......
...@@ -20,6 +20,7 @@ urlpatterns = [ ...@@ -20,6 +20,7 @@ urlpatterns = [
re_path(r'^reports/$', views.reports, name='reports'), re_path(r'^reports/$', views.reports, name='reports'),
re_path(r'^reports/results/$', views.get_report_results), re_path(r'^reports/results/$', views.get_report_results),
re_path(r'^reports/embed/$', views.get_embedded_results), # javascript embedded version of report results re_path(r'^reports/embed/$', views.get_embedded_results), # javascript embedded version of report results
re_path(r'^energy-reports/$', views.energy_reports),
re_path(r'^custom-reports/$', views.custom_report_list), re_path(r'^custom-reports/$', views.custom_report_list),
re_path(r'^custom-reports/(.+)$', views.custom_report), re_path(r'^custom-reports/(.+)$', views.custom_report),
re_path(r'^show-log/$', views.show_log), re_path(r'^show-log/$', views.show_log),
......
...@@ -139,6 +139,30 @@ def get_embedded_results(request): ...@@ -139,6 +139,30 @@ def get_embedded_results(request):
script_content = view_util.get_embedded_results_script(request, result) script_content = view_util.get_embedded_results_script(request, result)
return HttpResponse(script_content, content_type="application/javascript") return HttpResponse(script_content, content_type="application/javascript")
def energy_reports(request):
"""Presents the BMON Essential Energy Reports page.
"""
# determine the base Energy Reports URL to pass to the template
if hasattr(settings, 'ENERGY_REPORTS_URL') and settings.ENERGY_REPORTS_URL is not None:
energy_reports_url = settings.ENERGY_REPORTS_URL
if energy_reports_url[-1] != '/':
# add a slash at end, as it did not contain one.
energy_reports_url += '/'
error_message = ''
else:
energy_reports_url = ''
error_message = 'Energy Reports are not Available. Contact your System Administrator for more information.'
ctx = base_context()
ctx.update(
{
'energy_reports_url': energy_reports_url,
'error_message': error_message,
}
)
return render_to_response('bmsapp/energy-reports.html', ctx)
def custom_report_list(request): def custom_report_list(request):
"""The main Custom Reports page - lists available custom reports for the """The main Custom Reports page - lists available custom reports for the
organization identified by the query parameter 'select_org'. organization identified by the query parameter 'select_org'.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment