#Region Notes
' Server WebSocket Class Module: LEDSwitchPage
' Purpose:
' Manage browser connection and switching of LED
#End Region
'
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 = "SignalPage"
' name of the app, same as in ABMApplication
Public AppName As String = "dnc-node"
' will hold the unique browsers window id
Private ABMPageId As String = ""
' own project vars
Dim LogTimer As Timer
Dim FirstNames As List
Dim LastNames As List
Dim tbl1Counter As Int = 1
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
Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
Log("WebSocket Connected")
ws = WebSocket1
ABMPageId = ABM.GetPageID(page, Name,ws)
' 讀取網頁參數
'Dim s1 As String=ws.UpgradeRequest.FullRequestURI
'Dim n1 As Int=ws.UpgradeRequest.FullRequestURI.IndexOf("EqipPage?")
'If n1>0 Then
' Dim sp() As String=Regex.Split(",",s1.SubString(n1+9))
' If sp.Length>=3 Then
' sideReturn = sp(1)
' subsideReturn = sp(2)
' ABMShared.BuildNavigationBar(page, "單機稼動及數據","../images/logo.png","",sideReturn,subsideReturn)
' End If
'End If
If ABMShared.NeedsAuthorization Then
If ws.Session.GetAttribute2("IsAuthorized", "") = "" Then
ABMShared.NavigateToPage(ws,ABMPageId, "../")
Return
End If
End If
' connect our page with the websocket
page.SetWebSocket(ws)
' Prepare the page IMPORTANT!
page.Prepare
'ConnectPage
LogTimer.Initialize("LogTimer", 3000)
LogTimer.Enabled = True
End Sub
Private Sub WebSocket_Disconnected
Log("WebSocket Disconnected")
LogTimer.Enabled = False
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 SubExists(Me, eventName) Then
Params.Remove("eventname")
Params.Remove("eventparams")
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 diretly, to many param
CallSub2(Me, eventName, Params)
End Select
End If
End Sub
public Sub BuildTheme()
' start with the base theme defined in ABMShared
theme.Initialize("pagetheme")
theme.AddABMTheme(ABMShared.MyTheme)
' add additional themes specific for this page
theme.AddTableTheme("tbl1theme")
theme.Table("tbl1theme").ZDepth = ABM.ZDEPTH_1
theme.Table("tbl1theme").AddCellTheme("headerfooter")
theme.Table("tbl1theme").Cell("headerfooter").BackColor = ABM.COLOR_BLUEGREY
theme.Table("tbl1theme").Cell("headerfooter").ForeColor = ABM.COLOR_WHITE
theme.Table("tbl1theme").AddCellTheme("headerfooterright")
theme.Table("tbl1theme").Cell("headerfooterright").BackColor = ABM.COLOR_BLUEGREY
theme.Table("tbl1theme").Cell("headerfooterright").ForeColor = ABM.COLOR_WHITE
theme.Table("tbl1theme").Cell("headerfooterright").Align = ABM.TABLECELL_HORIZONTALALIGN_RIGHT
theme.Table("tbl1theme").AddCellTheme("nocolor")
theme.Table("tbl1theme").Cell("nocolor").ActiveBackColor = ABM.COLOR_BLUEGREY
theme.Table("tbl1theme").Cell("nocolor").ActiveBackColorIntensity = ABM.INTENSITY_LIGHTEN2
theme.Table("tbl1theme").AddCellTheme("nocoloredit")
theme.Table("tbl1theme").Cell("nocoloredit").ActiveBackColor = ABM.COLOR_BLUEGREY
theme.Table("tbl1theme").Cell("nocoloredit").ActiveBackColorIntensity = ABM.INTENSITY_LIGHTEN2
theme.Table("tbl1theme").Cell("nocoloredit").IsEditable = True
theme.Table("tbl1theme").Cell("nocoloredit").InputMask = "'alias':'decimal', 'digits': 2"
theme.Table("tbl1theme").Cell("nocoloredit").AllowEnterKey = False
theme.Table("tbl1theme").AddCellTheme("positive")
theme.Table("tbl1theme").Cell("positive").BackColor = ABM.COLOR_GREEN
theme.Table("tbl1theme").Cell("positive").BackColorIntensity = ABM.INTENSITY_LIGHTEN3
theme.Table("tbl1theme").Cell("positive").ActiveBackColor = ABM.COLOR_GREEN
theme.Table("tbl1theme").Cell("positive").ActiveBackColorIntensity = ABM.INTENSITY_LIGHTEN1
theme.Table("tbl1theme").Cell("positive").Align = ABM.TABLECELL_HORIZONTALALIGN_RIGHT
theme.Table("tbl1theme").AddCellTheme("negative")
theme.Table("tbl1theme").Cell("negative").BackColor = ABM.COLOR_RED
theme.Table("tbl1theme").Cell("negative").BackColorIntensity = ABM.INTENSITY_LIGHTEN3
theme.Table("tbl1theme").Cell("negative").ActiveBackColor = ABM.COLOR_RED
theme.Table("tbl1theme").Cell("negative").ActiveBackColorIntensity = ABM.INTENSITY_LIGHTEN1
theme.Table("tbl1theme").Cell("negative").Align = ABM.TABLECELL_HORIZONTALALIGN_RIGHT
theme.Table("tbl1theme").AddCellTheme("aligntop")
theme.Table("tbl1theme").Cell("aligntop").VerticalAlign = ABM.TABLECELL_VERTICALALIGN_TOP
' add additional themes specific for this page
End Sub
public Sub BuildPage()
' initialize the theme
Dim s1 As String=page.Handler
BuildTheme
' initialize this page using our theme
page.InitializeWithTheme(Name, "/ws/" & AppName & "/" & Name, False,3, theme)
page.ShowLoader=True
page.PageHTMLName = "index.html"
page.PageTitle = "DNC-Node"
page.PageDescription = "顯示所有設定信號的即時狀態."
page.PageKeywords = "IoT, B4J"
page.PageSiteMapPriority = ""
page.PageSiteMapFrequency = ABM.SITEMAP_FREQ_YEARLY
page.ShowConnectedIndicator = True
ABMShared.BuildNavigationBar(page, "信號即時狀態","../images/logo.png","","signal","signal")
' adding a navigation bar
' create the page grid
page.AddRows(1,True, "").AddCells12(1,"")
page.AddRows(1, True,"").AddCellsOS(1,0,0,0,5,5,5,"").AddCellsOS(1,1,1,1,1,1,1,"").AddCellsOS(1,0,0,0,5,5,5,"")
page.BuildGrid 'IMPORTANT loaded the complete grid prior adding components
'
' Fixed Footer
ABMShared.BuildFooterFixed(page)
End Sub
Sub BuildItem(id As String, text As String, messages As String, isnew As Boolean) As ABMContainer
Dim ItemCont As ABMContainer
ItemCont.Initialize(page, id, "")
ItemCont.AddRowsM(1,False,0,0,"").AddCellsOSMP(1,0,0,0,4,4,4,6,0,0,0,"").AddCellsOSMP(1,0,0,0,8,8,8,6,0,0,0,"")
ItemCont.BuildGrid ' IMPORTANT once you loaded the complete grid And before you start adding components
Dim lbl As ABMLabel
lbl.Initialize(page, id & "lbl", text, ABM.SIZE_PARAGRAPH, False, "")
lbl.Text=text
ItemCont.Cell(1,1).AddComponent(lbl)
Dim lbl1 As ABMLabel
lbl1.Initialize(page, id & "val", text, ABM.SIZE_H5, False, "")
lbl1.Text = messages
ItemCont.Cell(1,2).AddComponent(lbl1)
Return ItemCont
End Sub
Sub UpdateEquipValue
End Sub
' clicked on the navigation bar
Sub Page_NavigationbarClicked(Action As String, Value As String)
page.SaveNavigationBarPosition
If Action = "ABMModalSheet" Then Return
If Action = "Contact" Then
page.ShowToast("toast", "toastred", "Hello to you too!", 5000)
Return
End If
If Action = "Logoff" Then
ABMShared.LogOff(page)
Return
End If
ABMShared.NavigateToPage(ws, ABMPageId, Value)
End Sub
' When the download is finished, you'll receive an FileUploaded() event on the page.
Sub Page_FileUploaded(FileName As String, success As Boolean)
End Sub
Sub Page_ToastClicked(ToastId As String, Action As String)
End Sub
Sub Page_ToastDismissed(ToastId As String)
End Sub
Sub Page_Ready()
ConnectPage
End Sub
Sub ConnectPage()
'NEW
ABMShared.ConnectNavigationBar(page)
FirstNames.Initialize2(Array As String("Alain", "Jos", "Paul", "Bertrande", "Julie", "Stephanie", "Bert", "Charles", "James", "Walter"))
LastNames.Initialize2(Array As String("Bailleul", "Rogiers", "Dougherty", "Rodrigues", "Ostrander", "Kenyon", "Grant", "Klinger", "Sheffield", "Poindexter"))
' add paragraph
page.Cell(1,1).AddComponent(ABMShared.BuildParagraphBQ(page,"par1b", "The Id of a table {B}MAY NOT CONTAIN A _ CHARACTER!{/B}. This is because of the inner working of nested table and the _ character is reserved.") )
' create a table
Dim tbl1 As ABMTable
tbl1.Initialize(page, "tbl1", False, False, True, "tbl1theme")
tbl1.SetHeaders(Array As String("Signal Name", "Value"))
tbl1.SetColumnDataFields(Array As String("Alias/Signal", "Value"))
tbl1.SetColumnWidths(Array As Int(250,180))
tbl1.SetHeaderThemes(Array As String("headerfooter", "headerfooterright"))
' add some random values
If db.signals.Size>0 Then
For i0 = 0 To db.signals.Size-1
Dim ip As String=db.signals.GetKeyAt(i0)
Dim mp1 As Map=db.signals.GetValueAt(i0)
If mp1.Size>0 Then
For i2=0 To 3
If mp1.ContainsKey("DI"&i2) Then
Dim mp2 As Map=mp1.Get("DI"&i2)
Dim s1 As String=mp2.Getdefault("pin","")
Dim s2 As String=mp2.Getdefault("alias","")
Dim r As List
Dim rCellThemes As List
r.Initialize
rCellThemes.Initialize
r.Add(s2)
rCellThemes.Add("nocolor") ' nocoloredit
'
r.Add("false")
rCellThemes.Add("negative") ' nocoloredit
'
tbl1.AddRow(s2, r)
tbl1.SetRowThemes(rCellThemes) ' make sure you have as many items in rCellThemes as in r!
End If
Next
End If
Next
End If
tbl1.SetFooter("位元型信號.", 12,"headerfooter")
' create a table2
Dim tbl2 As ABMTable
tbl2.Initialize(page, "tbl2", False, False, True, "tbl1theme")
tbl2.SetHeaders(Array As String("Alias/Name", "Value"))
tbl2.SetColumnDataFields(Array As String("Alias/Name", "Value"))
tbl2.SetColumnWidths(Array As Int(250,180))
tbl2.SetHeaderThemes(Array As String("headerfooter", "headerfooterright"))
' add some random values
If db.signals.Size>0 Then
For i0 = 0 To db.signals.Size-1
Dim ip As String=db.signals.GetKeyAt(i0)
Dim mp1 As Map=db.signals.GetValueAt(i0)
If mp1.Size>0 Then
For i2=0 To 3
If mp1.ContainsKey("AI"&i2) Then
Dim mp2 As Map=mp1.Get("AI"&i2)
Dim s1 As String=mp2.Getdefault("pin","")
Dim s2 As String=mp2.Getdefault("alias","")
Dim r As List
Dim rCellThemes As List
r.Initialize
rCellThemes.Initialize
r.Add(s2)
rCellThemes.Add("nocolor") ' nocoloredit
'
r.Add("0")
rCellThemes.Add("positiive") ' nocoloredit
'
tbl2.AddRow(s2, r)
tbl2.SetRowThemes(rCellThemes) ' make sure you have as many items in rCellThemes as in r!
End If
Next
End If
Next
End If
tbl2.SetFooter("數字型信號.", 12,"headerfooter")
page.Cell(2,1).AddComponent(tbl1)
page.Cell(2,3).AddComponent(tbl2)
page.Refresh ' IMPORTANT
' NEW, because we use ShowLoaderType=ABM.LOADER_TYPE_MANUAL
page.FinishedLoading 'IMPORTANT
page.RestoreNavigationBarPosition
End Sub
Sub LogTimer_Tick
End Sub
Sub tbl1_Clicked(PassedRowsAndColumns As List)
End Sub
#Region Buttons
#End Region
#Region User Function
Sub BuildSimpleItem0(id As String, icon As String, Title As String) As ABMLabel
Dim lbl As ABMLabel
If icon <> "" Then
lbl.Initialize(page, id, Title, ABM.SIZE_H6, True, "header")
Else
lbl.Initialize(page, id, Title, ABM.SIZE_H6, True, "")
End If
lbl.VerticalAlign = True
lbl.IconName = icon
Return lbl
End Sub
Sub BuildSimpleItem1(id As String, icon As String, Title As String) As ABMLabel
Dim lbl As ABMLabel
If icon <> "" Then
lbl.Initialize(page, id, Title, ABM.SIZE_H6, True, "header")
Else
lbl.Initialize(page, id, Title, ABM.SIZE_H6, True, "")
End If
lbl.VerticalAlign = True
lbl.IconName = icon
Return lbl
End Sub
#End Region