-
Notifications
You must be signed in to change notification settings - Fork 2
Issue 32: Admin can see users timesheets #37
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,10 +25,22 @@ | |
font-size: 12px; | ||
} | ||
|
||
#weekdays-list>li { | ||
#weekdays-list > li { | ||
text-align: center; | ||
|
||
a { font-size: 16px; } | ||
} | ||
|
||
#users-list { | ||
|
||
right: 0; | ||
left: auto; | ||
|
||
& > li a { | ||
display: block; | ||
border-style: none; | ||
border-radius: 0px; | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add the following style attributes, in order to improve the position of the dropdown menu: |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,27 @@ | ||
class TimesheetController < ApplicationController | ||
|
||
# GET /timesheet(/:year/:month/:day) | ||
# GET /timesheet/:user_id(/:year/:month/:day) | ||
def show | ||
if params[:year].present? && params[:month].present? && params[:day].present? | ||
@date = Time.zone.parse("#{params[:year]}-#{params[:month]}-#{params[:day]}").to_date | ||
@weekdays = (@[email protected]_end_of_week) | ||
@week_summary = Timesheet.new(current_user).week_hours(@date) | ||
@day_entries = Timesheet.new(current_user).day_entries(@date) | ||
@users = User.all | ||
args = params.clone | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try to avoid changing the params hash. Do something like "args = params.clone" and work with the "args" hash. |
||
if args[:user_id].blank? | ||
args[:user_id] = current_user.id | ||
end | ||
|
||
if current_user.is_admin || (current_user.id == args[:user_id].to_i) | ||
if args[:year].present? && args[:month].present? && args[:day].present? | ||
@timesheet = Timesheet.new(args) | ||
else | ||
date = Time.zone.now | ||
redirect_to timesheet_url(user_id: args[:user_id], year: date.year, month: date.month, day: date.day) | ||
end | ||
else | ||
date = Time.zone.now | ||
redirect_to timesheet_url(year: date.year, month: date.month, day: date.day) | ||
redirect_to timesheet_url(user_id: current_user.id, year: date.year, month: date.month, day: date.day), | ||
alert: flash_message(:have_no_right, User) | ||
end | ||
|
||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,25 @@ | ||
class Timesheet | ||
|
||
def initialize(user) | ||
@user = user | ||
end | ||
attr_reader :user, :date, :day_entries, :weekdays, :week_summary | ||
|
||
def week_hours(day = Time.zone.now) | ||
day = day.to_date | ||
week = (day.at_beginning_of_week..day.at_end_of_week) | ||
def initialize(args) | ||
@user = User.find_by_id(args[:user_id]) | ||
@date = parse_to_date(args[:day], args[:month], args[:year]) | ||
@day_entries = day_entries_for(@date) | ||
@weekdays = (@[email protected]_end_of_week) | ||
@week_summary = week_hours(@weekdays) | ||
end | ||
|
||
week.map { |weekday| { weekday.day => day_time(weekday) } }.reduce(:merge) | ||
def day_entries_for(day) | ||
TimeEntry.for_user(@user).for_day(day) | ||
end | ||
|
||
def day_time(day) | ||
TimeEntry.for_user(@user).for_day(day).sum(:total_time) | ||
def week_hours(weekdays) | ||
weekdays.map { |weekday| { weekday.day => day_entries_for(weekday).sum(:total_time) } }.reduce(:merge) | ||
end | ||
|
||
def day_entries(day = Time.zone.now) | ||
TimeEntry.for_user(@user).for_day(day) | ||
def parse_to_date(day, month, year) | ||
Time.zone.parse("#{year}-#{month}-#{day}").to_date | ||
end | ||
|
||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@henriquelampert I see that there's only one route for "timesheet#show". So there's no need to rename the path to "/timesheet_for/". Please, revert this and use "/timesheet/" again.