Javascript/HTML: Show a table from JSON data stored in LittleFS (ESP32)

I’m trying to show a table in HTML from a JSON file stored in LittleFS in ESP32 microcontroller.

This file (named log.txt in LittleFS) is updated from a RFID routine or manually by /manage-users page, and this functions are working.

The JSON file is correctly uploaded and readed by the program (ArduinoJson.h) and the structure is:

[
  {
    "room": 302,
    "uid": "AAAAAAAA",
    "guest": 2,
    "hour": "20/05/25 10:45"
  },
  {
    "room": 203,
    "uid": "BBBBBBBB",
    "guest": 1,
    "hour": "05/12/91 10:25"
  }
]

I’m trying to show it in a HTML table with javascript but I fail miserably, the data is coming from:

server.on("/view-log", HTTP_GET, [](AsyncWebServerRequest* request) {
    request->send(LittleFS, "/log.txt", "text/plain", false);
});

This is served from ESPAsyncWebServer.h library, the HTML code is:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="refresh" content="30">
        <meta charset="UTF8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>ESP WEBSERVER</title>
        <link rel="stylesheet" href="style.css">
    </head>
<body>
    <nav>
        <div class="nav-container">
            <a href="/" class="brand">User Management</a>
            <ul class="nav-menu">
                <li><a href="/"> full log</a></li>
                <li><a href="add-user">Add user</a></li>
                <li><a href="manage-users">Manage users</a></li>
            </ul>
        </div>
    </nav>
    <div class="main-container">
        <section class="main-selection">
            <h2>Full access log</h2>
            <table id="tableData">
                <thead>
                    <tr>
                        <th>Room</th>
                        <th>Uid</th>
                        <th>Guest</th>
                        <th>hour</th>
                    </tr>                       
                </thead>
                <tbody id="data-output">
                    <!-- DATA -->
                </tbody>
            </table>
        </section>
    </div>
    <div class="main-container">
        <a href="get?delete=log"><buttton class="button button-delete">DELETE log.txt</button></a>
    </div>
    <script>
        async function loadTableData(){
            try{
                const response = await fetch('view-log');
                const data = await reponse.text();
                var table = document.getElementById('data-output')
                for (var i = 0; i < data.length; i++){
                    var row = `<tr>
                            <td>${data[i].room}</td>
                            <td>${data[i].uid}</td>
                            <td>${data[i].guest}</td>
                            <td>${data[i].hour}</td>
                        </tr>`
                    tab.innerHTML += row
                }
            } catch (error) {
                console.error('Error loading log data:', error);
            }
        }
        loadTableData();
    </script>
</body>
</html>

In the browser console I’m getting the error

(index):58 Error loading log data: ReferenceError: reponse is not defined at loadTableData ((index):46:18)

Probably for the way i’m feeding data to the script, but I’m completely a noob with javascript so I’m forced to ask for help here.
By now I’m feeding the table in only HTML code but it’s not fittable in an expasion of the website so I want to reach a javascript solution for this kind of problem.
Thank you in advance for helping me!

How to pass Cypress environment variables to cypress-parallel command?

I have one scenario where I need to pass URL, USERNAME and Password for the execution.

Usually I do passing environment variables through command line similar to

npx cypress run --headed --browser chrome --env URL=https://testurl.com,USER=admin,PASSWORD=test

But when I tried to implement cypress-parallel to enable parallel execution, I’m not able to pass Environment variables.

Have provided the below code in package.json

  "scripts": {
    "cy:run": "npx cypress run --headed --browser chrome",
    "cy:parallel": "cypress-parallel -d 'cypress/e2e/ui/FunctionalValidations/' -t 3 -s cy:run"
  }`

and tried to run script with Environment variables it is not accepting the values.

npm run cy:parallel --env URL=https://testurl.com,USER=admin,PASSWORD=test`

How can I pass environment variables to the cypress-parallel method to get executed?

Closures and performance of js [closed]

what is the better : code A or code B , for more performance and why.

Code A :

document.getElementById("ff").addEventListener("click", VV);
    function VV() {
        let cc = document.getElementById("cc");
        function CC() {
             cc.innerHTML = "cc";
        }
        return CC();
    }

Code B :

document.getElementById("ff").addEventListener("click", VV);
        function VV() {
            let cc = document.getElementById("cc");
           cc.innerHTML = "cc";
        }

Function call causes a setState function to become undefined before it is even called

I am facing a truly peculiar problem. I have a function that calls another function to validate height

const validateHeight= async () => {
  const {currentFormData} = cloneDeep(state);
  let validHeight;
  //heightValidationLogic here, also includes API calls
  if(validHeight){
      return [true, max_height];
    } 
  else {
    return [false, 0];
  }
  const peculiarFunction = async () => { //This is the main function
    let isvalidHeight = true;
    let maxHeight = 0;
    const {currentFormData} = cloneDeep(state);
      if(currentFormData.map){ //checks if the map property is true
        setState({...state, isLoading:'hasMap'})
        [isValidHeight,maxHeight] = await validateHeight(); //Here, the other function is called
        //Other height based logic
        setState({...state, isLoading:''})
      }
    //Code to continue with form submission or show to error for invalid height 
  };

Issue is, the setState({...state, isLoading:'hasMap'}) line before the function call returns the error setState(...) is undefined, and the peculiar behaviour is, if I return the response from the validateHeight() function as an object return {isValidHeight: true, availableHeight: max_height}rather than as an array to be destructured, the error goes away. How does the function call cause an error in a line before it is even called?

I’ve logged the response from validateHeight() in both cases constantly, there are no errors in the function and the values are always exactly what I expect when the function runs. I added a try catch statement in the peculiar function and slowly limited the number of lines in it to see if its an issue with asynchronous operations and that the error is occuring somewhere else. As long as both the setState() call and the validateheight() function are in the same block/scope, the error occurs. The moment any one of them is no longer under the same try-catch statement, the error goes away, everything is working now.
The issue also does NOT occur with the second setState() statement that comes after the function call, it never returns an error with any combination of try-catch statements.
I understand that I have the alternative of returning the response as an object and will be moving forward with it, but I do want to understand this strange behaviour and find an answer for it. Hopefully someone here can help.

How print every line of a php script as its being executed?

How to print every line of a php script as it’s being executed?

For example in Python you can do

$ cat test.py 
import time
print('hello')
time.sleep(3)
print('goodbye')

$ python -m trace -t test.py 
 --- modulename: test, funcname: <module>
test.py(1): import time
test.py(2): print('hello')
hello
test.py(3): time.sleep(3)
test.py(4): print('goodbye')
goodbye

Is there a PHP equivalent?

Cannot drag and drop test case to re-order

I installed testlink 1.9.20 and found an issue that the test case is unable to re-oder by drag and drop on the tree view.

Anyone has resolved the issue, please let me know.

I tried to compare the code between 1.9.19 and 1.9.20, do some code reverts but didn’t help.

Laravel application not loading some images when using php artisan serve at http://127.0.0.1:8000/login [closed]

I’m building a Laravel application and running it locally using php artisan serve. The login page at http://127.0.0.1:8000/login is working, but some of the images (like logos, backgrounds, or icons) are not loading in the browser.

Why are some images not loading when running the Laravel app with php artisan serve? How can I fix this?

Displaying individual rows with same key as part of larger associative array using PHP and HTML

I am trying to display data from multiple MySQL tables in individual text fields in an HTML form using PHP. Here are three sample tables from a database, followed by code that I am using to select the data and echo it to text fields in HMTL.

item_id item_title user_id
1 Abc 2
2 Def 4
document_id document_title item_id
1 Ghi 1
2 Jkl 1
3 Mno 1
4 Pqr 2
user_id user_name
1 John Doe
2 Jane Doe
3 James Doe
4 Jan Doe

Here is the code that I am using:

<?php
$sql = "SELECT i.item_title, d.document_title, u.user_name 
       FROM items as i 
       INNER JOIN documents as d
       ON i.item_id = d.item_id
       INNER JOIN users as u
       ON i.user_id = datat.item_number
       WHERE i.item_id = 1;";
    $result = mysqli_query($db_server, $sql);
    while($row=mysqli_fetch_assoc($result))
        {foreach($row as $key=>$value) ${$key}=$value;}
?>
    
    <form method="POST" action="updateItem.php">
    <p><textarea name="item_title"> <?php echo $item_title;?> </textarea></p>
    <p><input type="text" name="user_name" value="<?php echo $user_name?>"/></p>
    <p><input type="text" name="document_title[]" value="<?php echo $document_title?>"/></p>
    <p><input type="text" name="document_title[]" value="<?php echo $document_title?>"/></p>
    <p><input type="text" name="document_title[]" value="<?php echo $document_title?>"/></p>

The problem that I am running into is with the three fields that are supposed to display the document titles. The associate array produces a key=>value combo for these three rows in the document table that all have the same key (document_title). So how can I access these and display these three rows individually in individual fields in the HTML form?

Thank you in advance!

JS PivotTable library [closed]

Kindly advice some good libraries for pivotTable tree for web (js, react, or any others).

Also, I need expandable rows and columns to hide some data and see totals.

Can you advice some from your practice?

Something like that, and library should handle dates data in header. Many of discovered libs either are not good at that, or asks money.

enter image description here

I`ve try webdatarocks.com solution, but after reaching its limit in 1 Mb (JSON size) it asks to purchase full for ~$1k.

Example

How can I execute compiled Linux programs using JavaScript on my browser? [closed]

TLDR: I want to use JavaScript to execute Linux programs on the browser (as an experiment) but I don’t know how to use JavaScript to execute any programs.

I wanted to experiment if I could take a compiled program from Linux usually written in a language like C/C++. Then execute and show results in a website.

For example, Taking a compiled C program that takes user input and gives it as output. Then making my website execute it. Taking input in a input form and returning output as a div. But How can JavaScript be used to execute programs?

Can’t click on image even though I’ve added onclick attribute [closed]

I want an image to be clickable, and display a popup when clicked, but even though I’ve added the onclick attribute, when I run the servlet the image isn’t clickable.

I don’t get any errors, I just can’t click on the image. I don’t think the showPopup function is getting called at all. I tried checking with console.log and it doesn’t print anything.

const PFPpopudID = "PFP-Select";

function ShowPopup(popupID) {
  const popup = document.getElementById(popupID);
  popup.classList.toggle("show");
}
.profile {
  display: flex;
}

.user-info {
  background-color: #0089D1;
  border-right: solid 5px #FFBCB8;
  display: flex;
  flex-direction: column;
  justify-content: right;
  align-items: center;
  flex-grow: 1;
  max-width: 300px;
  min-height: 100vh;
  padding-top: 10px;
  padding-bottom: 10px;
}

.profile-pic {
  width: 200px;
  height: 200px;
}

.profile-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  visibility: hidden;
  z-index: 10;
  background-color: white;
  border: solid #FFBCB8 5px;
  border-radius: 10%;
}

.profile-popup-show {
  visibility: visible;
  -webkit-animation: fadeIn 1s;
  animation: fadeIn 0.5s
}
<div class="profile">
  <div class="user-info">
    <c:set var="un" value="${sessionScope.username}" />
    <img class="profile-pic" src="Default images/Default PFP.png" alt="Profile Picture" onclick="ShowPopup(PFPpopudID)">
    <h1>${un}</h1>
    <div class="user-desc">
      ${userDAO.getUserDescription(un)}
    </div>
  </div>
  <span id="PFP-select" class="profile-popup">
    Popup
  </span>
</div>

Why is the book cover image not showing up even though I’m using Google Books API?

I am working on a book management system, and I am using the Google Books API to fetch book cover images. However, even though I am correctly fetching the data from the API, the book cover images are not being displayed on the page.

I tried to use the imageLinks.thumbnail field from the API response to load the cover image, but it’s not appearing on the page. Instead, it either shows a broken image or doesn’t display anything at all.

API URL Example:

const url = `https://www.googleapis.com/books/v1/volumes?q=isbn:${isbn13}`;

AOU Resoibse Example :

{
  "items": [
    {
      "volumeInfo": {
        "imageLinks": {
          "thumbnail": "http://books.google.com/books/content?id=LTs6MwAACAAJ&printsec=frontcover&img=1&zoom=1&source=gbs_api"
        }
      }
    }
  ]
}

But the image doesn’t load as expected.

I used the following code to fetch and display the cover image:

let coverUrl = data.items[0].volumeInfo.imageLinks.thumbnail;

I expected the book cover to be displayed using this URL, but the image either doesn’t load or gives an error like “There was an error processing this image.” I’ve also tried validating the image URL by checking it directly in the browser, and it works fine, but it doesn’t work in my app.

I would like to know how to properly display book cover images using Google Books API, and why the image might not be loading in my app.

How to parallelize async calls while awaiting an property assignment?

I’ve hit a roadblock with parallel processing of async methods. Specifically, in the following code, I’m waiting for each chat’s promise to resolve sequentially, which ends up being slow:

for (const member of response.chatMembers) {
  const chat: ChatsDto = member.chat;
  if (!chat.isGroup) {
    const secondUser = chat.chatMembers[0]?.user;
    if (!secondUser) throw new NotFoundException('Other user not found');
    chat.isOnline = await this.utilGateway.isUserOnline(secondUser.id);
  }
}

I’ve tried using Promise.all, but I can’t assign chat.isOnline without awaiting the isUserOnline function. As a result, Promise.all doesn’t seem to help in this case:

const chats = await Promise.all(
  t2.map(async (member) => {
    const chat: ChatsDto = member.chat;
    if (!chat.isGroup) {
      const secondUser = chat.chatMembers[0]?.user;
      if (!secondUser) throw new NotFoundException('Other user not found');
      chat.isOnline = await this.utilGateway.isUserOnline(secondUser.id);
    }
  })
);

I couldn’t find any solutions online, so I’d appreciate any advice from more experienced JS developers.