Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed undesired behavior on "Add or Modify Sensors" page #144

Merged
merged 1 commit into from Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 28 additions & 18 deletions mercury/static/mercury/js/sensor.js
Expand Up @@ -48,28 +48,38 @@ add_field_button.onclick = function() {
addRow();
}

function displayCurrentSensors() {
/*
selectView displays the correct view of the "Add or Modify Sensors" page
-the default view is to show existing sensors
-if a user submits a new sensor which posts and reloads page, then the add new sensor view should remain
*/
function selectView() {
var newSensorDiv = document.getElementById("add-new-sensor");
var existingSensorDiv = document.getElementById("existing-sensors");
var modifyButton = document.getElementById("current-sensor-btn");
var newButton = document.getElementById("add-sensor-btn");
if (existingSensorDiv.style.display === "none") {
newSensorDiv.style.display = "none";
existingSensorDiv.style.display = 'block';
modifyButton.style.backgroundColor = 'var(--green)';
newButton.style.backgroundColor = 'var(--light-accent)';
}
if (sessionStorage.getItem('viewing') == 'addingNew'){
newSensorDiv.style.display = "block";
existingSensorDiv.style.display = 'none';

modifyButton.style.backgroundColor = 'var(--light-accent)';
newButton.style.backgroundColor = 'var(--green)';
}
else {
newSensorDiv.style.display = "none";
existingSensorDiv.style.display = 'block';

modifyButton.style.backgroundColor = 'var(--green)';
newButton.style.backgroundColor = 'var(--light-accent)';
}
}

function displayCurrentSensors() {
sessionStorage.setItem('viewing', 'existing');
selectView()
}

function displayAddNewSensor() {
var newSensorDiv = document.getElementById("add-new-sensor");
var existingSensorDiv = document.getElementById("existing-sensors");
var modifyButton = document.getElementById("current-sensor-btn");
var newButton = document.getElementById("add-sensor-btn");
if (newSensorDiv.style.display === "none") {
newSensorDiv.style.display = "block";
existingSensorDiv.style.display = 'none';
modifyButton.style.backgroundColor = 'var(--light-accent)';
newButton.style.backgroundColor = 'var(--green)';
}
}
sessionStorage.setItem('viewing', 'addingNew');
selectView()
}
6 changes: 3 additions & 3 deletions mercury/templates/sensor.html
Expand Up @@ -10,7 +10,7 @@
<script src="{% static "mercury/js/sensor.js" %}" defer></script>
</head>

<body>
<body onload="selectView();">
{% include 'sidebar.html' %}
<div id="grafana-base"> <!-- app default background -->
<div class="panel">
Expand All @@ -23,7 +23,7 @@ <h1> Add or Modify Sensors </h1>
<div class="panel">
<nav>
<ul>
<li><button onclick="displayCurrentSensors()" id="current-sensor-btn" class="grafana-btn" style="background-color:var(--green);"> Modify Current Sensors </button></li>
<li><button onclick="displayCurrentSensors()" id="current-sensor-btn" class="grafana-btn"> Modify Current Sensors </button></li>
<li><button onclick="displayAddNewSensor()" id="add-sensor-btn" class="grafana-btn"> Add New Sensor </button></li>
</ul>
</nav>
Expand Down Expand Up @@ -78,7 +78,7 @@ <h4 class="inline-block-child"><u>Field Unit</u></h4>
{% endif%}
</div> <!-- end existing sensors -->

<div class="panel" id="add-new-sensor" style="display:none;">
<div class="panel" id="add-new-sensor">
<h2>Add a New Sensor</h2>
<br>

Expand Down