Commit ec053dd9 authored by Alan Mitchell's avatar Alan Mitchell

Progress on adding Building and Report Selectors.

parent 2bf51c07
...@@ -14,6 +14,52 @@ _bldg_reports = {} ...@@ -14,6 +14,52 @@ _bldg_reports = {}
# An object mapping organization ID to a list of organization reports # An object mapping organization ID to a list of organization reports
_org_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())
# 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) ->
html = """
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="##{ 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 Organization reports if this building is in the list
if _org_reports[org]?
add_report rpt for rpt in _org_reports[org]
# Select the first tab
$("#report-tab-list a:first").addClass("active")
# --------------------------------------------------------------- # ---------------------------------------------------------------
# function that runs when the document is ready. # function that runs when the document is ready.
$ -> $ ->
...@@ -26,6 +72,8 @@ $ -> ...@@ -26,6 +72,8 @@ $ ->
$.getJSON(base_url + "org_to_bldgs.json").done((results) -> $.getJSON(base_url + "org_to_bldgs.json").done((results) ->
_org_to_bldgs = results _org_to_bldgs = results
update_bldg_list()
update_report_list()
).fail (jqxhr, textStatus, error) -> ).fail (jqxhr, textStatus, error) ->
$("body").css "cursor", "default" # remove hourglass cursor $("body").css "cursor", "default" # remove hourglass cursor
err = textStatus + ", " + error err = textStatus + ", " + error
...@@ -33,6 +81,7 @@ $ -> ...@@ -33,6 +81,7 @@ $ ->
$.getJSON(base_url + "building.json").done((results) -> $.getJSON(base_url + "building.json").done((results) ->
_bldg_reports = results _bldg_reports = results
update_report_list()
).fail (jqxhr, textStatus, error) -> ).fail (jqxhr, textStatus, error) ->
$("body").css "cursor", "default" # remove hourglass cursor $("body").css "cursor", "default" # remove hourglass cursor
err = textStatus + ", " + error err = textStatus + ", " + error
...@@ -40,9 +89,14 @@ $ -> ...@@ -40,9 +89,14 @@ $ ->
$.getJSON(base_url + "organization.json").done((results) -> $.getJSON(base_url + "organization.json").done((results) ->
_org_reports = results _org_reports = results
$("#debug-out").text JSON.stringify(_org_reports) update_report_list()
).fail (jqxhr, textStatus, error) -> ).fail (jqxhr, textStatus, error) ->
$("body").css "cursor", "default" # remove hourglass cursor $("body").css "cursor", "default" # remove hourglass cursor
err = textStatus + ", " + error err = textStatus + ", " + error
alert "Error Occurred: " + err 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 // Generated by CoffeeScript 1.12.7
(function() { (function() {
var _bldg_reports, _org_reports, _org_to_bldgs; var _bldg_reports, _org_reports, _org_to_bldgs, update_bldg_list, update_report_list;
_org_to_bldgs = {}; _org_to_bldgs = {};
...@@ -8,12 +8,60 @@ ...@@ -8,12 +8,60 @@
_org_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);
}
return $("#select_bldg").val($("#select_bldg option:first").val());
}
};
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) {
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>";
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);
}
}
if (_org_reports[org] != null) {
ref1 = _org_reports[org];
for (j = 0, len1 = ref1.length; j < len1; j++) {
rpt = ref1[j];
add_report(rpt);
}
}
return $("#report-tab-list a:first").addClass("active");
};
$(function() { $(function() {
var base_url; var base_url;
base_url = $("#energy-reports-url").text(); base_url = $("#energy-reports-url").text();
if (base_url.length > 0) { if (base_url.length > 0) {
$.getJSON(base_url + "org_to_bldgs.json").done(function(results) { $.getJSON(base_url + "org_to_bldgs.json").done(function(results) {
return _org_to_bldgs = results; _org_to_bldgs = results;
update_bldg_list();
return update_report_list();
}).fail(function(jqxhr, textStatus, error) { }).fail(function(jqxhr, textStatus, error) {
var err; var err;
$("body").css("cursor", "default"); $("body").css("cursor", "default");
...@@ -21,22 +69,26 @@ ...@@ -21,22 +69,26 @@
return alert("Error Occurred: " + err); return alert("Error Occurred: " + err);
}); });
$.getJSON(base_url + "building.json").done(function(results) { $.getJSON(base_url + "building.json").done(function(results) {
return _bldg_reports = results; _bldg_reports = results;
return update_report_list();
}).fail(function(jqxhr, textStatus, error) { }).fail(function(jqxhr, textStatus, error) {
var err; var err;
$("body").css("cursor", "default"); $("body").css("cursor", "default");
err = textStatus + ", " + error; err = textStatus + ", " + error;
return alert("Error Occurred: " + err); return alert("Error Occurred: " + err);
}); });
return $.getJSON(base_url + "organization.json").done(function(results) { $.getJSON(base_url + "organization.json").done(function(results) {
_org_reports = results; _org_reports = results;
return $("#debug-out").text(JSON.stringify(_org_reports)); return update_report_list();
}).fail(function(jqxhr, textStatus, error) { }).fail(function(jqxhr, textStatus, error) {
var err; var err;
$("body").css("cursor", "default"); $("body").css("cursor", "default");
err = textStatus + ", " + error; err = textStatus + ", " + error;
return alert("Error Occurred: " + err); return alert("Error Occurred: " + err);
}); });
$("#select_org").change(update_bldg_list);
$("#select_org").change(update_report_list);
return $("#select_bldg").change(update_report_list);
} }
}); });
......
...@@ -20,17 +20,36 @@ ...@@ -20,17 +20,36 @@
<div id="debug-out"></div> <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>
<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>
{% endblock %} {% endblock %}
{% block scripts %} {% block scripts %}
<script>
forceReload = function() {
location.reload(true);
};
$(function () {
$("#select_org").change(forceReload);
});
</script>
{% endblock %} {% 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