From 0a52934d084a8b8deb668760b8332eb13e9ec70b Mon Sep 17 00:00:00 2001 From: Alan Mitchell Date: Wed, 11 Mar 2020 18:57:40 -0800 Subject: [PATCH] Got most features working for BMON Essential Reports. --- bmsapp/static/bmsapp/css/bmsapp.css | 14 +++--- .../bmsapp/scripts/energy-reports.coffee | 41 ++++++++++++----- .../static/bmsapp/scripts/energy-reports.js | 45 +++++++++++++------ bmsapp/templates/bmsapp/energy-reports.html | 21 ++++----- 4 files changed, 80 insertions(+), 41 deletions(-) diff --git a/bmsapp/static/bmsapp/css/bmsapp.css b/bmsapp/static/bmsapp/css/bmsapp.css index c76836a..831417f 100644 --- a/bmsapp/static/bmsapp/css/bmsapp.css +++ b/bmsapp/static/bmsapp/css/bmsapp.css @@ -1,21 +1,25 @@ /* 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); } diff --git a/bmsapp/static/bmsapp/scripts/energy-reports.coffee b/bmsapp/static/bmsapp/scripts/energy-reports.coffee index 43337e9..f7b35df 100644 --- a/bmsapp/static/bmsapp/scripts/energy-reports.coffee +++ b/bmsapp/static/bmsapp/scripts/energy-reports.coffee @@ -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 = """ """ $("#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 - diff --git a/bmsapp/static/bmsapp/scripts/energy-reports.js b/bmsapp/static/bmsapp/scripts/energy-reports.js index 50e2d68..ff496ec 100644 --- a/bmsapp/static/bmsapp/scripts/energy-reports.js +++ b/bmsapp/static/bmsapp/scripts/energy-reports.js @@ -1,6 +1,8 @@ // 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 = "
  • \n " + rpt.title + "\n
  • "; + html = "
  • \n " + rpt.title + "\n
  • "; 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) { diff --git a/bmsapp/templates/bmsapp/energy-reports.html b/bmsapp/templates/bmsapp/energy-reports.html index 4ca4024..f5e65f9 100644 --- a/bmsapp/templates/bmsapp/energy-reports.html +++ b/bmsapp/templates/bmsapp/energy-reports.html @@ -16,6 +16,10 @@

    Energy Reports

    +
    Under Construction: Formatting Improvements in Progress
    + +
    +
    {{ error_message }}
    @@ -29,23 +33,16 @@ +
    +
    +
    + +
    {% endblock %} -- 2.26.2