aboutsummaryrefslogtreecommitdiff
path: root/picarones-elm/src/Cover.elm
blob: fee40c01ca3b2342805cf5aed09f396e1a552ab9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
module Cover exposing (..)

import Browser
import Html exposing (..)
import Html.Events exposing (onInput, onClick)
import Html.Attributes exposing (..)


main = Browser.document { init = init, update = update, view = view, subscriptions = (\m -> Sub.none)}



type alias Model = (String, Int, String)

init : String -> (Model, Cmd Msg)
init baseurl = (("", 10, baseurl), Cmd.none)

type Msg = Change String | SlideInc | SlideDec

update : Msg -> Model -> (Model, Cmd Msg)
update msg (prefix,m,b) = let model = case msg of
                                          Change new -> (new, m, b)
                                          SlideInc -> (prefix, m + 1, b)
                                          SlideDec -> (prefix, Basics.max (m - 1) 1, b)
                          in (model, Cmd.none)


view : Model -> Browser.Document Msg
view model = { title = "Picarones"
             , body = [body model]
             }


body : Model -> Html Msg
body (prefix, max, baseurl) =
  div [class "input-form"] [ h1 [] [text "Create new slide session:"], div [] []
         , div [ class "grid" ]
             [ divtext "enter slide uri:", input [ placeholder "https://yourdomain.tld/path-to-slides", value prefix, onInput Change ] []
             , divtext "number of slides:", mkNumberInput max
             , divtext "your link:", mkLink (prefix, max, baseurl)
             ]
         , mkRemark prefix
         ]

divtext : String -> Html Msg
divtext str = div [class "gridentry"] [text str]

mkNumberInput : Int -> Html Msg
mkNumberInput i =
    span []
        [ button [onClick SlideDec] [text "-"]
        , text (String.fromInt i)
        , button [onClick SlideInc] [text "+"]
        ]

mkLink : Model -> Html Msg
mkLink (p, max, baseurl) = case p of
    "" -> text "(none yet)"
    prefix -> let link = baseurl ++ "/slide.html#" ++ prefix ++ "#" ++ (String.fromInt max)
              in a [ href link ] [ text link ]


mkRemark : String -> Html Msg
mkRemark prefix = let example = case prefix of
                                    "" -> "https://yourdomain.tld/path-to-slides/01.png"
                                    _ -> prefix ++ "01.png"
                  in div [class "remark"] [
                       p [] [text ("""Your slides should be available at the above uri, postfixed with a
                                      double-digit  number and a .png extension, e.g. """ ++ example ++
                                    " should contain an image.")]
                      , p [] [text "You can convert a pdf to images like this:"]
                      , pre [] [text "pdftoppm -png slides.pdf -scale-to-y 1080 -scale-to-x -1 slide"]
                      ]