B4J Question [ABMaterial] page_NextContent cann't working

jinyistudio

Well-Known Member
Licensed User
Longtime User
Hi
my abm is 4.30.
I have running the example of facebook. it is working.
my following code can showing page but it cann't add new post to end when i scroll window to end.
because page_NextContent cann't working. :mad:

P.S I donn't have any exception showing in the log.

B4X:
'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 = "TimeLinePage"  '<-------------------------------------------------------- IMPORTANT
    ' will hold the unique browsers window id
    Private ABMPageId As String = ""
    ' your own variables
    Private loginuser As Map
    Private postCounter As Int
    Private Posts As List
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)
    '----------------------MODIFICATION-------------------------------
    Log("Connected")
    ws = WebSocket1
    ABMPageId = ABM.GetPageID(page, Name,ws)
    Dim session As HttpSession = ABM.GetSession(ws, ABMShared.SessionMaxInactiveIntervalSeconds)
    '----------------------START MODIFICATION 4.00-------------------------------
    If session.IsNew Then
        session.Invalidate
        ABMShared.NavigateToPage(ws, "", "./")
        Return
    End If
    '----------------------END MODIFICATION 4.00-------------------------------
    'If ABMShared.NeedsAuthorization Then
    loginuser = db.GetSessionAttribute(session) ' CreateMap("account":"","password":"","token":"","company":"","address":"")
    'If ABMShared.NeedsAuthorization Then
    If  db.GsaToken(loginuser) = "" Then
        ABMShared.NavigateToPage(ws, "", "../about")
        Return
    End If
    Log($"User. ${db.GsaToken(loginuser)}"$)
 
    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)
    '----------------------MODIFICATION-------------------------------
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 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")
            ' BEGIN NEW DRAGDROP
            If eventName = "page_dropped" Then
                page.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
        else if eventName.IndexOf("pageurl")>=0 Then
            CallSub2(Me,"pageurl_clicked",eventName.SubString2(0,eventName.IndexOf("pageurl")).ToUpperCase)
         
        else if eventName.IndexOf("shareurl")>=0 Then
            CallSub2(Me,"shareurl_clicked",eventName.SubString2(0,eventName.IndexOf("shareurl")).ToUpperCase)
         
        End If
    Else
        CallSubDelayed2(caller, "ParseEvent", Params) 'ignore
    End If
End Sub

Sub pageurl_clicked(page1 As String)
    #if DEBUG
    Log($"pageurl_clicked. ${page1}"$)
    #End If
    ws.Eval($"window.open("/jinpage/pages/${page1}?id=${db.GsaToken(loginuser)}&${DateTime.Time(DateTime.Now)}","jinpage");"$,Null)
End Sub

Sub shareurl_clicked(page1 As String)
    #if DEBUG
    Log($"shareurl_clicked. ${page1}"$)
    #End If
    ' ws.Eval($"window.open("/jinpage/pages/${page1.ToUpperCase}?id=${db.GsaToken(loginuser)}&${DateTime.Time(DateTime.Now)}","jinpage");"$,Null)
End Sub

public Sub BuildTheme()
    ' start with the base theme defined in ABMShared
    theme.Initialize("pagetheme")
    theme.AddABMTheme(ABMShared.MyTheme)
 
    theme.Page.BackColor = ABM.COLOR_BLUEGREY
    theme.Page.BackColorIntensity = ABM.INTENSITY_LIGHTEN5
 
    theme.AddCellTheme("border")
    theme.Cell("border").BorderColor = ABM.COLOR_GREY
    theme.Cell("border").BorderColorIntensity = ABM.INTENSITY_LIGHTEN3
    theme.Cell("border").BorderWidth = 1
 
    theme.AddContainerTheme("zdepth")
    theme.Container("zdepth").BackColor = ABM.COLOR_WHITE
    theme.container("zdepth").ZDepth = ABM.ZDEPTH_1
 
    theme.AddCellTheme("lightgrey")
    theme.Cell("lightgrey").BackColor = ABM.COLOR_GREY
    theme.Cell("lightgrey").BackColorIntensity = ABM.INTENSITY_LIGHTEN5
 
    theme.AddDividerTheme("divider")
    theme.Divider("divider").ForeColor = ABM.COLOR_GREY
    theme.Divider("divider").ForeColorIntensity = ABM.INTENSITY_LIGHTEN3
 
    theme.AddCellTheme("right")
    theme.Cell("right").Align = ABM.CELL_ALIGN_RIGHT
 
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 = ""
    page.PageDescription = ""
    page.PageKeywords = ""
    page.PageSiteMapPriority = ""
    page.PageSiteMapFrequency = ABM.SITEMAP_FREQ_YEARLY
 
    'page.ShowConnectedIndicator = True
    'page.AlwaysShowVerticalScrollBar = True
 
    page.AddExtraCSSFile("custom/reaction.css")
    page.AddExtraJavaScriptFile("custom/reaction.js")
 
     
    ' adding a navigation bar
    ABMShared.BuildNavigationBar(page, $"{C:#FFCC00}JIN{/C}{C:#ff0000}{B}!{/B}{/C} Page"$,"../images/logo.png", "", "", "")
         
    ' create the page grid
    page.AddRowsM(1,True,0,0, "").AddCellsOSMP(1,0,2,3,12,8,6,20,0,0,0,"")
    page.BuildGrid 'IMPORTANT once you loaded the complete grid AND before you start adding components
 
    page.AddModalSheetTemplate(ABMShared.BuildMessageSheet(page))
    page.AddModalSheetTemplate(ABMShared.BuildLoginSheet(page))
     
