« Part 5: Continuing with DXL to create the Gallery feature in the Icon and Images database | Main| The template for the "Icon And Images" database will be available shortly »

Part 6: Continuing with DXL to create the Favorites feature in the Icon and Images database

Tags: Lotus Notes Software DXL LotusScript
0
This is part 6 of a series of articles about the Icon and Images database (started in this article), This article focus on the Favorites page and how it was made.
A picture named M2
This is the sixth article in the series covering the Icon and Images database. The previous articles are;

Part 1: Icon and Images database -or- How I store more than 1.8 million icon files in a single Notes database
Part 2; Programming details on Icon and Images - Enumerating files
Part 3: Using DXL to create imagery in documents
Part 4: Using DXL to create imagery in documents - continued
Part 5: Continuing with DXL to create the Gallery feature in the Icon and Images database

If you don't know Icons and Images, please catch up with the previous articles!

In this article I'll cover the second of two new features in the database, the Favorites page, and how I made it. The pepper here is that the new features is direct reuse of the cool DXL techniques described especially in part 3 and 4.


The Favorite-page

The Favorite-page is visible directly on the main frameset, like this;

A picture named M2
It displays the icons you have chosen to "Add to favorites" when you perform an icon action from the dialog box below;

A picture named M3

When the user chose "Add to favorites", the agent code in agnIconClickedActionHandler-agent will add the selected icon an its data to the users own favorites document in the database. In other words, as long as the user don't clean up the favorites documednt, it will contain more and more icon-references.

By clicking on the icon on the Favorite-page you bring up the following dialog box;

A picture named M4

You can choose to go directly to the image document, extract the selected icon as a file to your hard disk, or copy the image to the clipboard.

The primary goal for the Favorite-page was to be able to collect icons you might need in a single project or similar. The code might easyly be enhanced to support favorites for multiple projects etc.

How was the Favorites support created?

You guessed it! By DXL and the existing concepts and techniques decribed in this article and part 3 and 4.

The function is CreateFavoriteImagesForUser  in the same script library as for the Gallery processing; Gallery And Favorites Processing.

The first part of the function, declares and set up the templates for Favorites-usage;

        On Error Resume Next
       
        ' The sequence of the fields
        listB64FieldSeq("1") = "256x256"
        listB64FieldSeq("2") = "128x128"
        listB64FieldSeq("3") = "72x72"
        listB64FieldSeq("4") = "48x48"
        listB64FieldSeq("5") = "32x32"
        listB64FieldSeq("6") = "24x24"
        listB64FieldSeq("7") = "16x16"
       
       
        ' Get temporary path and ensure it has a suffux backslash
        strTempPath = Environ("TEMP")
        If Right(strTempPath,1) <> "\" Then strTempPath = strTempPath & "\"
       
        ' Prepare to output the DXL file
        strDXLFileName = strTempPath & "IconAndImagesFavorite.dxl"
        fout = Freefile()
       
        ' The following strDXLTemplateXXX will contain the DXL templates to build the table
        Dim strDXLTemplateDocumentPrefix As String        
        Dim strDXLTemplateTablePrefix As String
        Dim strDXLTemplateImageTableCell As String
        Dim strDXLTemplateEmptyTableCell As String
        Dim strDXLTemplateDocumentSuffix As String        
       
        ' And set those template variables above for a table with 6 icons  24x24
        Call SetDXLTemplatesForFavorite24x24(strDXLTemplateDocumentPrefix, _
        strDXLTemplateTablePrefix, _
        strDXLTemplateImageTableCell,_
        strDXLTemplateEmptyTableCell,_
        strDXLTemplateDocumentSuffix)
       
        Set db = session.CurrentDatabase
       
        ' Get the view containing the favorite users
        Set viewFavoriteUsers = db.GetView("lupFavoriteImagesByUserName")
        Call viewFavoriteUsers.Refresh
       
        ' Get the users favorite images document
        Set docFavorite = viewFavoriteUsers.GetDocumentByKey(session.UserName)
        If docFavorite Is Nothing Then Exit Function
       
        ' Output the initial DXL Document header stuff
        iParCountPerDoc = 2
        iIConPerRowCount = 0
        Kill strDXLFileName
        Open strDXLFileName For Output As fout
       
        strTmp = strDXLTemplateDocumentPrefix
        strTmp = Replace(strTmp, "$(REPLICAID)",db.ReplicaID)
        strTmp = Replace(strTmp, "$(NOTEID)",docFavorite.NoteID)
        strTmp = Replace(strTmp, "$(UNID)",docFavorite.UniversalID)
        Print #fout,strTmp
       
       
        ' Find the default view
        Dim views As Variant
        views = db.Views
        Forall v In views
                If v.IsDefaultView Then
                        Set viewDefault = v
                        Exit Forall
                End If
        End Forall
       
        ' Loop through the icons as specified by the txtImageLinks in the users favorite images document
        ' First I transfer the keys to my own listImageKey so I'm free to delete the docFavorite reference later
        lIconCount = 0
        Forall strCurKey In docFavorite.txtImageLinks
                listImageKey (Cstr(lIconCount)) = strCurKey
                lIconCount = lIconCount + 1
        End Forall
       
In the code above, I set the templates with the SetDXLTemplatesForFavorite24x24-function and open up the resulting DXL file, which will be imported later.

Below you see the result of the code, which loops through the icons stored in the favorites-document

     ' Now, drop the docFavorite as the DXL processing render it later!
        Set docFavorite = Nothing
       
        lIconCount = 0
        bFirstIconInDoc = True        
        Forall strImgKey In listImageKey
               
                ' Remember, the key contains NoteID_Index!!!
                vNoteIDAndIndex = Split(strImgKey, "_")
               
                ' Get the image document for the current NoteID ...
                Set docIcon = db.GetDocumentByID(vNoteIDAndIndex(0))
                If Not docIcon Is Nothing Then
                       
                        lIconCount = lIconCount + 1
                       
                        ' ROW CHANGE? Now determine whether we should start a new row or not
                        If iIConPerRowCount = 0 Or iIConPerRowCount = 6 Then
                               
                              ' Should I terminate any existing row?
                                If bFirstIconInDoc = False Then
                                        Print #fout,|</tablerow>
</table><par def='1'><run><font size='2pt' name='Arial' pitch='variable' truetype='true' familyid='20'/></run></par>|        
                                End If
                               
                                strTmp = strDXLTemplateTablePrefix
                                Print #fout,strTmp
                               
                                iIConPerRowCount = 0
                        End If ' end if new row
                       
                        ' Now, get the icon template
                        strTmp = strDXLTemplateImageTableCell
                        strTmp = Replace(strTmp, "$(PARID_COUNTER)",Cstr(iParCountPerDoc))
                        iParCountPerDoc = iParCountPerDoc + 1
                       
                        ' The code below relates to doclinks.I don't use that in favorites
                        'strTmp = Replace(strTmp, "$(SERVERNAME)",db.Server)
                        'strTmp = Replace(strTmp, "$(DOCUNID)",docIcon.UniversalID)
                        'strTmp = Replace(strTmp, "$(VIEWUNID)", viewDefault.UniversalID)
                        'strTmp = Replace(strTmp, "$(REPLICAID)",db.ReplicaID)
                        'strTmp = Replace(strTmp, "$(TARGETFRAME)","_blank")
                        'strTmp = Replace(strTmp, "$(TITLE)",docIcon.Title(0))
                       
                        strTmp = Replace(strTmp, "$(KEY)",strImgKey)
                       
                        ' Determine whether I've got the specified size or not
                        bFoundGalleryGIF = False
                       
                        Forall strSize In listB64FieldSeq
                                ' Ensure I start at the desired level in the sequnece list, 24x24 in this case!
                                If Cint(Listtag(strSize)) >= 6 Then
                                        strFieldName = "GalleryGIF" & strSize
                                        If docIcon.HasItem(strFieldName) Then
                                                Set item = docIcon.GetFirstItem(strFieldName)
                                                vRc = Split(strSize, "x")
                                                strTmp = Replace(strTmp, "$(IMGSIZE)",vRc(0)) ' Ensure we've got the correct size!
                                                strTmp = Replace(strTmp, "$(BASE64)",item.Text)
                                                bFoundGalleryGIF = True
                                                Exit Forall
                                        End If
                                End If
                        End Forall
                       
                        ' If we haven't found an matching icon, then output the default problem-icon!
                        If bFoundGalleryGIF = False Then
                                strTmp = Replace(strTmp, "$(IMGSIZE)","24") ' Ensure we've got the correct size!
                                strTmp = Replace(strTmp, "$(BASE64)",g_strIconNotFound24x24)
                        End If
                       
                        Print #fout,strTmp
                       
                        ' Loop to the next icon
                        bFirstIconInDoc = False                        
                        iIConPerRowCount = iIConPerRowCount + 1
                End If ' end If Not docIcon Is Nothing Then
               
        End Forall ' end forall strImgKey ...
       
        ' Ensure terminaing row has all cells filled in with empty cell content
        For iCount = iIConPerRowCount + 1 To 6
                strTmp = strDXLTemplateEmptyTableCell
                strTmp = Replace(strTmp, "$(PARID_COUNTER)",Cstr(iParCountPerDoc))
                iParCountPerDoc = iParCountPerDoc + 1
                Print #fout,strTmp
        Next
        Print #fout, |</tablerow>
                                </table>|
        strTmp = strDXLTemplateDocumentSuffix
        strTmp = Replace(strTmp, "$(PARID_COUNTER)",Cstr(iParCountPerDoc))
        Print #fout,strTmp
        Close fout        
        vRc =  ImportDXL(db, strDXLFileName)                

The code above does 4 primary things. It checks wthether or not we have filled in 13 icons per row or not. If it's time to start a new row, a new row template is grabbed and I start to fill in variables for the new row. Secondly I grab the tablecell-template and replace variables in that. Finally I get the existing encoded base64 data stored in the GalleryGIF24x24 field, an replace the $(BASE64) and $(IMGSIZE) variables with the actual content.  The last line in the code above import the programmatically generated DXL.

Above you have been presented more or less the complete code to generate Favorites-page with 24x24 icons based upon existing base64 data.

Comments

Gravatar Image1 - Hej, great serie!

Maybe I have overlooked but is the database available as a download?

kr, Patrick

Post A Comment

:-D:-o:-p:-x:-(:-):-\:angry::cool::cry::emb::grin::huh::laugh::lips::rolleyes:;-)