Implemented adding/deleting time registrations.
This commit is contained in:
parent
d9da9568c8
commit
28fa689a52
117
stoptime.rb
117
stoptime.rb
|
@ -43,6 +43,7 @@ module StopTime::Models
|
||||||
|
|
||||||
class Task < Base
|
class Task < Base
|
||||||
has_many :time_entries
|
has_many :time_entries
|
||||||
|
belongs_to :customer
|
||||||
end
|
end
|
||||||
|
|
||||||
class TimeEntry < Base
|
class TimeEntry < Base
|
||||||
|
@ -82,7 +83,7 @@ module StopTime::Controllers
|
||||||
|
|
||||||
class Index
|
class Index
|
||||||
def get
|
def get
|
||||||
render :overview
|
redirect R(Timereg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -162,17 +163,44 @@ module StopTime::Controllers
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Tasks
|
class Timereg
|
||||||
def get
|
def get
|
||||||
@tasks = Tasks.all
|
@time_entries = TimeEntry.all
|
||||||
render :tasks
|
@customer_list = Customer.all.map { |c| [c.id, c.short_name] }
|
||||||
|
@task_list = Task.all.map { |t| [t.id, t.name] }
|
||||||
|
render :time_entries
|
||||||
|
end
|
||||||
|
|
||||||
|
def post
|
||||||
|
if @input.has_key? "enter"
|
||||||
|
@entry = TimeEntry.create(
|
||||||
|
:task_id => @input.task,
|
||||||
|
:start => @input.start,
|
||||||
|
:end => @input.end)
|
||||||
|
@entry.save
|
||||||
|
if @entry.invalid?
|
||||||
|
@errors = @entry.errors
|
||||||
|
end
|
||||||
|
elsif @input.has_key? "delete"
|
||||||
|
end
|
||||||
|
|
||||||
|
@time_entries = TimeEntry.all
|
||||||
|
@customer_list = Customer.all.map { |c| [c.id, c.short_name] }
|
||||||
|
@task_list = Task.all.map { |t| [t.id, t.name] }
|
||||||
|
render :time_entries
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class TimeEntries
|
class TimeregN
|
||||||
|
def post(entry_id)
|
||||||
|
TimeEntry.find(entry_id).delete
|
||||||
|
redirect R(Timereg)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class Invoices
|
||||||
def get
|
def get
|
||||||
@time_entries = TimeEntry.all
|
render :invoices
|
||||||
render :time_entries
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -187,23 +215,61 @@ module StopTime::Views
|
||||||
end
|
end
|
||||||
body do
|
body do
|
||||||
div.wrapper! do
|
div.wrapper! do
|
||||||
self << yield
|
h1 "Stop… Camping Time!"
|
||||||
|
_menu
|
||||||
|
div.content! do
|
||||||
|
self << yield
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def customers
|
def _menu
|
||||||
|
ol.menu! do
|
||||||
|
li { a "Time Registration", :href => R(Timereg) }
|
||||||
|
li { a "Customers", :href => R(Customers) }
|
||||||
|
li { a "Invoices", :href => R(Invoices) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def overview
|
def time_entries
|
||||||
h1 "Stop… Camping Time!"
|
h2 "List of time entries"
|
||||||
|
table do
|
||||||
p "You can check out:"
|
tr do
|
||||||
ul do
|
th "Customer"
|
||||||
li { a "Customers", :href => R(Customers) }
|
th "Project/task"
|
||||||
li { a "Task", :href=> R(Tasks) }
|
th "Start time"
|
||||||
li { a "Time entries", :href => R(TimeEntries) }
|
th "End time"
|
||||||
|
th "Total"
|
||||||
|
end
|
||||||
|
form :action => R(Timereg), :method => :post do
|
||||||
|
tr do
|
||||||
|
td { _form_select("customer", @customer_list) }
|
||||||
|
td { _form_select("task", @task_list) }
|
||||||
|
td { input :type => :text, :name => "start" }
|
||||||
|
td { input :type => :text, :name => "end" }
|
||||||
|
td { "N/A" }
|
||||||
|
td do
|
||||||
|
input :type => :submit, :name => "enter", :value => "Enter"
|
||||||
|
input :type => :reset, :name => "clear", :value => "Clear"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@time_entries.each do |entry|
|
||||||
|
tr do
|
||||||
|
td { entry.task.customer.short_name }
|
||||||
|
td { entry.task.name }
|
||||||
|
td { entry.start }
|
||||||
|
td { entry.end }
|
||||||
|
td { "%.2fh" % ((entry.end - entry.start)/3600.0) }
|
||||||
|
td do
|
||||||
|
form :action => R(TimeregN, entry.id), :method => :post do
|
||||||
|
input :type => :submit, :name => "delete", :value => "Delete"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -263,6 +329,23 @@ module StopTime::Views
|
||||||
input :type => "submit", :name => "save", :value => "Save"
|
input :type => "submit", :name => "save", :value => "Save"
|
||||||
input :type => "submit", :name => "cancel", :value => "Cancel"
|
input :type => "submit", :name => "cancel", :value => "Cancel"
|
||||||
end
|
end
|
||||||
|
if @edit_task
|
||||||
|
form :action => R(CustomersNTasks, @customer.id), :method => :post do
|
||||||
|
h2 "Projects & Tasks"
|
||||||
|
select :name => "tasks[]", :multiple => "multiple", :size => 6 do
|
||||||
|
@customer.tasks.each do |task|
|
||||||
|
option(:value => task.id) { task.name }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
input :type => :text, :name => "new_task"
|
||||||
|
input :type => :submit, :name => "add", :value => "Add"
|
||||||
|
input :type => :submit, :name => "delete", :value => "Delete"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def invoices
|
||||||
|
h2 "List of invoices"
|
||||||
end
|
end
|
||||||
|
|
||||||
def _form_input(obj, label_name, input_name, type, options={})
|
def _form_input(obj, label_name, input_name, type, options={})
|
||||||
|
|
Loading…
Reference in New Issue