From 2ad6bee31e1b70099b375868b5221ffd7624f475 Mon Sep 17 00:00:00 2001 From: MarioTurco Date: Tue, 1 Sep 2020 15:31:53 +0200 Subject: [PATCH] Completata gestione del peso --- src/edit.html | 42 ++++++++++++++++--- src/edit.js | 97 ++++++++++++++++++++++++++++++++++++++++++- src/index.html | 14 ++++--- src/logic.js | 4 +- src/visualizeLogic.js | 5 ++- 5 files changed, 145 insertions(+), 17 deletions(-) diff --git a/src/edit.html b/src/edit.html index 5fa1c75..7c82d69 100644 --- a/src/edit.html +++ b/src/edit.html @@ -1,5 +1,5 @@ - + Gym Utils @@ -23,7 +23,9 @@ - Edit +
+

Seleziona una riga e compila i campi per modificarlo

+
@@ -34,10 +36,38 @@
- - - - +
+
+ +
+
+
+

+ +

+
+
+
+
+
+ +
+
+
+

+ +

+
+
+
+
+ +
diff --git a/src/edit.js b/src/edit.js index 447a2c4..138c42b 100644 --- a/src/edit.js +++ b/src/edit.js @@ -2,13 +2,23 @@ const db = require('electron-db'); const { app, BrowserWindow } = require('electron'); const { ipcRenderer } = require('electron') - +//Buttons +const editRowBtn = document.getElementById("editRowBtn"); //Tabs const visualizeTab = document.getElementById('visualizeTab'); const settingsTab = document.getElementById('settingsTab') const addTab = document.getElementById('addTab'); const deleteTab = document.getElementById('deleteTab'); +//Table +const table = document.getElementById('visualizeTable'); + +//Fields +const pesoText = document.getElementById('pesoText'); +const dataText = document.getElementById('dataText'); + +var lastSelectedRow = null; + //Tabs listeners visualizeTab.onclick = () =>{ ipcRenderer.sendSync('synchronous-message', 'visualize'); @@ -22,4 +32,87 @@ addTab.onclick = () =>{ } deleteTab.onclick = () =>{ ipcRenderer.sendSync('synchronous-message', 'delete'); -} \ No newline at end of file +} +function dataError(){ + document.getElementById("dataText").classList.add('is-danger'); +} +function pesoError(){ + document.getElementById("pesoText").classList.add('is-danger'); +} +//Button Listener +editRowBtn.onclick = () =>{ + deselectEffect(lastSelectedRow); + var oldData = lastSelectedRow.getElementsByTagName('td')[0].textContent; + var newPeso = pesoText.value; + var newData = dataText.value; + console.log("old data" , oldData); + console.log("new data" , newData); + console.log("new peso", newPeso); + if(newPeso.length == 0 || newData.length != 10){ + if(newPeso.length == 0) + pesoError(); + if(newData.length != 10) + dataError(); + return; + } + let where = { + "data" : oldData + }; + let set = { + "data" : newData, + "peso" : newPeso + }; + db.updateRow('peso', where, set, (succ, msg) => { + // succ - boolean, tells if the call is successful + console.log("Success: " + succ); + console.log("Message: " + msg); + }); + + location.reload(); + +} +function selectEffect(row){ + if(row != null) + row.classList.add('is-selected'); +} +function deselectEffect(row){ + if(row != null) + if ( row.classList.contains('is-selected') ) + row.classList.remove('is-selected'); + +} +function fillTable(){ + db.getAll('peso',(succ, data) => { + console.log(data); + let index = 1; + //create row + for(elems in data){ + var row = table.insertRow(index); + var dataCell = row.insertCell(0); + var pesoCell = row.insertCell(1); + dataCell.innerHTML = data[elems].data; + pesoCell.innerHTML = data[elems].peso; + index+=1; + } + return data; + }) +} +function addRowsListeners(){ + var rows = table.getElementsByTagName("tr"); + for(i=0; iImpostazioni -
- - +
+
+ +
+
-
- +
+
+ +
diff --git a/src/logic.js b/src/logic.js index 386602a..d219e3c 100644 --- a/src/logic.js +++ b/src/logic.js @@ -53,9 +53,7 @@ function pesoError(){ addBtn.onclick = () => { let record = new Object(); - tmp = document.getElementById('dataText').value; - - record.data = tmp.substring(8,11) + '-' + tmp.substring(5,7) + '-' + tmp.substring(0,4); + record.data = document.getElementById('dataText').value; console.log("Data:" , record.data); record.peso = document.getElementById('pesoText').value; if(record.data == '' || record.peso == ''){ diff --git a/src/visualizeLogic.js b/src/visualizeLogic.js index a3888df..81e58cf 100644 --- a/src/visualizeLogic.js +++ b/src/visualizeLogic.js @@ -33,6 +33,9 @@ var ctx = document.getElementById('chart').getContext('2d'); function sortDataByDate(data){ return( data.sort((a,b) => a.data < b.data ? -1 : 1)); } +function revereSortDataByDate(data){ + return( data.sort((a,b) => a.data < b.data ? 1 : -1)); +} function createChart(data){ sortDataByDate(data); let peso = [] @@ -41,7 +44,6 @@ function createChart(data){ peso.push(data[elems].peso); date.push(data[elems].data); } - console.log(data); var chart = new Chart(ctx, { // The type of chart we want to create type: 'line', @@ -66,6 +68,7 @@ function fillTable(){ db.getAll('peso',(succ, data) => { console.log(data); createChart(data); + revereSortDataByDate(data); let index = 1; for(elems in data){ var row = table.insertRow(index);