diff --git a/src/Data/Object/Component.elm b/src/Data/Object/Component.elm index 140e0a3c9..4bc99b06b 100644 --- a/src/Data/Object/Component.elm +++ b/src/Data/Object/Component.elm @@ -10,6 +10,8 @@ module Data.Object.Component exposing , decodeComponentItem , decodeList , encodeComponentItem + , expandComponentItems + , expandProcessItems , findById , idFromString , idToString @@ -82,17 +84,30 @@ componentItemToString components processes componentItem = ) -processItemToString : List Process -> ProcessItem -> Result String String -processItemToString processes processItem = - processItem.processId - |> Process.findById processes - |> Result.map - (\process -> - String.fromFloat (amountToFloat processItem.amount) - ++ process.unit - ++ " " - ++ process.displayName - ) +expandComponentItems : + { a | components : List Component, processes : List Process } + -> List ComponentItem + -> Result String (List ( Quantity, Component, List ( Amount, Process ) )) +expandComponentItems { components, processes } = + List.map + (\componentItem -> + components + |> findById componentItem.id + |> Result.andThen + (\component -> + component.processes + |> expandProcessItems processes + |> Result.map (\processItems -> ( componentItem.quantity, component, processItems )) + ) + ) + >> RE.combine + + +expandProcessItems : List Process -> List ProcessItem -> Result String (List ( Amount, Process )) +expandProcessItems processes = + List.map (\{ amount, processId } -> ( amount, processId )) + >> List.map (RE.combineMapSecond (Process.findById processes)) + >> RE.combine decode : Decoder Component @@ -147,6 +162,19 @@ idToString (Id uuid) = Uuid.toString uuid +processItemToString : List Process -> ProcessItem -> Result String String +processItemToString processes processItem = + processItem.processId + |> Process.findById processes + |> Result.map + (\process -> + String.fromFloat (amountToFloat processItem.amount) + ++ process.unit + ++ " " + ++ process.displayName + ) + + quantityFromInt : Int -> Quantity quantityFromInt int = Quantity int diff --git a/src/Data/Object/Simulator.elm b/src/Data/Object/Simulator.elm index 272e84820..b5ffd983b 100644 --- a/src/Data/Object/Simulator.elm +++ b/src/Data/Object/Simulator.elm @@ -3,8 +3,6 @@ module Data.Object.Simulator exposing , availableComponents , compute , emptyResults - , expandProcessItems - , expandProcesses , extractImpacts , extractItems , extractMass @@ -14,7 +12,7 @@ module Data.Object.Simulator exposing import Data.Impact as Impact exposing (Impacts, noStepsImpacts) import Data.Impact.Definition as Definition import Data.Object.Component as Component exposing (Component, ComponentItem, ProcessItem) -import Data.Object.Process as Process exposing (Process) +import Data.Object.Process as Process import Data.Object.Query exposing (Query) import Mass exposing (Mass) import Quantity @@ -113,31 +111,6 @@ emptyResults = } -expandProcessItems : Db -> Query -> Result String (List ( Component.Quantity, Component, List ( Component.Amount, Process ) )) -expandProcessItems db = - .components - >> List.map - (\componentItem -> - db.object.components - |> Component.findById componentItem.id - |> Result.andThen - (\component -> - component.processes - |> expandProcesses db - |> Result.map (\processes -> ( componentItem.quantity, component, processes )) - ) - ) - >> RE.combine - - -expandProcesses : Db -> List ProcessItem -> Result String (List ( Component.Amount, Process )) -expandProcesses db processes = - processes - |> List.map (\{ amount, processId } -> ( amount, processId )) - |> List.map (RE.combineMapSecond (Process.findById db.object.processes)) - |> RE.combine - - extractImpacts : Results -> Impacts extractImpacts (Results { impacts }) = impacts diff --git a/src/Page/Explore/ObjectComponents.elm b/src/Page/Explore/ObjectComponents.elm index 59526ff07..c233e6008 100644 --- a/src/Page/Explore/ObjectComponents.elm +++ b/src/Page/Explore/ObjectComponents.elm @@ -2,7 +2,6 @@ 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 (..) @@ -39,7 +38,7 @@ table db { detailed, scope } = , toValue = Table.StringValue <| \{ processes } -> - case Simulator.expandProcesses db processes of + case ObjectComponent.expandProcessItems db.object.processes processes of Err _ -> "" @@ -55,7 +54,7 @@ table db { detailed, scope } = |> String.join ", " , toCell = \{ processes } -> - case Simulator.expandProcesses db processes of + case ObjectComponent.expandProcessItems db.object.processes processes of Err err -> Alert.simple { close = Nothing diff --git a/src/Page/Object.elm b/src/Page/Object.elm index c1de56d7c..9dab73f67 100644 --- a/src/Page/Object.elm +++ b/src/Page/Object.elm @@ -535,7 +535,7 @@ componentListView db { detailedComponents, impact, results } query = div [ class "card-body" ] [ text "Aucun élément." ] else - case Simulator.expandProcessItems db query of + case Component.expandComponentItems db.object query.components of Err error -> Alert.simple { close = Nothing