Skip to content

Commit

Permalink
Increment count if reel with same params has already been added
Browse files Browse the repository at this point in the history
Also, add 'enter to select' for mobile/tablet view.
  • Loading branch information
kfrn committed Jan 27, 2019
1 parent 3194574 commit cd52605
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
21 changes: 20 additions & 1 deletion src/Audio/Reel/Model.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Audio.Reel.Model exposing (DurationInMinutes, Footage(..), Reel, baseDuration, footageToInt, formatTime, fullDuration, newReel, overallDuration, reelLengthInFeet, singleReelDuration)
module Audio.Reel.Model exposing (DurationInMinutes, Footage(..), Reel, baseDuration, existingReel, footageToInt, formatTime, fullDuration, newReel, overallDuration, reelLengthInFeet, singleReelDuration)

import Audio.Model exposing (AudioConfig, DiameterInInches(..), Direction, Passes, Quantity, RecordingSpeed(..), SelectorValues, TapeThickness(..), reelInfo)
import List.Extra as ListX
import Uuid


Expand Down Expand Up @@ -254,3 +255,21 @@ fullDuration reel =
overallDuration : List Reel -> DurationInMinutes
overallDuration reels =
List.sum <| List.map fullDuration reels


existingReel : SelectorValues -> List Reel -> Maybe Reel
existingReel selectorValues reels =
ListX.find
(\reel ->
{ config = reel.audioConfig
, diameter = reel.diameter
, thickness = reel.tapeThickness
, speed = reel.recordingSpeed
}
== { config = selectorValues.audioConfig
, diameter = selectorValues.diameter
, thickness = selectorValues.tapeThickness
, speed = selectorValues.recordingSpeed
}
)
reels
23 changes: 17 additions & 6 deletions src/Update.elm
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module Update exposing (update)

import AppSettings exposing (PageView(..), SystemOfMeasurement(..))
import Audio.Reel.Model exposing (Reel, newReel)
import Audio.Reel.Model exposing (Reel, existingReel, newReel)
import CsvOutput exposing (dataForCSV)
import List.Extra as ListX
import Messages exposing (Msg(..))
import Model exposing (Model)
import Ports
Expand All @@ -29,12 +30,8 @@ update msg model =
( uuid, newSeed ) =
step uuidGenerator model.currentSeed

newReels =
newReel uuid model.selectorValues q
:: model.reels

newModel =
{ model | currentSeed = newSeed, reels = newReels }
{ model | currentSeed = newSeed, reels = updateReels uuid model q }
in
( newModel, Cmd.none )

Expand Down Expand Up @@ -162,3 +159,17 @@ update msg model =
removeReel : Uuid -> List Reel -> List Reel
removeReel reelID allReels =
List.filter (\r -> r.id /= reelID) allReels


updateReels : Uuid -> Model -> Int -> List Reel
updateReels uuid model quantity =
case existingReel model.selectorValues model.reels of
Just reel ->
let
updatedReel =
{ reel | quantity = reel.quantity + quantity }
in
ListX.setIf (\r -> r == reel) updatedReel model.reels

Nothing ->
newReel uuid model.selectorValues quantity :: model.reels
2 changes: 1 addition & 1 deletion src/View/Helpers.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module View.Helpers exposing (onChange, onKeyDown, renderSelect, wrapSectionInLevelDiv)

import Html exposing (Html, div, option, select, span, text)
import Html exposing (Html, div, option, select, text)
import Html.Attributes exposing (class, selected)
import Html.Events exposing (keyCode, on)
import Json.Decode as Json
Expand Down
3 changes: 2 additions & 1 deletion src/View/ReelTable/Mobile.elm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Maybe.Extra exposing (isNothing)
import Messages exposing (Msg(..))
import Model exposing (Model)
import Translate exposing (AppString(..), Language, audioConfigDisplayName, directionString, translate)
import View.Helpers exposing (renderSelect)
import View.Helpers exposing (onKeyDown, renderSelect)


mobileReelTable : Model -> Html Msg
Expand Down Expand Up @@ -107,6 +107,7 @@ addReel model =
, id "quantity"
, placeholder "#"
, onInput UpdateQuantity
, onKeyDown KeyDown
]
[]
]
Expand Down

0 comments on commit cd52605

Please sign in to comment.