@ -581,7 +581,7 @@ function do_grid_weekly(myid, startingDate, data) {
. style ( "top" , ( d3 . event . pageY - 10 ) + "px" )
. style ( "background-color" , "#c3c3c3" )
. style ( "opacity" , 1 )
. html ( "Value: " + d . toFixed ( 2 ) ) ;
//.html("Value: " + d.toFixed(2));
} )
. on ( "mouseout" , ( ) => {
// Hide tooltip on mouseout
@ -1856,37 +1856,44 @@ function getCurrentBoardData(boardName, boardDesc) {
"col-center" : apiUrlsCenter ,
"col-right" : apiUrlsRight
} ;
//alert(JSON.stringify(result));
alert ( JSON . stringify ( result ) ) ;
return sendDataToAPI ( JSON . stringify ( result ) ) ;
}
// function to send and save the collected data from the current borad to the server thriugh the API
function sendDataToAPI ( myJSON ) {
//var myJSON = JSON.parse('{"Name":"YEAR","Description":"wwww","Hus":"Charlie","col-left":[],"col-center":[{"order":0,"id":"grid-996239","text":"","api_url":"grid/yearly?hus=Charlie&sensor=Temp_MP1_1_Pos1&type=celsius&year=2023"}],"col-right":[]}');
const form = document . getElementById ( "saveBoardForm" ) ; // Get the form element
const inputField = document . getElementById ( "boardName" ) ; // Get the input field element
form . addEventListener ( "submit" , function ( event ) {
if ( inputField . value . trim ( ) === "" ) { // Check if the input field is empty after trimming whitespace
event . preventDefault ( ) ; // Prevent form submission
cl ( "inputField" ) ;
cl ( inputField . value ) ;
form . addEventListener ( "click" , function ( event ) {
cl ( inputField . value ) ;
//JAUME
if ( inputField . value . trim ( ) === "" ) {
cl ( "It is null!!" ) ;
event . preventDefault ( ) ;
console . log ( "Empty field detected. Form submission blocked." ) ;
} else {
base _url _API = "http://localhost:5000" ;
const myApiUrl = base _url _API + "/boards/save" ; // Replace with your API URL
//base_url_API = "http://localhost:5000";
const myApiUrl = base _url _API + "/boards/save" ;
const requestOptions = {
method : "POST" ,
headers : {
"Content-Type" : "application/json"
} ,
body : myJSON //.stringify(myJSON)
headers : { "Content-Type" : "application/json" } ,
body : myJSON
} ;
fetch ( myApiUrl , requestOptions )
//.then(response => response.json())
. then ( response => {
console . log ( "Response from API:" , response ) ;
return response . text ( ) ;
} )
. then ( data => {
console . log ( "Response from API:" , myJSON ) ;
console . log ( "Response content:" , data ) ;
// Handle the response from the API as needed
const myModal = new bootstrap . Modal ( document . getElementById ( "saveBoardModal" ) ) ;
const submitBtn = document . getElementById ( "submitBoard" ) ;
submitBtn . addEventListener ( "click " , function ( ) {
submitBtn . addEventListener ( "submit " , function ( ) {
myModal . hide ( ) ;
} ) ;
alert ( "Board saved!" ) ;
@ -1918,6 +1925,12 @@ async function loadBoards(myJSON) {
//myJSON = {"Name":"dddd","Description":" f fa af ffsdfsdfs fsd","Hus":"Charlie","col-left":[],"col-center":[{"order":0,"id":"grid-710994","text":"","api_url":"grid/weekly?hus=Charlie&sensor=Temp_MP1_1_Pos1&type=celsius&year=2023&week=23"}],"col-right":[]};
var cols = [ "col-left" , "col-center" , "col-right" ] ;
cols . forEach ( col => {
// First clen the three clumns:
const colLeftDiv = document . getElementById ( col ) ;
while ( colLeftDiv . firstChild ) {
colLeftDiv . firstChild . remove ( ) ;
}
if ( col . length > 0 ) {
myJSON [ col ] . forEach ( async element => {
// Get necessary variables:
@ -1927,12 +1940,6 @@ async function loadBoards(myJSON) {
var myTitle = element . text ;
// Create DIV
await createMyDiv ( myid , myColumn , myTitle ) ;
// setTimeout(function() {
// console.log("After 2 seconds");
// // Code to be executed after the delay
// }, 2000);
// Check if is TXT or Diagram:
if ( element . api _url != null ) {
var apiurl = element . api _url ;
@ -1945,8 +1952,6 @@ async function loadBoards(myJSON) {
case "PD" :
var family = getValueByKeyFrrmUrl ( "family" , apiurl ) ;
var day = getValueByKeyFrrmUrl ( "day" , apiurl ) ;
// cl("PD LoadBoards:");
// cl(formId+" - "+apiurl+" - "+myid+" - "+myTitle+" - "+family+" - "+type+" - "+day);
makeApiRequest ( formId , apiurl , myid , myTitle , family , type , day ) ;
break ;
@ -1970,8 +1975,6 @@ async function loadBoards(myJSON) {
makeApiRequest ( formId , apiurl , myid ) ;
break ;
}
} else {
var formId = "TXT" ;
createTXT ( myid , element . text ) ;
@ -1979,7 +1982,6 @@ async function loadBoards(myJSON) {
} ) ;
}
} ) ;
}
// function to load THE LIST OF boards FOR AN SPECIFIC hOUSE