End Sub

public Sub ConnectPage()
    Posts.Initialize
    '    connecting the navigation bar
    ABMShared.ConnectNavigationBar(page)
    Dim n1 As Int=GetShared
 
    For i = 1 To 2
        addNewCard(False)
    Next
             
    ' refresh the page
    page.Refresh
    ' Tell the browser we finished loading
    page.FinishedLoading
    ' restoring the navigation bar position
    page.RestoreNavigationBarPosition
 
    ' add one that will start the NextContents, must be done AFTEr the page has finished loading!
    addNewCard(True)
End Sub

Sub GetShared As Int
    postCounter=0
    Dim sb As StringBuilder
    sb.Initialize
    sb.Append("Select a.*,b.account,c.amount,c.total from pages As a ")
    sb.Append("left join user As b on (a.token=b.token) ")
    sb.Append("left join (Select directory,count(token) As amount,sum(liked) As total from liked group by directory) As c on(a.directory=c.directory) ")
    sb.Append("where a.share=1 order by a.created;")
    'Dim ss As String=$"select a.*,b.account from pages as a,user as b where (a.token=b.token) and (a.share=1) order by a.updated desc;"$
    Try
        Dim sql1 As SQL=MySql.Connection
        Dim cur As ResultSet = sql1.ExecQuery(sb.ToString)
        Do While cur.NextRow
            Dim mp1 As Map
            mp1.Initialize
            mp1.Put("token",cur.GetString("token"))
            mp1.Put("account",cur.GetString("account"))
            mp1.Put("page",cur.GetString("page"))
            mp1.Put("directory",cur.GetString("directory"))
            mp1.Put("description",cur.GetString("description"))
            mp1.Put("count",cur.GetInt("amount"))
            mp1.Put("liked",cur.GetInt("total"))
            mp1.Put("updated",cur.GetString("updated"))
            Posts.Add(mp1)
        Loop
        sql1.Close
    Catch
        Log(LastException)
    End Try
    Return Posts.Size
End Sub

Sub addNewCard(RaiseNext As Boolean)
    'If postCounter<=Posts.Size Then
        Dim NewPost As PagePost
        NewPost.Initialize
        Dim item As Map=Posts.Get(postCounter)
        page.Cell(1,1).AddComponent(NewPost.Build(page, item))
        postCounter = postCounter + 1
        ' Posts.put(postCounter, NewPost)
 
        If RaiseNext Then
            Log($"NextContent.${postCounter}"$)
            page.Cell(1,1).Refresh
            page.RaiseNextContentOnComponent(NewPost.myCard,150)
        End If
    'End If
End Sub

Sub page_NextContent(TriggerComponent As String)
        Log($"Evt.NextContent.${postCounter}"$)
        addNewCard(True)
End Sub

public Sub LikeComponent_Liked(value As Map)
    #if DEBUG
    Log(value.Get("like") & " ===> " & value.Get("target"))
    #End If
    Dim liked As Map=CreateMap("Like":1,"Love":2,"HaHa":3,"Wow":4,"Sad":-1,"Angry":-2)
    Dim page1 As String=value.Get("target")
    page1=page1.SubString2(0,page1.IndexOf("post-")).ToUpperCase
    Dim score As Int=liked.Getdefault(value.Get("like"),0)
    MySql.PageLike(db.GsaToken(loginuser),page1,score)
End Sub

public Sub LikeComponent_UnLiked(value As Map)
    Log("Unliked ----> " & value.Get("target"))
End Sub

public Sub Reactions_Clicked(Target As String)
    Dim postNum As Int = Target.SubString(13)
    Dim NewPost As PagePost = Posts.Get(postNum)
    Dim CardReacts As ABMContainer = NewPost.myCard.Component("post" & postNum & "reactions")
    If NewPost.IsOpen Then
        CardReacts.CloseContent
    Else
        CardReacts.OpenContent
    End If
    NewPost.IsOpen = Not(NewPost.IsOpen)
