NonDesktop apps

Posted: 2017-01-20 in NonDesktop

Lianja.getElementByID(“page.section”).menu is exposed on the Desktop client only (Lianja/VFP), you can’t currently modify the Section custom menu options in JavaScript code for Web Apps.


Q:
If I have an app for desktop with language VFP, and I want to create the same app for WEB, do I have to replace all the code in Java
A:
The client side code that runs in the browser needs to be written in JavaScript but you can call Lianja/VFP procedures on the server.
If you follow best practices and use standard sections whenever possible, the app will run on desktop, web and mobile.


Q:
My client-side ‘evaluateJavascript’ call is working fine back to the server file but it will be great if you could expand a little on what actually makes the server file run server-side.
My understanding: evaluateJavascript effectively does an RPC to the backend, sending the call back in a JSON string, getting the result, and sending it back in a JSON string
A:
The client-side code is in LianjaHtmlClient*.js, which is present in minified form in the distribution. There are tools on the web for formatting minified scripts if you want to look at it.
The framework is not minified unless the app is previewed in release mode. Looking at the framework will not help to prove that it’s running server-side.
Development mode and runtime views are a core requirement to understand how to build apps in Lianja.
In this case the requirement of the OP to write in JavaScript on the client and the server is fully supported but not yet properly understood.


Q:
I’m writing a little server-side function that searches a table for a given value in a given field, and returns a different given field in the same record. For instance, you could tell it to return the name of a customer with ID=5. I’ve gotten it working (muliple ways, actually) on a desktop app but can’t seem to do it on a web/mobile app. The original basic logic was building a string out of my different variables and then run Lianja.execute on that string. Lianja.execute doesn’t work on web/mobile clients so I needed another way.

I found the PREPARE/EXECUTE commands in the documentation and tried them. I couldn’t work out how it handled different types of parameters but found a way to get it to work on desktop. What I thought should work was:

Code:
local mystring = "select ? from ? where ? = ?"
local selectfield = "total"
local tablename = "expenseclaim"
local searchfield = "claimid"
local searchvalue = 5
prepare stmt from :mystring
execute stmt using :selectfield, :tablename, :searchfield, :searchvalue

This seemed to behave oddly with respect to data types. For example, it accepted expenseclaim as the name of a table, but literally output the string “total” instead of the value in the field named total.

What I got to work on a desktop app was building “mystring” by placing the variables in it directly, then calling PREPARE/EXECUTE on it. Since EXECUTE needs at least one parameter and the table name seemed to behave properly, I left that in the string as a parameter:

Code:
local selectfield = "total"
local tablename = "expenseclaim"
local searchfield = "claimid"
local searchvalue = 5
local mystring = "select " + selectfield
mystring += " from ?"
mystring += " where " + searchfield + " = " + searchvalue
PREPARE stmt from :mystring
EXECUTE stmt USING :tablename

This works perfectly fine on desktop, but on web/mobile clients it breaks on the EXECUTE line.

That might be a bug , it might not be implemented on web/mobile or I might even be making some silly mistake, but even then it feels like a rather convoluted way of going about things. Is there a way to just execute a string within a Lianja/VFP script on a server? Or to just place variables into a Lianja/VFP command?
A:
just create a statement as a string using &macro substitution or use sprintf() if you find that easier.

Commands stored in character variables can be executed dynamically

Code:
cmd = "select * from " + p_tablename + " where id=&p_id"
&cmd

You can’t use &macros in the console. Just type

ed ryan

and put your code in that file then from the console issue

do ryan

you can call your server side proc from the client using

Code:
var result = Lianja.evaluate("ryan()");

to substitute parameters you can use {…} macros on the client too.


Q:
I’m building a web/mobile app and I’ve run into a really frustrating problem. I can’t open my database from a preview in my browser, but I can from the app builder and web preview screens? i’m trying to open it on the init of my app and do some manipulation to make sure it’s set up properly before the app loads, but I can’t even get past the opening part. It works fine with Southwind so I know I’ve done something wrong in the database itself. For reference the code in my app is:

app init delegate

Code:
var initstatus = Lianja.evaluate("appinit()");
Lianja.showNotification(initstatus,true);

appinit.prg

Code:
try
    open database mydatabase
catch
    return "unable to open database"
endtry
return "success"

This shows the message “unable to open database”, but when I replace mydatabase with southwind it shows “success”. Does anyone know what I could have messed up inside my database to cause this?
Oh and yes it’s deployed. It’s sitting in lianja\cloudserver\tenants\public\data, right next to where I deployed southwind.
A:
Have a look at strerror( errno() ) which will tell you what the issue is.
Does your database have a ‘dbc_opendata’ database open event delegate (empty or containing code)?

This is not currently supported in the Lianja Web Client, so needs to be removed before deployment.


