Zooflow: Custom Searches

This commit is contained in:
Jonathan Jenne
2022-06-08 16:31:34 +02:00
parent bd136bf6be
commit d5b9cae282
22 changed files with 1024 additions and 283 deletions

View File

@@ -7,6 +7,7 @@ Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Views.Tile
Imports DevExpress.XtraSplashScreen
Imports DigitalData.GUIs.ZooFlow.ClassConstants
Imports DigitalData.GUIs.ZooFlow.SavedSearch
Imports DigitalData.GUIs.ZooFlow.Search
Imports DigitalData.GUIs.ZooFlow.Search.SearchToken
Imports DigitalData.Modules.Language
@@ -21,24 +22,23 @@ Public Class frmSearchFlow
Private TokenTable As DataTable = Nothing
Private FormLoading As Boolean = True
Private TokenListDefault As New Dictionary(Of String, Object)
Private TokenListOperands As New Dictionary(Of String, Object)
Private TokenListAttrValues As New Dictionary(Of String, Object)
Private ReadOnly TokenListDefault As New Dictionary(Of String, Object)
Private ReadOnly TokenListOperands As New Dictionary(Of String, Object)
Private ReadOnly TokenListAttrValues As New Dictionary(Of String, Object)
Private Sub frmFlowSearch2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
SearchLoader = New SearchLoader(My.LogConfig, My.UIConfigManager, SvgImageCollection1)
SearchLoader = New SearchLoader(My.LogConfig, My.SystemConfigManager, SvgImageCollection1)
SearchRunner = New SearchRunner(My.LogConfig, My.Application.GetEnvironment, "FlowSearch") With {
.BaseSearchSQL = SQL_FLOW_SEARCH_BASE
}
AddHandler SearchRunner.NeedsNewSavedSearch, AddressOf SearchRunner_NewSavedSearch
TokenTable = GetTokenTable()
ComboBoxDateAttributes.Properties.Items.AddRange(LoadDateAttributes())
ComboBoxDateAttributes.SelectedIndex = 0
Dim oSearchBindingList As New BindingSource() With {
.DataSource = SearchLoader.LoadSearches()
}
GridSearches.DataSource = oSearchBindingList
GridSearches.DataSource = SearchLoader.LoadSearches()
Dim oTokens = GetTokensFromTable(Of AttributeValueToken)(TokenTable)
AddTokens(txtSearchInput, oTokens)
@@ -46,6 +46,16 @@ Public Class frmSearchFlow
ViewSearches.FocusedRowHandle = GridControl.InvalidRowHandle
FormLoading = False
End Sub
Private Sub SearchRunner_NewSavedSearch(sender As Object, e As EventArgs)
Dim oForm As New frmEditSearch With {.IsNew = True}
If oForm.ShowDialog() = DialogResult.OK Then
SearchLoader.CreateCustomSearch(oForm.Title, oForm.Description, New List(Of Token), oForm.ImageString)
GridSearches.DataSource = SearchLoader.LoadSearches()
End If
End Sub
Public Function GetTokenTable() As DataTable
@@ -55,54 +65,62 @@ Public Class frmSearchFlow
End Function
Public Function GetTokensFromTable(Of T As {New, Token})(pTable As DataTable) As List(Of T)
Dim oTokens As New List(Of T)
Dim oTermValueBlackList As New List(Of String) From {"", " "}
Try
Dim oTokens As New List(Of T)
Dim oTermValueBlackList As New List(Of String) From {"", " "}
For Each oRow As DataRow In pTable.Rows
Dim oTermValue = oRow.Item("TERM")
Dim oTermId = oRow.ItemEx("TERM_ID", 0)
Dim oAttributeTitle = oRow.Item("ATTR_TITLE")
Dim oAttributeId = oRow.ItemEx("ATTR_ID", 0)
For Each oRow As DataRow In pTable.Rows
Dim oTermValue = oRow.Item("TERM")
Dim oTermId = oRow.ItemEx("TERM_ID", 0)
Dim oAttributeTitle = oRow.Item("ATTR_TITLE")
Dim oAttributeId = oRow.ItemEx("ATTR_ID", 0)
If oTermValueBlackList.Contains(oTermValue) Then
Continue For
End If
If oTermValueBlackList.Contains(oTermValue) Then
Continue For
End If
oTokens.Add(New T() With {
.AttributeId = oAttributeId,
.AttributeTitle = oAttributeTitle,
.TermId = oTermId,
.TermValue = oTermValue
})
Next
oTokens.Add(New T() With {
.AttributeId = oAttributeId,
.AttributeTitle = oAttributeTitle,
.TermId = oTermId,
.TermValue = oTermValue
})
Next
Return oTokens.
OrderBy(Function(token) token.TermValue).
Distinct().
ToList()
Return oTokens.
OrderBy(Function(token) token.TermValue).
Distinct().
ToList()
Catch ex As Exception
Logger.error(ex)
Return New List(Of T)
End Try
End Function
Private Function LoadDateAttributes() As List(Of String)
Dim oAttributes = My.Tables.DTIDB_ATTRIBUTE.
AsEnumerable().
Where(Function(row) CBool(row.Item("SYS_ATTRIBUTE")) = False).
Where(Function(row) row.Item("TYP_ID") = 5 Or row.Item("TYP_ID") = 6).
Select(Function(row) row.Item("ATTR_TITLE")).
Cast(Of String).
ToList()
Try
Dim oAttributes = My.Tables.DTIDB_ATTRIBUTE.
AsEnumerable().
Where(Function(row) CBool(row.Item("SYS_ATTRIBUTE")) = False).
Where(Function(row) row.Item("TYP_ID") = 5 Or row.Item("TYP_ID") = 6).
Select(Function(row) row.Item("ATTR_TITLE")).
Cast(Of String).
ToList()
If My.Application.User.Language = "de-DE" Then
oAttributes.Add(IDB_ADDED_WHEN_String_German)
Else
oAttributes.Add(IDB_ADDED_WHEN_String_Englisch)
End If
If My.Application.User.Language = "de-DE" Then
oAttributes.Add(IDB_ADDED_WHEN_String_German)
Else
oAttributes.Add(IDB_ADDED_WHEN_String_Englisch)
End If
Return oAttributes
Return oAttributes
Catch ex As Exception
Logger.error(ex)
Return New List(Of String)
End Try
End Function
Private Function GetTokens() As IEnumerable(Of Token)
Dim oTokens = txtSearchInput.GetTokenList()
Return oTokens.Select(Of Token)(Function(token) token.Value).ToList()
@@ -115,7 +133,14 @@ Public Class frmSearchFlow
End Sub
Private Async Sub TileView1_ItemClick(sender As Object, e As TileViewItemClickEventArgs) Handles ViewSearches.ItemClick
Await RunSearch2(GetTokens())
Dim oSearch = ViewSearches.GetRow(ViewSearches.FocusedRowHandle)
If TypeOf oSearch Is CustomSearch Then
Dim oCustomSearch As CustomSearch = oSearch
Await RunSearch2(oCustomSearch.Tokens)
Else
Await RunSearch2(GetTokens())
End If
End Sub
Private Async Sub BarButtonItem1_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem1.ItemClick
@@ -129,8 +154,8 @@ Public Class frmSearchFlow
Try
' If the user clicked on a Search Tile, it will set the date constraint for this search
Dim oSearch = ViewSearches.GetRow(ViewSearches.FocusedRowHandle)
If oSearch IsNot Nothing AndAlso TypeOf oSearch Is SearchLoader.PredefinedDateSearch Then
Dim oDateSearch As SearchLoader.PredefinedDateSearch = oSearch
If oSearch IsNot Nothing AndAlso TypeOf oSearch Is SavedSearch.PredefinedDateSearch Then
Dim oDateSearch As SavedSearch.PredefinedDateSearch = oSearch
oSearchTitle = oDateSearch.DisplayName
SearchRunner.SetDateConstraint(oDateSearch.DateConstraint)
Else
@@ -185,8 +210,6 @@ Public Class frmSearchFlow
End Try
End Function
Private Function StartUpdateUI() As IOverlaySplashScreenHandle
SetStatusBarColor(Color.FromArgb(255, 240, 240, 240), Color.Black)
Dim oHandle = SplashScreenManager.ShowOverlayForm(LayoutControl1)
@@ -269,10 +292,6 @@ Public Class frmSearchFlow
End If
End Sub
Private Sub BarToggleSwitchItem2_CheckedChanged(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs)
End Sub
Private Sub BarCheckItem3_CheckedChanged(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles chkDatefilter2.CheckedChanged
If chkDatefilter2.Checked Then
LayoutControlGroupDate2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always
@@ -325,19 +344,19 @@ Public Class frmSearchFlow
FormLoading = False
End Sub
Private Sub TileView1_CustomItemTemplate(sender As Object, e As TileViewCustomItemTemplateEventArgs) Handles ViewSearches.CustomItemTemplate
Dim oSearch = ViewSearches.GetRow(e.RowHandle)
'If TypeOf oSearch Is PredefinedDateSearch Then
' e.Template = e.Templates.Item("DefaultSmall")
'Else
' e.Template = e.Templates.Item("Default")
'End If
e.Template = e.Templates.Item("Default")
Private Sub chkGridVertical_CheckedChanged(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles chkGridVertical.CheckedChanged
ViewSearches.OptionsTiles.Orientation = Orientation.Vertical
End Sub
Private Sub btnSaveSearch_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnSaveSearch.ItemClick
SearchLoader.CreateCustomSearch("TestSearch", "Some Stuff", GetTokens(), "invoice")
GridSearches.DataSource = SearchLoader.LoadSearches()
Private Sub chkGridHorizontal_CheckedChanged(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles chkGridHorizontal.CheckedChanged
ViewSearches.OptionsTiles.Orientation = Orientation.Horizontal
End Sub
Private Sub BarEditItem1_EditValueChanged(sender As Object, e As EventArgs) Handles BarEditItem1.EditValueChanged
ViewSearches.OptionsTiles.ColumnCount = BarEditItem1.EditValue
End Sub
Private Sub BarEditItem2_EditValueChanged(sender As Object, e As EventArgs) Handles BarEditItem2.EditValueChanged
ViewSearches.OptionsTiles.RowCount = BarEditItem2.EditValue
End Sub
End Class