From cf0f740364bed72cb7515cf74505a5f08406ab66 Mon Sep 17 00:00:00 2001 From: Joko Sanyang Date: Fri, 12 Apr 2019 11:41:19 +0100 Subject: [PATCH] remove opinion ids from index, getData and script Relates #18 --- public/index.html | 1 - public/script.js | 64 +++++++++++++++++----------------- src/scripts/queries/getData.js | 2 +- 3 files changed, 33 insertions(+), 34 deletions(-) diff --git a/public/index.html b/public/index.html index cfbee58..7a82651 100644 --- a/public/index.html +++ b/public/index.html @@ -21,7 +21,6 @@

Hello Onions

- diff --git a/public/script.js b/public/script.js index 5a89666..fc6042c 100644 --- a/public/script.js +++ b/public/script.js @@ -3,44 +3,44 @@ const opinionTable = document.querySelector('.opinion-table'); const formActionId = document.querySelector('#form-id-to-send'); const buildEachRow = (data, tableToFill) => { - console.log('This is the data:', data); + while(tableToFill.childNodes[2]) { + tableToFill.removeChild(tableToFill.childNodes[2]) + }; + + const inputs = data; - while(tableToFill.childNodes[2]) { - tableToFill.removeChild(tableToFill.childNodes[2]) - }; - - const inputs = data; - inputs.forEach((input) => { - const inputRow = document.createElement('tr'); - - inputRow.value = input.id; + inputs.forEach((input) => { + const inputRow = document.createElement('tr'); + inputRow.value = input.id; + if (tableToFill === actionTable) { const inputId = document.createElement('td'); inputId.textContent = input.id; inputRow.appendChild(inputId); - if (tableToFill === actionTable) { - const inputAction = document.createElement('td'); - inputAction.textContent = input.action_point; - inputRow.appendChild(inputAction); - } else { - const inputName = document.createElement('td'); - inputName.textContent = input.name; - const inputOpinion = document.createElement('td'); - inputOpinion.textContent = input.opinion; - inputRow.appendChild(inputName); - inputRow.appendChild(inputOpinion); - } - - const inputDate = document.createElement('td'); - inputDate.textContent = input.date; - inputRow.appendChild(inputDate); - - if (tableToFill === actionTable) { - inputRow.addEventListener('click', getOpinionTable ); - } - tableToFill.appendChild(inputRow); - }); + const inputAction = document.createElement('td'); + inputAction.textContent = input.action_point; + inputRow.appendChild(inputAction); + + } else if (tableToFill === opinionTable) { + const inputName = document.createElement('td'); + inputName.textContent = input.name; + inputRow.appendChild(inputName); + + const inputOpinion = document.createElement('td'); + inputOpinion.textContent = input.opinion; + inputRow.appendChild(inputOpinion); + } + + const inputDate = document.createElement('td'); + inputDate.textContent = input.date; + inputRow.appendChild(inputDate); + + if (tableToFill === actionTable) { + inputRow.addEventListener('click', getOpinionTable ); + } + tableToFill.appendChild(inputRow); + }); }; //on load function to get current actions table diff --git a/src/scripts/queries/getData.js b/src/scripts/queries/getData.js index 667c801..2c329da 100644 --- a/src/scripts/queries/getData.js +++ b/src/scripts/queries/getData.js @@ -10,7 +10,7 @@ const actionQuery = cb => { //FINISH THIS const opinionQuery = (cb, url) => { let id = url.split('=')[1]; - dbConnection.query(`SELECT id, name, opinion, date FROM opinions WHERE action_id = $1`,[id], + dbConnection.query(`SELECT name, opinion, date FROM opinions WHERE action_id = $1`,[id], (err, res) => { if (err) return cb(err); cb(null, res.rows);
ID Name Opinion Date