mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-23 10:58:26 +00:00
Integrate item merge dialog into home page
This commit is contained in:
62
modules/webapp/src/main/elm/Util/Item.elm
Normal file
62
modules/webapp/src/main/elm/Util/Item.elm
Normal file
@ -0,0 +1,62 @@
|
||||
{-
|
||||
Copyright 2020 Docspell Contributors
|
||||
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
-}
|
||||
|
||||
|
||||
module Util.Item exposing
|
||||
( concTemplate
|
||||
, corrTemplate
|
||||
)
|
||||
|
||||
import Api.Model.ItemLight exposing (ItemLight)
|
||||
import Data.Fields
|
||||
import Data.ItemTemplate as IT exposing (ItemTemplate)
|
||||
import Data.UiSettings exposing (UiSettings)
|
||||
|
||||
|
||||
corrTemplate : UiSettings -> ItemTemplate
|
||||
corrTemplate settings =
|
||||
let
|
||||
fieldHidden f =
|
||||
Data.UiSettings.fieldHidden settings f
|
||||
|
||||
hiddenTuple =
|
||||
( fieldHidden Data.Fields.CorrOrg, fieldHidden Data.Fields.CorrPerson )
|
||||
in
|
||||
case hiddenTuple of
|
||||
( True, True ) ->
|
||||
IT.empty
|
||||
|
||||
( True, False ) ->
|
||||
IT.corrPerson
|
||||
|
||||
( False, True ) ->
|
||||
IT.corrOrg
|
||||
|
||||
( False, False ) ->
|
||||
IT.correspondent
|
||||
|
||||
|
||||
concTemplate : UiSettings -> ItemTemplate
|
||||
concTemplate settings =
|
||||
let
|
||||
fieldHidden f =
|
||||
Data.UiSettings.fieldHidden settings f
|
||||
|
||||
hiddenTuple =
|
||||
( fieldHidden Data.Fields.ConcPerson, fieldHidden Data.Fields.ConcEquip )
|
||||
in
|
||||
case hiddenTuple of
|
||||
( True, True ) ->
|
||||
IT.empty
|
||||
|
||||
( True, False ) ->
|
||||
IT.concEquip
|
||||
|
||||
( False, True ) ->
|
||||
IT.concPerson
|
||||
|
||||
( False, False ) ->
|
||||
IT.concerning
|
@ -6,7 +6,8 @@
|
||||
|
||||
|
||||
module Util.List exposing
|
||||
( distinct
|
||||
( changePosition
|
||||
, distinct
|
||||
, dropRight
|
||||
, find
|
||||
, findIndexed
|
||||
@ -16,6 +17,47 @@ module Util.List exposing
|
||||
, sliding
|
||||
)
|
||||
|
||||
import Html.Attributes exposing (list)
|
||||
|
||||
|
||||
changePosition : Int -> Int -> List a -> List a
|
||||
changePosition source target list =
|
||||
let
|
||||
len =
|
||||
List.length list
|
||||
|
||||
noChange =
|
||||
source == target || source + 1 == target
|
||||
|
||||
outOfBounds n =
|
||||
n < 0 || n >= len
|
||||
|
||||
concat el acc =
|
||||
let
|
||||
idx =
|
||||
Tuple.first el
|
||||
|
||||
ela =
|
||||
Tuple.second el
|
||||
in
|
||||
if idx == source then
|
||||
( target, ela ) :: acc
|
||||
|
||||
else if idx >= target then
|
||||
( idx + 1, ela ) :: acc
|
||||
|
||||
else
|
||||
( idx, ela ) :: acc
|
||||
in
|
||||
if noChange || outOfBounds source || outOfBounds target then
|
||||
list
|
||||
|
||||
else
|
||||
List.indexedMap Tuple.pair list
|
||||
|> List.foldl concat []
|
||||
|> List.sortBy Tuple.first
|
||||
|> List.map Tuple.second
|
||||
|
||||
|
||||
get : List a -> Int -> Maybe a
|
||||
get list index =
|
||||
|
Reference in New Issue
Block a user