Class: WorksController

Inherits:
ApplicationController show all
Defined in:
app/controllers/works_controller.rb

Constant Summary

Constants included from Localization

Localization::LOCALIZED_STRINGS

Instance Method Summary collapse

Methods inherited from ApplicationController

in_place_edit_for

Methods included from Localization

#l, load_localized_strings, #valid_language?

Instance Method Details

#auto_complete_for_work_backlog_nameObject



106
107
108
109
110
111
112
113
# File 'app/controllers/works_controller.rb', line 106

def auto_complete_for_work_backlog_name
  @backlogs = Backlog.find(:all, 
                           :conditions => [ 'LOWER(name) LIKE ?',
  '%' + params[:work][:backlog_name].downcase + '%' ], 
  :order => 'name ASC',
  :limit => 16)
  render :partial => '/backlogs/name_list'
end

#auto_complete_for_work_task_descriptionObject



115
116
117
118
119
120
121
122
# File 'app/controllers/works_controller.rb', line 115

def auto_complete_for_work_task_description
  @tasks = Task.find(:all, 
                     :conditions => [ 'finished_at IS NULL AND LOWER(description) LIKE ?',
  '%' + params[:work][:task_description].downcase + '%' ], 
  :order => 'description ASC',
  :limit => 16)
  render :partial => '/tasks/description_list'
end

#createObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/works_controller.rb', line 34

def create
  convert_hours_param
  @work = Work.new(params[:work])
  @work.completed_at = Time.now unless @work.completed_at
  if @work.save!
    flash[:notice] = 'Work was successfully created.'
  else
    render :action => 'new'
    return
  end
  
  @work.task.estimates.create!(params[:estimate]) if params[:estimate]
  
  back_or_redirect_to :controller => 'periods', :action => 'show', :id => @work.task.period, :task_id => @work.task.id
end

#daily_work_sheetObject



81
82
83
84
85
86
87
88
89
90
# File 'app/controllers/works_controller.rb', line 81

def daily_work_sheet
  @date = (params[:date] && Date.parse(params[:date])) || Date.today
  @periods = []
  @works = Work.find(:all,
                     :conditions => "started_at < '#{@date+1}' AND completed_at >= '#{@date}'",
  :order => 'completed_at'
  )
  @started_works = Task.find_started
  render :layout => 'wide'
end

#destroyObject



74
75
76
77
78
79
# File 'app/controllers/works_controller.rb', line 74

def destroy
  work = Work.find(params[:id])
  period = work.task.period
  work.destroy
  redirect_to :controller => 'periods', :action => :list_work, :id => period 
end

#editObject



50
51
52
53
54
55
# File 'app/controllers/works_controller.rb', line 50

def edit
  @work = Work.find(params[:id])
  @work.attributes = params[:work]
  @estimate = Estimate.new(params[:estimate])
  @users = User.find(:all)
end

#indexObject



8
9
10
11
# File 'app/controllers/works_controller.rb', line 8

def index
  list
  render :action => 'list'
end

#listObject



17
18
19
20
# File 'app/controllers/works_controller.rb', line 17

def list
  @period = params[:id] && Period.find(params[:id])
  @work_pages, @works = paginate :works, :per_page => 20
end

#newObject



26
27
28
29
30
31
32
# File 'app/controllers/works_controller.rb', line 26

def new
  @work = Work.new(params[:work])
  @work.user = user
  @estimate = Estimate.new(params[:estimate])
  @tasks = Task.find_open
  @users = User.find(:all)
end

#showObject



22
23
24
# File 'app/controllers/works_controller.rb', line 22

def show
  @work = Work.find(params[:id])
end

#timelisteObject



98
99
100
101
102
103
104
# File 'app/controllers/works_controller.rb', line 98

def timeliste
  @week = (params[:id] && params[:id].to_i) || Date.today.cweek
  @backlogs = Work.work_totals_for_week(@week, user_id)
  headers["Content-Type"] = "application/vnd.ms-excel"
  headers["Content-Disposition"] = 'attachment; filename="export.xml"'
  render :layout => false
end

#updateObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/works_controller.rb', line 57

def update
  @work = Work.find(params[:id])
  
  convert_start_time_param
  convert_hours_param
  if @work.update_attributes(params[:work])
    flash[:notice] = 'Work was successfully updated.'
    if params[:estimate].nil? || (@estimate = @work.task.estimates.create(params[:estimate])).errors.size == 0
      back_or_redirect_to :controller => 'periods', :action => 'show', :id => @work.task.period, :task_id => @work.task.id
      return
    end
  end
  @task = @work.task
  edit
  render :action => 'edit'
end

#weekly_work_sheetObject



92
93
94
95
96
# File 'app/controllers/works_controller.rb', line 92

def weekly_work_sheet
  @week = (params[:id] && params[:id].to_i) || Date.today.cweek
  @rows = Work.works_for_week(@week, user)
  render :layout => 'wide'
end