Permalink
Browse files

Added summary file

  • Loading branch information...
1 parent f32e597 commit d2ad5e3f98f6abcb3a7d15ac99521c94a325cfd7 @chris2fr committed Sep 12, 2009
@@ -1,15 +1,29 @@
+
+
class WorkloadController < ApplicationController
+ unloadable
+ def timetable_summary
+ @current_date = get_current_date (params)
+ @current_user_id = get_current_user_id (params)
+ @interval = 30
+ #@return = get_timetable_info(@date, @interval, @current_user_id)
+ get_timetable_info(@current_date, @interval, @current_user_id)
- def timetable_summary
- end
+ end
- def timetable_update
- @flag = "non"
- act_id = Enumeration.find(:first,:conditions => {:opt => "ACTI"} ).id
- params[:time_entry].each do |issue_id, hours|
- @spent_hours = get_spent_hours(issue_id,params[:user_id].to_i(),params[:date])
- #unless @spent_hours == hours.to_f()
+ def timetable_update
+ @current_date = get_current_date (params)
+ @current_user_id = get_current_user_id (params)
+ #
+ # UPDATE PART
+ #
+ # See if the project has activities or not
+ act_id = Enumeration.find(:first,:conditions => {:opt => "ACTI"} ).id
+ # Update each time entry for the user, the day, the issue
+ params[:time_entry].each do |issue_id, hours|
+ @spent_hours = get_spent_hours(issue_id,params[:user_id].to_i(),params[:date])
+ # Non-zero time entry to add
if (@spent_hours == 0.0 and hours != "0") # Ajouter TimeEntry
@te = TimeEntry.create()
@te.hours = hours.to_i()
@@ -20,163 +34,153 @@ def timetable_update
@te.user_id = params[:user_id]
@te.spent_on = params[:date]
@te.save()
+ # Non-zero time-entry to delete
elsif @spent_hours != 0 and hours == "0"# and hours == "0" # Supprimer
TimeEntry.delete(TimeEntry.find(:first, :conditions => {:user_id => params[:user_id].to_i(),:issue_id => issue_id, :spent_on => params[:date]}).id)
- @flag = "oui"
+ # Non-zero time-entry to update
elsif @spent_hours != hours.to_f()
@te = TimeEntry.find(:first, :conditions => {:user_id => params[:user_id].to_i(),:issue_id => issue_id, :spent_on => params[:date]})
@te.hours = hours
@te.save()
end
- #end
- end
- @date = Date::parse(params[:date])
- @conditions = 'user_id = '+params[:user_id] + ' AND spent_on > "' + (@date - 30).to_s() + '" AND spent_on < "' + (@date + 30).to_s() + '"'
- @logged_te = TimeEntry.find(:all,:conditions => [@conditions], :order => ['issue_id,spent_on'] )
- @logged_issues = {}
- @logged_days = {}
- @total_days = {}
- @projcat = {}
- @projects = Project.find(:all, :conditions => {:status => 1}, :order => ['parent_id,name'])
- @projects.each do |projet|
- @projcat[projet.id] = {}
- @projcat[projet.id]["total"] = 0.0
- issue_categories = projet.issue_categories
- projet.issue_categories.each do |cat|
- @projcat[projet.id][cat.id] = {}
end
+ #
+ # TIMESHEET PRODUCTION PART
+ #
+ @current_date = Date::parse(params[:date])
+ @interval = 30
+ @current_user_id = params[:user_id]
+ get_timetable_info(@current_date, @interval, @current_user_id)
end
- @logged_te.each do |te|
- unless @logged_issues.has_key?(te.issue_id)
- @logged_issues[te.issue_id] = Issue.find(:first, :conditions => {:id => te.issue_id})
- @logged_days[te.issue_id] = {}
- #(-29..29).each do |delta|
- # @logged_days[te.issue_id][(@date + delta).to_s()] = 0
- #end
+
+ def timetable
+ @current_date = get_current_date (params)
+ @current_user_id = get_current_user_id (params)
+
+ @users = User.find(:all,:order => ['firstname'])
+ projects = Project.find(:all, :conditions => {:status => 1}, :order => ['parent_id,name'])
+ @project_list = {}
+ @category_list = {}
+ @status_list = {}
+ @tracker_list = {}
+ trackers = Tracker.find(:all)
+ trackers.each do |tracker|
+ @tracker_list[tracker.id] = tracker
end
- if te.spent_on
- @logged_days[te.issue_id][te.spent_on.to_s()] = te.hours.to_f() / 8
- ####### @projcat[te.project_id][te.project.category_id][te.spent_on.to_s()] = te.hours.to_f() / 8
- @projcat = add_to_projcat(@projcat, te.issue.project, te.issue.category, te)
- unless @total_days.has_key?(te.spent_on.to_s())
- @total_days[te.spent_on.to_s()] = te.hours.to_f() / 8
- else
- @total_days[te.spent_on.to_s()] += te.hours.to_f() / 8
- end
+ statuses = IssueStatus.find(:all)
+ statuses.each do |status|
+ @status_list[status.id] = status
end
- end
- end
-
- def timetable
- if params[:user_id]
- @current_user_id = params[:user_id].to_i()
- else
- @current_user_id = User.current.id.to_i()
- end
- if params[:date]
- @current_date = params[:date]
- else
- now = DateTime::now()
- date = Date::civil(now.year,now.month,now.mday)
- @current_date = date.to_s()
- end
- @users = User.find(:all,:order => ['firstname'])
- projects = Project.find(:all, :conditions => {:status => 1}, :order => ['parent_id,name'])
- @project_list = {}
- @category_list = {}
- @status_list = {}
- @tracker_list = {}
- trackers = Tracker.find(:all)
- trackers.each do |tracker|
- @tracker_list[tracker.id] = tracker
- end
- statuses = IssueStatus.find(:all)
- statuses.each do |status|
- @status_list[status.id] = status
- end
- projects.each do |project|
- @project_list[project.id] = project
- cats = IssueCategory.find(:all,:conditions => {:project_id => project.id},:order => ['name'])
- cats.each do |cat|
- @category_list[cat.id] = cat
+ projects.each do |project|
+ @project_list[project.id] = project
+ cats = IssueCategory.find(:all,:conditions => {:project_id => project.id},:order => ['name'])
+ cats.each do |cat|
+ @category_list[cat.id] = cat
+ end
end
- end
- #projet
- @hours_total = 0
- @time_entries_hours = {}
- # Time-logged issues
- @logged_issues = {}
- time_entries = TimeEntry.find(:all,:conditions => {:user_id => @current_user_id, :spent_on => @current_date})
- if time_entries
- seen_te = {}
- time_entries.each do |time_entry|
- if time_entry.hours > 8
- time_entry.hours = 8
- time_entry.save()
- end
- # Fuse all multiple te for a same date
- if seen_te.has_key?(time_entry.issue_id)
- seen_te[time_entry.issue_id].hours += time_entry.hours
- if time_entry.comments
- seen_te[time_entry.issue_id].comments += " + " + time_entry.comments
+ #projet
+ @hours_total = 0
+ @time_entries_hours = {}
+ # Time-logged issues
+ @logged_issues = {}
+ time_entries = TimeEntry.find(:all,:conditions => {:user_id => @current_user_id, :spent_on => @current_date})
+ if time_entries
+ seen_te = {}
+ time_entries.each do |time_entry|
+ if time_entry.hours > 8
+ time_entry.hours = 8
+ time_entry.save()
end
- @hours_total += time_entry.hours
- seen_te[time_entry.issue_id].save()
- TimeEntry.delete(time_entry.id)
- @logged_issues[time_entry.issue_id] = get_spent_hours(time_entry.issue_id, @current_user_id,@current_date)
- else
- seen_te[time_entry.issue_id] = time_entry
- @logged_issues[time_entry.issue_id] = Issue.find(:first,:conditions => {:id => time_entry.issue_id})
- @time_entries_hours[time_entry.issue_id] = get_spent_hours(time_entry.issue_id, @current_user_id,@current_date)
- @hours_total += time_entry.hours
- end
+ # Fuse all multiple te for a same date
+ if seen_te.has_key?(time_entry.issue_id)
+ seen_te[time_entry.issue_id].hours += time_entry.hours
+ if time_entry.comments
+ seen_te[time_entry.issue_id].comments += " + " + time_entry.comments
+ end
+ @hours_total += time_entry.hours
+ seen_te[time_entry.issue_id].save()
+ TimeEntry.delete(time_entry.id)
+ @logged_issues[time_entry.issue_id] = get_spent_hours(time_entry.issue_id, @current_user_id,@current_date)
+ else
+ seen_te[time_entry.issue_id] = time_entry
+ @logged_issues[time_entry.issue_id] = Issue.find(:first,:conditions => {:id => time_entry.issue_id})
+ @time_entries_hours[time_entry.issue_id] = get_spent_hours(time_entry.issue_id, @current_user_id,@current_date)
+ @hours_total += time_entry.hours
+ end
+ end
end
- end
- # Assigned issues
- @assigned_issues = {}
- issues = Issue.find(:all, :conditions => ["assigned_to_id = " + @current_user_id.to_s()], :order => ["project_id, category_id, id"] )
- issues.each do |issue|
- unless (@logged_issues and @logged_issues[issue.id])
- #@time_entries_hours[issue.id] = get_spent_hours(issue.id, params[:user_id],params[:date])
- @assigned_issues[issue.id] = issue
+ # Assigned issues
+ @assigned_issues = {}
+ issues = Issue.find(:all, :conditions => ["assigned_to_id = " + @current_user_id.to_s()], :order => ["project_id, category_id, id"] )
+ issues.each do |issue|
+ unless (@logged_issues and @logged_issues[issue.id])
+ #@time_entries_hours[issue.id] = get_spent_hours(issue.id, params[:user_id],params[:date])
+ @assigned_issues[issue.id] = issue
+ end
end
- end
- # Watched issues
- watched = Watcher.find(:all, :conditions => {:user_id => @current_user_id, :watchable_type => "issue"})
- @watched_issues = {}
- watched.each do |watched_issue|
- unless (@logged_issues and @logged_issues[watched_issue.watchable_id]) or (@assigned_issues and @assigned_issues[watched_issue.watchable_id])
- @watched_issues[watched_issue.watchable_id] = Issue.find(:first, :conditions => {:id => watched_issue.watchable_id})
+ # Watched issues
+ watched = Watcher.find(:all, :conditions => {:user_id => @current_user_id, :watchable_type => "issue"})
+ @watched_issues = {}
+ watched.each do |watched_issue|
+ unless (@logged_issues and @logged_issues[watched_issue.watchable_id]) or (@assigned_issues and @assigned_issues[watched_issue.watchable_id])
+ @watched_issues[watched_issue.watchable_id] = Issue.find(:first, :conditions => {:id => watched_issue.watchable_id})
+ end
end
+ @user = User.find(:first, :conditions => ["id = " + @current_user_id.to_s()])
end
- @user = User.find(:first, :conditions => ["id = " + @current_user_id.to_s()])
- #@time_entries = TimeEntry
- end
- def add_to_projcat (projcat, proj, cat, te)
- unless projcat.has_key?(proj.id)
- projcat[proj.id] = {}
- projcat[proj.id]["total"] = 0.0
- end
- #unless projcat[proj.id].has_key?("total")
- # projcat[proj.id]["total"] = 0.0
- #end
- unless cat
- cat_id = "other"
- end
- unless projcat[proj.id].has_key?(cat_id)
- projcat[proj.id][cat_id] = {}
- projcat[proj.id][cat_id]["total"] = 0.0
- end
- projcat[proj.id][cat_id][te.spent_on.to_s()] = te.hours.to_f() / 8.0
- projcat[proj.id][cat_id]["total"] += te.hours.to_f() / 8.0
- #projcat[proj.id]["total"] += te.hours.to_f() / 8.0
- return projcat
+
+
+ def index
end
+
+ def summary
+ #config.logger = Logger.new(STDOUT)
+ logger = Logger.new(STDOUT)
+ #logger.log_level = Logger::DEBUG
+
+ @current_date = get_current_date (params)
+
+ @start_date = params[:start_date] ? Date::parse(params[:start_date]) : @current_date - 10
+ @end_date = params[:end_date] ? Date::parse(params[:end_date]) : @current_date + 30
+
+ @current_user_id = get_current_user_id (params)
+ interval = params.has_key?("interval") ? params[:interval] : 15
+ conditions = ' spent_on > "' + (@current_date - interval).to_s() + '" AND spent_on < "' + (@current_date + interval).to_s() + '"'
+ @logged_te = TimeEntry.find(:all,:conditions => [conditions], :order => ['issue_id,spent_on'] )
- def index
- end
+ @logged_days = {}
+ @total_days = {}
+ @projcat = {}
+ @projects = Project.find(:all, :conditions => {:status => 1}, :order => ['parent_id,name'])
- def summary
- end
+ @projects.each do |projet|
+ @projcat[projet.id] = {}
+ @projcat[projet.id]["total"] = 0.0
+ @projcat[projet.id]["other"] = {}
+ @projcat[projet.id]["other"]["total"] = 0.0
+ issue_categories = projet.issue_categories
+ projet.issue_categories.each do |cat|
+ @projcat[projet.id][cat.id] = {}
+ @projcat[projet.id][cat.id]["total"] = 0.0
+ end
+ end
+ @logged_te.each do |te|
+ if te.spent_on and te.issue.project
+ cat_id = te.issue.category ? te.issue.category.id : "other"
+ logger.debug ("cat_id")
+ logger.debug (cat_id)
+ unless @projcat[te.issue.project.id][cat_id].has_key?(te.spent_on.to_s())
+ @projcat[te.issue.project.id][cat_id][te.spent_on.to_s()] = 0.0
+ end
+ @projcat[te.issue.project.id][cat_id][te.spent_on.to_s()] += te.hours.to_f() / 8
+ @projcat[te.issue.project.id][cat_id]["total"] += te.hours.to_f() / 8
+ unless @total_days.has_key?(te.spent_on.to_s())
+ @total_days[te.spent_on.to_s()] = 0.0
+ end
+ @total_days[te.spent_on.to_s()] += te.hours.to_f() / 8
+ end
+ end
+
+ end
end
Oops, something went wrong.

0 comments on commit d2ad5e3

Please sign in to comment.