Skip to content

Commit e4f941e

Browse files
authored
Refactoring Datasource Loading (#26)
* Xojo 2024r4.2 * WebLabel: Fix Alignment * Refactor: Datasource loading
1 parent 63fb960 commit e4f941e

File tree

2 files changed

+41
-69
lines changed

2 files changed

+41
-69
lines changed

cubesql-webadmin.xojo_project

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Type=Web2
2-
RBProjectVersion=2024.011
2+
RBProjectVersion=2024.042
33
MinIDEVersion=20200200
44
OrigIDEVersion=20240100
55
Folder=resources;resources;&h0000000035B107FF;&h0000000000000000;false
@@ -105,10 +105,11 @@ IncludePDB=False
105105
WinUIFramework=False
106106
IsWebProject=True
107107
WebDebugPort=8080
108+
WebLaunchBrowser=True
108109
WebLivePort=80
109110
WebSecurePort=443
110111
WebProtocol=1
111-
WebHTMLHeader=<style>\n.listboxDbHeaderAlignment th:nth-child(1)\x2C\n.listboxDbHeaderAlignment th:nth-child(3)\x2C\n.listboxDbHeaderAlignment th:nth-child(5) {\n text-align: center;\n}\n\n.listboxGroupsHeaderAlignment th:nth-child(2) {\n text-align: center;\n}\n\n.listboxUsersHeaderAlignment th:nth-child(2) {\n text-align: center;\n}\n\n.listboxClientsHeaderAlignment th:nth-child(1) {\n text-align: center;\n}\n\n.listboxSchedulesHeaderAlignment th:nth-child(3) {\n text-align: center;\n}\n\n.form-check-input {\n cursor:pointer;\n}\n\n.btn-light {\n --bs-btn-bg: #E5E5E8;\n}\n</style>
112+
WebHTMLHeader=<style>\n.listboxDbHeaderAlignment th:nth-child(1)\x2C\n.listboxDbHeaderAlignment th:nth-child(3)\x2C\n.listboxDbHeaderAlignment th:nth-child(5) {\n text-align: center;\n}\n\n.listboxGroupsHeaderAlignment th:nth-child(2) {\n text-align: center;\n}\n\n.listboxUsersHeaderAlignment th:nth-child(2) {\n text-align: center;\n}\n\n.listboxClientsHeaderAlignment th:nth-child(1) {\n text-align: center;\n}\n\n.listboxSchedulesHeaderAlignment th:nth-child(3) {\n text-align: center;\n}\n\n.form-check-input {\n cursor:pointer;\n}\n\n.btn-light {\n --bs-btn-bg: #E5E5E8;\n}\n\n/* Workaround for Xojo 2024r4 */\n.XojoLink {\n align-items: center;\n}\n</style>
112113
WebHostingIdentifier=
113114
WebHostingAppName=cubeSQLWebAdmin
114115
WebHostingDomain=

webapp/containers/base/cntDatasourceBase.xojo_code

Lines changed: 38 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,14 @@ Implements WebDataSource
6161
End Function
6262
#tag EndMethod
6363

64-
#tag Method, Flags = &h1
65-
Protected Sub LoadDatasource(rs As RowSet)
64+
#tag Method, Flags = &h21
65+
Private Sub LoadDatasource()
66+
If (Not ebNeedsLoadDatasource) Then Return
67+
68+
#Pragma DisableBackgroundTasks True
69+
70+
Var rs As RowSet = Me.TableLoadRowSet
71+
6672
Redim Me.TableRows(-1)
6773

6874
If (Me.Filters = Nil) Then Me.Filters = New Dictionary
@@ -151,6 +157,10 @@ Implements WebDataSource
151157

152158
Catch err As DatabaseException
153159

160+
Finally
161+
ebNeedsLoadDatasource = False
162+
163+
154164
End Try
155165
End Sub
156166
#tag EndMethod
@@ -159,6 +169,8 @@ Implements WebDataSource
159169
Private Function RowCount() As Integer
160170
// Part of the WebDataSource interface.
161171

172+
Me.LoadDatasource
173+
162174
Return Me.TableRows.Count
163175

164176
End Function
@@ -167,6 +179,8 @@ Implements WebDataSource
167179
#tag Method, Flags = &h21
168180
Private Function RowData(rowCount As Integer, rowOffset As Integer, sortColumns As String) As WebListboxRowData()
169181
// Part of the WebDataSource interface.
182+
Me.LoadDatasource
183+
170184
Var rows() As WebListboxRowData
171185
If (rowOffset < 0) Then Return rows
172186

@@ -249,54 +263,6 @@ Implements WebDataSource
249263
End Sub
250264
#tag EndMethod
251265

252-
#tag Method, Flags = &h21
253-
Private Function SortedPrimaryKeys(sortColumns As String) As Integer()
254-
// Part of the WebDataSource interface.
255-
256-
Var sortCol As String = sortColumns.NthField(" ", 1)
257-
Var bSortDesc As Boolean = sortColumns.NthField(" ", 2) = "desc"
258-
Var sortFieldType As DatasourceColumn.FieldTypes = DataSourceColumn.FieldTypes.Text
259-
For Each col As DatasourceColumn In Me.Columns
260-
If (col.DatabaseColumnName = sortCol) Then
261-
sortFieldType = col.FieldType
262-
Exit 'Loop
263-
End If
264-
Next
265-
266-
mSortColumname = sortCol
267-
mSortDesc = bSortDesc
268-
mSortFieldType = sortFieldType
269-
270-
Var keys() As Integer
271-
272-
For i As Integer = 0 To Me.TableRows.LastIndex
273-
keys.Add(i)
274-
Next
275-
276-
keys.Sort(AddressOf SortedPrimaryKeysDelegate)
277-
278-
'Primary Key is "id": 0-x
279-
280-
Var sortedPrimaryKeys() As Integer
281-
For i As Integer = 0 To keys.LastIndex
282-
sortedPrimaryKeys.Add(Me.TableRows(keys(i)).Lookup("id", -1).IntegerValue)
283-
Next
284-
285-
Return sortedPrimaryKeys
286-
287-
End Function
288-
#tag EndMethod
289-
290-
#tag Method, Flags = &h21
291-
Private Function SortedPrimaryKeysDelegate(index1 As Integer, index2 As Integer) As Integer
292-
Var row1 As Dictionary = Me.TableRows(index1)
293-
Var row2 As Dictionary = Me.TableRows(index2)
294-
295-
Return SortedTableRowsDelegate(row1, row2)
296-
297-
End Function
298-
#tag EndMethod
299-
300266
#tag Method, Flags = &h21
301267
Private Function SortedTableRowsDelegate(row1 As Dictionary, row2 As Dictionary) As Integer
302268
Var desc As Integer = 1
@@ -383,9 +349,10 @@ Implements WebDataSource
383349
#tag Method, Flags = &h1
384350
Protected Sub TableLoad()
385351
Me.Table.NoRowsMessage = Me.TableNoRowsMessage()
352+
Me.Table.ProcessingMessage = me.TableProcessingMessage()
386353

387354
Me.TableLoadFilters
388-
Me.LoadDatasource(Me.TableLoadRowSet)
355+
ebNeedsLoadDatasource = true
389356

390357
If (Me.Table.DataSource = Nil) Then
391358
Me.Table.DataSource = Self
@@ -416,6 +383,14 @@ Implements WebDataSource
416383
End Function
417384
#tag EndMethod
418385

386+
#tag Method, Flags = &h1
387+
Protected Function TableProcessingMessage() As String
388+
If (Me.Title.Trim <> "") Then Return "Loading " + Me.Title.Trim + "..."
389+
Return "Loading..."
390+
391+
End Function
392+
#tag EndMethod
393+
419394
#tag Method, Flags = &h1
420395
Protected Function TableRowColumnData(col As DatasourceColumn, row As Dictionary) As Variant
421396
Select Case col.FieldType
@@ -469,22 +444,6 @@ Implements WebDataSource
469444
End Function
470445
#tag EndMethod
471446

472-
#tag Method, Flags = &h21
473-
Private Function UnsortedPrimaryKeys() As Integer()
474-
// Part of the WebDataSource interface.
475-
476-
'Primary Key is "id": 0-x
477-
Var keys() As Integer
478-
479-
For i As Integer = 0 To Me.TableRows.LastIndex
480-
keys.Add(Me.TableRows(i).Lookup("id", -1).IntegerValue)
481-
Next
482-
483-
Return keys
484-
485-
End Function
486-
#tag EndMethod
487-
488447
#tag Method, Flags = &h21
489448
Private Sub WebTimer_RowDataLoaded(obj As WebTimer)
490449
obj.RunMode = WebTimer.RunModes.Off
@@ -500,6 +459,10 @@ Implements WebDataSource
500459
Protected Columns() As DatasourceColumn
501460
#tag EndProperty
502461

462+
#tag Property, Flags = &h21
463+
Private ebNeedsLoadDatasource As Boolean
464+
#tag EndProperty
465+
503466
#tag Property, Flags = &h1
504467
Protected Filters As Dictionary
505468
#tag EndProperty
@@ -534,6 +497,14 @@ Implements WebDataSource
534497

535498

536499
#tag ViewBehavior
500+
#tag ViewProperty
501+
Name="PanelIndex"
502+
Visible=false
503+
Group="Behavior"
504+
InitialValue=""
505+
Type="Integer"
506+
EditorType=""
507+
#tag EndViewProperty
537508
#tag ViewProperty
538509
Name="Area"
539510
Visible=false

0 commit comments

Comments
 (0)