'Class module
Sub Class_Globals
Private ws As WebSocket 'ignore
' will hold our page information
Public page As ABMPage
' page theme
Private theme As ABMTheme
' to access the constants
Private ABM As ABMaterial 'ignore
' name of the page, must be the same as the class name (case sensitive!)
Public Name As String = "SelectPaddockPage" '<-------------------------------------------------------- IMPORTANT
' will hold the unique browsers window id
Private ABMPageId As String = ""
' your own variables
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
' build the local structure IMPORTANT!
BuildPage
If page.IsInitialized Then
Log("At SelectPaddockPage.Initialize")
page.Refresh
End If
End Sub
#Region ABM
Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
Log("Connected")
ws = WebSocket1
ABMPageId = ABM.GetPageID(page, Name,ws)
Dim session As HttpSession = ABM.GetSession(ws, ABMShared.SessionMaxInactiveIntervalSeconds)
If session.IsNew Then
session.Invalidate
ABMShared.NavigateToPage(ws, "", "./")
Return
End If
If ABMShared.NeedsAuthorization Then
If session.GetAttribute2("IsAuthorized", "") = "" Then
ABMShared.NavigateToPage(ws, ABMPageId, "../")
Return
End If
End If
ABM.UpdateFromCache(Me, ABMShared.CachedPages, ABMPageId, ws)
If page.ComesFromPageCache Then
' when we have a page that is cached it doesn't matter if it comes or not from a new connection we serve the cached version.
Log("Comes from cache")
page.Refresh
page.FinishedLoading
Else
If page.WebsocketReconnected Then
Log("Websocket reconnected")
' when we have a client that doesn't have the page in cache and it's websocket reconnected and also it's session is new - basically when the client had internet problems and it's session (and also cache) expired before he reconnected so the user has content in the browser but we don't have any on the server. So we need to reload the page.
' when a client that doesn't have the page in cache and it's websocket reconnected but it's session is not new - when the client had internet problems and when he reconnected it's session was valid but he had no cache for this page we need to reload the page as the user browser has content, reconnected but we have no content in cache
ABMShared.NavigateToPage (ws, ABMPageId, "./" & page.PageHTMLName)
Else
' when the client did not reconnected it doesn't matter if the session was new or not because this is the websockets first connection so no dynamic content in the browser ... we are going to serve the dynamic content...
Log("Websocket first connection")
page.Prepare
ConnectPage
End If
End If
Log(ABMPageId)
End Sub
Private Sub WebSocket_Disconnected
Log("Disconnected")
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 DEBUG
Log($"Evt fired --->${eventName} Number params = ${Params.Size}"$)
For i = 0 To Params.Size-1
Log($" Key = ${Params.GetKeyAt(i)}, value = ${Params.GetValueAt(i)}"$)
Next
Log("-----------------------------------------------------")
#End if
If eventName = "beforeunload" Then
Log("preparing for url refresh")
ABM.RemoveMeFromCache(ABMShared.CachedPages, ABMPageId)
Return
End If
Dim caller As Object = page.GetEventHandler(Me, eventName)
If caller = Me Then
If SubExists(Me, eventName) Then
Params.Remove("eventname")
Params.Remove("eventparams")
If eventName = "page_dropped" Then
page.ProcessDroppedEvent(Params)
End If
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 BuildTheme()
' start with the base theme defined in ABMShared
theme.Initialize("pagetheme")
theme.AddABMTheme(ABMShared.MyTheme)
' add your specific page themes
theme.AddInputTheme("Inp")
theme.Input("Inp").DisabledForeColor=ABM.COLOR_BLUEGREY
End Sub
public Sub BuildPage()
' initialize the theme
BuildTheme
' initialize this page using our theme
page.InitializeWithTheme(Name, "/ws/" & ABMShared.AppName & "/" & Name, False, ABMShared.SessionMaxInactiveIntervalSeconds, theme)
page.ShowLoader=True
page.PageHTMLName = "index.html"
page.PageTitle = "Select paddock"
page.PageDescription = "Select paddock(s) to record/edit data"
page.PageKeywords = ""
page.PageSiteMapPriority = ""
page.PageSiteMapFrequency = ABM.SITEMAP_FREQ_YEARLY
page.ShowGridInfo = False
page.ShowConnectedIndicator = True
Dim NuClient As ABMModalSheet'Ignore - Initialised in the sub
NuClient = msNuClient.BuildModalNuClient(page)
' create the page grid
#Region NOT SAVED: 2021-07-04T07:11:37
'PHONE
'╔═══════════════════════════════════════════════════════════════════════════════════╗
'║ 1,1 | ║
'╠═══════════════════════════════════════════════════════════════════════════════════╣
'║ 2,1 | 2,2 | ║
'╠═══════════════════════════════════════════════════════════════════════════════════╣
'║ 3,1 | 3,2 | ║
'╠═══════════════════════════════════════════════════════════════════════════════════╣
'║ 4,1 | 4,2 | ║
'╠═══════════════════════════════════════════════════════════════════════════════════╣
'║ 5,1 | 5,2 | ║
'╠═══════════════════════════════════════════════════════════════════════════════════╣
'║ 6,1 | | 6,2 | | 6,3 | ║
'╚═══════════════════════════════════════════════════════════════════════════════════╝
'TABLET
'╔═══════════════════════════════════════════════════════════════════════════════════════════════════════════╗
'║ 1,1 | ║
'╠═══════════════════════════════════════════════════════════════════════════════════════════════════════════╣
'║ 2,1 | 2,2 | ║
'╠═══════════════════════════════════════════════════════════════════════════════════════════════════════════╣
'║ 3,1 | 3,2 | ║
'╠═══════════════════════════════════════════════════════════════════════════════════════════════════════════╣
'║ 4,1 | 4,2 | ║
'╠═══════════════════════════════════════════════════════════════════════════════════════════════════════════╣
'║ 5,1 | 5,2 | ║
'╠═══════════════════════════════════════════════════════════════════════════════════════════════════════════╣
'║ 6,1 | | 6,2 | | 6,3 | ║
'╚═══════════════════════════════════════════════════════════════════════════════════════════════════════════╝
'DESKTOP
'╔═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗
'║ 1,1 | ║
'╠═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╣
'║ 2,1 | 2,2 | ║
'╠═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╣
'║ 3,1 | 3,2 | ║
'╠═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╣
'║ 4,1 | 4,2 | ║
'╠═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╣
'║ 5,1 | 5,2 | ║
'╠═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╣
'║ 6,1 | | 6,2 | | 6,3 | ║
'╚═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝
page.AddRows(1,True,"").AddCellsOS(1,0,0,0,8,8,8,"")
page.AddRows(3,True,"").AddCellsOS(2,0,0,0,4,4,4,"")
page.AddRows(1,True,"").AddCellsOS(1,0,0,0,2,2,2,"").AddCellsOS(2,1,1,1,2,2,2,"")
page.BuildGrid ' IMPORTANT!
#End Region
End Sub
Sub nuclibut_clicked(target As String)
Act.Nu = "Client"
page.ShowModalSheet("NuClientMS")
End Sub
Sub canbut_clicked(target As String)
page.CloseModalSheet("NuClientMS")
'ABMShared.NavigateToPage(ws,"HomePage","../HomePage/")
End Sub
Sub createnuclient_clicked(Target As String)
Log("Create client button on modal form clicked")
If msNuClient.Savenu(page.ModalSheet("NuClientMS")) = False Then
Act.SendMess(Act.ErrMess,"NO data saved ")
page.ShowToast("Tost","mytheme","NO DATA SAVED - "&Act.ErrMess,5000,False)
End If
page.CloseModalSheet("NuClientMS")
Dim cbx As ABMCombo = page.Component("PadCBX")
cbx.Visibility = ABM.VISIBILITY_HIDE_ALL
cbx = page.Component("FarmCBX")
cbx.Visibility = ABM.VISIBILITY_HIDE_ALL
cbx = page.Component("ClientCBX")
cbx.SetActiveItemId(-1)
Dim but As ABMButton = page.Component("nuPadBut")
but.Visibility = ABM.VISIBILITY_HIDE_ALL
but = page.Component("nuFarmBut")
but.Visibility = ABM.VISIBILITY_HIDE_ALL
page.Refresh
End Sub
public Sub ConnectPage()
page.ShowGridInfo=False
page.AddModalSheetTemplate(msNuClient.BuildModalNuClient(page))
Dim Title As ABMLabel
Title.Initialize(page,"Tit",$"${Act.AbrevName} - ${Act.Name(Act.Index)} select paddock"$,ABM.SIZE_H5,False,"mytheme")
page.Cell(1,1).AddComponent(Title)
Dim NuClientBut As ABMButton
NuClientBut.InitializeFloating(page,"nuCliBut","mdi-content-add","")
page.Cell(2,2).MarginTop="20px"
page.Cell(2,2).AddComponent(NuClientBut)
Dim ClientCBX As ABMCombo
ClientCBX.Initialize(page,"ClientCBX","Client",300,"mytheme")
page.Cell(2,1).AddComponent(ClientCBX)
ClientCBX.Visibility=ABM.VISIBILITY_ALL
Act.FillCombo(page,ClientCBX,PD.Clients.SelectedData)
Dim NuFarmBut As ABMButton
NuFarmBut.InitializeFloating(page,"nuFarmBut","mdi-content-add","")
page.Cell(3,2).MarginTop="20px"
page.Cell(3,2).AddComponent(NuFarmBut)
NuFarmBut.Visibility = ABM.VISIBILITY_HIDE_ALL
Dim FarmCBX As ABMCombo
FarmCBX.Initialize(page,"FarmCBX","Farm",300,"mytheme")
page.Cell(3,1).AddComponent(FarmCBX)
FarmCBX.Visibility=ABM.VISIBILITY_HIDE_ALL
Dim NuPadBut As ABMButton
NuPadBut.InitializeFloating(page,"nuPadBut","mdi-content-add","")
page.Cell(4,2).MarginTop="20px"
page.Cell(4,2).AddComponent(NuPadBut)
NuPadBut.Visibility=ABM.VISIBILITY_HIDE_ALL
Dim PadCBX As ABMCombo
PadCBX.Initialize(page,"PadCBX","Paddock",300,"mytheme")
page.Cell(4,1).AddComponent(PadCBX)
PadCBX.Visibility=ABM.VISIBILITY_HIDE_ALL
Dim HomeBut As ABMButton
HomeBut.InitializeRaised(page,"HomeBut","","","Home","mytheme")
HomeBut.SetBorderEx(Act.ButColor,ABM.INTENSITY_DARKEN1,4,ABM.BORDER_SOLID,"20px")
page.Cell(5,1).AddComponent(HomeBut)
HomeBut.Visibility=ABM.VISIBILITY_HIDE_ALL
Dim EdtBut As ABMButton
EdtBut.InitializeRaised(page,"EdtBut","","","Last","mytheme")
EdtBut.SetBorderEx(Act.ButColor,ABM.INTENSITY_DARKEN1,4,ABM.BORDER_SOLID,"20px")
page.Cell(5,2).AddComponent(EdtBut)
EdtBut.Visibility=ABM.VISIBILITY_HIDE_ALL
Dim NewBut As ABMButton
NewBut.InitializeRaised(page,"NewBut","","","NEW","mytheme")
NewBut.SetBorderEx(Act.ButColor,ABM.INTENSITY_DARKEN1,4,ABM.BORDER_SOLID,"20px")
page.Cell(5,3).AddComponent(NewBut)
NewBut.Visibility=ABM.VISIBILITY_HIDE_ALL
' refresh the page
page.Refresh
' Tell the browser we finished loading
page.FinishedLoading
' restoring the navigation bar position
'page.RestoreNavigationBarPosition
Log("At bottom of SelectPage")
End Sub
Sub padcbx_clicked(Target As String)
Dim idx As Int = Target
PD.Paddocks.SetCurrIndx(idx)
Log($"Current paddock is ${PD.paddocks.GetCurrVal("Name")}, ID = ${PD.paddocks.GetCurrVal("ID")}"$)
Dim Hb As ABMButton = page.Component("HomeBut")
Hb.Visibility=ABM.VISIBILITY_ALL
Dim Edt As ABMButton = page.Component("EdtBut")
Edt.Visibility=ABM.VISIBILITY_ALL
Dim Gb As ABMButton = page.Component("NewBut")
Gb.Visibility=ABM.VISIBILITY_ALL
Edt.Refresh
Hb.Refresh
Gb.Refresh
End Sub
Sub homebut_clicked(Target As String)
ABMShared.NavigateToPage(ws,"HomePage","../HomePage/")
End Sub
Sub newbut_clicked(Target As String)
Act.EdtMode = False
ABMShared.NavigateToPage(ws,Act.EntryPage(Act.Index),$"../${Act.EntryPage(Act.Index)}/"$)
End Sub
Sub edtbut_clicked(Target As String)
Act.EdtMode = True
ABMShared.NavigateToPage(ws,Act.EntryPage(Act.Index),$"../${Act.EntryPage(Act.Index)}/"$)
End Sub
Sub page_modalsheetready(Target As String)
End Sub
Sub nufarmbut_clicked(Target As String)
Act.Nu = "Farm"
msNuClient.SetupEntryPt(page.ModalSheet("NuClientMS"))
page.ShowModalSheet("NuClientMS")
End Sub
Sub nupadbut_clicked(Target As String)
Act.Nu = "Paddock"
msNuClient.SetupEntryPt(page.ModalSheet("NuClientMS"))
page.ShowModalSheet("NuClientMS")
End Sub
Sub farmcbx_clicked(Target As String)
Dim idx As Int = Target
PD.Farms.SetCurrIndx(idx) 'Currfarm = PD.farms.Get(Target)
Log($"Current farm is ${PD.Farms.GetCurrVal("Name")}, ID = ${PD.Farms.GetCurrVal("ID")}"$)
PD.Paddocks.LoadWhere($"FarmID = ${PD.farms.GetCurrVal("ID")}"$,"Name")
Dim Pc As ABMCombo = page.Component("PadCBX")
Act.FillCombo(page,Pc,PD.paddocks.SelectedData)
Pc.Visibility=ABM.VISIBILITY_ALL
Dim B As ABMButton = page.Component("NuPadBut")
B.Visibility = ABM.VISIBILITY_ALL
Pc.Refresh
B.Refresh
End Sub
Sub clientcbx_clicked(Target As String)
PD.Clients.SetCurrIndx(Target)
Log($"Current client is ${PD.Clients.GetCurrVal("Name")} ID = ${PD.Clients.GetCurrVal("ID")} "$)
PD.Clients.DataRpt
Dim Fc As ABMCombo = page.Component("FarmCBX")
PD.Farms.LoadWhere($"ClientID = ${PD.Clients.GetCurrVal("ID")}"$,"")
If PD.Farms.Size > 0 Then
Act.FillCombo(page,Fc,PD.Farms.SelectedData)
else if PD.Farms.Size = 1 Then
Fc.SetActiveItemId("1")
Fc.SetFocus
End If
Dim B As ABMButton = page.Component("NuFarmBut")
B.Visibility = ABM.VISIBILITY_ALL
Fc.Visibility = ABM.VISIBILITY_ALL
Fc.Refresh
B.Refresh
End Sub
#end region
#Region ABMPage
' clicked on the navigation bar
Sub Page_NavigationbarClicked(Action As String, Value As String)
' saving the navigation bar position
page.SaveNavigationBarPosition
If Action = "LogOff" Then
ABMShared.LogOff(page)
Return
End If
ABMShared.NavigateToPage(ws, ABMPageId, Value)
End Sub
Sub Page_DebugConsole(message As String)
Log("---> " & message)
End Sub
#end region