Permalink for bookmark searches

This commit is contained in:
eikek 2022-01-26 21:21:36 +01:00
parent 631450cb16
commit cb3005211b
14 changed files with 114 additions and 81 deletions

View File

@ -209,7 +209,7 @@ type Msg
defaultPage : Flags -> Page
defaultPage _ =
SearchPage
DashboardPage
getUiLanguage : Model -> UiLanguage

View File

@ -323,11 +323,11 @@ updateWithSub msg model =
newModel =
{ model
| showNewItemsArrived = isProcessItem && model.page /= SearchPage
| showNewItemsArrived = isProcessItem && not (Page.isSearchPage model.page)
, jobsWaiting = max 0 (model.jobsWaiting - 1)
}
in
if model.page == SearchPage && isProcessItem then
if Page.isSearchPage model.page && isProcessItem then
updateSearch texts Page.Search.Data.RefreshView newModel
else
@ -375,7 +375,7 @@ updateDashboard : Messages -> Page.Dashboard.Data.Msg -> Model -> ( Model, Cmd M
updateDashboard texts lmsg model =
let
( dbm, dbc, dbs ) =
Page.Dashboard.Update.update texts.dashboard model.flags lmsg model.dashboardModel
Page.Dashboard.Update.update texts.dashboard model.key model.flags lmsg model.dashboardModel
in
( { model | dashboardModel = dbm }
, Cmd.map DashboardMsg dbc
@ -572,16 +572,16 @@ updateLogin lmsg model =
updateSearch : Messages -> Page.Search.Data.Msg -> Model -> ( Model, Cmd Msg, Sub Msg )
updateSearch texts lmsg model =
let
mid =
( mid, bmId ) =
case model.page of
SearchPage ->
Util.Maybe.fromString model.itemDetailModel.detail.item.id
SearchPage bId ->
( Util.Maybe.fromString model.itemDetailModel.detail.item.id, bId )
_ ->
Nothing
( Nothing, Nothing )
result =
Page.Search.Update.update mid model.key model.flags texts.search model.uiSettings lmsg model.searchModel
Page.Search.Update.update bmId mid model.key model.flags texts.search model.uiSettings lmsg model.searchModel
model_ =
{ model | searchModel = result.model }
@ -628,7 +628,7 @@ initPage model_ page =
Messages.get <| App.Data.getUiLanguage model
in
case page of
SearchPage ->
SearchPage _ ->
Util.Update.andThen2
[ updateSearch texts Page.Search.Data.Init
, updateQueue Page.Queue.Data.StopRefresh

View File

@ -78,7 +78,7 @@ topNavUser auth model =
[ class S.infoMessageBase
, class "my-2 px-1 py-1 rounded-lg inline-block hover:opacity-50"
, classList [ ( "hidden", not model.showNewItemsArrived ) ]
, Page.href SearchPage
, Page.href (SearchPage Nothing)
, onClick ToggleShowNewItemsArrived
]
[ i [ class "fa fa-exclamation-circle mr-1" ] []
@ -165,8 +165,8 @@ mainContent model =
DashboardPage ->
viewDashboard texts model
SearchPage ->
viewSearch texts model
SearchPage bmId ->
viewSearch texts bmId model
CollectiveSettingPage ->
viewCollectiveSettings texts model
@ -298,7 +298,7 @@ dataMenu texts _ model =
]
, div [ class "py-1" ] [ hr [ class S.border ] [] ]
, dataPageLink model
SearchPage
(SearchPage Nothing)
[]
[ Icons.searchIcon "w-6"
, span [ class "ml-1" ]
@ -541,8 +541,8 @@ viewShareDetail texts shareId itemId model =
]
viewSearch : Messages -> Model -> List (Html Msg)
viewSearch texts model =
viewSearch : Messages -> Maybe String -> Model -> List (Html Msg)
viewSearch texts bmId model =
[ Html.map SearchMsg
(Search.viewSidebar texts.search
model.sidebarVisible

View File

@ -42,10 +42,7 @@ import Comp.ItemDetail.Model
, UpdateResult
, ViewMode(..)
, initSelectViewModel
, initShowQrModel
, isEditNotes
, isShowQrAttach
, isShowQrItem
, resultModel
, resultModelCmd
, resultModelCmdSub
@ -741,7 +738,7 @@ update key flags inav settings msg model =
resultModelCmd ( model, Page.set key (ItemDetailPage id) )
Nothing ->
resultModelCmd ( model, Page.set key SearchPage )
resultModelCmd ( model, Page.set key (SearchPage Nothing) )
in
{ result_ | removedItem = Just removedId }

View File

@ -80,7 +80,7 @@ menuBar texts inav settings model =
[ MB.CustomElement <|
a
[ class S.secondaryBasicButton
, Page.href SearchPage
, Page.href (SearchPage Nothing)
, title texts.backToSearchResults
]
[ i [ class "fa fa-arrow-left" ] []

View File

@ -35,6 +35,7 @@ type LinkTarget
| LinkTag IdName
| LinkCustomField ItemFieldValue
| LinkSource String
| LinkBookmark String
| LinkNone

View File

@ -59,7 +59,7 @@ import Data.UiSettings exposing (UiSettings)
import DatePicker exposing (DatePicker)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (onClick, onInput)
import Html.Events exposing (onInput)
import Http
import Messages.Comp.SearchMenu exposing (Texts)
import Set exposing (Set)
@ -385,6 +385,7 @@ type Msg
| SetConcEquip IdName
| SetFolder IdName
| SetTag String
| SetBookmark String
| SetCustomField ItemFieldValue
| CustomFieldMsg Comp.CustomFieldMultiInput.Msg
| SetSource String
@ -432,6 +433,9 @@ linkTargetMsg linkTarget =
Comp.LinkTarget.LinkSource str ->
Just <| ResetToSource str
Comp.LinkTarget.LinkBookmark id ->
Just <| SetBookmark id
type alias NextState =
{ model : Model
@ -556,6 +560,22 @@ updateDrop ddm flags settings msg model =
SetTag id ->
resetAndSet (TagSelectMsg (Comp.TagSelect.toggleTag id))
SetBookmark id ->
let
nextModel =
resetModel model
sel =
{ bookmarks = Set.singleton id
, shares = Set.empty
}
in
{ model = { nextModel | selectedBookmarks = sel }
, cmd = Cmd.none
, stateChange = sel /= model.selectedBookmarks
, dragDrop = DD.DragDropData ddm Nothing
}
GetAllTagsResp (Ok stats) ->
let
tagSel =
@ -1064,7 +1084,7 @@ updateDrop ddm flags settings msg model =
AllBookmarksResp (Ok bm) ->
{ model = { model | allBookmarks = Comp.BookmarkChooser.init bm }
, cmd = Cmd.none
, stateChange = False
, stateChange = model.allBookmarks /= Comp.BookmarkChooser.init bm
, dragDrop = DD.DragDropData ddm Nothing
}
@ -1082,7 +1102,7 @@ updateDrop ddm flags settings msg model =
in
{ model = { model | allBookmarks = next, selectedBookmarks = sel }
, cmd = Cmd.none
, stateChange = sel /= model.selectedBookmarks
, stateChange = sel /= model.selectedBookmarks || model.allBookmarks /= next
, dragDrop = DD.DragDropData ddm Nothing
}

View File

@ -14,6 +14,7 @@ module Page exposing
, hasSidebar
, href
, isOpen
, isSearchPage
, isSecured
, loginPage
, loginPageReferrer
@ -51,7 +52,7 @@ emptyLoginData =
type Page
= SearchPage
= SearchPage (Maybe String)
| LoginPage LoginData
| ManageDataPage
| CollectiveSettingPage
@ -72,7 +73,7 @@ isSecured page =
DashboardPage ->
True
SearchPage ->
SearchPage _ ->
True
LoginPage _ ->
@ -142,13 +143,23 @@ loginPage p =
LoginPage { emptyLoginData | referrer = Just p }
isSearchPage : Page -> Bool
isSearchPage page =
case page of
SearchPage _ ->
True
_ ->
False
pageName : Page -> String
pageName page =
case page of
DashboardPage ->
"dashboard"
SearchPage ->
SearchPage _ ->
"Search"
LoginPage _ ->
@ -236,8 +247,13 @@ pageToString page =
DashboardPage ->
"/app/dashboard"
SearchPage ->
"/app/search"
SearchPage bmId ->
case bmId of
Just id ->
"/app/search?bm=" ++ id
Nothing ->
"/app/search"
LoginPage data ->
case data.referrer of
@ -329,7 +345,7 @@ parser =
, s pathPrefix </> s "dashboard"
]
)
, Parser.map SearchPage (s pathPrefix </> s "search")
, Parser.map SearchPage (s pathPrefix </> s "search" <?> Query.string "bm")
, Parser.map LoginPage (s pathPrefix </> s "login" <?> loginPageParser)
, Parser.map ManageDataPage (s pathPrefix </> s "managedata")
, Parser.map CollectiveSettingPage (s pathPrefix </> s "csettings")

View File

@ -17,7 +17,7 @@ view texts _ model =
div [ class "flex flex-col" ]
[ div [ class "mt-2" ]
[ menuLink [ onClick InitDashboard, href "#" ] (Icons.dashboardIcon "") "Dashboard"
, menuLink [ Page.href SearchPage ] (Icons.searchIcon "") "Items"
, menuLink [ Page.href (SearchPage Nothing) ] (Icons.searchIcon "") "Items"
]
, h3
[ class S.header3

View File

@ -7,6 +7,7 @@
module Page.Dashboard.Update exposing (update)
import Browser.Navigation as Nav
import Comp.BookmarkChooser
import Comp.EquipmentManage
import Comp.FolderManage
@ -19,11 +20,13 @@ import Comp.SourceManage
import Comp.TagManage
import Data.Flags exposing (Flags)
import Messages.Page.Dashboard exposing (Texts)
import Page exposing (Page(..))
import Page.Dashboard.Data exposing (..)
import Set
update : Texts -> Flags -> Msg -> Model -> ( Model, Cmd Msg, Sub Msg )
update texts flags msg model =
update : Texts -> Nav.Key -> Flags -> Msg -> Model -> ( Model, Cmd Msg, Sub Msg )
update texts navKey flags msg model =
case msg of
GetBookmarksResp list ->
let
@ -43,9 +46,12 @@ update texts flags msg model =
lm
sideMenu.bookmarkChooser
Comp.BookmarkChooser.emptySelection
bmId =
Set.toList sel.bookmarks |> List.head
in
( { model | sideMenu = { sideMenu | bookmarkChooser = bm } }
, Cmd.none
, Page.set navKey (SearchPage bmId)
, Sub.none
)

View File

@ -60,7 +60,7 @@ update key flags inav settings msg model =
Cmd.none
_ ->
Page.set key SearchPage
Page.set key (SearchPage Nothing)
in
{ model = { model | detail = result.model }
, cmd = Cmd.batch [ pageSwitch, Cmd.map ItemDetailMsg result.cmd ]

View File

@ -48,7 +48,6 @@ import Data.Items
import Data.UiSettings exposing (UiSettings)
import Http
import Set exposing (Set)
import Throttle exposing (Throttle)
import Util.Html exposing (KeyCode(..))
import Util.ItemDragDrop as DD
@ -61,7 +60,6 @@ type alias Model =
, searchOffset : Int
, moreAvailable : Bool
, moreInProgress : Bool
, throttle : Throttle Msg
, searchTypeDropdownValue : SearchType
, lastSearchType : SearchType
, dragDropData : DD.DragDropData
@ -129,7 +127,6 @@ init flags viewMode =
, searchOffset = 0
, moreAvailable = True
, moreInProgress = False
, throttle = Throttle.create 1
, searchTypeDropdownValue =
if Comp.SearchMenu.isFulltextSearch searchMenuModel then
ContentOnlySearch
@ -199,6 +196,7 @@ editActive model =
type Msg
= Init
| DoNothing
| SearchMenuMsg Comp.SearchMenu.Msg
| ResetSearch
| ItemCardListMsg Comp.ItemCardList.Msg
@ -208,7 +206,6 @@ type Msg
| ToggleSearchMenu
| ToggleSelectView
| LoadMore
| UpdateThrottle
| SetBasicSearch String
| ToggleSearchType
| KeyUpSearchbarMsg (Maybe KeyCode)
@ -310,10 +307,11 @@ doSearchDefaultCmd param model =
createQuery : Model -> Maybe Q.ItemQuery
createQuery model =
Q.and
[ Comp.SearchMenu.getItemQuery model.searchMenuModel
, Maybe.map Q.Fragment model.powerSearchInput.input
]
Debug.log "query" <|
Q.and
[ Comp.SearchMenu.getItemQuery model.searchMenuModel
, Maybe.map Q.Fragment model.powerSearchInput.input
]
resultsBelowLimit : UiSettings -> Model -> Bool

View File

@ -35,8 +35,6 @@ import Process
import Scroll
import Set exposing (Set)
import Task
import Throttle
import Time
import Util.Html exposing (KeyCode(..))
import Util.ItemDragDrop as DD
import Util.Update
@ -50,8 +48,8 @@ type alias UpdateResult =
}
update : Maybe String -> Nav.Key -> Flags -> Texts -> UiSettings -> Msg -> Model -> UpdateResult
update mId key flags texts settings msg model =
update : Maybe String -> Maybe String -> Nav.Key -> Flags -> Texts -> UiSettings -> Msg -> Model -> UpdateResult
update bookmarkId mId key flags texts settings msg model =
case msg of
Init ->
let
@ -62,20 +60,28 @@ update mId key flags texts settings msg model =
, offset = 0
, scroll = True
}
setBookmark =
Maybe.map (\bmId -> SearchMenuMsg <| Comp.SearchMenu.SetBookmark bmId) bookmarkId
|> Maybe.withDefault DoNothing
in
makeResult <|
Util.Update.andThen3
[ update mId key flags texts settings (SearchMenuMsg Comp.SearchMenu.Init)
[ update bookmarkId mId key flags texts settings (SearchMenuMsg Comp.SearchMenu.Init)
, update bookmarkId mId key flags texts settings setBookmark
, doSearch searchParam
]
model
DoNothing ->
UpdateResult model Cmd.none Sub.none Nothing
ResetSearch ->
let
nm =
{ model | searchOffset = 0, powerSearchInput = Comp.PowerSearchInput.init }
in
update mId key flags texts settings (SearchMenuMsg Comp.SearchMenu.ResetForm) nm
update bookmarkId mId key flags texts settings (SearchMenuMsg Comp.SearchMenu.ResetForm) nm
SearchMenuMsg m ->
let
@ -103,7 +109,7 @@ update mId key flags texts settings msg model =
}
result =
if nextState.stateChange && not model.searchInProgress then
if Debug.log "state" nextState.stateChange && not model.searchInProgress then
doSearch (SearchParam flags BasicSearch settings.itemSearchPageSize 0 False) newModel
else
@ -121,7 +127,7 @@ update mId key flags texts settings msg model =
SetLinkTarget lt ->
case linkTargetMsg lt of
Just m ->
update mId key flags texts settings m model
update bookmarkId mId key flags texts settings m model
Nothing ->
makeResult ( model, Cmd.none, Sub.none )
@ -193,7 +199,7 @@ update mId key flags texts settings msg model =
in
makeResult <|
Util.Update.andThen3
[ update mId key flags texts settings (ItemCardListMsg (Comp.ItemCardList.SetResults list))
[ update bookmarkId mId key flags texts settings (ItemCardListMsg (Comp.ItemCardList.SetResults list))
, if scroll then
scrollToCard mId
@ -215,7 +221,7 @@ update mId key flags texts settings msg model =
, moreAvailable = list.groups /= []
}
in
update mId key flags texts settings (ItemCardListMsg (Comp.ItemCardList.AddResults list)) m
update bookmarkId mId key flags texts settings (ItemCardListMsg (Comp.ItemCardList.AddResults list)) m
ItemSearchAddResp (Err _) ->
withSub
@ -319,30 +325,23 @@ update mId key flags texts settings msg model =
else
withSub ( model, Cmd.none )
UpdateThrottle ->
let
( newThrottle, cmd ) =
Throttle.update model.throttle
in
withSub ( { model | throttle = newThrottle }, cmd )
SetBasicSearch str ->
let
smMsg =
SearchMenuMsg (Comp.SearchMenu.SetTextSearch str)
in
update mId key flags texts settings smMsg model
update bookmarkId mId key flags texts settings smMsg model
ToggleSearchType ->
case model.searchTypeDropdownValue of
BasicSearch ->
update mId key flags texts settings (SearchMenuMsg Comp.SearchMenu.SetFulltextSearch) model
update bookmarkId mId key flags texts settings (SearchMenuMsg Comp.SearchMenu.SetFulltextSearch) model
ContentOnlySearch ->
update mId key flags texts settings (SearchMenuMsg Comp.SearchMenu.SetNamesSearch) model
update bookmarkId mId key flags texts settings (SearchMenuMsg Comp.SearchMenu.SetNamesSearch) model
KeyUpSearchbarMsg (Just Enter) ->
update mId key flags texts settings (DoSearch model.searchTypeDropdownValue) model
update bookmarkId mId key flags texts settings (DoSearch model.searchTypeDropdownValue) model
KeyUpSearchbarMsg _ ->
withSub ( model, Cmd.none )
@ -653,7 +652,8 @@ update mId key flags texts settings msg model =
{ model | viewMode = nextView }
in
if result.outcome == Comp.ItemMerge.OutcomeMerged then
update mId
update bookmarkId
mId
key
flags
texts
@ -733,7 +733,8 @@ update mId key flags texts settings msg model =
{ model | viewMode = nextView }
in
if result.outcome == Comp.PublishItems.OutcomeDone then
update mId
update bookmarkId
mId
key
flags
texts
@ -853,7 +854,7 @@ update mId key flags texts settings msg model =
model_ =
{ model | viewMode = viewMode }
in
update mId key flags texts settings (DoSearch model.lastSearchType) model_
update bookmarkId mId key flags texts settings (DoSearch model.lastSearchType) model_
SearchStatsResp result ->
let
@ -863,7 +864,7 @@ update mId key flags texts settings msg model =
stats =
Result.withDefault model.searchStats result
in
update mId key flags texts settings lm { model | searchStats = stats }
update bookmarkId mId key flags texts settings lm { model | searchStats = stats }
TogglePreviewFullWidth ->
let
@ -905,16 +906,16 @@ update mId key flags texts settings msg model =
makeResult ( model_, cmd_, Sub.map PowerSearchMsg result.subs )
Comp.PowerSearchInput.SubmitSearch ->
update mId key flags texts settings (DoSearch model_.searchTypeDropdownValue) model_
update bookmarkId mId key flags texts settings (DoSearch model_.searchTypeDropdownValue) model_
KeyUpPowerSearchbarMsg (Just Enter) ->
update mId key flags texts settings (DoSearch model.searchTypeDropdownValue) model
update bookmarkId mId key flags texts settings (DoSearch model.searchTypeDropdownValue) model
KeyUpPowerSearchbarMsg _ ->
withSub ( model, Cmd.none )
RemoveItem id ->
update mId key flags texts settings (ItemCardListMsg (Comp.ItemCardList.RemoveItem id)) model
update bookmarkId mId key flags texts settings (ItemCardListMsg (Comp.ItemCardList.RemoveItem id)) model
TogglePublishCurrentQueryView ->
case createQuery model of
@ -1146,18 +1147,14 @@ doSearch param model =
searchCmd =
doSearchCmd param_ model
( newThrottle, cmd ) =
Throttle.try searchCmd model.throttle
in
withSub
( { model
| searchInProgress = cmd /= Cmd.none
| searchInProgress = True
, searchOffset = 0
, throttle = newThrottle
, lastSearchType = param.searchType
}
, cmd
, searchCmd
)
@ -1190,9 +1187,7 @@ withSub ( m, c ) =
makeResult
( m
, c
, Throttle.ifNeeded
(Time.every 500 (\_ -> UpdateThrottle))
m.throttle
, Sub.none
)

View File

@ -195,7 +195,7 @@ renderSuccessMsg texts public model =
[ text texts.successBox.line1
, a
[ class S.successMessageLink
, Page.href SearchPage
, Page.href (SearchPage Nothing)
]
[ text texts.successBox.itemsPage
]