Logic Machine Forum
link on scada-vis - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: link on scada-vis (/showthread.php?tid=5712)



link on scada-vis - gdimaria - 30.10.2024

Hi,

is there a way to update the external link URL via script?

Thanks

PEPPE

   


RE: link on scada-vis - admin - 30.10.2024

See this: https://forum.logicmachine.net/showthread.php?tid=1903&pid=11806#pid11806


RE: link on scada-vis - gdimaria - 31.10.2024

(30.10.2024, 15:41)admin Wrote: See this: https://forum.logicmachine.net/showthread.php?tid=1903&pid=11806#pid11806

$(function() {
  $('.link').off('vclick').on('vclick', function() {
    window.open('http://openrb.com');
  });
});

That's fine, but I need to pass the URL from a key in storage... is it possible?


RE: link on scada-vis - admin - 01.11.2024

Use a virtual object with 250 byte string data type (32/0/1 in this example).
Code:
$(function() {
  if (typeof grp != 'object') {
    return;
  }
  
  var url;

  $('.link').off('vclick').on('vclick', function() {
    window.open(url);
  });

  grp.listen('32/0/1', function(obj) {
    url = obj.value;
  });
});



RE: link on scada-vis - gdimaria - 01.11.2024

(01.11.2024, 07:35)admin Wrote: Use a virtual object with 250 byte string data type (32/0/1 in this example).
Code:
$(function() {
  if (typeof grp != 'object') {
    return;
  }
 
  var url;

  $('.link').off('vclick').on('vclick', function() {
    window.open(url);
  });

  grp.listen('32/0/1', function(obj) {
    url = obj.value;
  });
});


in fact I had already thought of this solution, the problem is that the URL is too long and is truncated to 250 bytes as it contains an authentication token that changes every time:
http://10.0.0.146:8080/dashboard/28a2e200-75d2-11ef-80b8-2949263888cf?accessToken=eyJhbGciOiJIUzUeMiJ9.eyJzdWIiOiJnZGltYXJpYUBsaWJlcm8uaXQiLCJ1c2VySWQiOiI3NmE0ZmFjMC03MGU1LTExZWYtODBiOC0yOTQ5MjYzODg4Y2YiLCJzY29wZXMiOlsiQ1VTVE9NRVJfVVNFUiJdLCJzZXNzaW9uSWQiOiI4NmNmZDA4Yy04NzIwLTRmNzctOTAwYy0zYWFlNWIyNjZlNWQiLCJleHAiOjE3MzA0MzU0MDEsImlzcyI6InRoaW5nc2JvYXJkLmlvIiwiaWF0IjoxNzMwNDI2NDAxLCJmaXJzdE5hbWUiOiJQZXBwZSIsImxhc3ROYW1lIjoiTGliZXJvIiwiZW5hYmxlZCI6dHJ1ZSwiaXNQdWJsaWMiOmZhbHNlLCJ0ZW5hbnRJZCI6IjQzYTAxNGIwLWEwMjYtMTFlZS04MTJhLWU3M2JhZWFkYjcxMiIsImN1c3RvbWVySWQiOiJmZDAxOWIxMC03MGU0LTExZWYtODBiOC0yOTQ5MjYzODg4Y2YifQ.3N5fFV26nfh-ZuufXxDBRxzgfiv2ZLYSbrQJD_0Ke4-xCmGCe7wXh3z-d4f1bDRFzj4OY6I7svUU8So-6_WXUw


RE: link on scada-vis - admin - 01.11.2024

You can create a .lp file that redirects to the specified URL from a storage entry. This way you don't need Custom JS at all. Link URL should be set to /user/redirect.lp.
Code:
<?
require('apps')
url = storage.get('redirect_url')

if url then
  ngx.req.discard_body()
  ngx.redirect(url)
end



RE: link on scada-vis - gdimaria - 01.11.2024

(01.11.2024, 13:03)admin Wrote: You can create a .lp file that redirects to the specified URL from a storage entry. This way you don't need Custom JS at all. Link URL should be set to /user/redirect.lp.
Code:
<?
require('apps')
url = storage.get('redirect_url')

if url then
  ngx.req.discard_body()
  ngx.redirect(url)
end

sorry, but I have no idea about that...  as you can understand, I just need to set a button object or something to click on visu to open a new tab in the browser with the link.

Can you please give me the operating steps to do it?

where I have to put that code and how?

Thanks


RE: link on scada-vis - admin - 01.11.2024

Create redirect.lp file and upload it to user directory via FTP using apps login.
You might still need custom JS to open URL in a new window/tab.


RE: link on scada-vis - gdimaria - 01.11.2024

(01.11.2024, 13:25)admin Wrote: Create redirect.lp file and upload it to user directory via FTP using apps login.
You might still need custom JS to open URL in a new window/tab.

in the end I found an italian way to do it Smile

event script for the button on visu
Code:
url = storage.get('dashboard_url', 'https://www.google.com/')
lunghezza = string.len(url)
n=1
dashboard_url=''

for i = 1, lunghezza, 230 do
 
  blocco = string.sub(url, i, i+229)
 

 
  grp.write('33/2/'..n, blocco)
  log (i, blocco)
  sleep (0.5)
  sottostringa = grp.getvalue('33/2/'..n)
 
  dashboard_url = dashboard_url..sottostringa
 

  n= n +1
end


and  JS

Code:
  // Funzione per aggiornare l'URL una volta ricevuti tutti i blocchi
  function aggiornaUrl() {
   // if (blocco1 && blocco2 && blocco3 && blocco4) {
      url = blocco1 + blocco2 + blocco3 + blocco4;
   // }
  }

  // Listener per ogni indirizzo di gruppo
  grp.listen('33/2/1', function(obj) {
    blocco1 = obj.value;
    aggiornaUrl();
  });

  grp.listen('33/2/2', function(obj) {
    blocco2 = obj.value;
    aggiornaUrl();
  });

  grp.listen('33/2/3', function(obj) {
    blocco3 = obj.value;
    aggiornaUrl();
  });

  grp.listen('33/2/4', function(obj) {
    blocco4 = obj.value;
    aggiornaUrl();
  });
});


Best regards 

Peppe