137 lines
3.7 KiB
Ruby
137 lines
3.7 KiB
Ruby
|
class RulingTimersController < ApplicationController
|
||
|
before_action :set_timer
|
||
|
def save_work_times
|
||
|
@ruling_timer_temp.update_work_times(params[:work_times])
|
||
|
@ruling_timer_temp.recalc_all
|
||
|
render :json => @ruling_timer_temp.to_json
|
||
|
end
|
||
|
def get_work_times
|
||
|
render :json => @ruling_timer_temp.get_work_times(true)
|
||
|
end
|
||
|
def start
|
||
|
render :json => @ruling_timer_temp.start(params[:timer_offset])
|
||
|
end
|
||
|
def stop
|
||
|
render :json => @ruling_timer_temp.stop
|
||
|
end
|
||
|
def rest
|
||
|
render :json => @ruling_timer_temp.rest
|
||
|
end
|
||
|
def set_summary
|
||
|
begin
|
||
|
@ruling_timer_temp.summary = params[:summary]
|
||
|
@ruling_timer_temp.save!
|
||
|
render :json => {"success"=>true}
|
||
|
rescue => e
|
||
|
puts [e,e.backtrace]
|
||
|
render :json => {"success"=>false}
|
||
|
end
|
||
|
end
|
||
|
def add_task
|
||
|
begin
|
||
|
@ruling_timer_temp.tasks << params[:task]
|
||
|
task = RulingTimerTask.create(:task_name=>params[:task],:user_ids=>[current_user.id.to_s])
|
||
|
sub_task = task.ruling_timer_sub_tasks.first
|
||
|
@ruling_timer_temp.sub_task_ids << sub_task.id.to_s
|
||
|
@ruling_timer_temp.save!
|
||
|
if @ruling_timer_temp.status == "working"
|
||
|
sub_task.start(@ruling_timer_temp.time_offset)
|
||
|
else
|
||
|
sub_task.update(:time_offset =>@ruling_timer_temp.time_offset)
|
||
|
end
|
||
|
render :json => {"success"=>true,"task-id"=>sub_task.id,"task"=>sub_task.task_name}
|
||
|
rescue => e
|
||
|
puts [e,e.backtrace]
|
||
|
render :json => {"success"=>false}
|
||
|
end
|
||
|
end
|
||
|
def add_task_from_list
|
||
|
begin
|
||
|
task = RulingTimerTask.find(params[:task_id])
|
||
|
if !(task.user_ids.include?(current_user.id.to_s))
|
||
|
task.user_ids << current_user.id.to_s
|
||
|
task.save
|
||
|
end
|
||
|
sub_task = task.ruling_timer_sub_tasks.where(:user=>current_user).first
|
||
|
if !(@ruling_timer_temp.sub_task_ids.include?(sub_task.id.to_s))
|
||
|
@ruling_timer_temp.sub_task_ids << sub_task.id.to_s
|
||
|
@ruling_timer_temp.tasks << task.task_name
|
||
|
@ruling_timer_temp.save!
|
||
|
end
|
||
|
if @ruling_timer_temp.status == "working"
|
||
|
sub_task.start(@ruling_timer_temp.time_offset)
|
||
|
else
|
||
|
sub_task.update(:time_offset =>@ruling_timer_temp.time_offset)
|
||
|
end
|
||
|
render :json => {"success"=>true,"task-id"=>sub_task.id,"task"=>sub_task.task_name}
|
||
|
rescue => e
|
||
|
puts [e,e.backtrace]
|
||
|
render :json => {"success"=>false}
|
||
|
end
|
||
|
end
|
||
|
def remove_task
|
||
|
begin
|
||
|
@ruling_timer_temp.remove_task(params[:task_id])
|
||
|
render :json => {"success"=>true}
|
||
|
rescue => e
|
||
|
puts [e,e.backtrace]
|
||
|
render :json => {"success"=>false}
|
||
|
end
|
||
|
end
|
||
|
def start_task
|
||
|
task = RulingTimerSubTask.find(params[:task_id])
|
||
|
render :json => task.start
|
||
|
end
|
||
|
def stop_task
|
||
|
render :json => task.stop
|
||
|
end
|
||
|
def set_task_status
|
||
|
begin
|
||
|
idx = @ruling_timer_temp.sub_task_ids.index(params[:task_id])
|
||
|
if idx
|
||
|
task = RulingTimerSubTask.find(params[:task_id])
|
||
|
if params[:status].to_i == 0
|
||
|
@ruling_timer_temp.tasks_finished.delete(idx)
|
||
|
task.start
|
||
|
else
|
||
|
@ruling_timer_temp.tasks_finished << idx
|
||
|
@ruling_timer_temp.tasks_finished.uniq!
|
||
|
task.finish
|
||
|
end
|
||
|
@ruling_timer_temp.save!
|
||
|
end
|
||
|
render :json => {"success"=>true}
|
||
|
rescue => e
|
||
|
puts [e,e.backtrace]
|
||
|
render :json => {"success"=>false}
|
||
|
end
|
||
|
end
|
||
|
def add_event
|
||
|
begin
|
||
|
@ruling_timer_temp.add_event(*params[:event])
|
||
|
render :json => {"success"=>true}
|
||
|
rescue => e
|
||
|
puts [e,e.backtrace]
|
||
|
render :json => {"success"=>false}
|
||
|
end
|
||
|
end
|
||
|
def delete_event
|
||
|
begin
|
||
|
@ruling_timer_temp.delete_event(params[:event_idx].to_i)
|
||
|
render :json => {"success"=>true}
|
||
|
rescue => e
|
||
|
puts [e,e.backtrace]
|
||
|
render :json => {"success"=>false}
|
||
|
end
|
||
|
end
|
||
|
def set_timer
|
||
|
@ruling_timer_temp = nil
|
||
|
user = (current_user rescue nil)
|
||
|
if (user rescue false)
|
||
|
@ruling_timer_temp = RulingTimerTemp.where(:user=>user).first
|
||
|
if @ruling_timer_temp.nil?
|
||
|
@ruling_timer_temp = RulingTimerTemp.create(:user=>user)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|