Skip to content

Commit

Permalink
Merge pull request #807 from eikek/gallery-view
Browse files Browse the repository at this point in the history
Configure the initial view for a share url
  • Loading branch information
mergify[bot] authored Jun 26, 2022
2 parents 7dc6e16 + 4422665 commit fc6e5aa
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 23 deletions.
22 changes: 16 additions & 6 deletions modules/webapp/src/main/elm/App/Update.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import App.Data exposing (..)
import Browser exposing (UrlRequest(..))
import Browser.Navigation as Nav
import Data.Flags
import Data.InitialView exposing (InitialView)
import Data.UiTheme
import Page exposing (Page(..))
import Page.Account.Data
Expand Down Expand Up @@ -90,7 +91,16 @@ update msg model =
updateDetail lm model

OpenDetailMsg lm ->
updateOpenDetail lm model
let
initialView =
case model.page of
Page.OpenDetailPage _ iv ->
Data.InitialView.get iv

_ ->
Data.InitialView.default
in
updateOpenDetail initialView lm model

SetPage p ->
( { model | page = p }
Expand Down Expand Up @@ -246,11 +256,11 @@ update msg model =
)


updateOpenDetail : Page.OpenDetail.Data.Msg -> Model -> ( Model, Cmd Msg )
updateOpenDetail lmsg model =
updateOpenDetail : InitialView -> Page.OpenDetail.Data.Msg -> Model -> ( Model, Cmd Msg )
updateOpenDetail initialView lmsg model =
let
( lm, lc ) =
Page.OpenDetail.Update.update model.flags lmsg model.openDetailModel
Page.OpenDetail.Update.update model.flags initialView lmsg model.openDetailModel
in
( { model | openDetailModel = lm }
, Cmd.map OpenDetailMsg lc
Expand Down Expand Up @@ -440,5 +450,5 @@ initPage model page =
DetailPage id ->
updateDetail (Page.Detail.Data.Init id) model

OpenDetailPage id ->
updateOpenDetail (Page.OpenDetail.Data.Init id) model
OpenDetailPage id initialView ->
updateOpenDetail (Data.InitialView.get initialView) (Page.OpenDetail.Data.Init id) model
3 changes: 2 additions & 1 deletion modules/webapp/src/main/elm/App/View.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module App.View exposing (view)
import Api.Model.AuthResult exposing (AuthResult)
import App.Data exposing (..)
import Data.Flags
import Data.InitialView exposing (InitialView)
import Data.UiTheme
import Html exposing (..)
import Html.Attributes exposing (..)
Expand Down Expand Up @@ -328,7 +329,7 @@ mainContent texts model =
DetailPage id ->
viewDetail id texts model

OpenDetailPage id ->
OpenDetailPage id _ ->
viewOpenDetail id texts model
]

Expand Down
53 changes: 53 additions & 0 deletions modules/webapp/src/main/elm/Data/InitialView.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module Data.InitialView exposing (InitialView(..), all, default, fromInt, get, icon, toInt)


type InitialView
= Listing
| Cards
| Zoom


all : List InitialView
all =
[ Listing, Cards, Zoom ]


toInt : InitialView -> Int
toInt view =
case view of
Listing ->
1

Cards ->
2

Zoom ->
3


default : InitialView
default =
Listing


fromInt : Int -> Maybe InitialView
fromInt n =
List.filter (\e -> toInt e == n) all |> List.head


get : Maybe Int -> InitialView
get n =
Maybe.andThen fromInt n |> Maybe.withDefault default


icon : InitialView -> String
icon iv =
case iv of
Listing ->
"fa fa-list"

Cards ->
"fa fa-th"

Zoom ->
"fa fa-eye"
43 changes: 43 additions & 0 deletions modules/webapp/src/main/elm/Messages/DetailPage.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Messages.DetailPage exposing
, gb
)

import Data.InitialView exposing (InitialView)
import Language
import Messages.DateFormat
import Messages.Dropzone2
Expand Down Expand Up @@ -68,6 +69,8 @@ type alias Texts =
, passwordInvalid : String
, or : String
, dateTime : Int -> String
, initialViewLabel : InitialView -> String
, initialViewField : String
}


Expand Down Expand Up @@ -134,6 +137,18 @@ gb =
, passwordInvalid = "Password invalid"
, or = "Or"
, dateTime = Messages.DateFormat.formatDateTime Language.English
, initialViewLabel =
\iv ->
case iv of
Data.InitialView.Listing ->
"Listing"

Data.InitialView.Cards ->
"Cards"

Data.InitialView.Zoom ->
"Preview"
, initialViewField = "Initial view"
}


Expand Down Expand Up @@ -201,9 +216,25 @@ de =
, passwordInvalid = "Passwort ungültig"
, or = "Oder"
, dateTime = Messages.DateFormat.formatDateTime Language.German
, initialViewLabel =
\iv ->
case iv of
Data.InitialView.Listing ->
"Liste"

Data.InitialView.Cards ->
"Kacheln"

Data.InitialView.Zoom ->
"Vorschau"
, initialViewField = "Anfangsansicht"
}



-- TODO check French translations


