'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 = "TstCanPage" '<-------------------------------------------------------- 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
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"))
Log(eventName)
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
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 = "Template"
page.PageDescription = "Template"
page.PageKeywords = ""
page.PageSiteMapPriority = ""
page.PageSiteMapFrequency = ABM.SITEMAP_FREQ_YEARLY
page.ShowConnectedIndicator = True
' adding a navigation bar
' ABMShared.BuildNavigationBar(page, "My Page","../images/logo.png", "", "", "")
' create the page grid
page.AddRowsM(2,True,20,0, "").AddCells12MP(1,0,0,0,0,"")
page.BuildGrid 'IMPORTANT once you loaded the complete grid AND before you start adding components
page.AddCanvasImage("background", "../images/compass.png")
page.AddCanvasImage("spt", "../images/RedSpot.png")
End Sub
public Sub ConnectPage()
' connecting the navigation bar
' ABMShared.ConnectNavigationBar(page)
Dim canvas2 As ABMCanvas
canvas2.Initialize(page, "canvas2", ABM.COLOR_BLACK, ABM.INTENSITY_NORMAL, 300,300, False)
Dim clock As ABMCanvasObject = BuildClock
canvas2.AddObject(clock)
Dim Spot As ABMCanvasObject
Spot.InitializeAsRectangle(page,"spot",50,50,30,30,True)
'Spot.InitializeAsCircle(page,"spot",50,50,10,True)
Spot.SetDragZone(0,0,200,200)
Spot.drawImage("spt",30,30)
'Spot.Refresh
canvas2.AddObject(Spot)
canvas2.Refresh
page.Cell(1,1).AddComponent(canvas2)
' refresh the page
page.Refresh
' Tell the browser we finished loading
page.FinishedLoading
' restoring the navigation bar position
'page.RestoreNavigationBarPosition
End Sub
#end region
#Region ABMPage
' clicked on the navigation bar
Sub BuildClock() As ABMCanvasObject
Dim clock As ABMCanvasObject
Dim Radius As Double = 150
clock.InitializeAsRectangle(page, "clock", 0,0,300,300, True)
Radius = Radius * 0.9
' make background transparent
clock.clearRect(0,0,300,300)
' draw face
clock.translate(150,150)
clock.beginPath
clock.arc(0,0,Radius, 0, 2*cPI)
clock.fillStyleColor("#FFFFFF")
clock.fill
clock.strokeStyleRadialGradient(0,0,Radius*0.95,0,0,Radius*1.05, Array As Double(0,0.5,1), Array As String("#333", "green", "#333"))
clock.lineWidth(Radius*0.1)
clock.stroke()
clock.beginPath
clock.arc(0, 0, Radius*0.1, 0, 2*cPI)
clock.fillStyleColor("#333")
'clock.fill
'draw numbers
clock.font("arial", Radius*0.15)
clock.textBaseline(ABM.CANVAS_TEXTBASELINE_MIDDLE)
clock.textAlign(ABM.CANVAS_TEXTALIGN_CENTER)
Dim ang As Double
Dim dir() As String = Array As String ("N","NE","E","SE","S","SW","W","NW","Calm")
For num = 1 To 8
ang = num * cPI / 4
clock.rotate(ang)
clock.translate(0, -Radius*0.85)
clock.rotate(-ang)
clock.fillText("" & dir(num-1), 0, 0)
clock.rotate(ang)
clock.translate(0, Radius*0.85)
clock.rotate(-ang)
Next
clock.fillText(dir(8), 0, 0)
' draw time
'Dim hour As Double = DateTime.GetHour(DateTime.Now)
'Dim minute As Double = DateTime.GetMinute(DateTime.Now)
'Dim second As Double = DateTime.GetSecond(DateTime.Now)
'hour = hour Mod 12
'hour = (hour*cPI/6)+(minute*cPI/(6*60))+(second*cPI/(360*60))
'BuildHand(clock, hour, Radius*0.5, Radius*0.07)
'minute=(minute*cPI/30)+(second*cPI/(30*60))
'BuildHand(clock, minute, Radius*0.8, Radius*0.07)
'second=(second*cPI/30)
'BuildHand(clock, second, Radius*0.9, Radius*0.02)
Return clock
End Sub
Sub canvas2_objectup(objectId As String)
Log(objectId)
Dim c2 As ABMCanvas = page.Component("canvas2")
Dim S As ABMCanvasObject = c2.GetObject("spot")
Dim Pos As ABMPoint = S.GetPosition
S.Refresh
If Pos <> Null Then
Log(Pos.x &" - "& Pos.y)
End If
End Sub
Sub canvas2_CanvasUp(x As Int, y As Int)
Log("canvas up: " & x & " - " & y)
End Sub
Sub BuildHand(clock As ABMCanvasObject, pos As Int, length As Double, width As Double)
clock.beginPath
clock.lineWidth(width)
clock.lineCap(ABM.CANVAS_LINECAP_ROUND)
clock.moveTo(0,0)
clock.rotate(pos)
clock.lineTo(0, -length)
clock.stroke
clock.rotate(-pos)
End Sub
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