mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-23 02:48:26 +00:00
@ -41,6 +41,7 @@ type alias Config =
|
||||
|
||||
type alias Flags =
|
||||
{ account : Maybe AuthResult
|
||||
, pdfSupported : Bool
|
||||
, config : Config
|
||||
}
|
||||
|
||||
|
67
modules/webapp/src/main/elm/Data/Pdf.elm
Normal file
67
modules/webapp/src/main/elm/Data/Pdf.elm
Normal file
@ -0,0 +1,67 @@
|
||||
module Data.Pdf exposing (PdfMode(..), allModes, asString, detectUrl, fromString, serverUrl)
|
||||
|
||||
{-| Makes use of the fact, that docspell uses a `/view` suffix on the
|
||||
path to provide a browser independent PDF view.
|
||||
-}
|
||||
|
||||
import Data.Flags exposing (Flags)
|
||||
import Html exposing (..)
|
||||
import Html.Attributes exposing (..)
|
||||
|
||||
|
||||
type PdfMode
|
||||
= Detect
|
||||
| Native
|
||||
| Server
|
||||
|
||||
|
||||
allModes : List PdfMode
|
||||
allModes =
|
||||
[ Detect, Native, Server ]
|
||||
|
||||
|
||||
asString : PdfMode -> String
|
||||
asString mode =
|
||||
case mode of
|
||||
Detect ->
|
||||
"detect"
|
||||
|
||||
Native ->
|
||||
"native"
|
||||
|
||||
Server ->
|
||||
"server"
|
||||
|
||||
|
||||
fromString : String -> Maybe PdfMode
|
||||
fromString str =
|
||||
case String.toLower str of
|
||||
"detect" ->
|
||||
Just Detect
|
||||
|
||||
"native" ->
|
||||
Just Native
|
||||
|
||||
"server" ->
|
||||
Just Server
|
||||
|
||||
_ ->
|
||||
Nothing
|
||||
|
||||
|
||||
serverUrl : String -> String
|
||||
serverUrl url =
|
||||
if String.endsWith "/" url then
|
||||
url ++ "view"
|
||||
|
||||
else
|
||||
url ++ "/view"
|
||||
|
||||
|
||||
detectUrl : Flags -> String -> String
|
||||
detectUrl flags url =
|
||||
if flags.pdfSupported then
|
||||
url
|
||||
|
||||
else
|
||||
serverUrl url
|
@ -20,6 +20,7 @@ module Data.UiSettings exposing
|
||||
, fieldVisible
|
||||
, merge
|
||||
, mergeDefaults
|
||||
, pdfUrl
|
||||
, posFromString
|
||||
, posToString
|
||||
, storedUiSettingsDecoder
|
||||
@ -34,7 +35,9 @@ import Api.Model.Tag exposing (Tag)
|
||||
import Data.BasicSize exposing (BasicSize)
|
||||
import Data.Color exposing (Color)
|
||||
import Data.Fields exposing (Field)
|
||||
import Data.Flags exposing (Flags)
|
||||
import Data.ItemTemplate exposing (ItemTemplate)
|
||||
import Data.Pdf exposing (PdfMode)
|
||||
import Data.UiTheme exposing (UiTheme)
|
||||
import Dict exposing (Dict)
|
||||
import Html exposing (Attribute)
|
||||
@ -57,7 +60,7 @@ force default settings.
|
||||
type alias StoredUiSettings =
|
||||
{ itemSearchPageSize : Maybe Int
|
||||
, tagCategoryColors : List ( String, String )
|
||||
, nativePdfPreview : Bool
|
||||
, pdfMode : Maybe String
|
||||
, itemSearchNoteLength : Maybe Int
|
||||
, itemDetailNotesPosition : Maybe String
|
||||
, searchMenuFolderCount : Maybe Int
|
||||
@ -91,7 +94,7 @@ storedUiSettingsDecoder =
|
||||
Decode.succeed StoredUiSettings
|
||||
|> P.optional "itemSearchPageSize" maybeInt Nothing
|
||||
|> P.optional "tagCategoryColors" (Decode.keyValuePairs Decode.string) []
|
||||
|> P.optional "nativePdfPreview" Decode.bool False
|
||||
|> P.optional "pdfMode" maybeString Nothing
|
||||
|> P.optional "itemSearchNoteLength" maybeInt Nothing
|
||||
|> P.optional "itemDetailNotesPosition" maybeString Nothing
|
||||
|> P.optional "searchMenuFolderCount" maybeInt Nothing
|
||||
@ -121,7 +124,7 @@ storedUiSettingsEncode value =
|
||||
Encode.object
|
||||
[ ( "itemSearchPageSize", maybeEnc Encode.int value.itemSearchPageSize )
|
||||
, ( "tagCategoryColors", Encode.dict identity Encode.string (Dict.fromList value.tagCategoryColors) )
|
||||
, ( "nativePdfPreview", Encode.bool value.nativePdfPreview )
|
||||
, ( "pdfMode", maybeEnc Encode.string value.pdfMode )
|
||||
, ( "itemSearchNoteLength", maybeEnc Encode.int value.itemSearchNoteLength )
|
||||
, ( "itemDetailNotesPosition", maybeEnc Encode.string value.itemDetailNotesPosition )
|
||||
, ( "searchMenuFolderCount", maybeEnc Encode.int value.searchMenuFolderCount )
|
||||
@ -146,14 +149,15 @@ storedUiSettingsEncode value =
|
||||
{-| Settings for the web ui. These fields are all mandatory, since
|
||||
there is always a default value.
|
||||
|
||||
When loaded from local storage, all optional fields can fallback to a
|
||||
default value, converting the StoredUiSettings into a UiSettings.
|
||||
When loaded from local storage or the server, all optional fields can
|
||||
fallback to a default value, converting the StoredUiSettings into a
|
||||
UiSettings.
|
||||
|
||||
-}
|
||||
type alias UiSettings =
|
||||
{ itemSearchPageSize : Int
|
||||
, tagCategoryColors : Dict String Color
|
||||
, nativePdfPreview : Bool
|
||||
, pdfMode : PdfMode
|
||||
, itemSearchNoteLength : Int
|
||||
, itemDetailNotesPosition : Pos
|
||||
, searchMenuFolderCount : Int
|
||||
@ -219,7 +223,7 @@ defaults : UiSettings
|
||||
defaults =
|
||||
{ itemSearchPageSize = 60
|
||||
, tagCategoryColors = Dict.empty
|
||||
, nativePdfPreview = False
|
||||
, pdfMode = Data.Pdf.Detect
|
||||
, itemSearchNoteLength = 0
|
||||
, itemDetailNotesPosition = Bottom
|
||||
, searchMenuFolderCount = 3
|
||||
@ -259,7 +263,10 @@ merge given fallback =
|
||||
|> Dict.map (\_ -> Maybe.withDefault Data.Color.Grey)
|
||||
)
|
||||
fallback.tagCategoryColors
|
||||
, nativePdfPreview = given.nativePdfPreview
|
||||
, pdfMode =
|
||||
given.pdfMode
|
||||
|> Maybe.andThen Data.Pdf.fromString
|
||||
|> Maybe.withDefault fallback.pdfMode
|
||||
, itemSearchNoteLength =
|
||||
choose given.itemSearchNoteLength fallback.itemSearchNoteLength
|
||||
, itemDetailNotesPosition =
|
||||
@ -313,7 +320,7 @@ toStoredUiSettings settings =
|
||||
, tagCategoryColors =
|
||||
Dict.map (\_ -> Data.Color.toString) settings.tagCategoryColors
|
||||
|> Dict.toList
|
||||
, nativePdfPreview = settings.nativePdfPreview
|
||||
, pdfMode = Just (Data.Pdf.asString settings.pdfMode)
|
||||
, itemSearchNoteLength = Just settings.itemSearchNoteLength
|
||||
, itemDetailNotesPosition = Just (posToString settings.itemDetailNotesPosition)
|
||||
, searchMenuFolderCount = Just settings.searchMenuFolderCount
|
||||
@ -407,6 +414,19 @@ cardPreviewSize2 settings =
|
||||
"max-h-80"
|
||||
|
||||
|
||||
pdfUrl : UiSettings -> Flags -> String -> String
|
||||
pdfUrl settings flags originalUrl =
|
||||
case settings.pdfMode of
|
||||
Data.Pdf.Detect ->
|
||||
Data.Pdf.detectUrl flags originalUrl
|
||||
|
||||
Data.Pdf.Native ->
|
||||
originalUrl
|
||||
|
||||
Data.Pdf.Server ->
|
||||
Data.Pdf.serverUrl originalUrl
|
||||
|
||||
|
||||
|
||||
--- Helpers
|
||||
|
||||
|
Reference in New Issue
Block a user