It runs on the server when the database is opened not on the client.
Q2:
Ah, yes I do have an opendata script!
I wasn’t aware it wasn’t working in the cloud server.
A2:
Please submit a ticket. It runs on the server when the database is opened not on the client.


Q:
I am seeking advice for writing apps that will be used on web & mobile – should these be written in .rsp (I know php/asp) or regular Lianja pages that are enabled for web/mobile? + benefits of one approach over the other.
A:
If you want to hand code everything and ignore the Lianja development methodology of pages, sections, UI navigation, transparent client/server interaction, automatic data binding, roles and permissions, user authentication, etc… You can write everything in .rsp and roll your own framework and methodology.

To develop web and mobile apps you should follow Lianja best practices using pages and sections. Custom HTML content should be generated dynamically on the server and bound to a Webview section.

Lianja PhoneGap apps are executables that interact with the cloud server to handle CRUD operations.

rsp pages are used by various webviewwidgets in Lianja to dynamically generate content for charts, reports, and other static display content.


Q:
I created an App using Visual Foxpro as my scripting language and now cannot generate Web, Tablet or Phone Apps from it. I now understand that I should have used Javascript as the Scripting Language when I created the original app and I have subsequently changed the Scripting Language in the Settings but to no avail.
Is there anyway to correct this or must I redo the app from scratch and select Javascript at the time of app creation?
A:
You need to replace any custom libraries and delegates with JavaScript ones.
You probably have some strange setting in the app which is preventing it being generated for the web.


You need to configure your VM with “Bridged networking” so that your mobile phone or tablet can communicate on the same IP subnet that the Cloud Server is listening on.

NATing your IP address with the host will not work. You need bridged networking.

Oh and one last thing… Remember to enable port 8001 (that the Cloud Server uses) or else turn off your firewall for testing otherwise you won’t be able to talk to the Cloud Server.


In Lianja v2.1, Lianja Mobile Apps now allow you to navigate the records in your apps using the familiar left, right, up and down “swipe” gestures.

Swipe Left navigates to the next record, Swipe Right navigates to the previous record, Swipe Up goes to the last record and Swipe Down goes to the first record.
Tap and Hold edits the record.

These gestures are only effective in Form, Canvas and Custom sections.

You can override this behavior by enabling gestures in the section attributes and write your own gesture delegate (which may me specified using the inline delegate syntax).

Note also that navigation swipe gestures are not available if you have enabled “Swipe Navigation” in the page attributes. If you have enabled “Swipe Navigation” in the page attributes, then Swipe Left and Swipe Right navigates between the next and previous pages in the App. Swipe navigation is also available in TabPanel sections.Swiping Left and Right navigates between the different Tabs.


Q:
When I try to preview in Web App View, I get the “Server connection lost” message as shown below.
The connection to local host is ok from my other system which uses it (MS Visual Web Developer).
Do I need to set a parameter somewhere for “Local Host”, or…?
A:
when i’ve had the issue, it has a) been with a lot of records using a build < 1.5 release; or b) a sign that I messed up one of the grid's (I've only seen it in a grid) column controlsources.


Q:
I’m confused about how a phone app interacts with a cloud server. How do I access data on a Lianja cloud server from a mobile app (for that matter how do I access it with a desktop app)? I know how to run a web app on a cloud server and access it via a web browser, is there a way to just run a database on the server without an app? Does the associated database get packaged with the mobile app for local access or is it supposed to access it remotely?
A:
If you build a mobile app using best practices and standard sections the data is automatically bound for you. It is a seamless SPA interacting with the database under the control of the cloud server.

If everything is data bound and validation is handled by remote procedure calls for you, and… you can dynamically create HTML5 content into webview sections in what other way are you wanting to access data on the server? You have Lianja.evaluate() and Lianja.evaluateJavaScript() as well as a lot of built-in OData functionality.

Just to clarify…

– You deploy your app and its database.
– You specify the mobile app settings in the project settings for phonegap
– You build your mobile app
– In there while testing, it will inject a reference to your local machine and access the cloud server using port 8001
After you have fully tested everything you change that URL to point at your cloud server production installation

There are example mobile apps included that you can study and install on your mobile devices.
Mobile Apps are regular client/server apps with the UI on the mobile device and the database on a remote server under the control of the cloud server.
A2:

1) User app on mobile phone opens a page. It needs data. It says to the Cloud Server (using a JSON call) “hey, I need the data from view vt_myview with parameter x set to value n.”

2) The Cloud Server says, “OK, I need to get the data from vt_myview with parameter x set to value n” — it then runs the view, just as one would run the view from the command console, connected to the backend. Now, that could be Lianja SQL Server, which could be on the same machine or could be somewhere else on the network (reachable by ODBC). Or it could be MSSQL, etc.

3) Having gotten the data back, the Cloud Server replies to the mobile app: “OK, I’ve got your data, here it comes,” and sends it back as oData (a JSON string).

4) the Mobile app then gets the oData string, decodes it into a JSON object, and the UI does its work off that object. When the mobile app makes a change to the data it sends the old and changed values back to the the Cloud server and the general cycle repeats.


Integration with AWS (Amazon) — do you know how (expletive deleted) hard it is to set up AWS right? Do you know how many resources you’ll pay for when you aren’t sharing them? Basically, it’s a 3-year learning curve to do it on your own, and even then you’ll run into challenges. There’s no mention of pricing on the roadmap, but the concept for economies through sharing instances is there, so with a “share the wealth” pricing model, what you see will almost certainly be less than you would pay if you spent that 3 years learning enough to get it almost right.


Q:
I have a wedding application (for my son) that guests will be using during the wedding.
I would like them to not have to type in the entire url.

Meaning – to get there now, you need to type in.
Samswedding.online/apps/wedding/index.html

I would like them to only type samswedding.online and have it re-directed.
A:
you can create a QR code for a URL. There are several free sites. Then print the QR code on folding cards, and put them on each table.
A2:
you need to obtain a domain from someone like network solutions or setup a CNAME in DNS.
I use easydns.com for my domains and DNS. They have Forward and Stealth options (the latter continues to show the original entered URL).

If you’re using the IIS plug-in then you will have actual rewrite capabilities, of course. <a href="http://nicolas.guelpa.me/blog/2015/02/21/rewrite-redirect-iis.html&quot; target="_blank" rel="nofollow"http://nicolas.guelpa.me/blog/2015/02/21/rewrite-redirect-iis.html I haven’t tried a rewrite with the LCS, so let us know if you try it.


Q:
I understand that all delegates should be written in javascript (for now) if I want an app that will be both web & desktop. But what about other code?

I mean if I write a VFP function and use it as an expression in an attribute (eg. grid ‘Filter’) it works fine in desktop but it doesn’t work in web (I have tested this).
But to write these functions in javascript doesn’t make sense either if I need to use VFP Lianja.execX() to run them anyway (as per the replies in the other post).
A:
I can only speak for myself, but anything that I am doing that is web based, I am doing in javascript sections as this will work for both desktop and web.

I have my apps seperated into client side and server side.
My client side is all javascript, the server side foxpro.

I dont think you would need to go back to the client to filter a grid unless it was very large. But that should be handled with a virtual table (Not yet ready for the web client – but coming soon – I hope

For example, when I filter my grid in a javascript section, I dont go back to the server. I am using a button (as combobox and optiongroups are not yet available for a web canvas section).
The click event of the button is in a file called lib_page1_section2.js

Here is the sample code.

Code:
function page1_section2_field7_click()
{
Lianja.get("page1.section1").filter ="machine_type='Physical'";
Lianja.get("page1.section1").refresh();
}

This code is exaclty the same as it would be in foxpro except it is case sensitive and has a semi-colon.
That said, I could have put all sorts of logic in the function written in javascript and not need anything in Foxpro.

However if there was a call that had to be done in foxpro, then I would use the LianjaExec(), but only when client side would not work.

Best practices are to use the standard sections, not the custom sections if you want to make sure your app will run everywhere.

When I create a project, I select Javascript as my language.
If I didnt, I could always set it up in the App,Page or Section setting under Custom Delegates.

The App setting is the bottom left hand side of the app builder. It’s the cogwheel that says settings.
If you click on that, the settings panel will slide in from the right.
Navigate down to custom Delegates. There you will find the Scripting language.
You will find the same thing for the page (Cogwheel at the top of the page) and for each section.

As long as these are set to javascript, the functions for all your events will be in a .JS file.

So to put javascript code behind a button, do the following.

Set my app to Javascript.
select Sections | Canvas.
Make sure the canvas section is highlighed with a blue border around it.
Select Advanced from the bottom menu.
Click on CommandButton. A button will appear on the canvas section.
Select the edge of the commandbutton.
Double click the commandbutton to bring up the field attributes.
Scroll down and click on the click event.

The file editor will appear where you can add your javascript code.
A2:
if in your delegate you call LianjaExec(“yourprgontheserver()” all the ajax stuff is done for you.
everything in an .rsp or .jsp etc. is evaluated on the server, not on the client. This works out well for me, as I can have a webview section in a mobile app that is running VFP code, on the server. Delegates on the page, of course, have to be in Javascript. But if the language at the top is set to VFP, the code sections will run on the server.


Q:
I cant use a canvas section since they may be using a different size devices, so I need something responsive.

I decided to try and do this with a custom javascript section and not an rsp page. The click functions work on the phone, but the text for the buttons are not showing up.
Are the custom javascripts sections not yet fully supported on web/mobile?
A:
Yes they are fully supported, both canvas and custom.
You may want to just use a footer menu and prefix the captions with a + e.g.

+Add,View,Delete

That will layout the buttons across any device size and you can just use the footer menu delegate to do whatever you want.



Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s