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

Choose duration for tomato #291

Closed
wants to merge 11 commits into from
1 change: 1 addition & 0 deletions app/assets/javascripts/TT.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ var TT = function() {
show([settings.formId]);

$("#" + settings.formId + " input[type=text]").focus();
$("#tomato_duration").val(tomatoDuration * 60);
}

var stateSignIn = function() {
Expand Down
1 change: 1 addition & 0 deletions app/assets/javascripts/TT_init.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ soundManager.setup({

function startCallback(event) {
if('idle' == TT.getStatus()) {
tomatoDuration = parseInt(document.getElementById("duration_time_input").value)/60;
TT.start(tomatoDuration, currentUser ? TT.stateNewForm : TT.stateSignIn);
event.preventDefault();
}
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concerns/tomatoes_params.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module TomatoesParams
def resource_params
params.permit(tomato: [:tag_list]).require(:tomato)
params.permit(tomato: [:tag_list, :duration]).require(:tomato)
end
end
2 changes: 1 addition & 1 deletion app/helpers/tomatoes_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module TomatoesHelper
def tomato_duration(tomato)
"#{(tomato.created_at - Tomato::DURATION).strftime('%I:%M %p')} - #{tomato.created_at.strftime('%I:%M %p')}"
"#{(tomato.created_at - tomato.duration.to_i.minutes).strftime('%I:%M %p')} - #{tomato.created_at.strftime('%I:%M %p')}"
end
end
2 changes: 2 additions & 0 deletions app/models/tomato.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class Tomato

index(created_at: 1)

field :duration, type: String
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not Integer?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I've seen it after do the pull request, should be Integer


validate :must_not_overlap, on: :create

after_create :increment_score
Expand Down
1 change: 1 addition & 0 deletions app/views/tomatoes/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<% remote = false if local_assigns[:remote].nil? %>

<%= form_for(@tomato, remote: remote) do |f| %>
<%= f.hidden_field :duration %>
<% if @tomato.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@tomato.errors.count, "error") %> prohibited this tomato from being saved:</h2>
Expand Down
11 changes: 11 additions & 0 deletions app/views/welcome/_tomatoes_timer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,15 @@
<div id="start_container" class="center-block">
<%= link_to t('timer.start'), '#', id: 'start', class: 'btn btn-default btn-lg' %>
<p id="start_hint" class="help-block"><%= t('timer.or_press_space') %></p>
<div class="form-group" style="width: 50%; margin: 0 auto;">
<input name="duration_time"
id="duration_time_input"
class="form-control"
type="range"
min="5"
max="60"
value="5"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default value should be 25.

oninput="duration_time_output.value = duration_time_input.value">
<output style="display: inline-block;" name="duration_time_output" id="duration_time_output">5</output>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be more clear if we add a label, duration, and a unit of measurement, minutes.

</div>
</div>
5 changes: 3 additions & 2 deletions test/unit/helpers/tomatoes_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
class TomatoesHelperTest < ActionView::TestCase
test 'tomato_duration should return a formatted string' do
@created_at = Time.new(2011, 7, 24, 15, 10).in_time_zone
@ended_at = @created_at - Tomato::DURATION
@tomato = Tomato.new(created_at: @created_at)
duration = 5
@ended_at = @created_at - duration.minutes
@tomato = Tomato.new(created_at: @created_at, duration: duration)

assert tomato_duration(@tomato) == "#{@ended_at.strftime('%I:%M %p')} - #{@created_at.strftime('%I:%M %p')}"
end
Expand Down