Custom JavaScript examples - 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: Custom JavaScript examples (/showthread.php?tid=275) |
RE: Custom JavaScript examples - Roman - 16.12.2016 Добрый день. Появилась задача. При присвоении объекту определенного значения нужно открыть план. Не могли бы вы мне с этим помочь? Как я понимаю слушатель должен быть привязан к объекту допустим 1/1/1 и если объект изменил значение на 1, то showPlan(11); если 2, то showPlan(12); если 3, то showPlan(13); Это как я понимаю решается через "case", я не знаю JS. Кроме того мне это нужно не для vis, а для touch RE: Custom JavaScript examples - admin - 16.12.2016 Please post in English next time The task is to show a specific plan depending on a certain object value. Code: $(function(){ RE: Custom JavaScript examples - Roman - 16.12.2016 (16.12.2016, 14:58)admin Wrote: Please post in English next timeThank you very much. As it is applied to the "Touch"? RE: Custom JavaScript examples - admin - 16.12.2016 Yes, it will work in both visualizations RE: Custom JavaScript examples - FatMax - 24.12.2016 Is there any way to hide a object from visu when there´s no value? I´m monitoring a 4 byte float kW object, but there´s no point in having it show in visu when it´s 0.00 kW. RE: Custom JavaScript examples - buuuudzik - 24.12.2016 (24.12.2016, 00:08)FatMax Wrote: Is there any way to hide a object from visu when there´s no value? I´m monitoring a 4 byte float kW object, but there´s no point in having it show in visu when it´s 0.00 kW. This script should work. You must add to this object in visualisation editor text "power" in Additional classes and change the value for nothing(now is '0 kWh', can be empty '''). You can also change the color of this text e.g. black when 0 and yellow when more than 0. Code: //Change text to nothing when 0,00 kWh RE: Custom JavaScript examples - Roman - 10.01.2017 How open do not plan visualization, and widget. And its close at the end of time? RE: Custom JavaScript examples - AEK - 12.01.2017 Hi everyone! I will say Roman's quastion with another words: is there way to make widget autoclosing function. He need 1 widget which can close itself after some time RE: Custom JavaScript examples - buuuudzik - 16.01.2017 Do somebody know how can I use in javascript: - storage, - trends? RE: Custom JavaScript examples - Pawel - 19.01.2017 Information about accessing to storage via javascript you can found here: http://forum.logicmachine.net/showthread.php?tid=85 Everything working great. RE: Custom JavaScript examples - buuuudzik - 19.01.2017 (19.01.2017, 11:30)Pawel Wrote: Information about accessing to storage via javascript you can found here: http://forum.logicmachine.net/showthread.php?tid=85 Thanks Pawel, yes now I see that this is a solution but maybe do you know if there is some other way without creating a .lp file e.g. using lua in javascript? or exchanging some variables to this .lp? And also can you describe the mechanism of .lp files? Because this is for me now a little abstraction. Are these scripts run residentlyin the background or only when there is some request from js or apps? RE: Custom JavaScript examples - Erwin van der Zwart - 19.01.2017 Hi Buuuudzik, A .lp file is used for client side LUA scripting, the .lp file is executed once during page load, at that moment the LUA is executed and data is requested from server and the reply is transfered to client and you can use the reply as JSON object. When you want new data you have to do a http (xhtml / ajax) request to the .lp file (even with arguments) to get new or other information from the server. This way you can do a normal storage.get / storage.set LUA command (basicly any LUA command available inside the LM) and transfer the reply to a JSON object to use on client side. The content inside the .lp file is very flexible and when you master this you can build whatever you need. So there is nothing running on de background, only on page load and when you do a xhtml / ajax request to the .lp file. BR, Erwin RE: Custom JavaScript examples - buuuudzik - 19.01.2017 I see that this is a very nice tool. I've prepared what I wanted, script which read trends and calculate the cost of outdoor heating for defined periods and this is exported as a JSON. I see this is a very elastic tool but is there a possibility to send an ajax request with some variables. E.g. in .lp file there is an universal function for cost calculation and in javascript there is a possibility to select for what number of days. RE: Custom JavaScript examples - Erwin van der Zwart - 19.01.2017 Hi Buuuudzik, Yes you can send vars by the request by using xxx.xxx.xxx.xxx/yourfile.lp?argument1=yourfirstvalue&argument2=yoursecondvalue etcetera and than fetch them in your .lp file with: Code: require('apps') or if your values need to be escaped use: Code: require('apps') BR, Erwin RE: Custom JavaScript examples - buuuudzik - 19.01.2017 I didn't know about this so YES definitely this is an amazing tool! And of course thank you Erwin, you're traditionally a few(or much more) levels before me I only try to learn new things for having a good products for my clients Thanks So this is right way for run the .lp file with some arguments from outside? Code: $.get( "/user/systemtime.lp?argument1=yourfirstvalue&argument2=yoursecondvalue", function( data ) { RE: Custom JavaScript examples - buuuudzik - 20.01.2017 Maybe somebody has some advice, when I write custom javascripts and when I use jQuery to find objects everytime I has in the console a lot of founded objects and I think this is not caused by too wide filter but this is something else. It looks like the objects from scada-vis are also in trends and schedulers. For examle this 2 scripts for find a object with class '.sekator' generates the same result in console.log() (see screenshot). Script 1: Code: $(function(){ Script 2: Code: $(function(){ Is this result from console.log() is normal or can I something improve? RE: Custom JavaScript examples - admin - 21.01.2017 Custom JS runs both visualizations, trends and schedulers. If you have some specific functions for visualization only, you can check the type like this: Code: $(function() { RE: Custom JavaScript examples - buuuudzik - 21.01.2017 Thanks admin for advice I've checked this on the other LM which I've cleaned to only 1 visupage and 1 trend and 2 schedulers and I see that javascripts are working then perfectly. No such situation with searching something in other places. And also e.g this function is run only 1 time and I have in consol.log() only 1 result(but on my LM LB there is a lot of): Code: $(function(){ But your advice is the solution. It looks that loading is little shorter. Perfectly. Thanks RE: Custom JavaScript examples - buuuudzik - 25.01.2017 Maybe somebody knows how can I edit the svg which is the background of a plan? I tried but I can't reach what is inside this svg, only source. It looks like this kind of images has some security or aren't editable. RE: Custom JavaScript examples - admin - 25.01.2017 SVG backgrounds are placed using <img> tag so you cannot access the SVG document via JS. You can create a layout and place your SVG as an image instead of background. |