Add lamassu-admin-elm to this repo (#185)
This commit is contained in:
parent
5ee7e40872
commit
f4fc9d6328
134 changed files with 28171 additions and 83 deletions
15
lamassu-admin-elm/src/Customers/Rest.elm
Normal file
15
lamassu-admin-elm/src/Customers/Rest.elm
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
module Customers.Rest exposing (..)
|
||||
|
||||
import RemoteData exposing (..)
|
||||
import Http
|
||||
import HttpBuilder exposing (..)
|
||||
import Common.Customer.Decoder exposing (customersDecoder)
|
||||
import Customers.Types exposing (..)
|
||||
|
||||
|
||||
getCustomers : Cmd Msg
|
||||
getCustomers =
|
||||
get ("/api/customers")
|
||||
|> withExpect (Http.expectJson customersDecoder)
|
||||
|> send RemoteData.fromResult
|
||||
|> Cmd.map Load
|
||||
27
lamassu-admin-elm/src/Customers/State.elm
Normal file
27
lamassu-admin-elm/src/Customers/State.elm
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
module Customers.State exposing (..)
|
||||
|
||||
import RemoteData exposing (..)
|
||||
import Customers.Rest exposing (..)
|
||||
import Customers.Types exposing (..)
|
||||
|
||||
|
||||
init : Model
|
||||
init =
|
||||
NotAsked
|
||||
|
||||
|
||||
loadCmd : Cmd Msg
|
||||
loadCmd =
|
||||
getCustomers
|
||||
|
||||
|
||||
load : ( Model, Cmd Msg )
|
||||
load =
|
||||
( Loading, loadCmd )
|
||||
|
||||
|
||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||
update msg model =
|
||||
case msg of
|
||||
Load loadedModel ->
|
||||
loadedModel ! []
|
||||
12
lamassu-admin-elm/src/Customers/Types.elm
Normal file
12
lamassu-admin-elm/src/Customers/Types.elm
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
module Customers.Types exposing (..)
|
||||
|
||||
import RemoteData exposing (..)
|
||||
import Common.Customer.Types exposing (..)
|
||||
|
||||
|
||||
type alias Model =
|
||||
RemoteData.WebData Customers
|
||||
|
||||
|
||||
type Msg
|
||||
= Load Model
|
||||
70
lamassu-admin-elm/src/Customers/View.elm
Normal file
70
lamassu-admin-elm/src/Customers/View.elm
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
module Customers.View exposing (..)
|
||||
|
||||
import Html exposing (..)
|
||||
import Html.Attributes exposing (colspan, href)
|
||||
import Css.Admin exposing (..)
|
||||
import Css.Classes as C
|
||||
import RemoteData exposing (..)
|
||||
import List
|
||||
import Common.Customer.Types exposing (..)
|
||||
import Customers.Types exposing (..)
|
||||
import Date.Extra exposing (toFormattedString)
|
||||
|
||||
|
||||
customerLink : String -> Html Msg
|
||||
customerLink id =
|
||||
a [ href ("/#customer/" ++ id) ] [ text (String.left 8 id) ]
|
||||
|
||||
|
||||
maybeText : Maybe String -> Html Msg
|
||||
maybeText maybeString =
|
||||
text (Maybe.withDefault "" maybeString)
|
||||
|
||||
|
||||
rowView : Customer -> Html Msg
|
||||
rowView customer =
|
||||
tr [ class [] ]
|
||||
[ td [] [ customerLink customer.id ]
|
||||
, td [] [ text (toFormattedString "yyyy-MM-dd HH:mm" customer.created) ]
|
||||
, td [] [ maybeText customer.phone ]
|
||||
, td [] [ maybeText customer.name ]
|
||||
, td [] [ maybeText customer.status ]
|
||||
]
|
||||
|
||||
|
||||
tableView : Customers -> Html Msg
|
||||
tableView customers =
|
||||
if List.isEmpty customers then
|
||||
div [] [ text "No customers yet." ]
|
||||
else
|
||||
div []
|
||||
[ h1 [] [ text "Customers" ]
|
||||
, table [ class [ C.TxTable ] ]
|
||||
[ thead []
|
||||
[ tr []
|
||||
[ td [] [ text "Id" ]
|
||||
, td [] [ text "Created" ]
|
||||
, td [] [ text "Phone" ]
|
||||
, td [] [ text "Name" ]
|
||||
, td [] [ text "Status" ]
|
||||
]
|
||||
]
|
||||
, tbody [] (List.map rowView customers)
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
view : Model -> Html Msg
|
||||
view model =
|
||||
case model of
|
||||
NotAsked ->
|
||||
div [] []
|
||||
|
||||
Loading ->
|
||||
div [] [ text "Loading..." ]
|
||||
|
||||
Failure err ->
|
||||
div [] [ text (toString err) ]
|
||||
|
||||
Success customers ->
|
||||
div [] [ tableView customers ]
|
||||
Loading…
Add table
Add a link
Reference in a new issue