Commit 0a52934d authored by Alan Mitchell's avatar Alan Mitchell

Got most features working for BMON Essential Reports.

parent ec053dd9
/* App-specific styles */
body {
background: #D4E7F7;
background: #D4E7F7;
}
.group-row {
background-color: #B2DBFF;
background-color: #B2DBFF;
}
#main_header {
background-color:rgb(24, 102, 167);
background-color:rgb(24, 102, 167);
}
#nav_container {
background-color:rgb(237, 245, 252);
background-color:rgb(237, 245, 252);
}
.tooltip-inner {
max-width: 350px;
max-width: 350px;
}
hr {
border-top: 1px solid rgba(0, 0, 0, 0.2);
}
......@@ -4,6 +4,10 @@
# 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 = {}
......@@ -31,6 +35,7 @@ update_bldg_list = ->
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 = ->
......@@ -42,23 +47,38 @@ update_report_list = ->
$("#report-tab-list").empty()
# Add reports to Tabs
add_report = (rpt) ->
add_report = (rpt, rpt_type) ->
html = """
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="##{ rpt.file_name }" role="tab">#{ rpt.title }</a>
<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 for rpt in _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 for rpt in _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")
$("#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.
......@@ -66,11 +86,11 @@ $ ->
# 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()
_base_url = $("#energy-reports-url").text()
# only acquire data if there is a Base URL.
if base_url.length > 0
if _base_url.length > 0
$.getJSON(base_url + "org_to_bldgs.json").done((results) ->
$.getJSON(_base_url + "org_to_bldgs.json").done((results) ->
_org_to_bldgs = results
update_bldg_list()
update_report_list()
......@@ -79,7 +99,7 @@ $ ->
err = textStatus + ", " + error
alert "Error Occurred: " + err
$.getJSON(base_url + "building.json").done((results) ->
$.getJSON(_base_url + "building.json").done((results) ->
_bldg_reports = results
update_report_list()
).fail (jqxhr, textStatus, error) ->
......@@ -87,7 +107,7 @@ $ ->
err = textStatus + ", " + error
alert "Error Occurred: " + err
$.getJSON(base_url + "organization.json").done((results) ->
$.getJSON(_base_url + "organization.json").done((results) ->
_org_reports = results
update_report_list()
).fail (jqxhr, textStatus, error) ->
......@@ -99,4 +119,3 @@ $ ->
$("#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 _bldg_reports, _org_reports, _org_to_bldgs, update_bldg_list, update_report_list;
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 = {};
......@@ -23,42 +25,59 @@
bldg = ref[i];
add_bldg(bldg);
}
return $("#select_bldg").val($("#select_bldg option:first").val());
$("#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) {
add_report = function(rpt, rpt_type) {
var html;
html = "<li class=\"nav-item\">\n <a class=\"nav-link\" data-toggle=\"tab\" href=\"#" + rpt.file_name + "\" role=\"tab\">" + rpt.title + "</a>\n</li>";
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);
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);
add_report(rpt, "O");
}
}
return $("#report-tab-list a:first").addClass("active");
$("#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() {
var base_url;
base_url = $("#energy-reports-url").text();
if (base_url.length > 0) {
$.getJSON(base_url + "org_to_bldgs.json").done(function(results) {
_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();
......@@ -68,7 +87,7 @@
err = textStatus + ", " + error;
return alert("Error Occurred: " + err);
});
$.getJSON(base_url + "building.json").done(function(results) {
$.getJSON(_base_url + "building.json").done(function(results) {
_bldg_reports = results;
return update_report_list();
}).fail(function(jqxhr, textStatus, error) {
......@@ -77,7 +96,7 @@
err = textStatus + ", " + error;
return alert("Error Occurred: " + err);
});
$.getJSON(base_url + "organization.json").done(function(results) {
$.getJSON(_base_url + "organization.json").done(function(results) {
_org_reports = results;
return update_report_list();
}).fail(function(jqxhr, textStatus, error) {
......
......@@ -16,6 +16,10 @@
<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>
......@@ -29,23 +33,16 @@
</form>
</div>
<hr/>
<div class="row mx-1 mt-3">
<ul id="report-tab-list" class="nav nav-tabs flex-wrap" role="tablist">
<li class="nav-item">
<a class="nav-link active" data-toggle="tab" href="#home" role="tab">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#profile" role="tab">Profile</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#messages" role="tab">Messages</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#settings" role="tab">Settings</a>
</li>
</ul>
</div>
<div class="row mt-3">
<iframe id="report-content" src="" width="100%" height="1000px"></iframe>
</div>
{% endblock %}
......
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