Commit dd613314 authored by Alan Mitchell's avatar Alan Mitchell

Merge branch 'essential'

parents af8ecd50 0a52934d
......@@ -37,7 +37,8 @@ BMSAPP_HEADER = 'XYZ Remote Monitoring'
# The third item (optional) is True if this item should be the default index page for
# the application.
BMSAPP_NAV_LINKS = (('Map', 'map'),
('Graphs/Reports', 'reports', True),
('Graphs', 'reports', True),
('Energy Reports', 'energy-reports'),
('Custom Reports', 'custom-reports'),
('Training', 'training-anthc'),
('Sys Admin', 'admin-reports'),
......@@ -46,6 +47,11 @@ BMSAPP_NAV_LINKS = (('Map', 'map'),
# The number of hours before a sensor is considered to be inactive (not posting data).
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
# 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'.
......
......@@ -19,3 +19,7 @@ body {
.tooltip-inner {
max-width: 350px;
}
hr {
border-top: 1px solid rgba(0, 0, 0, 0.2);
}
# 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
# The base URL where building/organization mapping info is available and
# reports are available
_base_url = ""
# 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 = {}
# Updates the list of buildings associated with the Organization selected.
update_bldg_list = ->
org = $("#select_org").val()
# Clear out Facility select box
$("#select_bldg").empty()
# Add buildings to the Select box
add_bldg = (bldg) ->
optn = new Option(bldg[0], bldg[1])
$("#select_bldg").append(optn)
# make sure this org is in the mapping, which was created the
# night before.
if _org_to_bldgs[org]?
add_bldg bldg for bldg in _org_to_bldgs[org]
# select the first building
$("#select_bldg").val($("#select_bldg option:first").val())
update_report_list()
# Updates the tabs that show the Report titles
update_report_list = ->
# get selector values
org = $("#select_org").val()
bldg = $("#select_bldg").val()
# Clear out all tabs
$("#report-tab-list").empty()
# Add reports to Tabs
add_report = (rpt, rpt_type) ->
html = """
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="##{ rpt_type }-#{ rpt.file_name }" role="tab">#{ rpt.title }</a>
</li>
"""
$("#report-tab-list").append html
# Add building reports if this building is in the list
if _bldg_reports[bldg]?
add_report(rpt, "B") for rpt in _bldg_reports[bldg]
# Add Organization reports if this building is in the list
if _org_reports[org]?
add_report(rpt, "O") for rpt in _org_reports[org]
# add a handler for the click event on all of the a links associated
# with the tabs.
$("#report-tab-list a").click load_report
# Select the first tab
$("#report-tab-list a:first").addClass("active").click()
load_report = ->
# href attribute contains info about where the report is located
report_info = $(this).attr("href").substring(1)
report_file_name = report_info.substring(2)
if report_info.substring(0, 1) == "B"
report_url = "#{ _base_url }building/#{ $("#select_bldg").val() }/#{ report_file_name }"
else
report_url = "#{ _base_url }organization/#{ $("#select_org").val() }/#{ report_file_name }"
$("#report-content").attr("src", report_url)
# ---------------------------------------------------------------
# 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
update_bldg_list()
update_report_list()
).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
update_report_list()
).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
update_report_list()
).fail (jqxhr, textStatus, error) ->
$("body").css "cursor", "default" # remove hourglass cursor
err = textStatus + ", " + error
alert "Error Occurred: " + err
# Set up controls and functions to respond to events
$("#select_org").change update_bldg_list
$("#select_org").change update_report_list
$("#select_bldg").change update_report_list
// Generated by CoffeeScript 1.12.7
(function() {
var _base_url, _bldg_reports, _last_bldg, _last_org, _org_reports, _org_to_bldgs, load_report, update_bldg_list, update_report_list;
_base_url = "";
_org_to_bldgs = {};
_bldg_reports = {};
_org_reports = {};
update_bldg_list = function() {
var add_bldg, bldg, i, len, org, ref;
org = $("#select_org").val();
$("#select_bldg").empty();
add_bldg = function(bldg) {
var optn;
optn = new Option(bldg[0], bldg[1]);
return $("#select_bldg").append(optn);
};
if (_org_to_bldgs[org] != null) {
ref = _org_to_bldgs[org];
for (i = 0, len = ref.length; i < len; i++) {
bldg = ref[i];
add_bldg(bldg);
}
$("#select_bldg").val($("#select_bldg option:first").val());
return update_report_list();
}
};
_last_bldg = "";
_last_org = "";
update_report_list = function() {
var add_report, bldg, i, j, len, len1, org, ref, ref1, rpt;
org = $("#select_org").val();
bldg = $("#select_bldg").val();
$("#report-tab-list").empty();
add_report = function(rpt, rpt_type) {
var html;
html = "<li class=\"nav-item\">\n <a class=\"nav-link\" data-toggle=\"tab\" href=\"#" + rpt_type + "-" + rpt.file_name + "\" role=\"tab\">" + rpt.title + "</a>\n</li>";
return $("#report-tab-list").append(html);
};
if (_bldg_reports[bldg] != null) {
ref = _bldg_reports[bldg];
for (i = 0, len = ref.length; i < len; i++) {
rpt = ref[i];
add_report(rpt, "B");
}
}
if (_org_reports[org] != null) {
ref1 = _org_reports[org];
for (j = 0, len1 = ref1.length; j < len1; j++) {
rpt = ref1[j];
add_report(rpt, "O");
}
}
$("#report-tab-list a").click(load_report);
return $("#report-tab-list a:first").addClass("active").click();
};
load_report = function() {
var report_file_name, report_info, report_url;
report_info = $(this).attr("href").substring(1);
report_file_name = report_info.substring(2);
if (report_info.substring(0, 1) === "B") {
report_url = _base_url + "building/" + ($("#select_bldg").val()) + "/" + report_file_name;
} else {
report_url = _base_url + "organization/" + ($("#select_org").val()) + "/" + report_file_name;
}
return $("#report-content").attr("src", report_url);
};
$(function() {
_base_url = $("#energy-reports-url").text();
if (_base_url.length > 0) {
$.getJSON(_base_url + "org_to_bldgs.json").done(function(results) {
_org_to_bldgs = results;
update_bldg_list();
return update_report_list();
}).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) {
_bldg_reports = results;
return update_report_list();
}).fail(function(jqxhr, textStatus, error) {
var err;
$("body").css("cursor", "default");
err = textStatus + ", " + error;
return alert("Error Occurred: " + err);
});
$.getJSON(_base_url + "organization.json").done(function(results) {
_org_reports = results;
return update_report_list();
}).fail(function(jqxhr, textStatus, error) {
var err;
$("body").css("cursor", "default");
err = textStatus + ", " + error;
return alert("Error Occurred: " + err);
});
$("#select_org").change(update_bldg_list);
$("#select_org").change(update_report_list);
return $("#select_bldg").change(update_report_list);
}
});
}).call(this);
{% extends "bmsapp/base.html" %}
{% load staticfiles %}
{% block pagetitle %}Energy Reports{% endblock %}
{% block head %}
<style>
</style>
<script src="{% static 'bmsapp/scripts/energy-reports.js' %}"></script>
{% endblock %}
{% block this_nav_link %}link_energy-reports{% endblock %}
{% block content %}
<span id="energy-reports-url" style="display:none">{{ energy_reports_url }}</span>
<h2>Energy Reports</h2>
<h5><i>Under Construction: Formatting Improvements in Progress</i></h5>
<hr/>
<h5><i>{{ error_message }}</i></h5>
<div id="debug-out"></div>
<div class="row mx-1">
<form class="form-inline">
<label class="mr-2" for="select_bldg" id="label_bldg"">Facility:</label>
<select class="form-control" id="select_bldg" name="select_bldg">
<option>Test Option</option>
</select>
</form>
</div>
<hr/>
<div class="row mx-1 mt-3">
<ul id="report-tab-list" class="nav nav-tabs flex-wrap" role="tablist">
</ul>
</div>
<div class="row mt-3">
<iframe id="report-content" src="" width="100%" height="1000px"></iframe>
</div>
{% endblock %}
{% block scripts %}
{% endblock %}
......@@ -20,6 +20,7 @@ urlpatterns = [
re_path(r'^reports/$', views.reports, name='reports'),
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'^energy-reports/$', views.energy_reports),
re_path(r'^custom-reports/$', views.custom_report_list),
re_path(r'^custom-reports/(.+)$', views.custom_report),
re_path(r'^show-log/$', views.show_log),
......
......@@ -139,6 +139,30 @@ def get_embedded_results(request):
script_content = view_util.get_embedded_results_script(request, result)
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):
"""The main Custom Reports page - lists available custom reports for the
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