cleans up project structure

This commit is contained in:
2019-12-05 22:01:16 +01:00
parent 2c3f4ffc57
commit eb04c4f2b4
10 changed files with 78 additions and 1474 deletions

View File

@@ -29,7 +29,7 @@ icon params =
btn : msg -> { text : String, icon : String, color : String } -> Html msg
btn msg params =
button
[ class <| "button is-medium level-item " ++ params.color
[ class <| "button " ++ params.color
, onClick msg
]
[ icon { icon = params.icon, size = Nothing, ratio = Nothing }
@@ -38,7 +38,7 @@ btn msg params =
buttons btns =
div [ class "buttons" ] btns
div [ class "buttons level-item" ] btns
confirmButtons confirm cancel =
@@ -66,3 +66,7 @@ datatable headers rows =
headers
, tbody [] rows
]
-- Section

View File

@@ -1,9 +1,9 @@
module Page.Chest exposing (..)
module Chest exposing (..)
import Api exposing (Claims, Item, Loot)
import Chest.NewFromInventory as NewFromInventory
import Chest.Selection as Selection
import Html exposing (..)
import Page.Chest.NewFromInventory as NewFromInventory
import Page.Chest.Selection as Selection
import Table
import Utils

View File

@@ -1,6 +1,7 @@
module Page.Chest.NewFromInventory exposing (..)
module Chest.NewFromInventory exposing (..)
import Api exposing (Item, Loot)
import Bulma as B
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
@@ -25,25 +26,22 @@ init =
view : Model -> Html Msg
view model =
article []
[ div [ class "section" ]
[ textarea
[ class "textarea"
, value model.itemList
, onInput ItemListInput
, placeholder "Coller une liste d'objets"
]
[]
, button
[ class "button is-primary is-fullwidth"
, onClick ItemListSend
]
[ text "Mettre dans le coffre" ]
[ textarea
[ class "textarea"
, value model.itemList
, onInput ItemListInput
, placeholder "Coller une liste d'objets"
]
, div [ class "section" ]
[ model.validItems
++ model.invalidItems
|> Table.view (Table.renderRowLevel viewOrEditRenderer (\i -> []))
[]
, button
[ class "button is-primary is-fullwidth"
, onClick ItemListSend
]
[ text "Mettre dans le coffre" ]
, hr [] []
, model.validItems
++ model.invalidItems
|> Table.view (Table.renderRowLevel viewOrEditRenderer (\i -> []))
]
@@ -72,18 +70,21 @@ viewOrEditRenderer item =
priceValid =
item.base_price > 0
itemValid =
nameValid && priceValid
in
[ div [ class "field is-grouped" ]
[ div [ class "control" ]
[ input
[ class "input is-small "
, type_ "text"
, value item.name
, onInput <| InvalidItemNameChanged item.id
]
[]
[ div [ class "field level-item" ]
[ input
[ class "input is-small "
, type_ "text"
, value item.name
, onInput <| InvalidItemNameChanged item.id
]
, div [ class "control" ]
[]
]
, div [ class "field has-addons level-item" ]
[ p [ class "control" ]
[ input
[ class "input is-small "
, type_ "text"
@@ -92,7 +93,13 @@ viewOrEditRenderer item =
]
[]
]
, p [ class "control is-small" ] [ a [ class "button is-static" ] [ text "Prix" ] ]
]
, if itemValid then
B.icon { icon = "fas fa-check", size = Nothing, ratio = Nothing }
else
B.icon { icon = "fas fa-times", size = Nothing, ratio = Nothing }
]
else

View File

@@ -1,4 +1,4 @@
module Page.Chest.Selection exposing (Model, Msg, init, modifiers, selected, update, view)
module Chest.Selection exposing (Model, Msg, init, modifiers, selected, update, view)
import Api exposing (Item, Loot)
import Dict exposing (Dict)

View File

@@ -1,181 +0,0 @@
module Page.Admin exposing (Model)
import Api exposing (Loot)
import Api.Player as Player exposing (Player, Wealth)
import Browser.Navigation as Nav
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Page.Shop as Shop
import Route exposing (Route)
import Session exposing (Session)
type alias NewPlayerForm =
{ name : String
, wealth : Float
}
type alias Status =
{ session : Session
, players : List Player
, newPlayer : NewPlayerForm
}
type Model
= Dashboard Status
| MerchantLoot Shop.Model
init : Session -> ( Model, Cmd Msg )
init session =
( Dashboard (Status session [] (NewPlayerForm "" 0.0))
, Player.list GotPlayers
)
getSession model =
case model of
Dashboard status ->
Session.getSession status
MerchantLoot shop ->
Session.getSession shop
view : Model -> List (Html Msg)
view model =
case model of
Dashboard config ->
[ div [ class "container" ]
[ p [ class "title" ] [ text "Administration" ]
, div [ class "section" ]
[ table [ class "table is-fullwidth is-striped" ]
[ thead [ class "table-header" ]
[ th [] [ text "Joueurs" ] ]
, tbody [] <|
editNewPlayer config.newPlayer
:: List.map viewPlayer config.players
]
]
, div [ class "section" ]
[ p [] [ text "Campagnes" ] ]
]
]
MerchantLoot shop ->
let
toShopMsg =
Html.map ShopMsg
( controls, viewShop ) =
Shop.view shop
|> Tuple.mapBoth toShopMsg (List.map toShopMsg)
in
[ div [ class "container" ] <|
p [ class "title" ] [ text "Marchand" ]
:: controls
:: viewShop
]
viewPlayer : Player -> Html Msg
viewPlayer player =
tr [] [ td [] [ p [] [ text (player.name ++ " (" ++ String.fromInt player.id ++ ")") ] ] ]
editNewPlayer : NewPlayerForm -> Html Msg
editNewPlayer newPlayer =
tr []
[ td []
[ div [ class "field is-horizontal" ]
[ div [ class "field-body" ]
[ div [ class "field" ]
[ input
[ class "input"
, type_ "text"
, value newPlayer.name
, onInput <| GotFormMsg << NameChanged
]
[]
]
, div [ class "field" ]
[ input
[ class "input"
, type_ "text"
, value <| String.fromFloat newPlayer.wealth
, onInput <| GotFormMsg << WealthChanged
]
[]
]
]
]
]
]
type Msg
= GotPlayers (List Player)
| GotFormMsg FormMsg
| ShopMsg Shop.Msg
type FormMsg
= NameChanged String
| WealthChanged String
updateForm : FormMsg -> NewPlayerForm -> NewPlayerForm
updateForm msg form =
case msg of
NameChanged newName ->
{ form | name = newName }
WealthChanged newWealth ->
{ form | wealth = Maybe.withDefault 0.0 <| String.toFloat newWealth }
routeChanged : Route.Route -> Model -> ( Model, Cmd Msg )
routeChanged route model =
case model of
Dashboard config ->
case route of
Route.Home Route.MerchantLoot ->
Tuple.mapBoth
MerchantLoot
(Cmd.map ShopMsg)
(config.session |> Shop.init)
_ ->
( model, Cmd.none )
MerchantLoot shop ->
case route of
Route.Home Route.PlayerLoot ->
init shop.session
_ ->
( model, Cmd.none )
update msg model =
case ( msg, model ) of
( GotPlayers players, Dashboard config ) ->
( Dashboard { config | players = players }, Cmd.none )
( GotFormMsg formMsg, Dashboard config ) ->
( Dashboard { config | newPlayer = updateForm formMsg config.newPlayer }, Cmd.none )
( _, Dashboard _ ) ->
( model, Cmd.none )
( ShopMsg shopMsg, MerchantLoot shopModel ) ->
Shop.update shopMsg shopModel
|> Tuple.mapBoth
MerchantLoot
(Cmd.map ShopMsg)
( _, MerchantLoot _ ) ->
( model, Cmd.none )

File diff suppressed because it is too large Load Diff

View File

@@ -3,10 +3,10 @@ module Page.Dashboard exposing (Model, Msg(..), getSession, init, update, update
import Api
import Api.Player as Player exposing (Player, Wealth)
import Bulma as B
import Chest exposing (Chest)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Page.Chest as Chest exposing (Chest)
import Session exposing (Session)
@@ -99,16 +99,34 @@ view model =
Chest.View _ ->
case data.player.id of
0 ->
buttons [ modeButton "Vendre" (GotChestMsg Chest.sell), modeButton "Ajouter" (GotChestMsg Chest.new) ]
buttons
[ B.btn
(GotChestMsg Chest.sell)
{ text = "Vendre"
, icon = "fas fa-coins"
, color = "is-primary"
}
, B.btn
(GotChestMsg Chest.new)
{ text = "Nouveau loot"
, icon = "fas fa-plus"
, color = "is-primary"
}
]
_ ->
modeButton "Vendre" (GotChestMsg Chest.sell)
B.btn
(GotChestMsg Chest.sell)
{ text = "Vendre"
, icon = "fas fa-coins"
, color = "is-primary"
}
Chest.Sell _ ->
buttons [ modeButton "Ok" ConfirmSell, modeButton "Annuler" toShow ]
B.confirmButtons ConfirmSell toShow
Chest.New _ ->
buttons [ modeButton "Ok" ConfirmAdd, modeButton "Annuler" toShow ]
B.confirmButtons ConfirmAdd toShow
_ ->
text ""
@@ -126,7 +144,12 @@ view model =
Admin (AdminConfig session players playerForm) ->
( case playerForm of
Nothing ->
B.btn (AdminViewer EditPlayer) { text = "Ajouter un joueur", icon = "fas fa-plus", color = "is-primary" }
B.btn
(AdminViewer EditPlayer)
{ text = "Ajouter un joueur"
, icon = "fas fa-plus"
, color = "is-primary"
}
Just _ ->
B.confirmButtons ConfirmNewPlayer CloseEdit

View File

@@ -2,10 +2,10 @@ module Page.GroupChest exposing (Model, Msg(..), init, update, view)
import Api exposing (HttpResult, Loot)
import Bulma as B
import Chest exposing (Chest)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Page.Chest as Chest exposing (Chest)
import Session exposing (Session, User(..))

View File

@@ -1,7 +0,0 @@
module Page.LoggedOut exposing (view)
import Html exposing (..)
import Html.Attributes exposing (..)
view =
p [ class "header is-1" ] [ text "Loot-a-lot" ]

View File

@@ -2,11 +2,11 @@ module Page.Shop exposing (Model, Msg(..), init, update, view)
import Api exposing (HttpResult, Item, Loot)
import Bulma as B
import Chest exposing (Chest)
import Chest.NewFromInventory as NewChest
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Page.Chest as Chest exposing (Chest)
import Page.Chest.NewFromInventory as NewChest
import Session exposing (Session, getSession)
@@ -44,7 +44,7 @@ view model =
( Html.map Internal <|
case ( model.chest, Session.user model.session ) of
( Chest.View _, Session.Admin _ ) ->
B.btn (GotChestMsg Chest.new) { text = "Remplacer", icon = "fas fa-refresh", color = "is-primary" }
B.btn (GotChestMsg Chest.new) { text = "Remplacer", icon = "fas fa-sync-alt", color = "is-primary" }
( Chest.View _, Session.Player _ ) ->
B.btn (GotChestMsg Chest.buy) { text = "Acheter", icon = "fas fa-coins", color = "is-primary" }