Skip to content

Commit

Permalink
feat: render processes in component explorer.
Browse files Browse the repository at this point in the history
  • Loading branch information
n1k0 committed Nov 27, 2024
1 parent 1773495 commit 7c7c604
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/Data/Object/Simulator.elm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Data.Object.Simulator exposing
, compute
, emptyResults
, expandProcessItems
, expandProcesses
, extractImpacts
, extractItems
, extractMass
Expand Down
4 changes: 2 additions & 2 deletions src/Page/Explore.elm
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ objectComponentsExplorer :
objectComponentsExplorer db tableConfig tableState maybeId =
[ db.object.components
|> List.sortBy .name
|> Table.viewList OpenDetail tableConfig tableState Scope.Object ObjectComponents.table
|> Table.viewList OpenDetail tableConfig tableState Scope.Object (ObjectComponents.table db)
, case maybeId of
Just id ->
detailsModal
Expand All @@ -438,7 +438,7 @@ objectComponentsExplorer db tableConfig tableState maybeId =

Ok component ->
component
|> Table.viewDetails Scope.Object ObjectComponents.table
|> Table.viewDetails Scope.Object (ObjectComponents.table db)
)

Nothing ->
Expand Down
52 changes: 49 additions & 3 deletions src/Page/Explore/ObjectComponents.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ module Page.Explore.ObjectComponents exposing (table)

import Data.Dataset as Dataset
import Data.Object.Component as ObjectComponent
import Data.Object.Simulator as Simulator
import Data.Scope exposing (Scope)
import Html exposing (..)
import Html.Attributes exposing (..)
import Page.Explore.Table as Table exposing (Table)
import Route
import Static.Db exposing (Db)
import Views.Alert as Alert
import Views.Format as Format


table : { detailed : Bool, scope : Scope } -> Table ObjectComponent.Component String msg
table { detailed, scope } =
table : Db -> { detailed : Bool, scope : Scope } -> Table ObjectComponent.Component String msg
table db { detailed, scope } =
{ filename = "components"
, toId = .id >> ObjectComponent.idToString
, toRoute = .id >> Just >> Dataset.ObjectComponents >> Route.Explore scope
Expand All @@ -28,7 +33,48 @@ table { detailed, scope } =
}
, { label = "Nom"
, toValue = Table.StringValue .name
, toCell = .name >> text
, toCell = .name >> text >> List.singleton >> strong []
}
, { label = "Procédés"
, toValue =
Table.StringValue <|
\{ processes } ->
case Simulator.expandProcesses db processes of
Err _ ->
""

Ok list ->
list
|> List.map
(\( amount, process ) ->
String.fromFloat (ObjectComponent.amountToFloat amount)
++ process.unit
++ " de "
++ process.displayName
)
|> String.join ", "
, toCell =
\{ processes } ->
case Simulator.expandProcesses db processes of
Err err ->
Alert.simple
{ close = Nothing
, content = [ text err ]
, level = Alert.Danger
, title = Nothing
}

Ok list ->
list
|> List.map
(\( amount, process ) ->
li []
[ Format.amount process amount
, text <| " de " ++ process.displayName
]
)
|> List.intersperse (text ", ")
|> ul [ class "m-0 px-2" ]
}
]
}

0 comments on commit 7c7c604

Please sign in to comment.