Skip to content

Commit ddb29d0

Browse files
committed
Added colors and buttons
1 parent 75ead36 commit ddb29d0

4 files changed

Lines changed: 52 additions & 25 deletions

File tree

dr-controler.js

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,30 @@ async function stateChange(state) {
2525
}
2626
}
2727

28+
const questionnaryButtons = {};
2829
async function setQuestionnaries() {
29-
const select = document.getElementById("select-questionnary");
30-
const optionNull = document.createElement("option");
31-
optionNull.text = '---';
32-
optionNull.value = '';
33-
select.add(optionNull);
30+
// -- on load
31+
const selectedQuestionnary = getQuestionnaryFromUrl();
32+
33+
34+
const tbody = document.getElementById('questionnary-table').getElementsByTagName('tbody')[0];
35+
// clear previous content
36+
while (tbody.firstChild) {
37+
tbody.removeChild(tbody.firstChild);
38+
}
3439

3540
const quests = await drLib.getQuestionnaires();
3641
for (const [key, value] of Object.entries(quests)) {
37-
const option = document.createElement("option");
38-
option.text = value.title;
39-
option.value = key;
40-
select.add(option);
41-
}
42-
43-
// -- on change
44-
select.onchange = function () {
45-
if (select.value === '') {
46-
showQuestionnary(null);
47-
return;
48-
}
49-
showQuestionnary(select.value);
50-
}
51-
// -- on load
52-
const selectedQuestionnary = getQuestionnaryFromUrl();
42+
const row = tbody.insertRow(-1);
43+
const cellQuestionnary = row.insertCell(-1);
44+
cellQuestionnary.innerHTML = `<button type="button" class="btn btn-secondary mb-sm">${value.title}</button>`;
45+
questionnaryButtons[key] = cellQuestionnary.getElementsByTagName('button')[0];
46+
cellQuestionnary.onclick = function () {
47+
showQuestionnary(key);
48+
};
49+
};
50+
5351
if (selectedQuestionnary) {
54-
select.value = selectedQuestionnary;
5552
showQuestionnary(selectedQuestionnary);
5653
}
5754
}
@@ -63,7 +60,15 @@ function getQuestionnaryFromUrl() {
6360
return questionaryId
6461
}
6562

63+
function highlightQuestionnaryButton(questionaryId) {
64+
for (const [key, button] of Object.entries(questionnaryButtons)) {
65+
const color = (questionaryId === key) ? "LightSeaGreen" : 'lightgrey';
66+
button.style.backgroundColor = color;
67+
}
68+
}
69+
6670
async function showQuestionnary(questionaryId) {
71+
highlightQuestionnaryButton(questionaryId);
6772
console.log('## showQuestionnary', questionaryId);
6873
if (questionaryId == null) {
6974
document.getElementById('questionnary-view').style.visibility = 'hidden';

dr.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,15 @@ <h2 class="card-title">Welcome</h2>
3636
</div>
3737
</div>
3838
<div class="card" id="data-view" style="visibility: hidden;">
39-
Select a questionnary: <select id="select-questionnary" class="form-control"></select>
39+
<table id='questionnary-table' class="table">
40+
<thead>
41+
<th> Select a questionnary:</th>
42+
</thead>
43+
<tbody>
44+
<!-- will be filled by getQuestionaires-->
45+
</tbody>
46+
</table>
47+
4048
<div id="questionnary-view">
4149
<div class="card">
4250
<h2 class="card-title">Sharing link</h2>

patient-home-controler.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@ function getRequestFrormApiEndPoint() {
4040
}
4141

4242
// --------- Update form list --------- //
43+
const questionnaryRows = {};
4344
async function showFormList(formsInfo) {
4445
console.log('## showFormList', formsInfo);
4546

4647
// -- table
47-
const tbody = document.getElementById('questionnary-table').getElementsByTagName('tbody')[0];;
48+
const tbody = document.getElementById('questionnary-table').getElementsByTagName('tbody')[0];
4849

4950
// clear previous content
5051
while (tbody.firstChild) {
@@ -57,6 +58,9 @@ async function showFormList(formsInfo) {
5758
const cellQuestionnary = row.insertCell(-1);
5859
const formTitle = patientLib.getFormTitle(formInfo.questionaryId);
5960
cellQuestionnary.innerHTML = `<button type="button" class="btn btn-secondary mb-sm">${formTitle}</button>`;
61+
questionnaryRows[formInfo.questionaryId + ':' + formInfo.drUserId] = {
62+
row, button: cellQuestionnary.getElementsByTagName('button')[0]
63+
}
6064
cellQuestionnary.onclick = function () {
6165
showFormDetails(formInfo);
6266
};
@@ -69,8 +73,18 @@ async function showFormList(formsInfo) {
6973
}
7074
}
7175

76+
function highlightQuestionnaryButton(buttonKey) {
77+
for (const [key, entry] of Object.entries(questionnaryRows)) {
78+
const colorButton = (buttonKey === key) ? "LightSeaGreen" : 'lightgrey';
79+
const colorRow = (buttonKey === key) ? 'lightgrey' : '';
80+
entry.button.style.backgroundColor = colorButton;
81+
entry.row.style.backgroundColor = colorRow;
82+
}
83+
}
84+
7285
// ----------- Show form details ----------- //
7386
async function showFormDetails(formInfo) {
87+
highlightQuestionnaryButton(formInfo?.questionaryId + ':' + formInfo?.drUserId);
7488
const show = !!formInfo;
7589
document.getElementById('card-questionnary-details-nothing').style.display = show ? 'none' : 'block';
7690
document.getElementById('card-questionnary-details-something').style.display= show ? 'block' : 'none';

patient.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ <h2 class="card-title">Welcome</h2>
3939
<h2>Questionnaries</h2>
4040
<table id='questionnary-table' class="table">
4141
<thead>
42-
<th>Questionnary Id</th>
42+
<th>Questionnary</th>
4343
<th>Dr username</th>
4444
<th>Status</th>
4545
</thead>

0 commit comments

Comments
 (0)