End Sub

' clicked on the navigation bar
Sub Page_NavigationbarClicked(Action As String, Value As String)
    ' saving the navigation bar position
    page.SaveNavigationBarPosition
 
    If Action = "Login" Then
        ABMShared.ShowLoginSheet(page)
        Return
    End If
 
    If Action = "Logoff" Then
        ABMShared.LogOff(page)
        Return
    End If

    ABMShared.NavigateToPage(ws, ABMPageId, Value)
End Sub

Sub LoginOK_Clicked(Target As String)
    Dim mymodal As ABMModalSheet = page.ModalSheet("login")
    Dim inp1 As ABMInput = mymodal.Content.Component("inp1")
    Dim inp2 As ABMInput = mymodal.Content.Component("inp2")
    ' here check the login a page against your login database
    loginuser = MySql.UserLogin(inp1.Text,inp2.Text)
    If loginuser.GetDefault("token","")="" Then
        ABMShared.ShowMessage(page,"The login Or password are incorrect!")
        Return
    End If
    Log($"User login.${inp1.text},${inp2.text}=${loginuser.Get("token")}"$)
    ws.Session.SetAttribute("IsAuthorized",db.MapToString(loginuser))
    page.CloseModalSheet("login")
    ABMShared.ConnectNavigationBar(page)
    ' ABMShared.NavigateToPage(ws, "", "../AboutPage/")
End Sub
'
Sub LoginNO_Clicked(Target As String)
    page.CloseModalSheet("login")
    'ABMShared.NavigateToPage(ws, "", "./" & InitialPage)
End Sub

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_Authenticated(Params As Map)
 
End Sub

Sub Page_FirebaseAuthError(extra As String)
 
End Sub

Sub Page_FirebaseAuthStateChanged(IsLoggedIn As Boolean)
 
End Sub

Sub Page_FirebaseStorageError(jobID As String, extra As String)
 
End Sub

Sub Page_FirebaseStorageResult(jobID As String, extra As String)
 
End Sub

Sub Page_ModalSheetDismissed(ModalSheetName As String)
 
End Sub

Sub Page_SignedOffSocialNetwork(Network As String, Extra As String)
 
End Sub
I have change facebookpost to my pagepost
B4X:
'Class module
Sub Class_Globals
    Public myCard As ABMContainer
    Public myID As String
    Dim ABM As ABMaterial
    Dim myLike As LikeComponent
    Public IsOpen As Boolean
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    
End Sub

public Sub Build(page As ABMPage, ID As String) As ABMContainer
    myID = ID
    myCard.Initialize(page, ID, "zdepth")
    myCard.AddRowsM(1,False,0,0,"").AddCellsOSMP(1,0,0,0,2,2,1,10,0,20,0,"").AddCellsOSMP(1,0,0,0,10,10,11,0,0,50,0,"")
    myCard.AddRowsM(1,True,0,0,"").AddCells12MP(1,0,0,0,0,"")
    myCard.AddRowsM(1,True,0,0,"").AddCells12MP(1,0,0,11,11,"border")
    myCard.AddRowsM(1,True,10,0,"").AddCellsOSMP(1,0,0,0,6,6,6,0,10,0,0,"").AddCellsOSMP(1,0,0,0,6,6,6,0,10,0,0,"right")
    myCard.AddRowsM(1,True,0,0,"").AddCells12MP(1,0,0,0,0,"lightgrey")
    myCard.AddRowsM(1,False,0,10,"").AddCells12MP(1,0,10,0,0,"")
    myCard.BuildGrid
    
    Dim Poster As ABMImage
    Poster.Initialize(page, ID & "Poster", "../images/download" & Rnd(1,21) & ".jpg?" & ABMShared.AppVersion,1)
    myCard.Cell(1,1).AddComponent(Poster)
    
    Dim lblTitle As ABMLabel
    lblTitle.Initialize(page, ID & "Title", "{B}{C:#3658b2}" & ABM.Util.words(Rnd(2,5)) & "{/C}{/B}{BR}{C:#90949c}" & Rnd(1,60) & " minutes", ABM.SIZE_PARAGRAPH, False, "")
    myCard.Cell(1,2).AddComponent(lblTitle)
    
    Dim lblPost As ABMLabel
    lblPost.Initialize(page, ID & "Post", ABM.Util.Words(Rnd(5,10)), ABM.SIZE_PARAGRAPH, False, "")
    myCard.Cell(2,1).AddComponent(lblPost)
    
    myCard.Cell(3,1).AddComponent(CardContent(page, ID))
    
    myLike.initialize(page, ID & "Like", Rnd(20, 500))
    myCard.Cell(4,1).AddComponent(myLike.ABMComp)
    
    Dim reactionNumber As Int = Rnd(1,10)
    
    Dim lblReactionNum As ABMLabel
    lblReactionNum.Initialize(page, ID, reactionNumber & " reactions", ABM.SIZE_PARAGRAPH, False, "")
    lblReactionNum.Clickable = True
    myCard.Cell(4,2).AddArrayComponent(lblReactionNum, "Reactions")
    
    myCard.Cell(5,1).AddComponent(CardReactions(page, ID, reactionNumber))
    
    Return myCard
