mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-23 10:58:26 +00:00
Using elm-format for all files
This commit is contained in:
@ -1,37 +1,55 @@
|
||||
module Page.NewInvite.Data exposing (..)
|
||||
module Page.NewInvite.Data exposing
|
||||
( Model
|
||||
, Msg(..)
|
||||
, State(..)
|
||||
, emptyModel
|
||||
, isFailed
|
||||
, isSuccess
|
||||
)
|
||||
|
||||
import Http
|
||||
import Api.Model.InviteResult exposing (InviteResult)
|
||||
import Http
|
||||
|
||||
|
||||
type alias Model =
|
||||
{ password: String
|
||||
, result: State
|
||||
{ password : String
|
||||
, result : State
|
||||
}
|
||||
|
||||
|
||||
type State
|
||||
= Empty
|
||||
| Failed String
|
||||
| Success InviteResult
|
||||
|
||||
|
||||
isFailed: State -> Bool
|
||||
isFailed : State -> Bool
|
||||
isFailed state =
|
||||
case state of
|
||||
Failed _ -> True
|
||||
_ -> False
|
||||
Failed _ ->
|
||||
True
|
||||
|
||||
isSuccess: State -> Bool
|
||||
_ ->
|
||||
False
|
||||
|
||||
|
||||
isSuccess : State -> Bool
|
||||
isSuccess state =
|
||||
case state of
|
||||
Success _ -> True
|
||||
_ -> False
|
||||
Success _ ->
|
||||
True
|
||||
|
||||
emptyModel: Model
|
||||
_ ->
|
||||
False
|
||||
|
||||
|
||||
emptyModel : Model
|
||||
emptyModel =
|
||||
{ password = ""
|
||||
, result = Empty
|
||||
}
|
||||
|
||||
|
||||
type Msg
|
||||
= SetPassword String
|
||||
| GenerateInvite
|
||||
|
@ -1,27 +1,30 @@
|
||||
module Page.NewInvite.Update exposing (update)
|
||||
|
||||
import Api
|
||||
import Api.Model.GenInvite exposing (GenInvite)
|
||||
import Data.Flags exposing (Flags)
|
||||
import Page.NewInvite.Data exposing (..)
|
||||
import Api.Model.GenInvite exposing (GenInvite)
|
||||
import Api.Model.InviteResult
|
||||
import Util.Http
|
||||
|
||||
update: Flags -> Msg -> Model -> (Model, Cmd Msg)
|
||||
|
||||
update : Flags -> Msg -> Model -> ( Model, Cmd Msg )
|
||||
update flags msg model =
|
||||
case msg of
|
||||
SetPassword str ->
|
||||
({model|password = str}, Cmd.none)
|
||||
( { model | password = str }, Cmd.none )
|
||||
|
||||
Reset ->
|
||||
(emptyModel, Cmd.none)
|
||||
( emptyModel, Cmd.none )
|
||||
|
||||
GenerateInvite ->
|
||||
(model, Api.newInvite flags (GenInvite model.password) InviteResp)
|
||||
( model, Api.newInvite flags (GenInvite model.password) InviteResp )
|
||||
|
||||
InviteResp (Ok res) ->
|
||||
if res.success then ({model | result = (Success res)}, Cmd.none)
|
||||
else ({model | result = (Failed res.message)}, Cmd.none)
|
||||
if res.success then
|
||||
( { model | result = Success res }, Cmd.none )
|
||||
|
||||
else
|
||||
( { model | result = Failed res.message }, Cmd.none )
|
||||
|
||||
InviteResp (Err err) ->
|
||||
({model|result = Failed (Util.Http.errorToString err)}, Cmd.none)
|
||||
( { model | result = Failed (Util.Http.errorToString err) }, Cmd.none )
|
||||
|
@ -1,106 +1,121 @@
|
||||
module Page.NewInvite.View exposing (view)
|
||||
|
||||
import Data.Flags exposing (Flags)
|
||||
import Html exposing (..)
|
||||
import Html.Attributes exposing (..)
|
||||
import Html.Events exposing (onClick, onInput, onSubmit)
|
||||
import Data.Flags exposing (Flags)
|
||||
import Page.NewInvite.Data exposing (..)
|
||||
import Api.Model.InviteResult
|
||||
import Util.Maybe
|
||||
|
||||
view: Flags -> Model -> Html Msg
|
||||
|
||||
view : Flags -> Model -> Html Msg
|
||||
view flags model =
|
||||
div [class "newinvite-page"]
|
||||
[div [class "ui centered grid"]
|
||||
[div [class "row"]
|
||||
[div [class "eight wide column ui segment newinvite-view"]
|
||||
[h1 [class "ui cener aligned icon header"]
|
||||
[img [class "ui image"
|
||||
,src (flags.config.docspellAssetPath ++ "/img/logo-96.png")
|
||||
][]
|
||||
,div [class "content"]
|
||||
[text "Create new invitations"
|
||||
div [ class "newinvite-page" ]
|
||||
[ div [ class "ui centered grid" ]
|
||||
[ div [ class "row" ]
|
||||
[ div [ class "eight wide column ui segment newinvite-view" ]
|
||||
[ h1 [ class "ui cener aligned icon header" ]
|
||||
[ img
|
||||
[ class "ui image"
|
||||
, src (flags.config.docspellAssetPath ++ "/img/logo-96.png")
|
||||
]
|
||||
[]
|
||||
, div [ class "content" ]
|
||||
[ text "Create new invitations"
|
||||
]
|
||||
]
|
||||
, inviteMessage flags
|
||||
, Html.form
|
||||
[ classList
|
||||
[ ( "ui large form raised segment", True )
|
||||
, ( "error", isFailed model.result )
|
||||
, ( "success", isSuccess model.result )
|
||||
]
|
||||
, onSubmit GenerateInvite
|
||||
]
|
||||
[ div [ class "required field" ]
|
||||
[ label [] [ text "New Invitation Password" ]
|
||||
, div [ class "ui left icon input" ]
|
||||
[ input
|
||||
[ type_ "password"
|
||||
, onInput SetPassword
|
||||
, value model.password
|
||||
, autofocus True
|
||||
]
|
||||
[]
|
||||
, i [ class "key icon" ] []
|
||||
]
|
||||
]
|
||||
,inviteMessage flags
|
||||
,Html.form [classList [("ui large form raised segment", True)
|
||||
,("error", isFailed model.result)
|
||||
,("success", isSuccess model.result)
|
||||
]
|
||||
, onSubmit GenerateInvite]
|
||||
[div [class "required field"]
|
||||
[label [][text "New Invitation Password"]
|
||||
,div [class "ui left icon input"]
|
||||
[input [type_ "password"
|
||||
,onInput SetPassword
|
||||
,value model.password
|
||||
,autofocus True
|
||||
][]
|
||||
,i [class "key icon"][]
|
||||
]
|
||||
]
|
||||
,button [class "ui primary button"
|
||||
,type_ "submit"
|
||||
]
|
||||
[text "Submit"
|
||||
]
|
||||
,a [class "ui right floated button", href "", onClick Reset]
|
||||
[text "Reset"
|
||||
]
|
||||
,resultMessage model
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
, button
|
||||
[ class "ui primary button"
|
||||
, type_ "submit"
|
||||
]
|
||||
[ text "Submit"
|
||||
]
|
||||
, a [ class "ui right floated button", href "", onClick Reset ]
|
||||
[ text "Reset"
|
||||
]
|
||||
, resultMessage model
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
resultMessage: Model -> Html Msg
|
||||
|
||||
resultMessage : Model -> Html Msg
|
||||
resultMessage model =
|
||||
div [classList [("ui message", True)
|
||||
,("error", isFailed model.result)
|
||||
,("success", isSuccess model.result)
|
||||
,("hidden", model.result == Empty)
|
||||
]]
|
||||
[case model.result of
|
||||
Failed m ->
|
||||
div [class "content"]
|
||||
[div [class "header"][text "Error"]
|
||||
,p [][text m]
|
||||
]
|
||||
Success r ->
|
||||
div [class "content"]
|
||||
[div [class "header"][text "Success"]
|
||||
,p [][text r.message]
|
||||
,p [][text "Invitation Key:"]
|
||||
,pre[][Maybe.withDefault "" r.key |> text
|
||||
]
|
||||
]
|
||||
Empty ->
|
||||
span[][]
|
||||
div
|
||||
[ classList
|
||||
[ ( "ui message", True )
|
||||
, ( "error", isFailed model.result )
|
||||
, ( "success", isSuccess model.result )
|
||||
, ( "hidden", model.result == Empty )
|
||||
]
|
||||
]
|
||||
[ case model.result of
|
||||
Failed m ->
|
||||
div [ class "content" ]
|
||||
[ div [ class "header" ] [ text "Error" ]
|
||||
, p [] [ text m ]
|
||||
]
|
||||
|
||||
Success r ->
|
||||
div [ class "content" ]
|
||||
[ div [ class "header" ] [ text "Success" ]
|
||||
, p [] [ text r.message ]
|
||||
, p [] [ text "Invitation Key:" ]
|
||||
, pre []
|
||||
[ Maybe.withDefault "" r.key |> text
|
||||
]
|
||||
]
|
||||
|
||||
Empty ->
|
||||
span [] []
|
||||
]
|
||||
|
||||
inviteMessage: Flags -> Html Msg
|
||||
inviteMessage flags =
|
||||
div [classList [("ui message", True)
|
||||
,("hidden", flags.config.signupMode /= "invite")
|
||||
]]
|
||||
[p [][text
|
||||
|
||||
"""Docspell requires an invite when signing up. You can
|
||||
inviteMessage : Flags -> Html Msg
|
||||
inviteMessage flags =
|
||||
div
|
||||
[ classList
|
||||
[ ( "ui message", True )
|
||||
, ( "hidden", flags.config.signupMode /= "invite" )
|
||||
]
|
||||
]
|
||||
[ p []
|
||||
[ text
|
||||
"""Docspell requires an invite when signing up. You can
|
||||
create these invites here and send them to friends so
|
||||
they can signup with docspell."""
|
||||
|
||||
]
|
||||
,p [][text
|
||||
|
||||
"""Each invite can only be used once. You'll need to
|
||||
]
|
||||
, p []
|
||||
[ text
|
||||
"""Each invite can only be used once. You'll need to
|
||||
create one key for each person you want to invite."""
|
||||
|
||||
]
|
||||
,p [][text
|
||||
|
||||
"""Creating an invite requires providing the password
|
||||
]
|
||||
, p []
|
||||
[ text
|
||||
"""Creating an invite requires providing the password
|
||||
from the configuration."""
|
||||
|
||||
]
|
||||
]
|
||||
]
|
||||
|
Reference in New Issue
Block a user