From ca05b3c195a3046d297550ab15f0859f1fb81508 Mon Sep 17 00:00:00 2001 From: Eike Kettner Date: Fri, 25 Sep 2020 22:54:50 +0200 Subject: [PATCH 1/4] Fix initialising pages; improve scroll to item --- modules/webapp/src/main/elm/App/Update.elm | 8 ++++++-- modules/webapp/src/main/elm/Page/Home/Update.elm | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/webapp/src/main/elm/App/Update.elm b/modules/webapp/src/main/elm/App/Update.elm index 9e511809..59067a6a 100644 --- a/modules/webapp/src/main/elm/App/Update.elm +++ b/modules/webapp/src/main/elm/App/Update.elm @@ -342,9 +342,13 @@ updateManageData lmsg model = initPage : Model -> Page -> ( Model, Cmd Msg, Sub Msg ) -initPage model page = +initPage model_ page = + let + model = + { model_ | page = page } + in case page of - HomePage mid -> + HomePage _ -> Util.Update.andThen2 [ updateHome Page.Home.Data.Init , updateQueue Page.Queue.Data.StopRefresh diff --git a/modules/webapp/src/main/elm/Page/Home/Update.elm b/modules/webapp/src/main/elm/Page/Home/Update.elm index f307b727..c8c3c04f 100644 --- a/modules/webapp/src/main/elm/Page/Home/Update.elm +++ b/modules/webapp/src/main/elm/Page/Home/Update.elm @@ -26,7 +26,7 @@ update mId key flags settings msg model = Init -> Util.Update.andThen2 [ update mId key flags settings (SearchMenuMsg Comp.SearchMenu.Init) - , doSearch flags settings + , scrollToCard mId ] model @@ -251,7 +251,7 @@ update mId key flags settings msg model = ScrollResult _ -> let cmd = - Process.sleep 350 |> Task.perform (always ClearItemDetailId) + Process.sleep 800 |> Task.perform (always ClearItemDetailId) in withSub ( model, cmd ) From e831d7bdd75584f273ecdb809a428def8cf02877 Mon Sep 17 00:00:00 2001 From: Eike Kettner Date: Sat, 26 Sep 2020 01:11:56 +0200 Subject: [PATCH 2/4] Move attachment tabs into a menu If multiple attachments are present, the tab menu doesn't show all. So if there is more than one attachment they can be selected from a menu. --- .../elm/Comp/ItemDetail/AttachmentTabMenu.elm | 158 ++++++++++++++++++ .../src/main/elm/Comp/ItemDetail/Model.elm | 3 + .../src/main/elm/Comp/ItemDetail/Update.elm | 5 +- .../src/main/elm/Comp/ItemDetail/View.elm | 16 +- modules/webapp/src/main/webjar/docspell.css | 4 +- 5 files changed, 179 insertions(+), 7 deletions(-) create mode 100644 modules/webapp/src/main/elm/Comp/ItemDetail/AttachmentTabMenu.elm diff --git a/modules/webapp/src/main/elm/Comp/ItemDetail/AttachmentTabMenu.elm b/modules/webapp/src/main/elm/Comp/ItemDetail/AttachmentTabMenu.elm new file mode 100644 index 00000000..15062d27 --- /dev/null +++ b/modules/webapp/src/main/elm/Comp/ItemDetail/AttachmentTabMenu.elm @@ -0,0 +1,158 @@ +module Comp.ItemDetail.AttachmentTabMenu exposing (view) + +import Api.Model.Attachment exposing (Attachment) +import Comp.ItemDetail.Model exposing (Model, Msg(..)) +import Comp.SentMails +import Html exposing (Html, a, div, i, text) +import Html.Attributes exposing (class, classList, href, title) +import Html.Events exposing (onClick) +import Html5.DragDrop as DD +import Util.List +import Util.Maybe +import Util.String + + +view : Model -> Html Msg +view model = + div [ class "ui top attached tabular menu" ] + (activeAttach model + :: selectMenu model + ++ sentMailsTab model + ) + + +activeAttach : Model -> Html Msg +activeAttach model = + let + attachM = + Util.Maybe.or + [ Util.List.get model.item.attachments model.visibleAttach + |> Maybe.map (Tuple.pair model.visibleAttach) + , List.head model.item.attachments + |> Maybe.map (Tuple.pair 0) + ] + + visible = + not model.sentMailsOpen + in + case attachM of + Just ( pos, attach ) -> + a + ([ classList + [ ( "active", visible ) + , ( "item", True ) + ] + , title (Maybe.withDefault "No Name" attach.name) + , href "#" + ] + ++ (if visible then + [] + + else + [ onClick (SetActiveAttachment pos) ] + ) + ) + [ Maybe.map (Util.String.ellipsis 30) attach.name + |> Maybe.withDefault "No Name" + |> text + , a + [ classList + [ ( "right-tab-icon-link", True ) + , ( "invisible hidden", not visible ) + ] + , href "#" + , onClick (EditAttachNameStart attach.id) + ] + [ i [ class "grey edit link icon" ] [] + ] + ] + + Nothing -> + div [] [] + + +selectMenu : Model -> List (Html Msg) +selectMenu model = + case model.item.attachments of + [] -> + [] + + [ _ ] -> + [] + + _ -> + [ a + [ class "ui dropdown item" + , href "#" + , onClick ToggleAttachMenu + ] + [ i + [ classList + [ ( "large ellipsis icon", True ) + , ( "horizontal", not model.attachMenuOpen ) + , ( "vertical", model.attachMenuOpen ) + ] + ] + [] + , div + [ classList + [ ( "menu transition", True ) + , ( "visible", model.attachMenuOpen ) + , ( "hidden", not model.attachMenuOpen ) + ] + ] + (List.indexedMap (menuItem model) model.item.attachments) + ] + ] + + +menuItem : Model -> Int -> Attachment -> Html Msg +menuItem model pos attach = + let + highlight el = + let + dropId = + DD.getDropId model.attachDD + + dragId = + DD.getDragId model.attachDD + + enable = + Just el.id == dropId && dropId /= dragId + in + [ ( "current-drop-target", enable ) + ] + in + a + ([ classList <| + [ ( "item", True ) + ] + ++ highlight attach + , href "#" + , onClick (SetActiveAttachment pos) + ] + ++ DD.draggable AttachDDMsg attach.id + ++ DD.droppable AttachDDMsg attach.id + ) + [ Maybe.map (Util.String.ellipsis 60) attach.name + |> Maybe.withDefault "No Name" + |> text + ] + + +sentMailsTab : Model -> List (Html Msg) +sentMailsTab model = + if Comp.SentMails.isEmpty model.sentMails then + [] + + else + [ div + [ classList + [ ( "right item", True ) + , ( "active", model.sentMailsOpen ) + ] + , onClick ToggleSentMails + ] + [ text "E-Mails" + ] + ] diff --git a/modules/webapp/src/main/elm/Comp/ItemDetail/Model.elm b/modules/webapp/src/main/elm/Comp/ItemDetail/Model.elm index 949f043e..ea75691a 100644 --- a/modules/webapp/src/main/elm/Comp/ItemDetail/Model.elm +++ b/modules/webapp/src/main/elm/Comp/ItemDetail/Model.elm @@ -47,6 +47,7 @@ import Util.Tag type alias Model = { item : ItemDetail , visibleAttach : Int + , attachMenuOpen : Bool , menuOpen : Bool , tagModel : Comp.Dropdown.Model Tag , directionModel : Comp.Dropdown.Model Direction @@ -115,6 +116,7 @@ emptyModel : Model emptyModel = { item = Api.Model.ItemDetail.empty , visibleAttach = 0 + , attachMenuOpen = False , menuOpen = False , tagModel = Util.Tag.makeDropdownModel @@ -269,6 +271,7 @@ type Msg | SaveNameResp (Result Http.Error BasicResult) | UpdateThrottle | KeyInputMsg Comp.KeyInput.Msg + | ToggleAttachMenu type SaveNameState diff --git a/modules/webapp/src/main/elm/Comp/ItemDetail/Update.elm b/modules/webapp/src/main/elm/Comp/ItemDetail/Update.elm index 395f15f1..f6a8f5a9 100644 --- a/modules/webapp/src/main/elm/Comp/ItemDetail/Update.elm +++ b/modules/webapp/src/main/elm/Comp/ItemDetail/Update.elm @@ -758,7 +758,7 @@ update key flags inav settings msg model = noSub ( { model | sentMails = sm }, Cmd.none ) ToggleSentMails -> - noSub ( { model | sentMailsOpen = not model.sentMailsOpen, visibleAttach = -1 }, Cmd.none ) + noSub ( { model | sentMailsOpen = not model.sentMailsOpen }, Cmd.none ) SentMailsResp (Ok list) -> let @@ -1266,6 +1266,9 @@ update key flags inav settings msg model = -- field and requires to activate the throttle withSub ( model_, Cmd.none ) + ToggleAttachMenu -> + noSub ( { model | attachMenuOpen = not model.attachMenuOpen }, Cmd.none ) + --- Helper diff --git a/modules/webapp/src/main/elm/Comp/ItemDetail/View.elm b/modules/webapp/src/main/elm/Comp/ItemDetail/View.elm index 348f52a4..6b57eb76 100644 --- a/modules/webapp/src/main/elm/Comp/ItemDetail/View.elm +++ b/modules/webapp/src/main/elm/Comp/ItemDetail/View.elm @@ -6,6 +6,7 @@ import Comp.DatePicker import Comp.DetailEdit import Comp.Dropdown import Comp.Dropzone +import Comp.ItemDetail.AttachmentTabMenu import Comp.ItemDetail.Model exposing (Model, Msg(..), NotesField(..), SaveNameState(..)) import Comp.ItemMail import Comp.KeyInput @@ -302,15 +303,22 @@ renderNotes model = attachmentVisible : Model -> Int -> Bool attachmentVisible model pos = - if model.visibleAttach >= List.length model.item.attachments then - pos == 0 + not model.sentMailsOpen + && (if model.visibleAttach >= List.length model.item.attachments then + pos == 0 - else - model.visibleAttach == pos + else + model.visibleAttach == pos + ) renderAttachmentsTabMenu : Model -> Html Msg renderAttachmentsTabMenu model = + Comp.ItemDetail.AttachmentTabMenu.view model + + +renderAttachmentsTabMenuOld : Model -> Html Msg +renderAttachmentsTabMenuOld model = let mailTab = if Comp.SentMails.isEmpty model.sentMails then diff --git a/modules/webapp/src/main/webjar/docspell.css b/modules/webapp/src/main/webjar/docspell.css index 98537901..31ee7eda 100644 --- a/modules/webapp/src/main/webjar/docspell.css +++ b/modules/webapp/src/main/webjar/docspell.css @@ -170,8 +170,8 @@ textarea.markdown-editor { background: rgba(240,248,255,0.4); } -.default-layout .ui.menu .item.current-drop-target, .header.current-drop-target, .item.current-drop-target { - background: rgba(0,0,0,0.2); +.default-layout .ui.dropdown .menu .item.current-drop-target, .header.current-drop-target, .item.current-drop-target { + background: rgba(0,0,0,0.2) !important; } .default-layout .search-menu { From 284c42aec6116837f0526926acdeeb143f67f387 Mon Sep 17 00:00:00 2001 From: Eike Kettner Date: Sat, 26 Sep 2020 01:15:16 +0200 Subject: [PATCH 3/4] Remove attachment tab menu --- .../src/main/elm/Comp/ItemDetail/View.elm | 84 ------------------- 1 file changed, 84 deletions(-) diff --git a/modules/webapp/src/main/elm/Comp/ItemDetail/View.elm b/modules/webapp/src/main/elm/Comp/ItemDetail/View.elm index 6b57eb76..131c1c8f 100644 --- a/modules/webapp/src/main/elm/Comp/ItemDetail/View.elm +++ b/modules/webapp/src/main/elm/Comp/ItemDetail/View.elm @@ -317,90 +317,6 @@ renderAttachmentsTabMenu model = Comp.ItemDetail.AttachmentTabMenu.view model -renderAttachmentsTabMenuOld : Model -> Html Msg -renderAttachmentsTabMenuOld model = - let - mailTab = - if Comp.SentMails.isEmpty model.sentMails then - [] - - else - [ div - [ classList - [ ( "right item", True ) - , ( "active", model.sentMailsOpen ) - ] - , onClick ToggleSentMails - ] - [ text "E-Mails" - ] - ] - - highlight el = - let - dropId = - DD.getDropId model.attachDD - - dragId = - DD.getDragId model.attachDD - - enable = - Just el.id == dropId && dropId /= dragId - in - [ ( "current-drop-target", enable ) - ] - in - div [ class "ui top attached tabular menu" ] - (List.indexedMap - (\pos -> - \el -> - if attachmentVisible model pos then - a - ([ classList <| - [ ( "active item", True ) - ] - ++ highlight el - , title (Maybe.withDefault "No Name" el.name) - , href "" - ] - ++ DD.draggable AttachDDMsg el.id - ++ DD.droppable AttachDDMsg el.id - ) - [ Maybe.map (Util.String.ellipsis 30) el.name - |> Maybe.withDefault "No Name" - |> text - , a - [ class "right-tab-icon-link" - , href "#" - , onClick (EditAttachNameStart el.id) - ] - [ i [ class "grey edit link icon" ] [] - ] - ] - - else - a - ([ classList <| - [ ( "item", True ) - ] - ++ highlight el - , title (Maybe.withDefault "No Name" el.name) - , href "" - , onClick (SetActiveAttachment pos) - ] - ++ DD.draggable AttachDDMsg el.id - ++ DD.droppable AttachDDMsg el.id - ) - [ Maybe.map (Util.String.ellipsis 20) el.name - |> Maybe.withDefault "No Name" - |> text - ] - ) - model.item.attachments - ++ mailTab - ) - - renderAttachmentView : UiSettings -> Model -> Int -> Attachment -> Html Msg renderAttachmentView settings model pos attach = let From 72048b9b34826a46df0b6fecaeb3ee393495d52f Mon Sep 17 00:00:00 2001 From: Eike Kettner Date: Sat, 26 Sep 2020 01:28:34 +0200 Subject: [PATCH 4/4] Drop deferred message if user clicked away --- modules/webapp/src/main/elm/Page/Home/Data.elm | 2 +- .../webapp/src/main/elm/Page/Home/Update.elm | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/modules/webapp/src/main/elm/Page/Home/Data.elm b/modules/webapp/src/main/elm/Page/Home/Data.elm index fb2ee3c3..eda1efbf 100644 --- a/modules/webapp/src/main/elm/Page/Home/Data.elm +++ b/modules/webapp/src/main/elm/Page/Home/Data.elm @@ -98,7 +98,7 @@ type Msg | KeyUpMsg (Maybe KeyCode) | SetContentOnly String | ScrollResult (Result Dom.Error ()) - | ClearItemDetailId + | ClearItemDetailId (Maybe String) type SearchType diff --git a/modules/webapp/src/main/elm/Page/Home/Update.elm b/modules/webapp/src/main/elm/Page/Home/Update.elm index c8c3c04f..9db104d2 100644 --- a/modules/webapp/src/main/elm/Page/Home/Update.elm +++ b/modules/webapp/src/main/elm/Page/Home/Update.elm @@ -251,12 +251,18 @@ update mId key flags settings msg model = ScrollResult _ -> let cmd = - Process.sleep 800 |> Task.perform (always ClearItemDetailId) + Process.sleep 800 |> Task.perform (always (ClearItemDetailId mId)) in withSub ( model, cmd ) - ClearItemDetailId -> - withSub ( model, Page.set key (HomePage Nothing) ) + ClearItemDetailId id -> + -- if user clicks quickly away (e.g. on another item), the + -- deferred command should be ignored + if mId == id then + noSub ( model, Page.set key (HomePage Nothing) ) + + else + noSub ( model, Cmd.none ) @@ -328,3 +334,8 @@ withSub ( m, c ) = (Time.every 500 (\_ -> UpdateThrottle)) m.throttle ) + + +noSub : ( Model, Cmd Msg ) -> ( Model, Cmd Msg, Sub Msg ) +noSub ( m, c ) = + ( m, c, Sub.none )