Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2ff2aa9
Showing
151 changed files
with
11,721 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Add your own tasks in files placed in lib/tasks ending in .rake, | ||
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. | ||
|
||
require(File.join(File.dirname(__FILE__), 'config', 'boot')) | ||
|
||
require 'rake' | ||
require 'rake/testtask' | ||
require 'rake/rdoctask' | ||
|
||
require 'tasks/rails' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Filters added to this controller apply to all controllers in the application. | ||
# Likewise, all the methods added will be available for all controllers. | ||
|
||
class ApplicationController < ActionController::Base | ||
include AuthenticatedSystem | ||
|
||
layout 'default' | ||
|
||
helper :all # include all helpers, all the time | ||
protect_from_forgery # See ActionController::RequestForgeryProtection for details | ||
|
||
before_filter :login_required | ||
before_filter :set_time_zone | ||
|
||
# Scrub sensitive parameters from your log | ||
# filter_parameter_logging :password | ||
|
||
protected | ||
|
||
def error_status(error, message, args={}, continue_ok=true) | ||
if request.format == :html | ||
flash[:error] = error | ||
flash[:message] = t(message, args) | ||
else | ||
@flash_error = error | ||
@flash_message = t(message, args) | ||
end | ||
|
||
return unless (error and continue_ok) | ||
|
||
# Construct a reply with a relevant error | ||
respond_to do |format| | ||
format.html { redirect_back_or_default('/') } | ||
format.js { render(:update) do |page| | ||
page.replace_html('statusBar', h(flash[:message])) | ||
page.show 'statusBar' | ||
end } | ||
format.xml { head(error ? :unprocessable_entity : :ok) } | ||
end | ||
end | ||
|
||
def set_time_zone | ||
Time.zone = @logged_user.timezone if @logged_user | ||
@time_now = Time.zone.now | ||
end | ||
|
||
def find_project | ||
begin | ||
@project = @logged_user.projects.find(params[:project_id]) | ||
rescue | ||
respond_to do |f| | ||
f.html { flash[:error] = "Invalid project!" } | ||
end | ||
|
||
return false | ||
end | ||
|
||
true | ||
end | ||
|
||
def find_project_opt | ||
begin | ||
@project = @logged_user.projects.find(params[:project_id]) | ||
rescue | ||
return true | ||
end | ||
|
||
true | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
class ClientsController < ApplicationController | ||
before_filter :find_client, :except => [:index, :new, :create] | ||
|
||
def index | ||
@clients = @logged_user.clients | ||
@grouped_projects = @logged_user.projects.reject{|r|r.client.nil?}.group_by(&:client) | ||
|
||
respond_to do |f| | ||
f.html {} | ||
end | ||
end | ||
|
||
def new | ||
@client = @logged_user.clients.build() | ||
end | ||
|
||
def create | ||
@client = @logged_user.clients.build(params[:client]) | ||
|
||
respond_to do |f| | ||
if @client.save | ||
f.html{ flash.now[:info] = "Created!"; redirect_to(clients_path) } | ||
else | ||
f.html{ flash.now[:info] = "Error!"; render :new } | ||
end | ||
end | ||
end | ||
|
||
def edit | ||
end | ||
|
||
def update | ||
respond_to do |f| | ||
if @client.update_attributes(params[:client]) | ||
f.html{ flash.now[:info] = "Saved!"; redirect_to(clients_path) } | ||
else | ||
f.html{ flash.now[:info] = "Error!"; render :edit } | ||
end | ||
end | ||
end | ||
|
||
def destroy | ||
respond_to do |f| | ||
if @client.is_default_project? | ||
f.html { flash[:error] = "Client is default"; redirect_to clients_path } | ||
else | ||
@client.destroy | ||
f.html { redirect_to clients_path } | ||
end | ||
end | ||
end | ||
|
||
def show | ||
@client_projects = @client.projects | ||
respond_to do |f| | ||
f.html {} | ||
end | ||
end | ||
|
||
def report | ||
@clients = @logged_user.clients | ||
@client_times = @clients.map {|s| ((s.total_time / 60.0 / 60.0) * 10).round.to_f / 10 } | ||
@client_rates = @clients.map {|s| s.total_rate} | ||
@client_names = @clients.map {|s| s.name} | ||
|
||
respond_to do |f| | ||
f.html {} | ||
end | ||
end | ||
|
||
protected | ||
|
||
def find_client | ||
begin | ||
@client = @logged_user.clients.find(params[:id]) | ||
rescue | ||
respond_to do |f| | ||
f.html { flash[:error] = "Invalid client!" } | ||
end | ||
|
||
return false | ||
end | ||
|
||
true | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
class EntriesController < ApplicationController | ||
before_filter :find_project_opt, :except => [:new, :create] | ||
before_filter :find_project, :only => [:new, :create] | ||
before_filter :find_entry, :except => [:index, :new, :create, :report] | ||
|
||
def index | ||
@entries = (@project || @logged_user).entries.find(:all) | ||
end | ||
|
||
def new | ||
@entry = @project.entries.build() | ||
end | ||
|
||
def create | ||
@entry = (@project || @logged_user.default_project).entries.build(params[:entry]) | ||
@entry.user = @logged_user | ||
|
||
respond_to do |f| | ||
if @entry.save | ||
f.html{ flash.now[:info] = "Created!"; redirect_to(entries_path) } | ||
f.js {} | ||
else | ||
f.html{ flash.now[:info] = "Error!"; render :action => :new } | ||
end | ||
end | ||
end | ||
|
||
def edit | ||
end | ||
|
||
def update | ||
respond_to do |f| | ||
if @entry.update_attributes(params[:entry]) | ||
f.html{ flash.now[:info] = "Saved!"; redirect_to(entries_path) } | ||
f.js {} | ||
else | ||
f.html{ flash.now[:info] = "Error!"; render :action => :edit } | ||
end | ||
end | ||
end | ||
|
||
def restart | ||
@cloned_entry = @project.entries.build() | ||
@cloned_entry.clone_from(@entry) | ||
@entry = @cloned_entry | ||
|
||
respond_to do |f| | ||
if @entry.save | ||
f.html{ flash.now[:info] = "Cloned!"; redirect_to(entries_path) } | ||
f.js { render :action => :create } | ||
else | ||
f.html{ flash.now[:info] = "Error!"; render :action => :edit } | ||
end | ||
end | ||
end | ||
|
||
def terminate | ||
@entry.terminate | ||
|
||
respond_to do |f| | ||
if @entry.save | ||
f.html{ flash.now[:info] = "Terminated!"; redirect_to(entries_path) } | ||
f.js { render :action => :update } | ||
else | ||
f.html{ flash.now[:info] = "Error!"; render :action => :edit } | ||
end | ||
end | ||
end | ||
|
||
def destroy | ||
@entry_id = @entry.id | ||
@entry.destroy | ||
respond_to do |f| | ||
f.html { redirect_to(entries_path) } | ||
f.js { } | ||
end | ||
end | ||
|
||
def show | ||
end | ||
|
||
def report | ||
now = (params[:date] || Time.now).to_date | ||
report_period = params[:period] | ||
report_year = now.year | ||
|
||
days_past_week = Proc.new {|entry| (now - entry.start_date.to_date) > 7.days} | ||
days_past_month = Proc.new {|entry| (now - entry.start_date.to_date) > 1.month} | ||
days_this_year = Proc.new {|entry| now.year != entry.year} | ||
|
||
case report_period | ||
when 'week' | ||
day_list = make_time_list(now - 1.month + 1, now) {|d| d.cweek} | ||
daymap = [0] + day_list | ||
@grouped_entries = @logged_user.entries.reject(&days_past_month).group_by do |entry| | ||
entry.start_date.to_date.cweek | ||
end | ||
else | ||
day_list = make_time_list(now - 1.week + 1, now) {|d| d.cwday} | ||
daymap = [", ""Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat"] | ||
@grouped_entries = @logged_user.entries.reject(&days_past_week).group_by do |entry| | ||
entry.start_date.to_date.cwday | ||
end | ||
end | ||
|
||
@summed_rates = day_list.map do |key| | ||
if @grouped_entries.has_key?(key) | ||
[key, @grouped_entries[key].map{|e|e.cost}.sum] | ||
else | ||
[key, 0] | ||
end | ||
end | ||
|
||
@summed_expected_rates = day_list.map do |key| | ||
if @grouped_entries.has_key?(key) | ||
[key, @grouped_entries[key].map{|e|e.expected_cost}.sum] | ||
else | ||
[key, 0] | ||
end | ||
end | ||
|
||
@summed_times = day_list.map do |key| | ||
if @grouped_entries.has_key?(key) | ||
[key, @grouped_entries[key].map{|e|e.hours}.sum] | ||
else | ||
[key, 0] | ||
end | ||
end | ||
|
||
@summed_expected_times = day_list.map do |key| | ||
if @grouped_entries.has_key?(key) | ||
[key, @grouped_entries[key].map{|e|e.hours_limit}.sum] | ||
else | ||
[key, 0] | ||
end | ||
end | ||
|
||
@sum_range_list = day_list.map {|d|daymap[d]} | ||
|
||
respond_to do |f| | ||
f.html {} | ||
end | ||
end | ||
|
||
private | ||
|
||
def make_time_list(start_date, end_date, &block) | ||
# includes start, up to and including end | ||
cur_date = start_date | ||
list = [] | ||
while (cur_date <= end_date) | ||
list << block.call(cur_date) | ||
cur_date += 1 | ||
end | ||
list | ||
end | ||
|
||
def find_entry | ||
begin | ||
@entry = (@project || @logged_user).entries.find(params[:id]) | ||
rescue | ||
respond_to do |f| | ||
f.html { flash[:error] = "Invalid entry!" } | ||
end | ||
|
||
return false | ||
end | ||
|
||
true | ||
end | ||
end |
Oops, something went wrong.