mirror of
				https://github.com/TheAnachronism/docspell.git
				synced 2025-10-31 17:50:11 +00:00 
			
		
		
		
	Add pdf-preview checkbox to ui settings
This commit is contained in:
		| @@ -84,7 +84,7 @@ type alias Model = | ||||
|     , sentMailsOpen : Bool | ||||
|     , attachMeta : Dict String Comp.AttachmentMeta.Model | ||||
|     , attachMetaOpen : Bool | ||||
|     , pdfNativeView : Bool | ||||
|     , pdfNativeView : Maybe Bool | ||||
|     , deleteAttachConfirm : Comp.YesNoDimmer.Model | ||||
|     , addFilesOpen : Bool | ||||
|     , addFilesModel : Comp.Dropzone.Model | ||||
| @@ -170,7 +170,7 @@ emptyModel = | ||||
|     , sentMailsOpen = False | ||||
|     , attachMeta = Dict.empty | ||||
|     , attachMetaOpen = False | ||||
|     , pdfNativeView = False | ||||
|     , pdfNativeView = Nothing | ||||
|     , deleteAttachConfirm = Comp.YesNoDimmer.emptyModel | ||||
|     , addFilesOpen = False | ||||
|     , addFilesModel = Comp.Dropzone.init Comp.Dropzone.defaultSettings | ||||
| @@ -231,7 +231,7 @@ type Msg | ||||
|     | SentMailsResp (Result Http.Error SentMails) | ||||
|     | AttachMetaClick String | ||||
|     | AttachMetaMsg String Comp.AttachmentMeta.Msg | ||||
|     | TogglePdfNativeView | ||||
|     | TogglePdfNativeView Bool | ||||
|     | RequestDeleteAttachment String | ||||
|     | DeleteAttachConfirm String Comp.YesNoDimmer.Msg | ||||
|     | DeleteAttachResp (Result Http.Error BasicResult) | ||||
| @@ -1027,9 +1027,17 @@ update key flags next msg model = | ||||
|                 Nothing -> | ||||
|                     noSub ( model, Cmd.none ) | ||||
|  | ||||
|         TogglePdfNativeView -> | ||||
|         TogglePdfNativeView default -> | ||||
|             noSub | ||||
|                 ( { model | pdfNativeView = not model.pdfNativeView } | ||||
|                 ( { model | ||||
|                     | pdfNativeView = | ||||
|                         case model.pdfNativeView of | ||||
|                             Just flag -> | ||||
|                                 Just (not flag) | ||||
|  | ||||
|                             Nothing -> | ||||
|                                 Just (not default) | ||||
|                   } | ||||
|                 , Cmd.none | ||||
|                 ) | ||||
|  | ||||
| @@ -1328,7 +1336,7 @@ view inav settings model = | ||||
|                 List.concat | ||||
|                     [ [ renderAttachmentsTabMenu model | ||||
|                       ] | ||||
|                     , renderAttachmentsTabBody model | ||||
|                     , renderAttachmentsTabBody settings model | ||||
|                     , renderIdInfo model | ||||
|                     ] | ||||
|             ] | ||||
| @@ -1481,8 +1489,8 @@ renderAttachmentsTabMenu model = | ||||
|         ) | ||||
|  | ||||
|  | ||||
| renderAttachmentView : Model -> Int -> Attachment -> Html Msg | ||||
| renderAttachmentView model pos attach = | ||||
| renderAttachmentView : UiSettings -> Model -> Int -> Attachment -> Html Msg | ||||
| renderAttachmentView settings model pos attach = | ||||
|     let | ||||
|         fileUrl = | ||||
|             "/api/v1/sec/attachment/" ++ attach.id | ||||
| @@ -1513,8 +1521,8 @@ renderAttachmentView model pos attach = | ||||
|                 [ div [ class "ui slider checkbox" ] | ||||
|                     [ input | ||||
|                         [ type_ "checkbox" | ||||
|                         , onCheck (\_ -> TogglePdfNativeView) | ||||
|                         , checked model.pdfNativeView | ||||
|                         , onCheck (\_ -> TogglePdfNativeView settings.nativePdfPreview) | ||||
|                         , checked (Maybe.withDefault settings.nativePdfPreview model.pdfNativeView) | ||||
|                         ] | ||||
|                         [] | ||||
|                     , label [] [ text "Native view" ] | ||||
| @@ -1593,7 +1601,7 @@ renderAttachmentView model pos attach = | ||||
|                 ] | ||||
|             ] | ||||
|             [ iframe | ||||
|                 [ if model.pdfNativeView then | ||||
|                 [ if Maybe.withDefault settings.nativePdfPreview model.pdfNativeView then | ||||
|                     src fileUrl | ||||
|  | ||||
|                   else | ||||
| @@ -1623,8 +1631,8 @@ isAttachMetaOpen model id = | ||||
|     model.attachMetaOpen && (Dict.get id model.attachMeta /= Nothing) | ||||
|  | ||||
|  | ||||
| renderAttachmentsTabBody : Model -> List (Html Msg) | ||||
| renderAttachmentsTabBody model = | ||||
| renderAttachmentsTabBody : UiSettings -> Model -> List (Html Msg) | ||||
| renderAttachmentsTabBody settings model = | ||||
|     let | ||||
|         mailTab = | ||||
|             if Comp.SentMails.isEmpty model.sentMails then | ||||
| @@ -1644,7 +1652,7 @@ renderAttachmentsTabBody model = | ||||
|                     ] | ||||
|                 ] | ||||
|     in | ||||
|     List.indexedMap (renderAttachmentView model) model.item.attachments | ||||
|     List.indexedMap (renderAttachmentView settings model) model.item.attachments | ||||
|         ++ mailTab | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -16,6 +16,7 @@ import Data.UiSettings exposing (StoredUiSettings, UiSettings) | ||||
| import Dict exposing (Dict) | ||||
| import Html exposing (..) | ||||
| import Html.Attributes exposing (..) | ||||
| import Html.Events exposing (onCheck) | ||||
| import Http | ||||
| import Util.List | ||||
|  | ||||
| @@ -25,6 +26,7 @@ type alias Model = | ||||
|     , searchPageSizeModel : Comp.IntField.Model | ||||
|     , tagColors : Dict String String | ||||
|     , tagColorModel : Comp.MappingForm.Model | ||||
|     , nativePdfPreview : Bool | ||||
|     } | ||||
|  | ||||
|  | ||||
| @@ -42,6 +44,7 @@ init flags settings = | ||||
|             Comp.MappingForm.init | ||||
|                 [] | ||||
|                 Data.Color.allString | ||||
|       , nativePdfPreview = settings.nativePdfPreview | ||||
|       } | ||||
|     , Api.getTags flags "" GetTagsResp | ||||
|     ) | ||||
| @@ -51,6 +54,7 @@ type Msg | ||||
|     = SearchPageSizeMsg Comp.IntField.Msg | ||||
|     | TagColorMsg Comp.MappingForm.Msg | ||||
|     | GetTagsResp (Result Http.Error TagList) | ||||
|     | TogglePdfPreview | ||||
|  | ||||
|  | ||||
|  | ||||
| @@ -92,6 +96,15 @@ update sett msg model = | ||||
|             in | ||||
|             ( model_, nextSettings ) | ||||
|  | ||||
|         TogglePdfPreview -> | ||||
|             let | ||||
|                 flag = | ||||
|                     not model.nativePdfPreview | ||||
|             in | ||||
|             ( { model | nativePdfPreview = flag } | ||||
|             , Just { sett | nativePdfPreview = flag } | ||||
|             ) | ||||
|  | ||||
|         GetTagsResp (Ok tl) -> | ||||
|             let | ||||
|                 categories = | ||||
| @@ -139,6 +152,22 @@ view settings model = | ||||
|                 "field" | ||||
|                 model.searchPageSizeModel | ||||
|             ) | ||||
|         , div [ class "ui dividing header" ] | ||||
|             [ text "Item Detail" | ||||
|             ] | ||||
|         , div [ class "field" ] | ||||
|             [ div [ class "ui checkbox" ] | ||||
|                 [ input | ||||
|                     [ type_ "checkbox" | ||||
|                     , onCheck (\_ -> TogglePdfPreview) | ||||
|                     , checked model.nativePdfPreview | ||||
|                     ] | ||||
|                     [] | ||||
|                 , label [] | ||||
|                     [ text "Browser-native PDF preview" | ||||
|                     ] | ||||
|                 ] | ||||
|             ] | ||||
|         , div [ class "ui dividing header" ] | ||||
|             [ text "Tag Category Colors" | ||||
|             ] | ||||
|   | ||||
| @@ -25,6 +25,7 @@ force default settings. | ||||
| type alias StoredUiSettings = | ||||
|     { itemSearchPageSize : Maybe Int | ||||
|     , tagCategoryColors : List ( String, String ) | ||||
|     , nativePdfPreview : Bool | ||||
|     } | ||||
|  | ||||
|  | ||||
| @@ -38,6 +39,7 @@ default value, converting the StoredUiSettings into a UiSettings. | ||||
| type alias UiSettings = | ||||
|     { itemSearchPageSize : Int | ||||
|     , tagCategoryColors : Dict String String | ||||
|     , nativePdfPreview : Bool | ||||
|     } | ||||
|  | ||||
|  | ||||
| @@ -45,6 +47,7 @@ defaults : UiSettings | ||||
| defaults = | ||||
|     { itemSearchPageSize = 60 | ||||
|     , tagCategoryColors = Dict.empty | ||||
|     , nativePdfPreview = False | ||||
|     } | ||||
|  | ||||
|  | ||||
| @@ -55,6 +58,7 @@ merge given fallback = | ||||
|     , tagCategoryColors = | ||||
|         Dict.union (Dict.fromList given.tagCategoryColors) | ||||
|             fallback.tagCategoryColors | ||||
|     , nativePdfPreview = given.nativePdfPreview | ||||
|     } | ||||
|  | ||||
|  | ||||
| @@ -67,6 +71,7 @@ toStoredUiSettings : UiSettings -> StoredUiSettings | ||||
| toStoredUiSettings settings = | ||||
|     { itemSearchPageSize = Just settings.itemSearchPageSize | ||||
|     , tagCategoryColors = Dict.toList settings.tagCategoryColors | ||||
|     , nativePdfPreview = settings.nativePdfPreview | ||||
|     } | ||||
|  | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user