fr : Texts
fr =
{ mailSend = Messages.MailSend.fr
Expand Down Expand Up @@ -267,4 +298,16 @@ fr =
, passwordInvalid = "Mot de passe invalide"
, or = "Ou"
, dateTime = Messages.DateFormat.formatDateTime Language.French
, initialViewLabel =
\iv ->
case iv of
Data.InitialView.Listing ->
"Listing"

Data.InitialView.Cards ->
"Cards"

Data.InitialView.Zoom ->
"Preview"
, initialViewField = "Initial view"
}
21 changes: 15 additions & 6 deletions modules/webapp/src/main/elm/Page.elm
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Page
| OpenSharePage String
| SettingsPage
| DetailPage String
| OpenDetailPage String
| OpenDetailPage String (Maybe Int)


isSecured : Page -> Bool
Expand Down Expand Up @@ -78,7 +78,7 @@ isSecured page =
DetailPage _ ->
True

OpenDetailPage _ ->
OpenDetailPage _ _ ->
False


Expand Down Expand Up @@ -142,7 +142,7 @@ pageToString page =
HomePage ->
"/app/home"

LoginPage ( referer, oauth ) ->
LoginPage ( referer, _ ) ->
Maybe.map (\p -> "?r=" ++ p) referer
|> Maybe.withDefault ""
|> (++) "/app/login"
Expand Down Expand Up @@ -187,8 +187,17 @@ pageToString page =
DetailPage id ->
"/app/upload/" ++ id

OpenDetailPage id ->
"/app/open/" ++ id
OpenDetailPage id initialView ->
let
viewParam =
case initialView of
Just n ->
"?view=" ++ String.fromInt n

Nothing ->
""
in
"/app/open/" ++ id ++ viewParam


pageFromString : String -> Maybe Page
Expand Down Expand Up @@ -245,7 +254,7 @@ parser =
, Parser.map OpenSharePage (s pathPrefix </> s "share" </> string)
, Parser.map SharePage (s pathPrefix </> s "share")
, Parser.map SettingsPage (s pathPrefix </> s "settings")
, Parser.map OpenDetailPage (s pathPrefix </> s "open" </> string)
, Parser.map OpenDetailPage (s pathPrefix </> s "open" </> string <?> Query.int "view")
]


Expand Down
4 changes: 4 additions & 0 deletions modules/webapp/src/main/elm/Page/Detail/Data.elm
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import Comp.PasswordInput
import Comp.ShareFileList
import Comp.ValidityField
import Data.Flags exposing (Flags)
import Data.InitialView exposing (InitialView)
import Data.UploadDict exposing (UploadDict)
import Data.UploadState exposing (UploadState)
import Data.ValidityValue exposing (ValidityValue)
Expand All @@ -49,6 +50,7 @@ type alias Model =
, uploadPaused : Bool
, uploadFormState : BasicResult
, mailForm : Maybe Comp.MailSend.Model
, shareUrlMode : InitialView
}


Expand Down Expand Up @@ -109,6 +111,7 @@ emptyModel =
, uploadPaused = True
, uploadFormState = BasicResult True ""
, mailForm = Nothing
, shareUrlMode = Data.InitialView.default
}


Expand Down Expand Up @@ -191,6 +194,7 @@ type Msg
| InitMail
| CopyToClipboard String
| EditKey (Maybe KeyCode)
| SetShareUrlMode InitialView


isPublished : ShareDetail -> PublishState
Expand Down
3 changes: 3 additions & 0 deletions modules/webapp/src/main/elm/Page/Detail/Update.elm
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,9 @@ update flags msg model =
CopyToClipboard _ ->
( model, Cmd.none )

SetShareUrlMode iv ->
( { model | shareUrlMode = iv }, Cmd.none )


trackUpload : Model -> UploadState -> Model
trackUpload model state =
Expand Down
30 changes: 29 additions & 1 deletion modules/webapp/src/main/elm/Page/Detail/View.elm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Comp.ShareFileList exposing (ViewMode(..))
import Comp.ValidityField
import Comp.Zoom
import Data.Flags exposing (Flags)
import Data.InitialView
import Data.ValidityOptions
import Html exposing (..)
import Html.Attributes exposing (..)
Expand Down Expand Up @@ -171,7 +172,7 @@ shareLinkPublished texts flags model =
|> Maybe.withDefault ""

url =
flags.config.baseUrl ++ Page.pageToString (OpenDetailPage pid)
flags.config.baseUrl ++ Page.pageToString (OpenDetailPage pid (Just <| Data.InitialView.toInt model.shareUrlMode))

qrCodeView : String -> Html msg
qrCodeView message =
Expand All @@ -192,6 +193,12 @@ shareLinkPublished texts flags model =
]
, text texts.shareAsYouLike
]
, div [ class "flex flex-row space-x-2 items-center" ]
[ div [ class "flex-grow text-right" ]
[ text texts.initialViewField
]
, showUrlSwitch texts model
]
, case model.mailForm of
Just mf ->
Html.map MailFormMsg
Expand Down Expand Up @@ -239,6 +246,27 @@ shareLinkPublished texts flags model =
]


showUrlSwitch : Texts -> Model -> Html Msg
showUrlSwitch texts model =
MB.view
{ start = []
, end =
List.map
(\iv ->
MB.ToggleButton
{ tagger = SetShareUrlMode iv
, title = texts.initialViewLabel iv
, icon = Just <| Data.InitialView.icon iv
, label = texts.initialViewLabel iv
, active = model.shareUrlMode == iv
}
)
Data.InitialView.all
, rootClasses = "py-1 text-xs"
, sticky = False
}


messageDiv : Model -> Html Msg
messageDiv model =
Util.Html.resultMsgMaybe model.message
Expand Down
Loading

0 comments on commit fc6e5aa

Please sign in to comment.