From a9c02e9e88db46ee01d90a565a3b14f510252609 Mon Sep 17 00:00:00 2001 From: Stefan Scheidewig <stefan.scheidewig@staffbase.com> Date: Sat, 17 Apr 2021 13:04:30 +0200 Subject: [PATCH] Prepared multiselect view mode for attachment list --- .../src/main/elm/Comp/ItemDetail/Model.elm | 23 ++++++++ .../elm/Comp/ItemDetail/SingleAttachment.elm | 55 ++++++++++++++++--- .../src/main/elm/Comp/ItemDetail/Update.elm | 26 +++++++-- .../Comp/ItemDetail/SingleAttachment.elm | 6 ++ 4 files changed, 98 insertions(+), 12 deletions(-) diff --git a/modules/webapp/src/main/elm/Comp/ItemDetail/Model.elm b/modules/webapp/src/main/elm/Comp/ItemDetail/Model.elm index 02e2e2d8..7a6db775 100644 --- a/modules/webapp/src/main/elm/Comp/ItemDetail/Model.elm +++ b/modules/webapp/src/main/elm/Comp/ItemDetail/Model.elm @@ -5,12 +5,14 @@ module Comp.ItemDetail.Model exposing , NotesField(..) , SaveNameState(..) , UpdateResult + , ViewMode(..) , emptyModel , isEditNotes , personMatchesOrg , resultModel , resultModelCmd , resultModelCmdSub + , initSelectViewModel ) import Api.Model.BasicResult exposing (BasicResult) @@ -105,8 +107,21 @@ type alias Model = , allPersons : Dict String Person , attachmentDropdownOpen : Bool , editMenuTabsOpen : Set String + , viewMode : ViewMode } +type ViewMode + = SimpleView + | SelectView SelectViewModel + +type alias SelectViewModel = + { ids : Set String + , action : SelectActionMode + } + +type SelectActionMode + = NoneAction + | DeleteSelected type NotesField = ViewNotes @@ -185,6 +200,13 @@ emptyModel = , allPersons = Dict.empty , attachmentDropdownOpen = False , editMenuTabsOpen = Set.empty + , viewMode = SimpleView + } + +initSelectViewModel : SelectViewModel +initSelectViewModel = + { ids = Set.empty + , action = NoneAction } @@ -283,6 +305,7 @@ type Msg | ReprocessFileResp (Result Http.Error BasicResult) | RequestReprocessItem | ReprocessItemConfirmed + | ToggleSelectView type SaveNameState diff --git a/modules/webapp/src/main/elm/Comp/ItemDetail/SingleAttachment.elm b/modules/webapp/src/main/elm/Comp/ItemDetail/SingleAttachment.elm index 75c51dfc..fe49677c 100644 --- a/modules/webapp/src/main/elm/Comp/ItemDetail/SingleAttachment.elm +++ b/modules/webapp/src/main/elm/Comp/ItemDetail/SingleAttachment.elm @@ -4,13 +4,7 @@ import Api import Api.Model.Attachment exposing (Attachment) import Comp.AttachmentMeta import Comp.ConfirmModal -import Comp.ItemDetail.Model - exposing - ( Model - , Msg(..) - , NotesField(..) - , SaveNameState(..) - ) +import Comp.ItemDetail.Model exposing (Model, Msg(..), NotesField(..), SaveNameState(..), ViewMode(..)) import Comp.MenuBar as MB import Data.UiSettings exposing (UiSettings) import Dict @@ -19,7 +13,6 @@ import Html.Attributes exposing (..) import Html.Events exposing (onClick, onInput) import Html5.DragDrop as DD import Messages.Comp.ItemDetail.SingleAttachment exposing (Texts) -import Page exposing (Page(..)) import Styles as S import Util.Maybe import Util.Size @@ -87,6 +80,7 @@ view texts settings model pos attach = - toggle thumbs - name + size - eye icon to open it + - toggle multi select - menu - rename - meta data @@ -112,6 +106,26 @@ attachHeader texts settings model _ attach = multiAttach = List.length model.item.attachments > 1 + selectPossible = + multiAttach && model.attachMenuOpen + + selectView = + case model.viewMode of + SelectView _ -> + True + _ -> + False + + selectToggleText = + case model.viewMode of + SelectView _ -> + texts.exitSelectMode + _ -> + texts.selectModeTitle + + noAttachmentsSelected = + List.isEmpty model.item.attachments + attachSelectToggle mobile = a [ href "#" @@ -143,15 +157,40 @@ attachHeader texts settings model _ attach = , title texts.openFileInNewTab , class S.secondaryBasicButton , class "ml-2" + , classList [ ( "hidden", selectView ) ] ] [ i [ class "fa fa-eye font-thin" ] [] ] + , a + [ classList [ (S.secondaryBasicButton ++ " text-sm", True) + , ( "bg-gray-200 dark:bg-bluegray-600", selectView ) + , ( "hidden", not selectPossible ) + , ( "ml-2", True ) + ] + , href "#" + , title selectToggleText + , onClick ToggleSelectView + ] + [ i [ class "fa fa-tasks" ] [] + ] + , a + [ classList [ ( S.deleteButton, True ) + , ( "disabled", noAttachmentsSelected ) + , ( "hidden", not selectPossible || not selectView ) + , ( "ml-2", True ) + ] + , href "#" + , title texts.deleteAttachments + ] + [ i [ class "fa fa-trash" ] [] + ] , MB.viewItem <| MB.Dropdown { linkIcon = "fa fa-bars" , linkClass = [ ( "ml-2", True ) , ( S.secondaryBasicButton, True ) + , ( "hidden", selectView ) ] , toggleMenu = ToggleAttachmentDropdown , menuOpen = model.attachmentDropdownOpen diff --git a/modules/webapp/src/main/elm/Comp/ItemDetail/Update.elm b/modules/webapp/src/main/elm/Comp/ItemDetail/Update.elm index c8ebf07a..544ed354 100644 --- a/modules/webapp/src/main/elm/Comp/ItemDetail/Update.elm +++ b/modules/webapp/src/main/elm/Comp/ItemDetail/Update.elm @@ -23,7 +23,6 @@ import Comp.DetailEdit import Comp.Dropdown exposing (isDropdownChangeMsg) import Comp.Dropzone import Comp.EquipmentForm -import Comp.ItemDetail.EditForm import Comp.ItemDetail.FieldTabState as FTabState import Comp.ItemDetail.Model exposing @@ -54,11 +53,10 @@ import Data.PersonUse import Data.UiSettings exposing (UiSettings) import DatePicker import Dict -import Html exposing (..) -import Html.Attributes exposing (..) import Html5.DragDrop as DD import Http import Page exposing (Page(..)) +import Comp.ItemDetail.Model exposing (ViewMode(..), initSelectViewModel) import Set exposing (Set) import Throttle import Time @@ -1360,7 +1358,10 @@ update key flags inav settings msg model = withSub ( model_, Cmd.none ) ToggleAttachMenu -> - resultModel { model | attachMenuOpen = not model.attachMenuOpen } + resultModel { model + | attachMenuOpen = not model.attachMenuOpen + , viewMode = SimpleView + } UiSettingsUpdated -> let @@ -1571,6 +1572,23 @@ update key flags inav settings msg model = in resultModelCmd ( { model | itemModal = Nothing }, cmd ) + ToggleSelectView -> + let + ( nextView, cmd ) = + case model.viewMode of + SimpleView -> + ( SelectView initSelectViewModel, Cmd.none ) + + SelectView _ -> + ( SimpleView, Cmd.none ) + in + withSub + ( { model + | viewMode = nextView + } + , cmd + ) + --- Helper diff --git a/modules/webapp/src/main/elm/Messages/Comp/ItemDetail/SingleAttachment.elm b/modules/webapp/src/main/elm/Messages/Comp/ItemDetail/SingleAttachment.elm index 4acdef22..ec52d724 100644 --- a/modules/webapp/src/main/elm/Messages/Comp/ItemDetail/SingleAttachment.elm +++ b/modules/webapp/src/main/elm/Messages/Comp/ItemDetail/SingleAttachment.elm @@ -15,6 +15,9 @@ type alias Texts = , viewExtractedData : String , reprocessFile : String , deleteThisFile : String + , selectModeTitle : String + , exitSelectMode : String + , deleteAttachments: String } @@ -31,4 +34,7 @@ gb = , viewExtractedData = "View extracted data" , reprocessFile = "Re-process this file" , deleteThisFile = "Delete this file" + , selectModeTitle = "Select Mode" + , exitSelectMode = "Exit Select Mode" + , deleteAttachments = "Delete attachments" }