'Main application
Sub Class_Globals
Private AppPage As ABMPage
Private ws As WebSocket 'ignore
Private ABM As ABMaterial 'ignore
Private Pages As List
Private PageNeedsUpload As List
Public DownloadFolder As String = "/www/" & ABMShared.AppName & "/uploads/"
Public DownloadMaxSize As String = 1000*1024
Private ABMPageId As String = ""
Public TopBar As PSGTopBar
Dim ModalSheetLogoHolder As ABMImage
Dim ModalSheetLogoHolderFileInput As ABMFileInput
End Sub
Public Sub Initialize
Pages.Initialize
PageNeedsUpload.Initialize
ABM.AppVersion = ABMShared.AppVersion
ABM.AppPublishedStartURL = ABMShared.AppPublishedStartURL
' add your icons
' ABM.AddAppleTouchIcon("", "")
' ABM.AddMSTileIcon("", "")
' ABM.AddFavorityIcon("", "")
#If RELEASE
'ABM.ActivateUseCDN("DONATORKEY", "https://cdn.jsdelivr.net/gh/RealAlwaysbusy/[email protected]/")
'ABM.PreloadAllJavascriptAndCSSFiles=True ' NEW
ABM.ActivateGZip("DONATORKEY", 1000) ' NEW
Dim folders As List ' NEW
folders.Initialize
folders.Add(File.DirApp & "/www/" & ABMShared.AppName & "/images")
ABM.ActivatePNGOptimize("DONATORKEY", folders, False , 9, False, True )
#End If
' build the local structure IMPORTANT!
BuildPage
End Sub
Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
Log("Connected")
ws = WebSocket1
ABMPageId = ABM.GetPageID(AppPage, ABMShared.AppName,ws)
'----------------------START MODIFICATION 4.00-------------------------------
If AppPage.WebsocketReconnected Then
ABMShared.NavigateToPage(ws, "", "./")
Return
End If
Dim session As HttpSession = ABM.GetSession(ws, ABMShared.SessionMaxInactiveIntervalSeconds) 'ignore
If session.IsNew Then
session.Invalidate
ABMShared.NavigateToPage(ws, "", "./")
Return
End If
'----------------------END MODIFICATION 4.00-------------------------------
' Prepare the page IMPORTANT!
AppPage.Prepare
' Run ConnectPage here in ABMApplication
ConnectPage
' this page uses uploads, so needs some settings
ws.Session.SetAttribute("abmcallback", Me)
ws.Session.SetAttribute("abmdownloadfolder", DownloadFolder)
ws.Session.SetAttribute("abmmaxsize", DownloadMaxSize)
End Sub
Private Sub WebSocket_Disconnected
Log("Disconnected")
Try
ws.Session.RemoveAttribute("abmcallback")
ws.Session.RemoveAttribute("abmdownloadfolder")
ws.Session.RemoveAttribute("abmmaxsize")
Catch
Log(LastException.Message)
End Try
End Sub
Sub Page_ParseEvent(Params As Map)
Dim eventName As String = Params.Get("eventname")
Dim eventParams() As String = Regex.Split(",",Params.Get("eventparams"))
If eventName = "beforeunload" Then
Log("preparing for url refresh")
ABM.RemoveMeFromCache(ABMShared.CachedPages, ABMPageId)
Return
End If
Dim caller As Object = AppPage.GetEventHandler(Me, eventName)
If caller = Me Then
If SubExists(Me, eventName) Then
Params.Remove("eventname")
Params.Remove("eventparams")
' BEGIN NEW DRAGDROP
If eventName = "page_dropped" Then
AppPage.ProcessDroppedEvent(Params)
End If
' END NEW DRAGDROP
Select Case Params.Size
Case 0
CallSub(Me, eventName)
Case 1
CallSub2(Me, eventName, Params.Get(eventParams(0)))
Case 2
If Params.get(eventParams(0)) = "abmistable" Then
Dim PassedTables As List = ABM.ProcessTablesFromTargetName(Params.get(eventParams(1)))
CallSub2(Me, eventName, PassedTables)
Else
CallSub3(Me, eventName, Params.Get(eventParams(0)), Params.Get(eventParams(1)))
End If
Case Else
' cannot be called directly, to many param
CallSub2(Me, eventName, Params)
End Select
End If
Else
CallSubDelayed2(caller, "ParseEvent", Params) 'ignore
End If
End Sub
public Sub AddPage(Page As ABMPage)
Pages.Add(Page.Name)
PageNeedsUpload.Add(ABM.WritePageToDisk(Page, File.DirApp & "/www/" & ABMShared.AppName & "/" & Page.Name & "/", Page.PageHTMLName, ABMShared.NeedsAuthorization))
End Sub
'----------------------START MODIFICATION 4.00-------------------------------
public Sub StartServer(srvr As Server, srvrName As String, srvrPort As Int)
ABM.WriteAppLauchPageToDisk(AppPage, File.DirApp & "/www/" & ABMShared.AppName, "index.html", ABMShared.NeedsAuthorization)
' start the server
srvr.Initialize(srvrName)
' uncomment this if you want to directly access the app in the url without having to add the app name
' e.g. 192.168.1.105:51042 or 192.168.1.105 if you are using port 80
'srvr.AddFilter( "/", "ABMRootFilter", False )
' NEW V3 Cache Control
srvr.AddFilter("/*", "ABMCacheControl", False)
' NEW 4.00 custom error pages (optional) Needs the ABMErrorHandler class
srvr.SetCustomErrorPages(CreateMap("org.eclipse.jetty.server.error_page.global": "/" & ABMShared.AppName & "/error")) ' OPTIONAL
srvr.AddHandler("/" & ABMShared.AppName & "/error", "ABMErrorHandler", False) ' OPTIONAL
srvr.AddWebSocket("/ws/" & ABMShared.AppName, "ABMApplication")
For i =0 To Pages.Size - 1
srvr.AddWebSocket("/ws/" & ABMShared.AppName & "/" & Pages.Get(i) , Pages.Get(i))
If PageNeedsUpload.Get(i) Then
srvr.AddHandler("/" & ABMShared.AppName & "/" & Pages.Get(i) & "/abmuploadhandler", "ABMUploadHandler", False)
End If
Next
srvr.AddBackgroundWorker("ABMCacheScavenger")
srvr.Port = srvrPort
#If RELEASE
srvr.SetStaticFilesOptions(CreateMap("gzip":True,"dirAllowed":False))
#Else
srvr.SetStaticFilesOptions(CreateMap("gzip":False,"dirAllowed":False))
#End If
srvr.Start
Dim joServer As JavaObject = srvr
joServer.GetFieldJO("server").RunMethod("stop", Null)
joServer.GetFieldJO("context").RunMethodJO("getSessionHandler", Null).RunMethodJO("getSessionCookieConfig", Null).RunMethod("setMaxAge", Array(31536000)) ' 1 year
' NEW FEATURE! Each App has its own Session Cookie
joServer.GetFieldJO("context").RunMethodJO("getSessionHandler", Null).RunMethodJO("getSessionCookieConfig", Null).RunMethod("setName", Array(ABMShared.AppName.ToUpperCase))
joServer.GetFieldJO("server").RunMethod("start", Null)
Dim secs As Long = ABMShared.CacheScavengePeriodSeconds ' must be defined as a long, else you get a 'java.lang.RuntimeException: Method: setIntervalSec not matched.' error
joServer.GetFieldJO("context").RunMethodJO("getSessionHandler", Null).RunMethodJO("getSessionIdManager", Null).RunMethodJO("getSessionHouseKeeper", Null).RunMethod("setIntervalSec", Array As Object(secs))
Dim jo As JavaObject = srvr
Dim connectors() As Object = jo.GetFieldJO("server").RunMethod("getConnectors", Null)
Dim timeout As Long = ABMShared.SessionMaxInactiveIntervalSeconds*1000
For Each c As JavaObject In connectors
c.RunMethod("setIdleTimeout", Array(timeout))
Next
ABMShared.CachedPages = srvr.CreateThreadSafeMap
End Sub
public Sub StartServerHTTP2(srvr As Server, srvrName As String, srvrPort As Int, SSLsvrPort As Int, SSLKeyStoreFileName As String, SSLKeyStorePassword As String, SSLKeyManagerPassword As String)
ABM.WriteAppLauchPageToDisk(AppPage, File.DirApp & "/www/" & ABMShared.AppName, "index.html", ABMShared.NeedsAuthorization)
Dim ssl As SslConfiguration
ssl.Initialize
ssl.SetKeyStorePath(File.DirApp, SSLKeyStoreFileName) 'path to keystore file
ssl.KeyStorePassword = SSLKeyStorePassword
ssl.KeyManagerPassword = SSLKeyManagerPassword
srvr.SetSslConfiguration(ssl, SSLsvrPort)
' start the server
srvr.Initialize(srvrName)
' uncomment this if you want to directly access the app in the url without having to add the app name
' e.g. 192.168.1.105:51042 or 192.168.1.105 if you are using port 80
'srvr.AddFilter( "/", "ABMRootFilter", False )
' NEW V3 Cache Control
srvr.AddFilter("/*", "ABMCacheControl", False)
' NEW 4.00 custom error pages (optional) Needs the ABMErrorHandler class
srvr.SetCustomErrorPages(CreateMap("org.eclipse.jetty.server.error_page.global": "/" & ABMShared.AppName & "/error")) ' OPTIONAL
srvr.AddHandler("/" & ABMShared.AppName & "/error", "ABMErrorHandler", False) ' OPTIONAL
srvr.AddWebSocket("/ws/" & ABMShared.AppName, "ABMApplication")
For i =0 To Pages.Size - 1
srvr.AddWebSocket("/ws/" & ABMShared.AppName & "/" & Pages.Get(i) , Pages.Get(i))
If PageNeedsUpload.Get(i) Then
srvr.AddHandler("/" & ABMShared.AppName & "/" & Pages.Get(i) & "/abmuploadhandler", "ABMUploadHandler", False)
End If
Next
srvr.AddBackgroundWorker("ABMCacheScavenger")
srvr.Port = srvrPort
srvr.Http2Enabled = True
#If RELEASE
srvr.SetStaticFilesOptions(CreateMap("gzip":True,"dirAllowed":False))
#Else
srvr.SetStaticFilesOptions(CreateMap("gzip":False,"dirAllowed":False))
#End If
srvr.Start
Dim joServer As JavaObject = srvr
joServer.GetFieldJO("server").RunMethod("stop", Null)
joServer.GetFieldJO("context").RunMethodJO("getSessionHandler", Null).RunMethodJO("getSessionCookieConfig", Null).RunMethod("setMaxAge", Array(31536000)) ' 1 year
' NEW FEATURE! Each App has its own Session Cookie
joServer.GetFieldJO("context").RunMethodJO("getSessionHandler", Null).RunMethodJO("getSessionCookieConfig", Null).RunMethod("setName", Array(ABMShared.AppName.ToUpperCase))
joServer.GetFieldJO("server").RunMethod("start", Null)
Dim secs As Long = ABMShared.CacheScavengePeriodSeconds ' must be defined as a long, else you get a 'java.lang.RuntimeException: Method: setIntervalSec not matched.' error
joServer.GetFieldJO("context").RunMethodJO("getSessionHandler", Null).RunMethodJO("getSessionIdManager", Null).RunMethodJO("getSessionHouseKeeper", Null).RunMethod("setIntervalSec", Array As Object(secs))
Dim jo As JavaObject = srvr
Dim connectors() As Object = jo.GetFieldJO("server").RunMethod("getConnectors", Null)
Dim timeout As Long = ABMShared.SessionMaxInactiveIntervalSeconds*1000
For Each c As JavaObject In connectors
c.RunMethod("setIdleTimeout", Array(timeout))
Next
ABMShared.CachedPages = srvr.CreateThreadSafeMap
End Sub
'----------------------END MODIFICATION 4.00-------------------------------
public Sub BuildPage()
' initialize this page using our theme
AppPage.InitializeWithTheme(ABMShared.AppName, "/ws/" & ABMShared.AppName, False, ABMShared.SessionMaxInactiveIntervalSeconds , ABMShared.MainTheme)
AppPage.ShowLoader=True
AppPage.PageTitle = "iFTTH Manager"
AppPage.PageDescription = ""
AppPage.PageHTMLName = "index.html"
AppPage.PageKeywords = ""
AppPage.PageSiteMapPriority = "0.00"
AppPage.PageSiteMapFrequency = ABM.SITEMAP_FREQ_YEARLY
AppPage.ShowConnectedIndicator = True
'AppPage.ShowGridInfo = True
' create the page grid
AppPage.AddRows(1,False, "").AddCells12(1,"")
AppPage.BuildGrid 'IMPORTANT once you loaded the complete grid AND before you start adding components
'Add TopBar to AppPage
TopBar.Initialize(AppPage, "TopBar", "", "TopBar")
AppPage.Cell(1,1).AddComponent(TopBar.TopBarContainer)
AppPage.AddModalSheetTemplate(BuildPreferencesModalSheet)
End Sub
public Sub ConnectPage()
' you dynamic stuff
AppPage.Refresh ' IMPORTANT
' Tell the browser we finished loading
AppPage.FinishedLoading 'IMPORTANT
AppPage.RestoreNavigationBarPosition
'
AppPage.ShowModalSheet("PreferencesModalSheet")
End Sub
Sub BuildPreferencesModalSheet As ABMModalSheet
Dim ThisModalSheet As ABMModalSheet
ThisModalSheet.Initialize(AppPage, "PreferencesModalSheet",False, False, "PreferencesModalSheet")
ThisModalSheet.Header.AddRows(1,True,"").AddCells12(1,"")
ThisModalSheet.Header.BuildGrid ' IMPORTANT!
Dim PreferencesModalSheetTitle As ABMLabel
PreferencesModalSheetTitle.Initialize(AppPage, "PreferencesModalSheetTitle", "Aplication Preferences", ABM.SIZE_H5, False, "PreferencesModalSheet")
ThisModalSheet.Header.Cell(1,1).AddComponent(PreferencesModalSheetTitle)
'ThisModalSHeet Content
ThisModalSheet.Content.AddRowsV(1,True,ABM.VISIBILITY_SHOW_ON_LARGE_ONLY,"").AddCellsOSV(1,0,0,0,3,3,3,ABM.VISIBILITY_SHOW_ON_LARGE_ONLY,"").AddCellsOSV(1,0,0,0,9,9,9,ABM.VISIBILITY_SHOW_ON_LARGE_ONLY,"")
ThisModalSheet.Content.AddRowsV(1,True,ABM.VISIBILITY_SHOW_ON_LARGE_ONLY,"").AddCells12(1,"")
ThisModalSheet.Content.AddRowsV(2,True,ABM.VISIBILITY_SHOW_ON_LARGE_ONLY,"").AddCells12V(1, ABM.VISIBILITY_SHOW_ON_LARGE_ONLY,"")
ThisModalSheet.Content.BuildGrid ' IMPORTANT!
ModalSheetLogoHolder.Initialize(AppPage, "ModalSheetLogoHolder", "../iFTTH-Manager/images/yourlogohere.png", 1)
ThisModalSheet.Content.Cell(1,1).AddComponent(ModalSheetLogoHolder)
ModalSheetLogoHolder.SetFixedSize(150, 75)
ModalSheetLogoHolderFileInput.Initialize(AppPage, "ModalSheetLogoHolderFileInput", "Select a file", "Open", True, "", "")
ThisModalSheet.Content.Cell(1,2).AddComponent(ModalSheetLogoHolderFileInput)
ThisModalSheet.UseTheme("PreferencesModalSheet")
Return ThisModalSheet
End Sub
Sub ModalSheetLogoHolderFileInput_Changed(value As String)
Log("value : " & value)
ModalSheetLogoHolderFileInput.UploadToServer
End Sub
Sub Page_FileUploaded(FileName As String, success As Boolean)
ModalSheetLogoHolderFileInput.Clear
Log(FileName & " = " & success)
End Sub