Integrate item merge dialog into home page

This commit is contained in:
eikek
2021-08-15 14:18:33 +02:00
parent 5782166273
commit 22d331f082
9 changed files with 777 additions and 3 deletions

View 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

View File

@ -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 =