cleans up project structure
This commit is contained in:
@@ -29,7 +29,7 @@ icon params =
|
|||||||
btn : msg -> { text : String, icon : String, color : String } -> Html msg
|
btn : msg -> { text : String, icon : String, color : String } -> Html msg
|
||||||
btn msg params =
|
btn msg params =
|
||||||
button
|
button
|
||||||
[ class <| "button is-medium level-item " ++ params.color
|
[ class <| "button " ++ params.color
|
||||||
, onClick msg
|
, onClick msg
|
||||||
]
|
]
|
||||||
[ icon { icon = params.icon, size = Nothing, ratio = Nothing }
|
[ icon { icon = params.icon, size = Nothing, ratio = Nothing }
|
||||||
@@ -38,7 +38,7 @@ btn msg params =
|
|||||||
|
|
||||||
|
|
||||||
buttons btns =
|
buttons btns =
|
||||||
div [ class "buttons" ] btns
|
div [ class "buttons level-item" ] btns
|
||||||
|
|
||||||
|
|
||||||
confirmButtons confirm cancel =
|
confirmButtons confirm cancel =
|
||||||
@@ -66,3 +66,7 @@ datatable headers rows =
|
|||||||
headers
|
headers
|
||||||
, tbody [] rows
|
, tbody [] rows
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- Section
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
module Page.Chest exposing (..)
|
module Chest exposing (..)
|
||||||
|
|
||||||
import Api exposing (Claims, Item, Loot)
|
import Api exposing (Claims, Item, Loot)
|
||||||
|
import Chest.NewFromInventory as NewFromInventory
|
||||||
|
import Chest.Selection as Selection
|
||||||
import Html exposing (..)
|
import Html exposing (..)
|
||||||
import Page.Chest.NewFromInventory as NewFromInventory
|
|
||||||
import Page.Chest.Selection as Selection
|
|
||||||
import Table
|
import Table
|
||||||
import Utils
|
import Utils
|
||||||
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
module Page.Chest.NewFromInventory exposing (..)
|
module Chest.NewFromInventory exposing (..)
|
||||||
|
|
||||||
import Api exposing (Item, Loot)
|
import Api exposing (Item, Loot)
|
||||||
|
import Bulma as B
|
||||||
import Html exposing (..)
|
import Html exposing (..)
|
||||||
import Html.Attributes exposing (..)
|
import Html.Attributes exposing (..)
|
||||||
import Html.Events exposing (..)
|
import Html.Events exposing (..)
|
||||||
@@ -25,25 +26,22 @@ init =
|
|||||||
view : Model -> Html Msg
|
view : Model -> Html Msg
|
||||||
view model =
|
view model =
|
||||||
article []
|
article []
|
||||||
[ div [ class "section" ]
|
[ textarea
|
||||||
[ textarea
|
[ class "textarea"
|
||||||
[ class "textarea"
|
, value model.itemList
|
||||||
, value model.itemList
|
, onInput ItemListInput
|
||||||
, onInput ItemListInput
|
, placeholder "Coller une liste d'objets"
|
||||||
, placeholder "Coller une liste d'objets"
|
|
||||||
]
|
|
||||||
[]
|
|
||||||
, button
|
|
||||||
[ class "button is-primary is-fullwidth"
|
|
||||||
, onClick ItemListSend
|
|
||||||
]
|
|
||||||
[ text "Mettre dans le coffre" ]
|
|
||||||
]
|
]
|
||||||
, div [ class "section" ]
|
[]
|
||||||
[ model.validItems
|
, button
|
||||||
++ model.invalidItems
|
[ class "button is-primary is-fullwidth"
|
||||||
|> Table.view (Table.renderRowLevel viewOrEditRenderer (\i -> []))
|
, 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 =
|
priceValid =
|
||||||
item.base_price > 0
|
item.base_price > 0
|
||||||
|
|
||||||
|
itemValid =
|
||||||
|
nameValid && priceValid
|
||||||
in
|
in
|
||||||
[ div [ class "field is-grouped" ]
|
[ div [ class "field level-item" ]
|
||||||
[ div [ class "control" ]
|
[ input
|
||||||
[ input
|
[ class "input is-small "
|
||||||
[ class "input is-small "
|
, type_ "text"
|
||||||
, type_ "text"
|
, value item.name
|
||||||
, value item.name
|
, onInput <| InvalidItemNameChanged item.id
|
||||||
, onInput <| InvalidItemNameChanged item.id
|
|
||||||
]
|
|
||||||
[]
|
|
||||||
]
|
]
|
||||||
, div [ class "control" ]
|
[]
|
||||||
|
]
|
||||||
|
, div [ class "field has-addons level-item" ]
|
||||||
|
[ p [ class "control" ]
|
||||||
[ input
|
[ input
|
||||||
[ class "input is-small "
|
[ class "input is-small "
|
||||||
, type_ "text"
|
, 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
|
else
|
||||||
@@ -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 Api exposing (Item, Loot)
|
||||||
import Dict exposing (Dict)
|
import Dict exposing (Dict)
|
||||||
@@ -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
@@ -3,10 +3,10 @@ module Page.Dashboard exposing (Model, Msg(..), getSession, init, update, update
|
|||||||
import Api
|
import Api
|
||||||
import Api.Player as Player exposing (Player, Wealth)
|
import Api.Player as Player exposing (Player, Wealth)
|
||||||
import Bulma as B
|
import Bulma as B
|
||||||
|
import Chest exposing (Chest)
|
||||||
import Html exposing (..)
|
import Html exposing (..)
|
||||||
import Html.Attributes exposing (..)
|
import Html.Attributes exposing (..)
|
||||||
import Html.Events exposing (..)
|
import Html.Events exposing (..)
|
||||||
import Page.Chest as Chest exposing (Chest)
|
|
||||||
import Session exposing (Session)
|
import Session exposing (Session)
|
||||||
|
|
||||||
|
|
||||||
@@ -99,16 +99,34 @@ view model =
|
|||||||
Chest.View _ ->
|
Chest.View _ ->
|
||||||
case data.player.id of
|
case data.player.id of
|
||||||
0 ->
|
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 _ ->
|
Chest.Sell _ ->
|
||||||
buttons [ modeButton "Ok" ConfirmSell, modeButton "Annuler" toShow ]
|
B.confirmButtons ConfirmSell toShow
|
||||||
|
|
||||||
Chest.New _ ->
|
Chest.New _ ->
|
||||||
buttons [ modeButton "Ok" ConfirmAdd, modeButton "Annuler" toShow ]
|
B.confirmButtons ConfirmAdd toShow
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
text ""
|
text ""
|
||||||
@@ -126,7 +144,12 @@ view model =
|
|||||||
Admin (AdminConfig session players playerForm) ->
|
Admin (AdminConfig session players playerForm) ->
|
||||||
( case playerForm of
|
( case playerForm of
|
||||||
Nothing ->
|
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 _ ->
|
Just _ ->
|
||||||
B.confirmButtons ConfirmNewPlayer CloseEdit
|
B.confirmButtons ConfirmNewPlayer CloseEdit
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ module Page.GroupChest exposing (Model, Msg(..), init, update, view)
|
|||||||
|
|
||||||
import Api exposing (HttpResult, Loot)
|
import Api exposing (HttpResult, Loot)
|
||||||
import Bulma as B
|
import Bulma as B
|
||||||
|
import Chest exposing (Chest)
|
||||||
import Html exposing (..)
|
import Html exposing (..)
|
||||||
import Html.Attributes exposing (..)
|
import Html.Attributes exposing (..)
|
||||||
import Html.Events exposing (..)
|
import Html.Events exposing (..)
|
||||||
import Page.Chest as Chest exposing (Chest)
|
|
||||||
import Session exposing (Session, User(..))
|
import Session exposing (Session, User(..))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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" ]
|
|
||||||
@@ -2,11 +2,11 @@ module Page.Shop exposing (Model, Msg(..), init, update, view)
|
|||||||
|
|
||||||
import Api exposing (HttpResult, Item, Loot)
|
import Api exposing (HttpResult, Item, Loot)
|
||||||
import Bulma as B
|
import Bulma as B
|
||||||
|
import Chest exposing (Chest)
|
||||||
|
import Chest.NewFromInventory as NewChest
|
||||||
import Html exposing (..)
|
import Html exposing (..)
|
||||||
import Html.Attributes exposing (..)
|
import Html.Attributes exposing (..)
|
||||||
import Html.Events exposing (..)
|
import Html.Events exposing (..)
|
||||||
import Page.Chest as Chest exposing (Chest)
|
|
||||||
import Page.Chest.NewFromInventory as NewChest
|
|
||||||
import Session exposing (Session, getSession)
|
import Session exposing (Session, getSession)
|
||||||
|
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ view model =
|
|||||||
( Html.map Internal <|
|
( Html.map Internal <|
|
||||||
case ( model.chest, Session.user model.session ) of
|
case ( model.chest, Session.user model.session ) of
|
||||||
( Chest.View _, Session.Admin _ ) ->
|
( 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 _ ) ->
|
( Chest.View _, Session.Player _ ) ->
|
||||||
B.btn (GotChestMsg Chest.buy) { text = "Acheter", icon = "fas fa-coins", color = "is-primary" }
|
B.btn (GotChestMsg Chest.buy) { text = "Acheter", icon = "fas fa-coins", color = "is-primary" }
|
||||||
|
|||||||
Reference in New Issue
Block a user