From faf95f842e1c4fc0237f319f610e46066a8b8e13 Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Tue, 15 Dec 2015 12:46:27 +0100 Subject: [PATCH 1/8] Small textual tweak --- stoptime.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stoptime.rb b/stoptime.rb index 8dbef5b..ac45c58 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -1834,7 +1834,7 @@ module StopTime::Views elsif @active_tasks[customer].empty? p do em "No active projects/tasks found! " + - "Register time on one of these tasks: " + "Register time on one of these projects/tasks: " br @tasks[customer].each do |task| a task.name, href: R(CustomersNTasksN, customer.id, task.id) From 81e6db24ef8055caa6453343b4ae16c098ae69ca Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Thu, 17 Dec 2015 09:41:58 +0100 Subject: [PATCH 2/8] Fix wrong CSS class name --- stoptime.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stoptime.rb b/stoptime.rb index ac45c58..d705822 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -2919,7 +2919,7 @@ module StopTime::Views tbody do invoices.each do |invoice| due_class = invoice.past_due? ? "warning" : "" - due_class = "error" if invoice.way_past_due? + due_class = "danger" if invoice.way_past_due? tr(class: due_class) do td do a invoice.number, From 49bfdff822afbfd5c3815385895b6eca0ee3db35 Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Fri, 26 Feb 2016 23:12:36 +0100 Subject: [PATCH 3/8] Add support for choosing what date/time is used for new entries --- config.yaml.example | 4 ++++ stoptime.rb | 30 +++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/config.yaml.example b/config.yaml.example index 53557af..8d5b841 100644 --- a/config.yaml.example +++ b/config.yaml.example @@ -3,6 +3,10 @@ # Time resolution in minutes #time_resolution: 1 +# Which date to use for new entries +# Supported values are: previous, today, none +#date_new_entry: today + # The default hourly rate #hourly_rate: 20.0 diff --git a/stoptime.rb b/stoptime.rb index d705822..7791ecf 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -166,6 +166,7 @@ module StopTime::Models "invoice_template" => "invoice", "hourly_rate" => 20.0, "time_resolution" => 1, + "date_new_entry" => "today", "vat_rate" => 21.0 } # Creates a new configuration object and loads the configuation. @@ -888,6 +889,22 @@ module StopTime::Models end # StopTime::Models +# = The Stop… Camping Time! helpers +module StopTime::Helpers + + def date_time_new_entry(last_entry = nil) + case @config["date_new_entry"] + when "previous" + TimeEntry.last.end + when "today" + DateTime.now + when "none" + nil + end + end + +end + # = The Stop… Camping Time! controllers module StopTime::Controllers @@ -1550,9 +1567,11 @@ module StopTime::Controllers @task_list[t.customer.shortest_name] << [t.id, t.name] end @input["bill"] = true - @input["date"] = DateTime.now.to_date - @input["start"] = Time.now.to_formatted_s(:time_only) - + date_time_new = date_time_new_entry(TimeEntry.last) + if date_time_new + @input["date"] = date_time_new.to_date.to_formatted_s + @input["start"] = date_time_new.to_formatted_s(:time_only) + end @target = [Timeline] @button = "enter" render :time_entry_form @@ -3123,6 +3142,7 @@ module StopTime::Views # @param [Customer, nil] task a task to show time entries for # @return [Mab::Mixin::Tag] the main menu def _time_entries(customer=nil, task=nil) + date_time_new = date_time_new_entry(@time_entries.first) form.form_inline action: R(Timeline), method: :post do table.table.table_condensed.table_striped.table_hover do thead do @@ -3156,11 +3176,11 @@ module StopTime::Views end td.col_md_1 do input.form_control type: :text, name: "date", - value: DateTime.now.to_date.to_formatted_s + value: date_time_new && date_time_new.to_date.to_formatted_s end td.col_md_1 do input.form_control type: :text, name: "start", - value: DateTime.now.to_time.to_formatted_s(:time_only) + value: date_time_new && date_time_new.to_formatted_s(:time_only) end td.col_md_1 do input.form_control type: :text, name: "end" From 7c41c32dfdd66bde29ba811aafc4ec755dc7df17 Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Sun, 6 Mar 2016 12:17:46 +0100 Subject: [PATCH 4/8] Add documentation for the #date_time_new_entry helper method --- stoptime.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/stoptime.rb b/stoptime.rb index 7791ecf..5331ffa 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -892,6 +892,14 @@ end # StopTime::Models # = The Stop… Camping Time! helpers module StopTime::Helpers + # Returns the date/time to use for new time entry defaults, or +nil+ if + # none is to be used. This method can use the last time entry (if any + # and if so configured). The result is based on the +date_new_entry+ + # configuration option. + # + # @param last_entry [DateTime] the last time entry to use if configured + # for "previous" + # @return [DateTime, nil] the date/time to be used for new entry defaults def date_time_new_entry(last_entry = nil) case @config["date_new_entry"] when "previous" From bbf2566352700659a4e7b2b0bc83cd4c06ed09a5 Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Sun, 6 Mar 2016 14:59:57 +0100 Subject: [PATCH 5/8] Use #dup to copy models Since we require ActiveRecord >= 3.2, #dup should be used, not #clone (which is <= 3.1). --- stoptime.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stoptime.rb b/stoptime.rb index 5331ffa..a3bdfab 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -1306,7 +1306,7 @@ module StopTime::Controllers tasks.each_key do |task| # Create a new (billed) task clone that contains the selected time # entries, leave the rest unbilled and associated with their task. - bill_task = task.dup # FIXME: depends on rails version! + bill_task = task.dup task.time_entries = task.time_entries - tasks[task] task.save bill_task.time_entries = tasks[task] @@ -1729,7 +1729,7 @@ module StopTime::Controllers @history_warn = true if @company != CompanyInfo.last if @company == CompanyInfo.last and @company.invoices.length > 0 old_company = @company - @company = old_company.clone # FIXME: depends on rails version! + @company = old_company.dup @company.original = old_company end From 7184248ccdf4e35390f0677d8bfeac9218c9883b Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Sun, 6 Mar 2016 15:01:14 +0100 Subject: [PATCH 6/8] Fix the last company info is used-check --- stoptime.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stoptime.rb b/stoptime.rb index a3bdfab..d44edb7 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -1727,7 +1727,7 @@ module StopTime::Controllers # If we are editing the current info and it is already associated # with some invoices, create a new revision. @history_warn = true if @company != CompanyInfo.last - if @company == CompanyInfo.last and @company.invoices.length > 0 + if @company.id == CompanyInfo.last.id and @company.invoices.length > 0 old_company = @company @company = old_company.dup @company.original = old_company From cb215e54ebd1f87aa16632603c31a8e29960e470 Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Sun, 11 Sep 2016 15:02:40 +0200 Subject: [PATCH 7/8] Ensure that only time entries with tasks are selected (closes: #89c2a1) Time entries without tasks shouldn't exist/be possible though. --- stoptime.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/stoptime.rb b/stoptime.rb index d44edb7..9e85636 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -1520,6 +1520,7 @@ module StopTime::Controllers .where("stoptime_tasks.invoice_id" => nil)\ .order("start DESC") end + @time_entries = @time_entries.where.not(task_id: nil) @time_entries.each do |te| @input["bill_#{te.id}"] = true if te.bill? end From 958551556594d273ffbb4ba012ab946578e28556 Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Sun, 11 Sep 2016 15:10:01 +0200 Subject: [PATCH 8/8] Bump bump to 1.17.0 --- stoptime.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stoptime.rb b/stoptime.rb index 9e85636..3e02338 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -55,7 +55,7 @@ end module StopTime # The version of the application - VERSION = '1.16.1' + VERSION = '1.17.0' puts "Starting Stop… Camping Time! version #{VERSION}" # @return [Hash{String=>Object}] The parsed configuration.