Skip to content
This repository has been archived by the owner on Nov 11, 2019. It is now read-only.

Commit

Permalink
releng_frontend: recent changes form
Browse files Browse the repository at this point in the history
  • Loading branch information
garbas committed Jan 17, 2017
1 parent e1a8789 commit 9e589a4
Show file tree
Hide file tree
Showing 10 changed files with 538 additions and 297 deletions.
23 changes: 21 additions & 2 deletions lib/elm_common/TaskclusterLogin.elm
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
port module TaskclusterLogin exposing (..)

import Dict exposing (Dict)
import Html exposing (..)
import Html.Attributes exposing (..)
import Dict exposing (Dict)
import Json.Decode as JsonDecode exposing ((:=))
import Redirect
import Maybe
import Redirect
import String


type alias Certificate =
Expand Down Expand Up @@ -119,6 +120,24 @@ redirectToLogin outMsg returnRoute description =



-- UTILS


shortUsername username =
let
parts =
String.split "/" username
in
if List.length parts == 2 then
parts
|> List.reverse
|> List.head
|> Maybe.withDefault username
else
username



-- SUBSCRIPTIONS


Expand Down
46 changes: 27 additions & 19 deletions src/releng_frontend/src/App/Form.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module App.Form exposing (..)


import Form
import Form.Error
import Form.Input
Expand All @@ -10,32 +9,38 @@ import VirtualDom


maybeAppend : Maybe a -> (a -> b) -> List b -> List b
maybeAppend maybeValue f =
maybeAppend maybeValue f =
maybeValue
|> Maybe.map (\x -> [f x])
|> Maybe.map (\x -> [ f x ])
|> Maybe.withDefault []
|> List.append


maybeAppendError : Maybe a -> List (Html b) -> List (Html b)
maybeAppendError maybeError =
maybeAppend maybeError (\x -> div [ class "form-control-feedback" ]
[ text (toString x) ]
)
maybeAppend maybeError
(\x ->
div [ class "form-control-feedback" ]
[ text (toString x) ]
)


maybeAppendHelp : Maybe String -> List (Html a) -> List (Html a)
maybeAppendHelp maybeHelp =
maybeAppend maybeHelp (\x -> small [ class "form-text text-muted" ]
[ text x ]
)
maybeAppend maybeHelp
(\x ->
small [ class "form-text text-muted" ]
[ text x ]
)


maybeAppendLabel : Maybe String -> List (Html a) -> List (Html a)
maybeAppendLabel maybeLabel =
maybeAppend maybeLabel (\x -> label [ class "control-label" ]
[ text x ]
)
maybeAppend maybeLabel
(\x ->
label [ class "control-label" ]
[ text x ]
)


errorClass : Maybe error -> String
Expand All @@ -55,7 +60,7 @@ viewField maybeError maybeLabel helpNodes inputNode =
div
[ class ("form-group " ++ (errorClass maybeError)) ]
([]
|> maybeAppendError maybeError
|> maybeAppendError maybeError
|> List.append [ inputNode ]
|> List.append helpNodes
|> maybeAppendLabel maybeLabel
Expand All @@ -75,9 +80,10 @@ viewTextInput state labelText helpNodes attributes =
helpNodes
(Form.Input.textInput state
(attributes
|> List.append [ class "form-control"
, value (Maybe.withDefault "" state.value)
]
|> List.append
[ class "form-control"
, value (Maybe.withDefault "" state.value)
]
)
)

Expand Down Expand Up @@ -120,8 +126,10 @@ viewCheckboxInput state labelText =

viewButton labelText attributes =
button
(attributes |> List.append [ type' "submit"
, class "btn btn-outline-primary"
]
(attributes
|> List.append
[ type' "submit"
, class "btn btn-outline-primary"
]
)
[ text labelText ]
Loading

0 comments on commit 9e589a4

Please sign in to comment.