Add selection to search menu

This commit is contained in:
eikek 2022-02-27 19:47:16 +01:00
parent 63e0258db7
commit adcfe10460
9 changed files with 280 additions and 99 deletions

View File

@ -19,6 +19,7 @@ module Comp.SearchMenu exposing
, linkTargetMsg
, refreshBookmarks
, setFromStats
, setIncludeSelection
, textSearchString
, update
, updateDrop
@ -52,6 +53,7 @@ import Data.EquipmentOrder
import Data.EquipmentUse
import Data.Fields
import Data.Flags exposing (Flags)
import Data.ItemIds exposing (ItemIdChange, ItemIds)
import Data.ItemQuery as Q exposing (ItemQuery)
import Data.PersonOrder
import Data.PersonUse
@ -102,6 +104,7 @@ type alias Model =
, sourceModel : Maybe String
, allBookmarks : Comp.BookmarkChooser.Model
, selectedBookmarks : Comp.BookmarkChooser.Selection
, includeSelection : Bool
, openTabs : Set String
, searchMode : SearchMode
}
@ -149,6 +152,7 @@ init flags =
, sourceModel = Nothing
, allBookmarks = Comp.BookmarkChooser.init Data.Bookmarks.empty
, selectedBookmarks = Comp.BookmarkChooser.emptySelection
, includeSelection = False
, openTabs = Set.fromList [ "Tags", "Inbox" ]
, searchMode = Data.SearchMode.Normal
}
@ -222,8 +226,8 @@ isNamesSearch model =
True
getItemQuery : Model -> Maybe ItemQuery
getItemQuery model =
getItemQuery : ItemIds -> Model -> Maybe ItemQuery
getItemQuery selectedItems model =
let
when flag body =
if flag then
@ -258,6 +262,11 @@ getItemQuery model =
in
Q.and
[ when model.inboxCheckbox (Q.Inbox True)
, if model.includeSelection then
Data.ItemIds.toQuery selectedItems
else
Nothing
, whenNotEmpty (model.tagSelection.includeTags |> Set.toList)
(Q.TagIds Q.AllMatch)
, whenNotEmpty (model.tagSelection.excludeTags |> Set.toList)
@ -347,6 +356,7 @@ resetModel model =
, customValues = Data.CustomFieldChange.emptyCollect
, sourceModel = Nothing
, selectedBookmarks = Comp.BookmarkChooser.emptySelection
, includeSelection = False
, searchMode = Data.SearchMode.Normal
}
@ -397,6 +407,8 @@ type Msg
| ToggleOpenAllAkkordionTabs
| AllBookmarksResp (Result Http.Error AllBookmarks)
| SelectBookmarkMsg Comp.BookmarkChooser.Msg
| SetIncludeSelection Bool
| ClearSelection
setFromStats : SearchStats -> Msg
@ -409,6 +421,11 @@ initFromStats stats =
GetAllTagsResp (Ok stats)
setIncludeSelection : Bool -> Msg
setIncludeSelection flag =
SetIncludeSelection flag
linkTargetMsg : LinkTarget -> Maybe Msg
linkTargetMsg linkTarget =
case linkTarget of
@ -449,6 +466,7 @@ type alias NextState =
, sub : Sub Msg
, stateChange : Bool
, dragDrop : DD.DragDropData
, selectionChange : ItemIdChange
}
@ -483,6 +501,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = True
, dragDrop = set.dragDrop
, selectionChange = Data.ItemIds.noChange
}
in
case msg of
@ -525,6 +544,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = False
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
ResetForm ->
@ -533,6 +553,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = True
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
SetCorrOrg id ->
@ -555,6 +576,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = False
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
SetConcEquip id ->
@ -586,6 +608,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = sel /= model.selectedBookmarks
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
GetAllTagsResp (Ok stats) ->
@ -600,6 +623,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = False
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
GetAllTagsResp (Err _) ->
@ -608,6 +632,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = False
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
GetStatsResp (Ok stats) ->
@ -676,6 +701,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = False
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
GetStatsResp (Err _) ->
@ -684,6 +710,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = False
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
GetEquipResp (Ok equips) ->
@ -699,6 +726,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = False
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
GetOrgResp (Ok orgs) ->
@ -714,6 +742,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = False
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
GetPersonResp (Ok ps) ->
@ -749,6 +778,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = False
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
TagSelectMsg m ->
@ -765,6 +795,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = sel /= model.tagSelection
, dragDrop = ddd
, selectionChange = Data.ItemIds.noChange
}
DirectionMsg m ->
@ -777,6 +808,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = isDropdownChangeMsg m
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
OrgMsg m ->
@ -789,6 +821,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = isDropdownChangeMsg m
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
CorrPersonMsg m ->
@ -801,6 +834,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = isDropdownChangeMsg m
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
ConcPersonMsg m ->
@ -813,6 +847,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = isDropdownChangeMsg m
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
ConcEquipmentMsg m ->
@ -825,6 +860,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = isDropdownChangeMsg m
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
ToggleInbox ->
@ -837,6 +873,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = True
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
ToggleSearchMode ->
@ -856,6 +893,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = True
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
FromDateMsg m ->
@ -876,6 +914,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = model.fromDate /= nextDate
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
UntilDateMsg m ->
@ -896,6 +935,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = model.untilDate /= nextDate
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
FromDueDateMsg m ->
@ -916,6 +956,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = model.fromDueDate /= nextDate
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
UntilDueDateMsg m ->
@ -936,6 +977,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = model.untilDueDate /= nextDate
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
SetName str ->
@ -948,6 +990,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = False
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
SetTextSearch str ->
@ -956,6 +999,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = False
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
SwapTextSearch ->
@ -965,6 +1009,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = False
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
else
@ -973,6 +1018,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = False
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
SetFulltextSearch ->
@ -983,6 +1029,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = False
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
Names s ->
@ -991,6 +1038,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = False
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
SetNamesSearch ->
@ -1001,6 +1049,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = False
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
Names _ ->
@ -1009,6 +1058,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = False
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
KeyUpMsg (Just Enter) ->
@ -1017,6 +1067,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = True
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
KeyUpMsg _ ->
@ -1025,6 +1076,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = False
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
FolderSelectMsg lm ->
@ -1041,6 +1093,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = model.selectedFolder /= sel
, dragDrop = ddd
, selectionChange = Data.ItemIds.noChange
}
CustomFieldMsg lm ->
@ -1058,6 +1111,7 @@ updateDrop ddm flags settings msg model =
, stateChange =
Data.CustomFieldChange.isValueChange res.result
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
SetCustomField cv ->
@ -1086,6 +1140,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = False
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
ResetToSource str ->
@ -1105,6 +1160,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = False
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
ToggleOpenAllAkkordionTabs ->
@ -1125,6 +1181,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = False
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
AllBookmarksResp (Ok bm) ->
@ -1133,6 +1190,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = model.allBookmarks /= Comp.BookmarkChooser.init bm
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
AllBookmarksResp (Err _) ->
@ -1141,6 +1199,7 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = False
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
SelectBookmarkMsg lm ->
@ -1153,6 +1212,26 @@ updateDrop ddm flags settings msg model =
, sub = Sub.none
, stateChange = sel /= model.selectedBookmarks || model.allBookmarks /= next
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
SetIncludeSelection flag ->
{ model =
{ model | includeSelection = flag }
, cmd = Cmd.none
, sub = Sub.none
, stateChange = True
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.noChange
}
ClearSelection ->
{ model = { model | includeSelection = False }
, cmd = Cmd.none
, sub = Sub.none
, stateChange = True
, dragDrop = DD.DragDropData ddm Nothing
, selectionChange = Data.ItemIds.clearAll
}
@ -1162,6 +1241,7 @@ updateDrop ddm flags settings msg model =
type alias ViewConfig =
{ overrideTabLook : SearchTab -> Comp.Tabs.Look -> Comp.Tabs.Look
, selectedItems : ItemIds
}
@ -1174,7 +1254,7 @@ viewDrop2 texts ddd flags cfg settings model =
Comp.Tabs.akkordion
akkordionStyle
(searchTabState settings cfg model)
(searchTabs texts ddd flags settings model)
(searchTabs texts ddd flags settings cfg.selectedItems model)
type SearchTab
@ -1191,6 +1271,7 @@ type SearchTab
| TabSource
| TabDirection
| TabTrashed
| TabSelection
allTabs : List SearchTab
@ -1208,6 +1289,7 @@ allTabs =
, TabSource
, TabDirection
, TabTrashed
, TabSelection
]
@ -1253,6 +1335,9 @@ tabName tab =
TabTrashed ->
"trashed"
TabSelection ->
"selection"
findTab : Comp.Tabs.Tab msg -> Maybe SearchTab
findTab tab =
@ -1296,12 +1381,15 @@ findTab tab =
"trashed" ->
Just TabTrashed
"selection" ->
Just TabSelection
_ ->
Nothing
tabLook : UiSettings -> Model -> SearchTab -> Comp.Tabs.Look
tabLook settings model tab =
tabLook : UiSettings -> ItemIds -> Model -> SearchTab -> Comp.Tabs.Look
tabLook settings selectedItems model tab =
let
isHidden f =
Data.UiSettings.fieldHidden settings f
@ -1396,6 +1484,16 @@ tabLook settings model tab =
TabTrashed ->
activeWhen (model.searchMode == Data.SearchMode.Trashed)
TabSelection ->
if Data.ItemIds.isEmpty selectedItems then
Comp.Tabs.Hidden
else if model.includeSelection then
Comp.Tabs.Active
else
Comp.Tabs.Normal
_ ->
Comp.Tabs.Normal
@ -1416,15 +1514,15 @@ searchTabState settings cfg model tab =
state =
{ folded = folded
, look =
Maybe.map (\t -> tabLook settings model t |> cfg.overrideTabLook t) searchTab
Maybe.map (\t -> tabLook settings cfg.selectedItems model t |> cfg.overrideTabLook t) searchTab
|> Maybe.withDefault Comp.Tabs.Normal
}
in
( state, ToggleAkkordionTab tab.name )
searchTabs : Texts -> DD.DragDropData -> Flags -> UiSettings -> Model -> List (Comp.Tabs.Tab Msg)
searchTabs texts ddd flags settings model =
searchTabs : Texts -> DD.DragDropData -> Flags -> UiSettings -> ItemIds -> Model -> List (Comp.Tabs.Tab Msg)
searchTabs texts ddd flags settings selectedItems model =
let
isHidden f =
Data.UiSettings.fieldHidden settings f
@ -1477,6 +1575,40 @@ searchTabs texts ddd flags settings model =
(Comp.BookmarkChooser.view texts.bookmarkChooser model.allBookmarks model.selectedBookmarks)
]
}
, { name = tabName TabSelection
, title = texts.selection
, titleRight =
[ span [ class "flex items-center rounded-full bg-blue-100 dark:bg-sky-600 text-xs px-2 py-0.5 " ]
[ text (String.fromInt (Data.ItemIds.size selectedItems)) ]
]
, info = Nothing
, body =
[ div [ class "flex flex-col ml-1" ]
[ a
[ class "flex flex-row items-center"
, class "rounded px-1 py-1 hover:bg-blue-100 dark:hover:bg-slate-600"
, href "#"
, Html.Events.onClick (SetIncludeSelection (not model.includeSelection))
]
[ if model.includeSelection then
i [ class "fa fa-check mr-2" ] []
else
i [ class "fa fa-list mr-2" ] []
, text "Show selection"
]
, a
[ class "flex flex-row items-center"
, class "rounded px-1 py-1 hover:bg-blue-100 dark:hover:bg-slate-600"
, href "#"
, Html.Events.onClick ClearSelection
]
[ i [ class "fa fa-times mr-2" ] []
, text "Clear selection"
]
]
]
}
, { name = tabName TabTags
, title = texts.basics.tags
, titleRight = []

View File

@ -9,6 +9,7 @@ module Data.ItemIds exposing
( ItemIdChange
, ItemIds
, apply
, clearAll
, combine
, combineAll
, deselect
@ -17,6 +18,7 @@ module Data.ItemIds exposing
, isEmpty
, isMember
, noChange
, nonEmpty
, select
, selectAll
, size
@ -44,6 +46,11 @@ isEmpty (ItemIds ids) =
Set.isEmpty ids
nonEmpty : ItemIds -> Bool
nonEmpty ids =
not (isEmpty ids)
isMember : ItemIds -> String -> Bool
isMember (ItemIds ids) id =
Set.member id ids
@ -69,9 +76,13 @@ toList (ItemIds ids) =
Set.toList ids
toQuery : ItemIds -> ItemQuery
toQuery : ItemIds -> Maybe ItemQuery
toQuery (ItemIds ids) =
Data.ItemQuery.ItemIdIn (Set.toList ids)
if Set.isEmpty ids then
Nothing
else
Just <| Data.ItemQuery.ItemIdIn (Set.toList ids)
@ -82,17 +93,22 @@ type ItemIdChange
= ItemIdChange
{ remove : Set String
, add : Set String
, clear : Bool
}
apply : ItemIds -> ItemIdChange -> ItemIds
apply (ItemIds ids) (ItemIdChange { remove, add }) =
ItemIds (Set.diff ids remove |> Set.union add)
apply (ItemIds ids) (ItemIdChange { remove, add, clear }) =
if clear then
empty
else
ItemIds (Set.diff ids remove |> Set.union add)
noChange : ItemIdChange
noChange =
ItemIdChange { remove = Set.empty, add = Set.empty }
ItemIdChange { remove = Set.empty, add = Set.empty, clear = False }
combine : ItemIdChange -> ItemIdChange -> ItemIdChange
@ -100,6 +116,7 @@ combine (ItemIdChange c1) (ItemIdChange c2) =
ItemIdChange
{ remove = Set.union c1.remove c2.remove
, add = Set.union c1.add c2.add
, clear = False
}
@ -110,17 +127,22 @@ combineAll all =
select : String -> ItemIdChange
select id =
ItemIdChange { add = Set.singleton id, remove = Set.empty }
ItemIdChange { add = Set.singleton id, remove = Set.empty, clear = False }
selectAll : Set String -> ItemIdChange
selectAll ids =
ItemIdChange { add = ids, remove = Set.empty }
ItemIdChange { add = ids, remove = Set.empty, clear = False }
deselect : String -> ItemIdChange
deselect id =
ItemIdChange { add = Set.empty, remove = Set.singleton id }
ItemIdChange { add = Set.empty, remove = Set.singleton id, clear = False }
clearAll : ItemIdChange
clearAll =
ItemIdChange { add = Set.empty, remove = Set.empty, clear = True }
toggle : ItemIds -> String -> ItemIdChange

View File

@ -50,6 +50,7 @@ type alias Texts =
, direction : Direction -> String
, trashcan : String
, bookmarks : String
, selection : String
}
@ -84,6 +85,7 @@ gb =
, direction = Messages.Data.Direction.gb
, trashcan = "Trash"
, bookmarks = "Bookmarks"
, selection = "Selection"
}
@ -118,4 +120,5 @@ de =
, direction = Messages.Data.Direction.de
, trashcan = "Papierkorb"
, bookmarks = "Bookmarks"
, selection = "Auswahl"
}

