diff --git a/src/Data/Object/Simulator.elm b/src/Data/Object/Simulator.elm index 6604ad545..272e84820 100644 --- a/src/Data/Object/Simulator.elm +++ b/src/Data/Object/Simulator.elm @@ -4,6 +4,7 @@ module Data.Object.Simulator exposing , compute , emptyResults , expandProcessItems + , expandProcesses , extractImpacts , extractItems , extractMass diff --git a/src/Page/Explore.elm b/src/Page/Explore.elm index 72cf10b20..278fae913 100644 --- a/src/Page/Explore.elm +++ b/src/Page/Explore.elm @@ -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 @@ -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 -> diff --git a/src/Page/Explore/ObjectComponents.elm b/src/Page/Explore/ObjectComponents.elm index 18c2b8efe..59526ff07 100644 --- a/src/Page/Explore/ObjectComponents.elm +++ b/src/Page/Explore/ObjectComponents.elm @@ -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 @@ -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" ] } ] }