End Sub

private Sub CardContent(page As ABMPage, ID As String) As ABMContainer
    Dim CardCont As ABMContainer
    CardCont.Initialize(page, ID & "Contents", "")
    CardCont.AddRowsM(1, False, 0,0, "").AddCells12(1,"")
    CardCont.AddRowsM(1, False, 0,0, "").AddCells12MP(1,0,0,10,10,"")
    CardCont.AddRowsM(1, False, 0,0, "").AddCells12MP(1,0,0,10,10,"")
    CardCont.BuildGrid
    
    Dim image As ABMImage
    image.Initialize(page, ID & "image", "../images2/" & Rnd(1,21) & ".jpg?" & ABMShared.AppVersion,1)
    image.IsResponsive = True
    CardCont.Cell(1,1).AddComponent(image)
    
    Dim imageTitle As ABMLabel
    imageTitle.Initialize(page, ID & "imageTitle", "{B}" & ABM.Util.words(Rnd(5,8)) & "{/B}", ABM.SIZE_H5, False, "")
    imageTitle.IsFlowText = True
    CardCont.Cell(2,1).AddComponent(imageTitle)
    
'    Dim divider As ABMDivider
'    divider.Initialize(page, ID & "Divider", "divider")
'    CardCont.Cell(3,1).AddComponent(divider)
    
    Dim imageBy As ABMLabel
    imageBy.Initialize(page, ID & "imageBy", "{C:#90949c}COPYRIGHT BY | {/C}{C:#5f72c1}" & ABM.Util.words(Rnd(1,3)).ToUpperCase & "{/C}", ABM.SIZE_PARAGRAPH, True, "")
    CardCont.Cell(3,1).AddComponent(imageBy)
    
    Return CardCont
End Sub

private Sub CardReactions(page As ABMPage, ID As String, reactionNumber As Int) As ABMContainer
    Dim CardReacts As ABMContainer
    CardReacts.Initialize(page, ID & "reactions", "")
    CardReacts.AddRowsM(1, False, 0,0, "").AddCells12MP(1,0,0,10,10,"")
    CardReacts.BuildGrid
    CardReacts.SetContentIsOpen(False)
    For i = 1 To reactionNumber
        CardReacts.Cell(1,1).AddComponent(Reaction(page, ID, i))
    Next
    Return CardReacts
End Sub

private Sub Reaction(page As ABMPage, ID As String, counter As Int) As ABMContainer
    Dim React As ABMContainer
    React.Initialize(page, ID & "reaction" & counter, "")
    React.AddRowsM(1, False, 0,0, "").AddCellsOSMP(1,0,0,0,2,2,1,10,0,20,0,"").AddCellsOSMP(1,0,0,0,10,10,11,0,0,50,50,"")
    React.BuildGrid
    
    Dim PosterReact As ABMImage
    PosterReact.Initialize(page, ID & "PosterReact" & counter, "../images/download" & Rnd(1,21) & ".jpg?" & ABMShared.AppVersion,1)
    React.Cell(1,1).AddComponent(PosterReact)
    
    Dim PosterText As ABMLabel
    PosterText.Initialize(page, ID & "PosterText" & counter, "{B}{C:#5f72c1}" & ABM.Util.words(Rnd(2,5)) & "{/C}{/B} " & ABM.Util.Words(Rnd(2,15)), ABM.SIZE_PARAGRAPH, True, "")
    React.Cell(1,2).AddComponent(PosterText)
    
    Return React
End Sub
 
Last edited:

jinyistudio

Well-Known Member
Licensed User
Longtime User
1. I forget this item.put("post", NewPost).
2. It isn't OK when i copy all to vps(remote server). Local is OK. :mad:
 
Upvote 0

jinyistudio

Well-Known Member
Licensed User
Longtime User
Hi

i have following message :p i try to debug it,thank's
SyntaxError: '#990f0apost' is not a valid selector 32 core.4.30.min.js:1
 
Upvote 0

jinyistudio

Well-Known Member
Licensed User
Longtime User
Hi

It's OK. because the ID has numbers in front of the name. :oops:
 
Upvote 0
Top