View File

@ -42,6 +42,7 @@ import Comp.PublishItems
import Comp.SearchMenu
import Data.Flags exposing (Flags)
import Data.ItemArrange exposing (ItemArrange)
import Data.ItemIds exposing (ItemIds)
import Data.ItemNav exposing (ItemNav)
import Data.ItemQuery as Q
import Data.Items
@ -256,6 +257,7 @@ type alias SearchParam =
, pageSize : Int
, offset : Int
, scroll : Bool
, selectedItems : ItemIds
}
@ -274,7 +276,7 @@ doSearchDefaultCmd param model =
let
smask =
Q.request model.searchMenuModel.searchMode <|
createQuery model
createQuery param.selectedItems model
mask =
{ smask
@ -292,10 +294,10 @@ doSearchDefaultCmd param model =
Api.itemSearch param.flags mask ItemSearchAddResp
createQuery : Model -> Maybe Q.ItemQuery
createQuery model =
createQuery : ItemIds -> Model -> Maybe Q.ItemQuery
createQuery selectedItems model =
Q.and
[ Comp.SearchMenu.getItemQuery model.searchMenuModel
[ Comp.SearchMenu.getItemQuery selectedItems model.searchMenuModel
, Maybe.map Q.Fragment (Comp.PowerSearchInput.getSearchString model.powerSearchInput)
]

View File

@ -11,6 +11,7 @@ import Comp.Basic as B
import Comp.ItemDetail.MultiEditMenu
import Comp.MenuBar as MB
import Comp.SearchMenu
import Data.Environment as Env
import Data.Flags exposing (Flags)
import Data.UiSettings exposing (UiSettings)
import Html exposing (..)
@ -22,8 +23,8 @@ import Set
import Styles as S
view : Texts -> Flags -> UiSettings -> Model -> Html Msg
view texts flags settings model =
view : Texts -> Env.View -> Model -> Html Msg
view texts env model =
div
[ class "flex flex-col"
]
@ -56,19 +57,19 @@ view texts flags settings model =
SelectView svm ->
case svm.action of
EditSelected ->
viewEditMenu texts flags svm settings
viewEditMenu texts env.flags svm env.settings
_ ->
viewSearch texts flags settings model
viewSearch texts env model
_ ->
viewSearch texts flags settings model
viewSearch texts env model
)
]
viewSearch : Texts -> Flags -> UiSettings -> Model -> List (Html Msg)
viewSearch texts flags settings model =
viewSearch : Texts -> Env.View -> Model -> List (Html Msg)
viewSearch texts env model =
[ MB.viewSide
{ start =
[ MB.CustomElement <|
@ -87,14 +88,15 @@ viewSearch texts flags settings model =
, let
searchMenuCfg =
{ overrideTabLook = \_ -> identity
, selectedItems = env.selectedItems
}
in
Html.map SearchMenuMsg
(Comp.SearchMenu.viewDrop2 texts.searchMenu
model.dragDropData
flags
env.flags
searchMenuCfg
settings
env.settings
model.searchMenuModel
)
]

View File

@ -29,7 +29,6 @@ import Data.ItemIds exposing (ItemIds)
import Data.ItemQuery as Q
import Data.Items
import Data.SearchMode exposing (SearchMode)
import Data.UiSettings exposing (UiSettings)
import Messages.Page.Search exposing (Texts)
import Page exposing (Page(..))
import Page.Search.Data exposing (..)
@ -62,6 +61,7 @@ update texts env msg model =
, pageSize = env.settings.itemSearchPageSize
, offset = 0
, scroll = True
, selectedItems = env.selectedItems
}
setBookmark =
@ -111,9 +111,21 @@ update texts env msg model =
BasicSearch
}
newSelection =
Data.ItemIds.apply env.selectedItems nextState.selectionChange
searchParam =
{ flags = env.flags
, searchType = BasicSearch
, pageSize = env.settings.itemSearchPageSize
, offset = 0
, scroll = False
, selectedItems = newSelection
}
result =
if nextState.stateChange && not model.searchInProgress then
doSearch env (SearchParam env.flags BasicSearch env.settings.itemSearchPageSize 0 False) newModel
doSearch env searchParam newModel
else
resultModelCmd env ( newModel, Cmd.none )
@ -126,6 +138,7 @@ update texts env msg model =
, dropCmd
]
, sub = Sub.map SearchMenuMsg nextState.sub
, selectedItems = newSelection
}
SetLinkTarget lt ->
@ -251,6 +264,7 @@ update texts env msg model =
, pageSize = env.settings.itemSearchPageSize
, offset = 0
, scroll = False
, selectedItems = env.selectedItems
}
in
if model.searchInProgress then
@ -267,6 +281,7 @@ update texts env msg model =
, pageSize = env.settings.itemSearchPageSize
, offset = model.searchOffset
, scroll = False
, selectedItems = env.selectedItems
}
in
if model.searchInProgress then
@ -292,7 +307,7 @@ update texts env msg model =
LoadMore ->
if model.moreAvailable then
doSearchMore env.flags env.settings model |> resultModelCmd env
doSearchMore env model |> resultModelCmd env
else
resultModelCmd env ( model, Cmd.none )
@ -344,7 +359,7 @@ update texts env msg model =
SelectNoItems ->
let
result =
resultModelCmd env ( model, Cmd.none )
update texts env (SearchMenuMsg <| Comp.SearchMenu.setIncludeSelection False) model
in
{ result | selectedItems = Data.ItemIds.empty }
@ -404,6 +419,7 @@ update texts env msg model =
, pageSize = env.settings.itemSearchPageSize
, offset = 0
, scroll = False
, selectedItems = env.selectedItems
}
in
doSearch env param nm
@ -559,28 +575,27 @@ update texts env msg model =
, Cmd.none
)
else if Data.ItemIds.isEmpty env.selectedItems then
resultModelCmd env ( model, Cmd.none )
else
let
( mm, mc ) =
Comp.ItemMerge.initQuery
env.flags
model.searchMenuModel.searchMode
(Data.ItemIds.toQuery env.selectedItems)
in
resultModelCmd env
( { model
| viewMode =
SelectView
{ svm
| action = MergeSelected
, mergeModel = mm
}
}
, Cmd.map MergeItemsMsg mc
)
case Data.ItemIds.toQuery env.selectedItems of
Just q ->
let
( mm, mc ) =
Comp.ItemMerge.initQuery env.flags model.searchMenuModel.searchMode q
in
resultModelCmd env
( { model
| viewMode =
SelectView
{ svm
| action = MergeSelected
, mergeModel = mm
}
}
, Cmd.map MergeItemsMsg mc
)
Nothing ->
resultModelCmd env ( model, Cmd.none )
_ ->
resultModelCmd env ( model, Cmd.none )
@ -641,26 +656,27 @@ update texts env msg model =
, Cmd.map PublishItemsMsg mc
)
else if Data.ItemIds.isEmpty env.selectedItems then
resultModelCmd env ( model, Cmd.none )
else
let
( mm, mc ) =
Comp.PublishItems.initQuery env.flags
(Data.ItemIds.toQuery env.selectedItems)
in
resultModelCmd env
( { model
| viewMode =
SelectView
{ svm
| action = PublishSelected
, publishModel = mm
}
}
, Cmd.map PublishItemsMsg mc
)
case Data.ItemIds.toQuery env.selectedItems of
Just q ->
let
( mm, mc ) =
Comp.PublishItems.initQuery env.flags q
in
resultModelCmd env
( { model
| viewMode =
SelectView
{ svm
| action = PublishSelected
, publishModel = mm
}
}
, Cmd.map PublishItemsMsg mc
)
Nothing ->
resultModelCmd env ( model, Cmd.none )
_ ->
resultModelCmd env ( model, Cmd.none )
@ -854,7 +870,7 @@ update texts env msg model =
update texts env (ItemCardListMsg (Comp.ItemCardList.RemoveItem id)) model
TogglePublishCurrentQueryView ->
case createQuery model of
case createQuery env.selectedItems model of
Just q ->
let
( pm, pc ) =
@ -866,7 +882,7 @@ update texts env msg model =
resultModelCmd env ( model, Cmd.none )
ToggleBookmarkCurrentQueryView ->
case createQuery model of
case createQuery env.selectedItems model of
Just q ->
case model.topWidgetModel of
BookmarkQuery _ ->
@ -1099,15 +1115,16 @@ linkTargetMsg linkTarget =
Maybe.map SearchMenuMsg (Comp.SearchMenu.linkTargetMsg linkTarget)
doSearchMore : Flags -> UiSettings -> Model -> ( Model, Cmd Msg )
doSearchMore flags settings model =
doSearchMore : Env.Update -> Model -> ( Model, Cmd Msg )
doSearchMore env model =
let
param =
{ flags = flags
{ flags = env.flags
, searchType = model.lastSearchType
, pageSize = settings.itemSearchPageSize
, pageSize = env.settings.itemSearchPageSize
, offset = model.searchOffset
, scroll = False
, selectedItems = env.selectedItems
}
cmd =

View File

@ -46,7 +46,7 @@ viewSidebar texts env model =
, class S.sidebarBg
, classList [ ( "hidden", not env.sidebarVisible ) ]
]
[ Page.Search.SideMenu.view texts.sideMenu env.flags env.settings model
[ Page.Search.SideMenu.view texts.sideMenu env model
]
@ -188,17 +188,17 @@ itemsBar : Texts -> Env.View -> Model -> List (Html Msg)
itemsBar texts env model =
case model.viewMode of
SearchView ->
[ defaultMenuBar texts env.flags env.settings model ]
[ defaultMenuBar texts env model ]
SelectView svm ->
[ editMenuBar texts model env.selectedItems svm ]
PublishView _ ->
[ defaultMenuBar texts env.flags env.settings model ]
[ defaultMenuBar texts env model ]
defaultMenuBar : Texts -> Flags -> UiSettings -> Model -> Html Msg
defaultMenuBar texts flags settings model =
defaultMenuBar : Texts -> Env.View -> Model -> Html Msg
defaultMenuBar texts env model =
let
btnStyle =
S.secondaryBasicButton ++ " text-sm"
@ -226,7 +226,7 @@ defaultMenuBar texts flags settings model =
|> Maybe.withDefault (value "")
, class (String.replace "rounded" "" S.textInput)
, class "py-2 text-sm"
, if flags.config.fullTextSearchEnabled then
, if env.flags.config.fullTextSearchEnabled then
class " border-r-0 rounded-l"
else
@ -237,7 +237,7 @@ defaultMenuBar texts flags settings model =
[ class S.secondaryBasicButtonPlain
, class "text-sm px-4 py-2 border rounded-r"
, classList
[ ( "hidden", not flags.config.fullTextSearchEnabled )
[ ( "hidden", not env.flags.config.fullTextSearchEnabled )
]
, href "#"
, onClick ToggleSearchType
@ -260,10 +260,10 @@ defaultMenuBar texts flags settings model =
]
isCardView =
settings.itemSearchArrange == Data.ItemArrange.Cards
env.settings.itemSearchArrange == Data.ItemArrange.Cards
isListView =
settings.itemSearchArrange == Data.ItemArrange.List
env.settings.itemSearchArrange == Data.ItemArrange.List
menuSep =
{ icon = i [] []
@ -276,7 +276,7 @@ defaultMenuBar texts flags settings model =
MB.view
{ start =
[ MB.CustomElement <|
if settings.powerSearchEnabled then
if env.settings.powerSearchEnabled then
powerSearchBar
else
@ -316,7 +316,7 @@ defaultMenuBar texts flags settings model =
, menuOpen = model.viewMenuOpen
, items =
[ { icon =
if settings.itemSearchShowGroups then
if env.settings.itemSearchShowGroups then
i [ class "fa fa-check-square font-thin" ] []
else
@ -370,16 +370,16 @@ defaultMenuBar texts flags settings model =
, menuSep
, { label = texts.shareResults
, icon = Icons.shareIcon ""
, disabled = createQuery model == Nothing
, disabled = createQuery env.selectedItems model == Nothing
, attrs =
[ title <|
if createQuery model == Nothing then
if createQuery env.selectedItems model == Nothing then
texts.nothingSelectedToShare
else
texts.publishCurrentQueryTitle
, href "#"
, if createQuery model == Nothing then
, if createQuery env.selectedItems model == Nothing then
class ""
else
@ -388,16 +388,16 @@ defaultMenuBar texts flags settings model =
}
, { label = texts.bookmarkQuery
, icon = i [ class "fa fa-bookmark" ] []
, disabled = createQuery model == Nothing
, disabled = createQuery env.selectedItems model == Nothing
, attrs =
[ title <|
if createQuery model == Nothing then
if createQuery env.selectedItems model == Nothing then
texts.nothingToBookmark
else
texts.bookmarkQuery
, href "#"
, if createQuery model == Nothing then
, if createQuery env.selectedItems model == Nothing then
class ""
else
@ -405,7 +405,7 @@ defaultMenuBar texts flags settings model =
]
}
, { label =
if settings.cardPreviewFullWidth then
if env.settings.cardPreviewFullWidth then
texts.fullHeightPreviewTitle
else
@ -417,7 +417,7 @@ defaultMenuBar texts flags settings model =
, onClick TogglePreviewFullWidth
, classList
[ ( "hidden sm:inline-block", False )
, ( "bg-gray-200 dark:bg-slate-600", settings.cardPreviewFullWidth )
, ( "bg-gray-200 dark:bg-slate-600", env.settings.cardPreviewFullWidth )
]
]
}

View File

@ -10,6 +10,7 @@ module Page.Share.Sidebar exposing (..)
import Comp.SearchMenu
import Comp.Tabs
import Data.Flags exposing (Flags)
import Data.ItemIds
import Html exposing (..)
import Html.Attributes exposing (..)
import Messages.Page.Share exposing (Texts)
@ -30,6 +31,7 @@ view texts flags model =
searchMenuCfg =
{ overrideTabLook = hideTrashTab
, selectedItems = Data.ItemIds.empty
}
in
div

View File

@ -14,6 +14,7 @@ import Comp.PowerSearchInput
import Comp.SearchMenu
import Comp.SharePasswordForm
import Data.Flags exposing (Flags)
import Data.ItemIds
import Data.ItemQuery as Q
import Data.SearchMode
import Data.UiSettings exposing (UiSettings)
@ -262,7 +263,7 @@ makeSearchCmd flags doInit model =
let
xq =
Q.and
[ Comp.SearchMenu.getItemQuery model.searchMenuModel
[ Comp.SearchMenu.getItemQuery Data.ItemIds.empty model.searchMenuModel
, Maybe.map Q.Fragment <|
case model.searchMode of
SearchBarNormal ->