This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

HTML in LogicMachine
#1
Hi group!

I'm trying to use HTML to have an editable table in LogicMachine, the goal in this project is to give the user the possibility to edit a list of users. I have a script were I put my HTML page. My bdd is in a .json script, and in my HTML code I have two funtion, x_get.lua and x_save.lua. In my x_get.lua i have the next script:


Code:
content("application/json")
local f = io.open('user/inquilinos.json', 'r')
if not f then
  print("[]")
  return
end
local data = f:read("*a")
f:close()
print(data) 


In my x_save.lua

Code:
content("application/json")

-- Leer cuerpo del POST
local len = tonumber(os.getenv("CONTENT_LENGTH") or 0)
local body = ""

if len > 0 then
  body = io.read(len)
end

if not body or #body == 0 then
  print('{"status":"error","msg":"POST vacío"}')
  return
end

-- Intentar escribir el archivo JSON
local f, err = io.open("/www/user/inquilinos.json", "w")
if not f then
  print('{"status":"error","msg":"No se pudo abrir el archivo: '..tostring(err)..'"}')
  return
end

f:write(body)
f:close()

print('{"status":"ok"}')

The firmware version of my homeLYnk is: 
HW: LM5 Lite (i.MX6)

The problem is that when i try to get into my get.lua, the response is a text, not the list of user that i have in my .json script.
In my version of LM I don't get acces to the /user/ file or the /ww/ file, I ask ChatGPT and it said that I have to create my scripts in those files, because when I try to get into the next url: IP-Server:port/x_get.lua, the response is a text and when I try to get into IP-Server:port/x_save.lua the response is 404 Not Found.

I try to update some packages in the LM, from an new version of homeLYNk, but the packages are:
url.lua
ftp.lua
http.lua
and the packages that are supported are .ipk.

I cannot upgrade the firmaware of the LM, because I don't want to lose the connection with the phisical machines that I have in the project.

Can someone help me with this issue please? Will appriciated!
Reply
#2
Why don't you use User access app?
------------------------------
Ctrl+F5
Reply
#3
(Today, 09:29)Daniel Wrote: Why don't you use User access app?

I have an interface, and I have two type of user, a master user that will have the possibility of edit the list of co-worker spaces, and other user that will only be able to visualize the list, it will not be able to edit any co-worker space.
Now, the list is server in a HTML page, but it doesn't save the changes that I made, edit, add new one or delete it.

Attached Files Thumbnail(s)
   
Reply
#4
Hello,

Please use the tested solution, which is the User Access Control application.

Within this application, you can configure different user roles:
1.) Users with access to the User Access Control app will be considered administrators.
They will have the ability to add new users or remove existing ones.

2.) Users without access to this app will be standard users.
Reply
#5
I don't think I explained myself clearly. The application only has two types of users:
The master user, who owns the building (and the project), and has complete control over the entire project.
The viewer user, who can only see the machine statuses and modify temperature settings according to the needs of their "clients."

What I need is a client list that the master user can modify. For example, if a client doesn't renew their rental agreement, the master user should be able to remove them from the list (displayed on the HTML page). Alternatively, if a client wants to rent additional areas or spaces, they could make a change. Clients don't have access to this view. Only the master user and the viewer user, who will be at reception, have access.
I only need to change the name of the client in the areas or spaces, on my HTML table, I don't need to give the clients access to the app
Reply
#6
This is exactly what they User access app does.
------------------------------
Ctrl+F5
Reply
#7
Sorry if my question is a fool question, but, where I can find the user access app? I see the user acces on LM, where I do the manage user access to the control panel. In the user access on LM I have the two user accounts (master and viewer), but where do I put the client list? These clients won't have access to the control panel; it's simply so the master user can edit the clients for the co-working spaces.

This is my Usser Access that I can see

Attached Files Thumbnail(s)
   
Reply
#8
As all apps User access app is in the app store, + in top right corner of a home screen.
------------------------------
Ctrl+F5
Reply
#9
(11 hours ago)Daniel Wrote: As all apps User access app is in the app store, + in top right corner of a home screen.

