Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create new timer linked to a capture #15

Open
3 tasks done
SimonLab opened this issue Mar 10, 2020 · 9 comments
Open
3 tasks done

Create new timer linked to a capture #15

SimonLab opened this issue Mar 10, 2020 · 9 comments

Comments

@SimonLab
Copy link
Member

SimonLab commented Mar 10, 2020

image

  • Send post request to create new timer linked to the capture
  • While waiting for the response disable the "start" button to not send multiple "start timer" events.
  • On response change "start" to "stop" and enable the button
@SimonLab
Copy link
Member Author

Looking at why the api doesn't associate the timer to the capture:
image

We can see that capture_id fields are null. I think this is an ecto mistake from my part.

@SimonLab
Copy link
Member Author

SimonLab commented Mar 11, 2020

Currently looking on how to convert a NaiveDateTime from Elixir to an Elm time type

So when a timer is created the api is returning a stringify json object similar to:

{"data":{"capture_id":3,"started_at":"2020-03-11T14:54:15","stopped_at":null,"timer_id":3}}

The stopped_at value is currently null as the timer hasn't been stopped yet.
We can see the started_at value is a string representation of a time that we'll need to convert to a time type in Elm to be able to display the counting timer.

current type to represent the timer in Elm:

type alias Timer =
    { startedAt : String
    , stoppedAt : Maybe String
    }

decoder when receiving the json:

timerDecoder : JD.Decoder Timer
timerDecoder =
    JD.field "data"
        (JD.map2 Timer
            (JD.field "started_at" JD.string)
            (JD.maybe (JD.field "stoped_at" JD.string))
        )

reviewing how time works with Elm:https://guide.elm-lang.org/effects/time.html

@SimonLab
Copy link
Member Author

I've spent a bit of time looking at how to convert the time from Elixir to Elm
The value in json, for example "2020-03-11T14:54:15" is in fact a is8601 format.
Using Iso8601 we can convert the string to a posix.

import Iso8601
Iso8601.toTime "2020-03-11T14:54:15"
Ok (Posix 1583938455000)
    : Result (List Parser.DeadEnd) Time.Posix

@SimonLab
Copy link
Member Author

The status of a capture will depend on the timers linked to it.
I'm thinking updating the capture type from:

type alias Capture =
    { idCapture : Int
    , text : String
    , completed : Bool
    , disabled : Bool
    }

to

type alias Capture =
    { idCapture : Int
    , text : String
    , status: CaptureStatus
    }

where CaptureStatus represent the state of the capture:

type CaptureStatus = 
  ToDo -- when created
  | Completed -- when completed value is true in Postgres
  | InProgress -- when the most recent timer is running, ie the `stoppedAt` value is null
  | Disabled -- when waiting for a response from the api. This disable the button to avoid wrong state
  | Error String -- represent errors, e.g capture can't be saved, not authorized, multiple timers running at the same time...

I'm also thinking of creating a specific module for the Capture. This should make the capture page more readable

@SimonLab
Copy link
Member Author

Updating the Timer type to update the startedAt and stoppedAt values to be Posix value instead of String and

type alias Timer =
    { idTimer : Int
    , idCapture : Int
    , startedAt : String
    , stoppedAt : Maybe String
    }
type alias Timer =
    { idTimer : Int
    , idCapture : Int
    , startedAt : Posix
    , stoppedAt : Maybe Posix
    }

The elm-iso8601 package provides a decoder to convert a string value to a posix.
image

@SimonLab
Copy link
Member Author

Get current time on the capture page to be able to compare the posix of the timers to the current time:
image

@SimonLab
Copy link
Member Author

Displaying the total amount of time spent for each capture:
image

Looking now at displaying the time when a capture is "in progress"

@SimonLab
Copy link
Member Author

timers

@SimonLab
Copy link
Member Author

linked to dwyl/app#265

Create a new timer entry for the item_id when the start button is pressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant