this is a lot of work...
This commit is contained in:
20
src/Main.elm
20
src/Main.elm
@@ -143,7 +143,7 @@ update msg model =
|
|||||||
Just logged ->
|
Just logged ->
|
||||||
let
|
let
|
||||||
( page, cmd ) =
|
( page, cmd ) =
|
||||||
Page.gotoHome logged
|
Page.initHome logged
|
||||||
in
|
in
|
||||||
( model |> setPage page, Cmd.map PageMsg cmd )
|
( model |> setPage page, Cmd.map PageMsg cmd )
|
||||||
|
|
||||||
@@ -158,20 +158,22 @@ update msg model =
|
|||||||
Browser.External href ->
|
Browser.External href ->
|
||||||
( model, Cmd.none )
|
( model, Cmd.none )
|
||||||
|
|
||||||
( UrlChanged url, page ) ->
|
( UrlChanged url, from ) ->
|
||||||
-- Handle routing according to current page
|
-- Handle routing according to current page
|
||||||
case ( Route.fromUrl url, page ) of
|
case Route.fromUrl url of
|
||||||
( Just (Route.Home Route.MerchantLoot), Page.Admin admin ) ->
|
Just (Route.Home Route.MerchantLoot) ->
|
||||||
let
|
let
|
||||||
( shopPage, cmd ) =
|
( shopPage, cmd ) =
|
||||||
Page.gotoShop (Admin.getSession admin)
|
Page.gotoShop from
|
||||||
in
|
in
|
||||||
( model |> setPage shopPage, Cmd.map PageMsg cmd )
|
( model |> setPage shopPage, Cmd.map PageMsg cmd )
|
||||||
|
|
||||||
( Just (Route.Home content), Page.Chest chest ) ->
|
Just (Route.Home Route.PlayerLoot) ->
|
||||||
( model |> setPage (Page.Chest (Chest.setContent content chest))
|
let
|
||||||
, Cmd.none
|
( shopPage, cmd ) =
|
||||||
)
|
Page.gotoHome from
|
||||||
|
in
|
||||||
|
( model |> setPage shopPage, Cmd.map PageMsg cmd )
|
||||||
|
|
||||||
{-
|
{-
|
||||||
( Just route, Page.Admin admin ) ->
|
( Just route, Page.Admin admin ) ->
|
||||||
|
|||||||
289
src/Page.elm
289
src/Page.elm
@@ -1,39 +1,27 @@
|
|||||||
module Page exposing (Page(..), PageMsg, gotoHome, gotoShop, update, view)
|
module Page exposing (Page(..), PageMsg, gotoHome, gotoShop, initHome, update, view)
|
||||||
|
|
||||||
|
import Api
|
||||||
|
import Api.Player
|
||||||
import Html exposing (..)
|
import Html exposing (..)
|
||||||
import Html.Attributes exposing (..)
|
import Html.Attributes exposing (..)
|
||||||
import Html.Events exposing (..)
|
import Html.Events exposing (..)
|
||||||
import Page.Admin as Admin
|
import Page.Admin as Admin
|
||||||
import Page.Chest as Chest
|
import Page.Dashboard as Dashboard
|
||||||
import Page.Chest.Wealth as Wealth
|
import Page.GroupChest as GroupChest
|
||||||
import Page.Shop as Shop
|
import Page.Shop as Shop
|
||||||
import Session exposing (Session)
|
import Session exposing (Session)
|
||||||
import Utils exposing (renderIcon)
|
import Utils exposing (renderIcon)
|
||||||
|
import Wealth
|
||||||
|
|
||||||
|
|
||||||
type Page
|
type Page
|
||||||
= Chest Chest.Model
|
= Dashboard Dashboard.Model
|
||||||
| Admin Admin.Model
|
| GroupChest GroupChest.Model
|
||||||
| Shop Shop.Model
|
| Shop Shop.Model
|
||||||
| About
|
| About
|
||||||
| Loading
|
| Loading
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{-
|
|
||||||
|
|
||||||
type Page
|
|
||||||
= Dashboard Session
|
|
||||||
| GroupChest Session
|
|
||||||
| Shop Shop.Model
|
|
||||||
| NewLoot Session
|
|
||||||
| About
|
|
||||||
| Loading
|
|
||||||
|
|
||||||
|
|
||||||
-}
|
|
||||||
|
|
||||||
|
|
||||||
init =
|
init =
|
||||||
Loading
|
Loading
|
||||||
|
|
||||||
@@ -42,15 +30,13 @@ mapMsg toMsg =
|
|||||||
List.map (Html.map toMsg)
|
List.map (Html.map toMsg)
|
||||||
|
|
||||||
|
|
||||||
view page =
|
maybeSession page =
|
||||||
let
|
|
||||||
maybeSession =
|
|
||||||
case page of
|
case page of
|
||||||
Chest model ->
|
Dashboard model ->
|
||||||
Just <| Session.getSession model
|
Just <| Session.getSession model
|
||||||
|
|
||||||
Admin model ->
|
GroupChest model ->
|
||||||
Just <| Admin.getSession model
|
Just <| Session.getSession model
|
||||||
|
|
||||||
Shop model ->
|
Shop model ->
|
||||||
Just <| Session.getSession model
|
Just <| Session.getSession model
|
||||||
@@ -58,13 +44,26 @@ view page =
|
|||||||
_ ->
|
_ ->
|
||||||
Nothing
|
Nothing
|
||||||
|
|
||||||
|
|
||||||
|
view page =
|
||||||
|
let
|
||||||
( title, ( controls, content ) ) =
|
( title, ( controls, content ) ) =
|
||||||
case page of
|
case page of
|
||||||
Chest chest ->
|
Dashboard home ->
|
||||||
( "Lootalot", ( text "", mapMsg GotChestMsg <| Chest.view chest ) )
|
( "Lootalot"
|
||||||
|
, Dashboard.view home
|
||||||
|
|> Tuple.mapBoth
|
||||||
|
(Html.map GotDashboardMsg)
|
||||||
|
(mapMsg GotDashboardMsg)
|
||||||
|
)
|
||||||
|
|
||||||
Admin admin ->
|
GroupChest chest ->
|
||||||
( "Administration", ( text "", mapMsg GotAdminMsg <| Admin.view admin ) )
|
( "Lootalot"
|
||||||
|
, GroupChest.view chest
|
||||||
|
|> Tuple.mapBoth
|
||||||
|
(Html.map GotGroupChestMsg)
|
||||||
|
(mapMsg GotGroupChestMsg)
|
||||||
|
)
|
||||||
|
|
||||||
Shop shop ->
|
Shop shop ->
|
||||||
( "Marchand"
|
( "Marchand"
|
||||||
@@ -81,7 +80,7 @@ view page =
|
|||||||
( "Loot-a-lot", ( text "", [ p [] [ text "Chargement" ] ] ) )
|
( "Loot-a-lot", ( text "", [ p [] [ text "Chargement" ] ] ) )
|
||||||
|
|
||||||
navbarTitle =
|
navbarTitle =
|
||||||
case maybeSession of
|
case maybeSession page of
|
||||||
Just session ->
|
Just session ->
|
||||||
case Session.user session of
|
case Session.user session of
|
||||||
Session.Player player _ ->
|
Session.Player player _ ->
|
||||||
@@ -94,7 +93,7 @@ view page =
|
|||||||
"Loot-a-lot"
|
"Loot-a-lot"
|
||||||
|
|
||||||
navbarLinks =
|
navbarLinks =
|
||||||
case maybeSession of
|
case maybeSession page of
|
||||||
Just session ->
|
Just session ->
|
||||||
case Session.user session of
|
case Session.user session of
|
||||||
Session.Player player _ ->
|
Session.Player player _ ->
|
||||||
@@ -119,20 +118,24 @@ view page =
|
|||||||
( title
|
( title
|
||||||
, { title = navbarTitle, links = navbarLinks }
|
, { title = navbarTitle, links = navbarLinks }
|
||||||
, [ div [ class "container" ] <|
|
, [ div [ class "container" ] <|
|
||||||
viewSessionBar maybeSession [ controls ]
|
viewSessionBar (maybeSession page) [ controls ]
|
||||||
:: content
|
:: content
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
viewSessionBar maybeSession controls =
|
viewSessionBar session controls =
|
||||||
let
|
let
|
||||||
user =
|
user =
|
||||||
case Maybe.map Session.user maybeSession of
|
case Maybe.map Session.user session of
|
||||||
Nothing ->
|
Nothing ->
|
||||||
[ text "" ]
|
[ text "" ]
|
||||||
|
|
||||||
Just (Session.Player player wealth) ->
|
Just (Session.Player player wealth) ->
|
||||||
|
let
|
||||||
|
_ =
|
||||||
|
Debug.log "viewSessionBar wealth" player.wealth
|
||||||
|
in
|
||||||
Wealth.view player.wealth wealth
|
Wealth.view player.wealth wealth
|
||||||
++ (if player.debt > 0 then
|
++ (if player.debt > 0 then
|
||||||
[ div [ class "level-item" ]
|
[ div [ class "level-item" ]
|
||||||
@@ -176,30 +179,135 @@ navLink icon linkText url =
|
|||||||
|
|
||||||
-- UPDATE
|
-- UPDATE
|
||||||
--
|
--
|
||||||
|
-- Note : All pages 'update' function
|
||||||
|
-- shall return (subMode, Cmd Api.Msg)
|
||||||
|
|
||||||
|
|
||||||
type PageMsg
|
type PageMsg
|
||||||
= GotChestMsg Chest.Msg
|
= ApiMsg Api.Msg
|
||||||
| GotAdminMsg Admin.Msg
|
| GotGroupChestMsg GroupChest.Msg
|
||||||
|
| GotDashboardMsg Dashboard.Msg
|
||||||
| GotShopMsg Shop.Msg
|
| GotShopMsg Shop.Msg
|
||||||
| Wealth Wealth.Msg
|
| Wealth Wealth.Msg
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- Maps the page session to a function, if any
|
||||||
|
|
||||||
|
|
||||||
|
map func page =
|
||||||
|
case maybeSession page of
|
||||||
|
Nothing ->
|
||||||
|
page
|
||||||
|
|
||||||
|
Just session ->
|
||||||
|
case page of
|
||||||
|
Dashboard model ->
|
||||||
|
Dashboard { model | session = func session }
|
||||||
|
|
||||||
|
GroupChest model ->
|
||||||
|
GroupChest { model | session = func session }
|
||||||
|
|
||||||
|
Shop model ->
|
||||||
|
Shop { model | session = func session }
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
page
|
||||||
|
|
||||||
|
|
||||||
update msg page =
|
update msg page =
|
||||||
case ( msg, page ) of
|
case ( msg, page, maybeSession page ) of
|
||||||
( GotChestMsg subMsg, Chest chest ) ->
|
( GotGroupChestMsg subMsg, GroupChest chest, _ ) ->
|
||||||
Chest.update subMsg chest
|
GroupChest.update subMsg chest
|
||||||
|> updatePage Chest GotChestMsg
|
|> updatePage GroupChest GotGroupChestMsg
|
||||||
|
|
||||||
( GotAdminMsg subMsg, Admin admin ) ->
|
( GotGroupChestMsg _, _, _ ) ->
|
||||||
Admin.update subMsg admin
|
( page, Cmd.none )
|
||||||
|> updatePage Admin GotAdminMsg
|
|
||||||
|
|
||||||
( GotShopMsg subMsg, Shop shop ) ->
|
( GotDashboardMsg subMsg, Dashboard home, _ ) ->
|
||||||
|
Dashboard.update subMsg home
|
||||||
|
|> updatePage Dashboard GotDashboardMsg
|
||||||
|
|
||||||
|
( GotDashboardMsg _, _, _ ) ->
|
||||||
|
( page, Cmd.none )
|
||||||
|
|
||||||
|
( GotShopMsg subMsg, Shop shop, _ ) ->
|
||||||
Shop.update subMsg shop
|
Shop.update subMsg shop
|
||||||
|> updatePage Shop GotShopMsg
|
|> updatePage Shop GotShopMsg
|
||||||
|
|
||||||
|
( GotShopMsg _, _, _ ) ->
|
||||||
|
( page, Cmd.none )
|
||||||
|
|
||||||
|
( Wealth wealthMsg, _, Just session ) ->
|
||||||
|
let
|
||||||
|
wealthModel =
|
||||||
|
Session.wealth session
|
||||||
|
in
|
||||||
|
case Session.user session of
|
||||||
|
Session.Player player aModel ->
|
||||||
|
let
|
||||||
|
( newWealth, maybeEdit ) =
|
||||||
|
Wealth.update wealthMsg aModel
|
||||||
|
in
|
||||||
|
( map (Session.updateWealth newWealth) page
|
||||||
|
, case maybeEdit of
|
||||||
|
Just amount ->
|
||||||
|
Api.confirmAction
|
||||||
|
(String.fromInt (.id player))
|
||||||
|
(Api.WealthPayload amount)
|
||||||
|
|> Cmd.map ApiMsg
|
||||||
|
|
||||||
|
Nothing ->
|
||||||
|
Cmd.none
|
||||||
|
)
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
|
Debug.log "not a player but updates wealth"
|
||||||
|
( page, Cmd.none )
|
||||||
|
|
||||||
|
( Wealth wealthMsg, _, Nothing ) ->
|
||||||
|
( page, Cmd.none )
|
||||||
|
|
||||||
|
( ApiMsg (Api.GotActionResult response), _, Just session ) ->
|
||||||
|
let
|
||||||
|
_ =
|
||||||
|
Debug.log "got api response" response
|
||||||
|
in
|
||||||
|
case response of
|
||||||
|
Ok result ->
|
||||||
|
let
|
||||||
|
updates =
|
||||||
|
Maybe.withDefault [] result.updates
|
||||||
|
|
||||||
|
notification =
|
||||||
|
result.notification
|
||||||
|
|
||||||
|
errors =
|
||||||
|
Maybe.withDefault "" result.errors
|
||||||
|
|
||||||
|
newUser =
|
||||||
|
Debug.log "newUser" <|
|
||||||
|
List.foldl applyUpdate (Session.user session) updates
|
||||||
|
in
|
||||||
|
( map (Session.updateUser newUser) page
|
||||||
|
, Cmd.none
|
||||||
|
)
|
||||||
|
|
||||||
|
-- |> setNotification notification
|
||||||
|
-- |> setError errors
|
||||||
|
-- |> update (ModeSwitched View)
|
||||||
|
Err r ->
|
||||||
|
let
|
||||||
|
_ =
|
||||||
|
Debug.log "ERR: ActionResult:" r
|
||||||
|
in
|
||||||
|
( page, Cmd.none )
|
||||||
|
|
||||||
|
( ApiMsg apiMsg, _, Nothing ) ->
|
||||||
|
let
|
||||||
|
_ =
|
||||||
|
Debug.log "rogue api msg !" apiMsg
|
||||||
|
in
|
||||||
( page, Cmd.none )
|
( page, Cmd.none )
|
||||||
|
|
||||||
|
|
||||||
@@ -209,28 +317,95 @@ updatePage toPage toMsg ( subModel, subMsg ) =
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
applyUpdate : Api.Update -> Session.User -> Session.User
|
||||||
|
applyUpdate u user =
|
||||||
|
let
|
||||||
|
_ =
|
||||||
|
Debug.log "applyUpdate" u
|
||||||
|
|
||||||
|
_ =
|
||||||
|
Debug.log "on" user
|
||||||
|
in
|
||||||
|
{- Note: DbUpdates always refer to the active player -}
|
||||||
|
case user of
|
||||||
|
Session.Player player wealthModel ->
|
||||||
|
case u of
|
||||||
|
Api.ItemRemoved item ->
|
||||||
|
--List.filter (\i -> i.id /= item.id) model.state.playerLoot
|
||||||
|
user
|
||||||
|
|
||||||
|
Api.ItemAdded item ->
|
||||||
|
--{ model | state = { state | playerLoot = item :: model.state.playerLoot } }
|
||||||
|
user
|
||||||
|
|
||||||
|
Api.WealthUpdated diff ->
|
||||||
|
let
|
||||||
|
wealth =
|
||||||
|
player.wealth
|
||||||
|
|
||||||
|
_ =
|
||||||
|
Debug.log "updatePlayerWealth" diff
|
||||||
|
in
|
||||||
|
Session.Player
|
||||||
|
{ player
|
||||||
|
| wealth =
|
||||||
|
Api.Player.Wealth
|
||||||
|
(wealth.cp + diff.cp)
|
||||||
|
(wealth.sp + diff.sp)
|
||||||
|
(wealth.gp + diff.gp)
|
||||||
|
(wealth.pp + diff.pp)
|
||||||
|
}
|
||||||
|
wealthModel
|
||||||
|
|
||||||
|
Api.ClaimAdded claim ->
|
||||||
|
-- { model | claims = claim :: model.claims }
|
||||||
|
user
|
||||||
|
|
||||||
|
Api.ClaimRemoved claim ->
|
||||||
|
-- { model | claims = List.filter (\c -> c.id /= claim.id) model.claims }
|
||||||
|
user
|
||||||
|
|
||||||
|
Session.Admin ->
|
||||||
|
user
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- CHANGE ROUTE
|
-- CHANGE ROUTE
|
||||||
|
|
||||||
|
|
||||||
gotoHome session =
|
initHome session =
|
||||||
case Session.user session of
|
Dashboard.init session
|
||||||
Session.Player _ _ ->
|
|> updatePage Dashboard GotDashboardMsg
|
||||||
Chest.init session
|
|
||||||
|> updatePage Chest GotChestMsg
|
|
||||||
|
|
||||||
Session.Admin ->
|
|
||||||
Admin.init session
|
|
||||||
|> updatePage Admin GotAdminMsg
|
|
||||||
|
|
||||||
|
|
||||||
gotoShop session =
|
gotoHome page =
|
||||||
|
case maybeSession page of
|
||||||
|
Nothing ->
|
||||||
|
( page, Cmd.none )
|
||||||
|
|
||||||
|
Just session ->
|
||||||
|
Dashboard.init session
|
||||||
|
|> updatePage Dashboard GotDashboardMsg
|
||||||
|
|
||||||
|
|
||||||
|
gotoShop page =
|
||||||
|
case maybeSession page of
|
||||||
|
Nothing ->
|
||||||
|
( page, Cmd.none )
|
||||||
|
|
||||||
|
Just session ->
|
||||||
Shop.init session
|
Shop.init session
|
||||||
|> updatePage Shop GotShopMsg
|
|> updatePage Shop GotShopMsg
|
||||||
|
|
||||||
|
|
||||||
gotoGroupChest session =
|
gotoGroupChest page =
|
||||||
()
|
case maybeSession page of
|
||||||
|
Nothing ->
|
||||||
|
( page, Cmd.none )
|
||||||
|
|
||||||
|
Just session ->
|
||||||
|
GroupChest.init session
|
||||||
|
|> updatePage GroupChest GotGroupChestMsg
|
||||||
|
|
||||||
|
|
||||||
gotoInventory session =
|
gotoInventory session =
|
||||||
|
|||||||
1314
src/Page/Chest.elm
1314
src/Page/Chest.elm
File diff suppressed because it is too large
Load Diff
1301
src/Page/Chest.elm.old
Normal file
1301
src/Page/Chest.elm.old
Normal file
File diff suppressed because it is too large
Load Diff
@@ -7,11 +7,6 @@ import Html.Events exposing (..)
|
|||||||
import Table
|
import Table
|
||||||
|
|
||||||
|
|
||||||
type ExitStatus
|
|
||||||
= Confirmed Loot
|
|
||||||
| Canceled
|
|
||||||
|
|
||||||
|
|
||||||
type alias Model =
|
type alias Model =
|
||||||
{ itemList : String
|
{ itemList : String
|
||||||
, invalidItems : Loot
|
, invalidItems : Loot
|
||||||
@@ -27,30 +22,10 @@ init =
|
|||||||
[]
|
[]
|
||||||
|
|
||||||
|
|
||||||
view : Model -> ( Html Msg, List (Html Msg) )
|
view : Model -> Html Msg
|
||||||
view model =
|
view model =
|
||||||
let
|
article []
|
||||||
allLootValid =
|
[ div [ class "section" ]
|
||||||
if List.length model.invalidItems + List.length model.validItems == 0 then
|
|
||||||
False
|
|
||||||
|
|
||||||
else
|
|
||||||
List.all itemIsValid model.invalidItems
|
|
||||||
in
|
|
||||||
( div [ class "buttons" ]
|
|
||||||
[ button
|
|
||||||
[ class "button"
|
|
||||||
, disabled <| not allLootValid
|
|
||||||
, onClick ConfirmClicked
|
|
||||||
]
|
|
||||||
[ text "Ok" ]
|
|
||||||
, button
|
|
||||||
[ class "button"
|
|
||||||
, onClick CancelClicked
|
|
||||||
]
|
|
||||||
[ text "Annuler" ]
|
|
||||||
]
|
|
||||||
, [ div [ class "section" ]
|
|
||||||
[ textarea
|
[ textarea
|
||||||
[ class "textarea"
|
[ class "textarea"
|
||||||
, value model.itemList
|
, value model.itemList
|
||||||
@@ -65,9 +40,19 @@ view model =
|
|||||||
[ text "Mettre dans le coffre" ]
|
[ text "Mettre dans le coffre" ]
|
||||||
]
|
]
|
||||||
, div [ class "section" ]
|
, div [ class "section" ]
|
||||||
[ model.validItems ++ model.invalidItems |> Table.view viewOrEditRenderer ]
|
[ model.validItems
|
||||||
|
++ model.invalidItems
|
||||||
|
|> Table.view (Table.renderRowLevel viewOrEditRenderer (\i -> []))
|
||||||
]
|
]
|
||||||
)
|
]
|
||||||
|
|
||||||
|
|
||||||
|
allValid model =
|
||||||
|
if List.length model.invalidItems + List.length model.validItems == 0 then
|
||||||
|
False
|
||||||
|
|
||||||
|
else
|
||||||
|
List.all itemIsValid model.invalidItems
|
||||||
|
|
||||||
|
|
||||||
itemIsValid item =
|
itemIsValid item =
|
||||||
@@ -111,7 +96,7 @@ viewOrEditRenderer item =
|
|||||||
]
|
]
|
||||||
|
|
||||||
else
|
else
|
||||||
Table.name item
|
[ p [] [ text <| .name item ] ]
|
||||||
|
|
||||||
|
|
||||||
type Msg
|
type Msg
|
||||||
@@ -120,24 +105,20 @@ type Msg
|
|||||||
| InvalidItemNameChanged Int String
|
| InvalidItemNameChanged Int String
|
||||||
| InvalidItemPriceChanged Int String
|
| InvalidItemPriceChanged Int String
|
||||||
| GotCheckedItems Loot (Maybe String)
|
| GotCheckedItems Loot (Maybe String)
|
||||||
| ConfirmClicked
|
|
||||||
| CancelClicked
|
|
||||||
|
|
||||||
|
|
||||||
update : Msg -> Model -> ( Model, Cmd Msg, Maybe ExitStatus )
|
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||||
update msg model =
|
update msg model =
|
||||||
case msg of
|
case msg of
|
||||||
ItemListInput newList ->
|
ItemListInput newList ->
|
||||||
( { model | itemList = newList }
|
( { model | itemList = newList }
|
||||||
, Cmd.none
|
, Cmd.none
|
||||||
, Nothing
|
|
||||||
)
|
)
|
||||||
|
|
||||||
ItemListSend ->
|
ItemListSend ->
|
||||||
( { model | itemList = "" }
|
( { model | itemList = "" }
|
||||||
, Api.checkList GotCheckedItems <|
|
, Api.checkList GotCheckedItems <|
|
||||||
String.split "\n" model.itemList
|
String.split "\n" model.itemList
|
||||||
, Nothing
|
|
||||||
)
|
)
|
||||||
|
|
||||||
GotCheckedItems valid errors ->
|
GotCheckedItems valid errors ->
|
||||||
@@ -163,7 +144,6 @@ update msg model =
|
|||||||
, validItems = valid ++ model.validItems
|
, validItems = valid ++ model.validItems
|
||||||
}
|
}
|
||||||
, Cmd.none
|
, Cmd.none
|
||||||
, Nothing
|
|
||||||
)
|
)
|
||||||
|
|
||||||
InvalidItemNameChanged id newName ->
|
InvalidItemNameChanged id newName ->
|
||||||
@@ -173,7 +153,6 @@ update msg model =
|
|||||||
|> editItem (\item -> { item | name = newName }) id
|
|> editItem (\item -> { item | name = newName }) id
|
||||||
}
|
}
|
||||||
, Cmd.none
|
, Cmd.none
|
||||||
, Nothing
|
|
||||||
)
|
)
|
||||||
|
|
||||||
InvalidItemPriceChanged id newPrice ->
|
InvalidItemPriceChanged id newPrice ->
|
||||||
@@ -186,15 +165,8 @@ update msg model =
|
|||||||
model.invalidItems |> editItem (\item -> { item | base_price = price }) id
|
model.invalidItems |> editItem (\item -> { item | base_price = price }) id
|
||||||
}
|
}
|
||||||
, Cmd.none
|
, Cmd.none
|
||||||
, Nothing
|
|
||||||
)
|
)
|
||||||
|
|
||||||
ConfirmClicked ->
|
|
||||||
( model, Cmd.none, Just (Confirmed <| allLoot model) )
|
|
||||||
|
|
||||||
CancelClicked ->
|
|
||||||
( model, Cmd.none, Just Canceled )
|
|
||||||
|
|
||||||
|
|
||||||
allLoot model =
|
allLoot model =
|
||||||
model.invalidItems ++ model.validItems
|
model.invalidItems ++ model.validItems
|
||||||
|
|||||||
37
src/Page/Chest/Selection.elm
Normal file
37
src/Page/Chest/Selection.elm
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
module Page.Chest.Selection exposing (Model, Msg, init, update, view)
|
||||||
|
|
||||||
|
import Api exposing (Loot)
|
||||||
|
import Html exposing (..)
|
||||||
|
import Html.Attributes exposing (..)
|
||||||
|
import Table
|
||||||
|
|
||||||
|
|
||||||
|
type Selection
|
||||||
|
= Selection
|
||||||
|
|
||||||
|
|
||||||
|
type Model
|
||||||
|
= Model Selection
|
||||||
|
|
||||||
|
|
||||||
|
init =
|
||||||
|
Model Selection
|
||||||
|
|
||||||
|
|
||||||
|
view : Model -> Loot -> Html Msg
|
||||||
|
view model loot =
|
||||||
|
Table.view
|
||||||
|
(Table.renderRowLevel
|
||||||
|
(\item -> [ p [] [ text <| item.name ++ "selectable" ] ])
|
||||||
|
(\item -> [ input [ type_ "checkbox" ] [] ])
|
||||||
|
)
|
||||||
|
loot
|
||||||
|
|
||||||
|
|
||||||
|
type Msg
|
||||||
|
= Msg
|
||||||
|
|
||||||
|
|
||||||
|
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||||
|
update msg model =
|
||||||
|
( model, Cmd.none )
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
module Page.Dashboard exposing (Model, Msg, init, update, view)
|
||||||
|
|
||||||
|
import Html exposing (..)
|
||||||
|
import Html.Attributes exposing (..)
|
||||||
|
import Html.Events exposing (..)
|
||||||
|
import Page.Chest as Chest exposing (Chest)
|
||||||
|
import Session exposing (Session)
|
||||||
|
|
||||||
|
|
||||||
|
type alias Model =
|
||||||
|
{ session : Session
|
||||||
|
, chest : Mode
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
type Mode
|
||||||
|
= View Chest
|
||||||
|
|
||||||
|
|
||||||
|
init : Session -> ( Model, Cmd Msg )
|
||||||
|
init session =
|
||||||
|
( Model session (View Chest.init)
|
||||||
|
, Cmd.none
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
view : Model -> ( Html Msg, List (Html Msg) )
|
||||||
|
view model =
|
||||||
|
case Session.user model.session of
|
||||||
|
Session.Player player _ ->
|
||||||
|
( text ""
|
||||||
|
, [ if player.id == 0 then
|
||||||
|
p [] [ text "Groupe" ]
|
||||||
|
|
||||||
|
else
|
||||||
|
p [] [ text "Joueur" ]
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
Session.Admin ->
|
||||||
|
( text "", [ p [] [ text "Joueur" ] ] )
|
||||||
|
|
||||||
|
|
||||||
|
type Msg
|
||||||
|
= Msg
|
||||||
|
|
||||||
|
|
||||||
|
update msg model =
|
||||||
|
( model, Cmd.none )
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ view model =
|
|||||||
Session.Admin ->
|
Session.Admin ->
|
||||||
text ""
|
text ""
|
||||||
|
|
||||||
Session.Player id ->
|
Session.Player p _ ->
|
||||||
if id == 0 then
|
if p.id == 0 then
|
||||||
button [ class "button" ] [ text "Vendre" ]
|
button [ class "button" ] [ text "Vendre" ]
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ import Dict exposing (Dict)
|
|||||||
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 Page.Chest.NewFromInventory as NewChest
|
||||||
|
import Page.Chest.Selection as Selection
|
||||||
import Session exposing (Session, getSession)
|
import Session exposing (Session, getSession)
|
||||||
import Set exposing (Set)
|
import Set exposing (Set)
|
||||||
import Table
|
import Table
|
||||||
@@ -13,20 +15,46 @@ import Table
|
|||||||
|
|
||||||
type alias Model =
|
type alias Model =
|
||||||
{ session : Session
|
{ session : Session
|
||||||
, state : State
|
, loot : Status Loot
|
||||||
|
, chest : Mode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type State
|
type Status a
|
||||||
= Loading
|
= Loading
|
||||||
| LoadError String
|
| LoadError String
|
||||||
|
| Loaded a
|
||||||
|
|
||||||
|
|
||||||
|
type Mode
|
||||||
|
= View Chest
|
||||||
|
| Buy Chest
|
||||||
|
| Refresh Chest
|
||||||
|
|
||||||
|
|
||||||
|
getChest mode =
|
||||||
|
case mode of
|
||||||
|
View c ->
|
||||||
|
c
|
||||||
|
|
||||||
|
Buy c ->
|
||||||
|
c
|
||||||
|
|
||||||
|
Refresh c ->
|
||||||
|
c
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{-
|
||||||
| View Loot
|
| View Loot
|
||||||
| Refresh NewChest.Model
|
| Refresh NewChest.Model
|
||||||
|
| Buy Selection.Model
|
||||||
| Sending
|
| Sending
|
||||||
|
-}
|
||||||
|
|
||||||
|
|
||||||
init session =
|
init session =
|
||||||
( Model session Loading, fetchShopItems )
|
( Model session Loading <| View Chest.init, fetchShopItems )
|
||||||
|
|
||||||
|
|
||||||
fetchShopItems =
|
fetchShopItems =
|
||||||
@@ -35,21 +63,52 @@ fetchShopItems =
|
|||||||
|
|
||||||
view : Model -> ( Html Msg, List (Html Msg) )
|
view : Model -> ( Html Msg, List (Html Msg) )
|
||||||
view model =
|
view model =
|
||||||
case model.state of
|
case model.loot of
|
||||||
Loading ->
|
Loading ->
|
||||||
( text "", [ p [ class "title" ] [ text "loading..." ] ] )
|
( text ""
|
||||||
|
, [ p [ class "title" ] [ text "loading..." ] ]
|
||||||
|
)
|
||||||
|
|
||||||
LoadError error ->
|
LoadError error ->
|
||||||
( text "", [ p [ class "has-text-danger" ] [ text <| "Error : " ++ error ] ] )
|
( text ""
|
||||||
|
, [ p [ class "has-text-danger" ] [ text <| "Error : " ++ error ] ]
|
||||||
|
)
|
||||||
|
|
||||||
View loot ->
|
Loaded loot ->
|
||||||
( case Session.user model.session of
|
let
|
||||||
|
controls =
|
||||||
|
case model.chest of
|
||||||
|
View chest ->
|
||||||
|
case Session.user model.session of
|
||||||
Session.Admin ->
|
Session.Admin ->
|
||||||
button [ class "button", onClick IntoRefresh ] [ text "Remplacer" ]
|
button [ class "button", onClick IntoRefresh ] [ text "Remplacer" ]
|
||||||
|
|
||||||
Session.Player _ _ ->
|
Session.Player _ _ ->
|
||||||
button [ class "button" ] [ text "Acheter" ]
|
button [ class "button" ] [ text "Acheter" ]
|
||||||
, [ Table.view Table.name loot ]
|
|
||||||
|
Buy chest ->
|
||||||
|
text ""
|
||||||
|
|
||||||
|
Refresh chest ->
|
||||||
|
text ""
|
||||||
|
in
|
||||||
|
( controls
|
||||||
|
, [ Chest.view (getChest model.chest) loot |> Html.map GotChestMsg ]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{-
|
||||||
|
Buy selection ->
|
||||||
|
let
|
||||||
|
( controls, content ) =
|
||||||
|
Selection.view selection
|
||||||
|
|
||||||
|
toMsg =
|
||||||
|
Html.map GotBuyMsg
|
||||||
|
in
|
||||||
|
( toMsg controls
|
||||||
|
, List.map toMsg content
|
||||||
)
|
)
|
||||||
|
|
||||||
Refresh chest ->
|
Refresh chest ->
|
||||||
@@ -66,36 +125,74 @@ view model =
|
|||||||
|
|
||||||
Sending ->
|
Sending ->
|
||||||
( text "", [ p [] [ text "En attente du serveur..." ] ] )
|
( text "", [ p [] [ text "En attente du serveur..." ] ] )
|
||||||
|
-}
|
||||||
|
|
||||||
|
|
||||||
type Msg
|
type Msg
|
||||||
= GotLoot Api.ToChest (HttpResult Loot)
|
= GotLoot Api.ToChest (HttpResult Loot)
|
||||||
| IntoRefresh
|
| IntoRefresh
|
||||||
| GotChestMsg NewChest.Msg
|
|
||||||
| GotRefreshResult (Maybe ())
|
|
||||||
| IntoBuy
|
| IntoBuy
|
||||||
|
| GotChestMsg Chest.Msg
|
||||||
|
|
||||||
|
|
||||||
|
updateChest model chest =
|
||||||
|
{ model
|
||||||
|
| chest =
|
||||||
|
case model.chest of
|
||||||
|
Buy _ ->
|
||||||
|
Buy chest
|
||||||
|
|
||||||
|
Refresh _ ->
|
||||||
|
Refresh chest
|
||||||
|
|
||||||
|
View _ ->
|
||||||
|
View chest
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- GotRefreshResult (Maybe ())
|
||||||
|
--| GotBuyMsg Selection.Msg
|
||||||
|
--| GotBuyResult (Maybe ())
|
||||||
|
|
||||||
|
|
||||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||||
update msg model =
|
update msg model =
|
||||||
case ( msg, model.state ) of
|
case msg of
|
||||||
( GotLoot Api.OfShop response, Loading ) ->
|
GotLoot Api.OfShop response ->
|
||||||
case response of
|
case response of
|
||||||
Ok loot ->
|
Ok loot ->
|
||||||
( { model | state = View loot }, Cmd.none )
|
( { model | loot = Loaded loot }, Cmd.none )
|
||||||
|
|
||||||
-- TODO: handle error
|
-- TODO: handle error
|
||||||
Err e ->
|
Err e ->
|
||||||
( { model | state = LoadError <| Debug.toString e }, Cmd.none )
|
( { model | loot = LoadError <| Debug.toString e }, Cmd.none )
|
||||||
|
|
||||||
( IntoRefresh, View _ ) ->
|
-- Refresh mode
|
||||||
|
IntoRefresh ->
|
||||||
case Session.user (getSession model) of
|
case Session.user (getSession model) of
|
||||||
Session.Admin ->
|
Session.Admin ->
|
||||||
( { model | state = Refresh NewChest.init }, Cmd.none )
|
( { model | chest = Refresh Chest.initCreate }, Cmd.none )
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
( model, Cmd.none )
|
( model, Cmd.none )
|
||||||
|
|
||||||
|
-- Buy mode
|
||||||
|
IntoBuy ->
|
||||||
|
case Session.user (getSession model) of
|
||||||
|
Session.Player _ _ ->
|
||||||
|
( { model | chest = Buy Chest.initSelection }, Cmd.none )
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
( model, Cmd.none )
|
||||||
|
|
||||||
|
GotChestMsg subMsg ->
|
||||||
|
Chest.update subMsg (getChest model.chest)
|
||||||
|
|> Tuple.mapBoth
|
||||||
|
(updateChest model)
|
||||||
|
(Cmd.map GotChestMsg)
|
||||||
|
|
||||||
|
{-
|
||||||
(GotChestMsg chestMsg, Refresh chest ) ->
|
(GotChestMsg chestMsg, Refresh chest ) ->
|
||||||
let
|
let
|
||||||
( newState, cmd, exit ) =
|
( newState, cmd, exit ) =
|
||||||
@@ -123,5 +220,11 @@ update msg model =
|
|||||||
, Cmd.none
|
, Cmd.none
|
||||||
)
|
)
|
||||||
|
|
||||||
|
( GotBuyMsg subMsg, Buy subModel ) ->
|
||||||
|
Selection.update subMsg subModel
|
||||||
|
|> Tuple.mapBoth
|
||||||
|
(\m -> { model | state = Buy m })
|
||||||
|
(\c -> Cmd.map GotBuyMsg c)
|
||||||
|
-}
|
||||||
_ ->
|
_ ->
|
||||||
( model, Cmd.none )
|
( model, Cmd.none )
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
module Session exposing (Session, User(..), getSession, init, key, user)
|
module Session exposing (Session, User(..), getSession, init, key, updateUser, updateWealth, user, wealth)
|
||||||
|
|
||||||
import Api
|
import Api
|
||||||
import Api.Player as Player exposing (Player)
|
import Api.Player as Player exposing (Player)
|
||||||
import Browser.Navigation as Nav
|
import Browser.Navigation as Nav
|
||||||
import Http
|
import Http
|
||||||
import Json.Decode as D
|
import Json.Decode as D
|
||||||
import Page.Chest.Wealth as Wealth
|
import Wealth
|
||||||
|
|
||||||
|
|
||||||
type User
|
type User
|
||||||
@@ -53,3 +53,49 @@ user session =
|
|||||||
session
|
session
|
||||||
in
|
in
|
||||||
loggedUser
|
loggedUser
|
||||||
|
|
||||||
|
|
||||||
|
wealth : Session -> Maybe Wealth.Model
|
||||||
|
wealth session =
|
||||||
|
case user session of
|
||||||
|
Player _ model ->
|
||||||
|
Just model
|
||||||
|
|
||||||
|
Admin ->
|
||||||
|
Nothing
|
||||||
|
|
||||||
|
|
||||||
|
setWealth wealthModel session =
|
||||||
|
let
|
||||||
|
(Session navKey isUser) =
|
||||||
|
session
|
||||||
|
in
|
||||||
|
case isUser of
|
||||||
|
Player p _ ->
|
||||||
|
Session navKey (Player p wealthModel)
|
||||||
|
|
||||||
|
Admin ->
|
||||||
|
Session navKey Admin
|
||||||
|
|
||||||
|
|
||||||
|
updateWealth : Wealth.Model -> Session -> Session
|
||||||
|
updateWealth newWealthModel model =
|
||||||
|
let
|
||||||
|
(Session navKey loggedUser) =
|
||||||
|
model
|
||||||
|
in
|
||||||
|
case loggedUser of
|
||||||
|
Player player _ ->
|
||||||
|
Session navKey (Player player newWealthModel)
|
||||||
|
|
||||||
|
Admin ->
|
||||||
|
Session navKey Admin
|
||||||
|
|
||||||
|
|
||||||
|
updateUser : User -> Session -> Session
|
||||||
|
updateUser newUser model =
|
||||||
|
let
|
||||||
|
(Session navKey _) =
|
||||||
|
model
|
||||||
|
in
|
||||||
|
Session navKey newUser
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
module Table exposing (name, view)
|
module Table exposing (name, renderRowLevel, view)
|
||||||
|
|
||||||
import Html exposing (..)
|
import Html exposing (..)
|
||||||
import Html.Attributes exposing (..)
|
import Html.Attributes exposing (..)
|
||||||
|
|
||||||
|
|
||||||
type alias RowRenderer a msg =
|
type alias RowRenderer a msg =
|
||||||
|
a -> Html msg
|
||||||
|
|
||||||
|
|
||||||
|
type alias ItemRenderer a msg =
|
||||||
a -> List (Html msg)
|
a -> List (Html msg)
|
||||||
|
|
||||||
|
|
||||||
@@ -15,10 +19,20 @@ view rowRenderer content =
|
|||||||
[ th [] [ text "Nom" ] ]
|
[ th [] [ text "Nom" ] ]
|
||||||
, tbody [] <|
|
, tbody [] <|
|
||||||
List.map
|
List.map
|
||||||
(\i -> tr [] [ td [] <| rowRenderer i ])
|
rowRenderer
|
||||||
content
|
content
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
name item =
|
renderRowLevel : ItemRenderer a msg -> ItemRenderer a msg -> RowRenderer a msg
|
||||||
[ p [] [ text item.name ] ]
|
renderRowLevel left right item =
|
||||||
|
tr []
|
||||||
|
[ td [ class "level" ]
|
||||||
|
[ div [ class "level-left" ] <| left item
|
||||||
|
, div [ class "level-right" ] <| right item
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
name =
|
||||||
|
renderRowLevel (\item -> [ p [] [ text item.name ] ]) (\item -> [])
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module Page.Chest.Wealth exposing (Model, Msg(..), editValue, init, update, view)
|
module Wealth exposing (Model, Msg(..), editValue, init, update, view)
|
||||||
|
|
||||||
import Api.Player exposing (Wealth)
|
import Api.Player exposing (Wealth)
|
||||||
import Html exposing (..)
|
import Html exposing (..)
|
||||||
@@ -71,20 +71,22 @@ type Msg
|
|||||||
| ConfirmEdit
|
| ConfirmEdit
|
||||||
|
|
||||||
|
|
||||||
update : Msg -> Model -> Model
|
update : Msg -> Model -> ( Model, Maybe Float )
|
||||||
update msg model =
|
update msg model =
|
||||||
case msg of
|
case msg of
|
||||||
StartEdit ->
|
StartEdit ->
|
||||||
Edit "0.0"
|
( Edit "0.0", Nothing )
|
||||||
|
|
||||||
QuitEdit ->
|
QuitEdit ->
|
||||||
View
|
( View, Nothing )
|
||||||
|
|
||||||
AmountChanged newAmount ->
|
AmountChanged newAmount ->
|
||||||
Edit <| String.replace "," "." newAmount
|
( Edit <| String.replace "," "." newAmount
|
||||||
|
, Nothing
|
||||||
|
)
|
||||||
|
|
||||||
_ ->
|
ConfirmEdit ->
|
||||||
View
|
( View, editValue model )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user