Daniel, when I try to get into my script x_get.lua, it's give me the response in the pic. I have a scrtipt that give me an HTML table, the code is:
Code:
local html = [[
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Gestión de Inquilinos</title>
<style>
body { font-family: sans-serif; margin: 20px; }
h2 { margin-bottom: 10px; }
button { padding: 6px 12px; margin: 4px; cursor: pointer; }
table { border-collapse: collapse; width: 100%; margin-top: 10px; }
th, td { border: 1px solid #ccc; padding: 6px; text-align: left; }
th { background: #eee; }
input[disabled] { background-color: #f8f8f8; color: #555; border: none; }
.edit { color: blue; }
.del { color: red; }
</style>
</head>
<body>
<h2>? Gestión de Inquilinos</h2>
<button id="backbtn">? Volver al menú principal</button>
<table id="tbl">
<thead>
<tr><th>#</th><th>Descripción</th><th>Código de Zona</th><th>Planta</th><th>Acciones</th></tr>
</thead>
<tbody></tbody>
</table>
<button id="addbtn"> Añadir nuevo</button>

<script>
const tbody = document.querySelector('#tbl tbody');
let inquilinos = [];

// Cargar datos iniciales
fetch('/user/inquilinos.json')
.then(r => r.json())
.then(data => { inquilinos = data; render(); });

function render() {
  tbody.innerHTML = '';
  inquilinos.forEach((x,i) => {
    tbody.innerHTML += `
      <tr>
        <td>${i+1}</td>
        <td><input value="${x.descripcion}" data-i="${i}" data-f="descripcion" disabled></td>
        <td><input value="${x.cod_zona}" data-i="${i}" data-f="cod_zona" disabled></td>
        <td><input value="${x.planta}" data-i="${i}" data-f="planta" disabled></td>
        <td>
          <button class="edit" data-i="${i}">️ Editar</button>
          <button class="del" data-i="${i}">? Borrar</button>
        </td>
      </tr>`;
  });
}

tbody.addEventListener('click', e=>{
  const i = e.target.dataset.i;
  if(e.target.classList.contains('edit')) {
    const row = tbody.querySelectorAll('tr')[i];
    const inputs = row.querySelectorAll('input');
    const editing = e.target.textContent.includes('Guardar');
    if(!editing) {
      // activar edición
      inputs.forEach(inp => inp.disabled = false);
      e.target.textContent = '? Guardar';
    } else {
      // guardar cambios
      inputs.forEach(inp => inp.disabled = true);
      inquilinos[i] = {
        descripcion: inputs[0].value,
        cod_zona: inputs[1].value,
        planta: inputs[2].value
      };
      e.target.textContent = '️ Editar';
            fetch('/inquilinos_save.lua', {method:'POST', body: JSON.stringify(inquilinos)})
      .then(()=>alert(' Cambios guardados'));
    }
  } else if(e.target.classList.contains('del')) {
    inquilinos.splice(i,1); render();
    fetch('/inquilinos_save.lua', {method:'POST', body: JSON.stringify(inquilinos)});
  }
});

document.querySelector('#addbtn').addEventListener('click', ()=>{
  inquilinos.push({descripcion:'Nuevo', cod_zona:'', planta:''});
  render();
});

document.getElementById('backbtn').onclick = () => {

  window.location.href = 'http://213.96.119.214:3672/scada-vis';
};
</script>
</body>
</html>
]]

local f = io.open('/www/user/inquilinos.html', 'w')
if f then
  f:write(html)
  f:close()
  log(' Archivo /www/user/inquilinos.html actualizado correctamente')
else
  log(' No se pudo crear el archivo HTML')
end

The user access app, it's usefull when we have to control a several users, i just have 2, and this list that i need is for clients or lease owners that can change anytime. This clients do not need to have access to the control, so, i don't need to create users for them. I just need an editable table that contains this lease owner's names for eah co-workers space. I already look for the app, and in the app store, I found apps but it is for user management, and I do not need that, I just need an editable table that the master user could change anytime.

Attached Files Thumbnail(s)
   
Reply


Forum Jump: