It is currently 28 February 2021, 3:42 Advanced search

Offline Web App on Laptop?

Questions and answers on how to best use Instant Developer

Offline Web App on Laptop?

Postby ATroyer » 2 September 2020, 16:21

I am seeing a lot of information on the forum and documentation for offline syncing for mobile apps.

My use case is a little different. I have an online web app, but many of my school customers do not have regular internet connectivity. I need to set up the app so that a customer can enter their information online on a laptop computer, then sync to a local sqlite db and go offline. They can then work on it offline, with multiple teachers using their own logins on the same machine. The machine can sync data with the central server whenever it goes back online.

There are very few posts about this type of use and very little detail how to set it up, https://forum.instantdeveloper.com/viewtopic.php?f=5&t=18825&p=35172&hilit=web+app+offline#p35172

If that method does not work very well, is there a way to install SQL Server on a local machine and enable it to sync with an online server via scripts when the computer is online? That method looks quite complex.
ATroyer
 
Posts: 19
Joined: 30 October 2019, 13:30

Re: Offline Web App on Laptop?

Postby ljwilson » 14 September 2020, 11:54

I've done some tests based on the post you found in the Italian Forum. I took an online web app (C#) published to IIS using IDManager, and tried the two suggestions from the thread:

  1. Switching the app to offline by checking the "Enable offline mode" in the app and any components which the app uses in the project.
  2. Leaving the app online, but changing the database from SQL Server to SQLite with the "Database and schema auto generated by applications at runtime" option enabled.

With both I was able to run the app locally hitting a local SQLite database, and sync to the server-based app.

Offline
The offline mode is the easiest since you just have to check that option in the web app properties. The only problem is it skips the onLogin event (since the reasoning is an offline mobile app has to access the app first to do anything--this is mentioned in the InDe mobile pdf).

Another issue with this is if you have customized the Login1.htm and put it in your custom folder file (say added a remember me function), then the compiler chokes on the fields added to Login1.htm it doesn't know about. A workaround for that mentioned in the InDe user guide pdf is to simply blank out the custom folder directory entry in the web app properties. This will cause it to ignore anything in that custom folder (even if you have embedded the custom folder into the app).

You could of course do your own login form for an offline web app.

Online
The online mode hitting a local SQLite database allows the onLogin event to fire, so if you want to use InDe's built-in login event page and handling you can use that. Be sure if to clear out all connection information in the db properties when you switch to SQLite, since the ide will fill in its own when you save the db properties.

Some other things I noticed when switching around:
  • Both options create the SQLite db in the DB folder of the app, but the databases are named differently depending on if it is offline or online. For example, offline will name the app with the name of the application prepended to it, like MyLocalApp_MyDbName.db. The online version names the database without the app name prepended, like MyDbName.db.
  • If you go with the online version setting the app to have the db set to SQLite, I recommend making a second project, which has the database and app and anything else the local app requires (like components) in this second app. Then you make what changes you need to in the main app, and drag and drop changes as needed from it to the second app. The reason is switching the database version changes the app's compilation since it compiles based on the type of database driver. Be sure for this second app that you create a new project first, then copy all that you need over to it. That way the second project will have a different GUID, which will come in handy if you ever put this project into TeamWorks.
  • I found another post in the Italian Forum on how to get connection information from a database https://forum.instantdeveloper.com/viewtopic.php?f=5&t=6522&p=18393
    Code: Select all
    IDDatabase idd = IDDatabase.cast(MyDatabase.me())
    MyApp.IsLocalDb = (idd.DBType == SQLite)

    if (MyApp.IsLocalDb)
    {
      //do SQLite stuff
    }
    else
    {
      //do non-SQLite stuff
    }


    By using code like the above you can easily put in the main app a global variable set in the initialization event which determines the type of db driver set. That way you can have conditional code in your main app which will fire based on DBType, so when it is copied to the second project which has the db set for SQLite instead of SQL Server db-specific code can be run.

...jack
ljwilson
 
Posts: 559
Joined: 26 November 2013, 14:15


Return to Tips & Tricks

Who is online

Users browsing this forum: No registered users and 10 guests

cron