Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/LunarLogicPolska/rubytime
Browse files Browse the repository at this point in the history
Conflicts:
	app/models/activity.rb
  • Loading branch information
jakubn committed Jan 3, 2011
2 parents 0cba711 + 9c4a089 commit 7a1befd
Show file tree
Hide file tree
Showing 34 changed files with 285 additions and 45 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ config/database.yml
config/deploy.rb
config/local_config.rb
config/rcov_stats.yml
config/schedule.rb

# regenerable
coverage/*
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG-API.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ been updated to the newest version which uses some new API actions, but the serv

-----

Version 2 - December 16, 2010

changes:
* Added price_as_json and role_name to /activities.json

-----

Version 1 - November 16, 2009

API actions available:
Expand Down
18 changes: 18 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
Release 3.4 - December 16, 2010

- New features:

* Admin can make another user admin
* Setup cron scheduler
* Added hourly rates setup to rubytime:kickstart
* Small chores like added indicators to ajax calls, added favicon
* Added price_as_json and role_name to /activities.json
* User cannot be able to create activity for a date that has not hourly rates specified

- Other changes:

* Fixed Basic Authentication issue in /activities
* Fixed some annoying bugs

----

Release 3.3 - April 27, 2010

- New features:
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ gem 'nokogiri', '1.4.1' # for rack_revision_info
# TODO: revision info doesn't work on the production now (which was the whole point) because Vlad deletes .git
# directory from deployed code so there's no way to check current revision... this should be fixed when we switch
# to Capistrano
gem 'whenever', :require => false
gem 'i18n' # for whenever

group :development do
gem 'vlad', '2.0.0', :require => []
Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ GIT
GEM
remote: http://rubygems.org/
specs:
aaronh-chronic (0.3.9)
abstract (1.0.0)
activesupport (3.0.3)
addressable (2.2.0)
bcrypt-ruby (2.1.2)
builder (2.1.2)
Expand Down Expand Up @@ -76,6 +78,7 @@ GEM
html5 (0.10.0)
chardet (>= 0.9.0)
hoe (>= 1.2.0)
i18n (0.5.0)
icalendar (1.1.5)
jslint_on_rails (1.0.3)
json_pure (1.2.4)
Expand Down Expand Up @@ -144,6 +147,9 @@ GEM
open4 (~> 0.9.0)
rake (~> 0.8.0)
vlad-git (2.0.0)
whenever (0.6.2)
aaronh-chronic (>= 0.3.9)
activesupport (>= 2.3.4)

PLATFORMS
ruby
Expand All @@ -164,6 +170,7 @@ DEPENDENCIES
dm-validations (= 0.10.2)
do_mysql
fastercsv (= 1.5.3)
i18n
icalendar (~> 1.1.0)
jslint_on_rails
merb-assets (= 1.1.0.pre)
Expand All @@ -187,3 +194,4 @@ DEPENDENCIES
ruby-debug
vlad (= 2.0.0)
vlad-git (= 2.0.0)
whenever
5 changes: 3 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ if Rake.application.options.show_tasks or Rake.application.top_level_tasks.any?
$TESTING = true # Required to bypass check for reserved_name? in vlad. DataMapper 0.9.x defines Kernel#repository...
require 'vlad'
Vlad.load :scm => "git", :app => "passenger", :web => nil
rescue LoadError
# do nothing
rescue Exception => e
p e
puts e.backtrace.join("\n")
end
end

Expand Down
32 changes: 13 additions & 19 deletions app/controllers/activities.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class Activities < Application
# TODO: extract everything related to calendar to separated Calendar controller
RECENT_ACTIVITIES_NUM = 3

provides :json

Expand Down Expand Up @@ -113,7 +112,7 @@ def destroy
def calendar
if current_user.is_admin?
if params[:user_id]
@users = Employee.all(:order => [:name.asc])
@users = Employee.active.all(:order => [:name.asc])
else
@projects = Project.all(:order => [:name.asc])
end
Expand All @@ -122,12 +121,12 @@ def calendar
end

date = if params.has_key?("year") && params.has_key?("month")
@year, @month = params[:year].to_i, params[:month].to_i
{ :year => @year, :month => @month }
else
@year, @month = Date.today.year, Date.today.month
:this_month
end
@year, @month = params[:year].to_i, params[:month].to_i
{ :year => @year, :month => @month }
else
@year, @month = Date.today.year, Date.today.month
:this_month
end

if @month == Date.today.month && @year == Date.today.year
@next_year = @next_month = nil
Expand All @@ -140,10 +139,10 @@ def calendar
@previous_year = @month == 1 ? @year.pred : @year

@activities = begin
@owner.activities.for date
rescue ArgumentError
raise BadRequest
end
@owner.activities.for date
rescue ArgumentError
raise BadRequest
end
@activities_by_date = @activities.group_by { |activity| activity.date }

if request.xhr?
Expand Down Expand Up @@ -203,13 +202,8 @@ def load_owner
end

def load_projects
@recent_projects = current_user.projects.active.sort_by do |p|
last_activity = Activity.first(:project_id => p.id, :user_id => current_user.id, :order => [:date.desc])
last_activity.date
end
@recent_projects = @recent_projects.reverse[0...RECENT_ACTIVITIES_NUM]
# .all(:order => ["activities.created_at DESC"], :limit => RECENT_ACTIVITIES_NUM)
@other_projects = Project.active.all(:order => [:name]) - @recent_projects
@recent_projects = current_user.recent_projects
@other_projects = Project.active.all(:id.not => @recent_projects.map(&:id), :order => [:name])
end

def load_users
Expand Down
7 changes: 6 additions & 1 deletion app/controllers/invoices.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def create
request.xhr? ? "" : redirect(resource(:invoices))
else
if request.xhr?
render_failure @invoice.errors.full_messages.reject { |m| m =~ /integer/ }.join(", ").capitalize
render_failure smart_errors_format(@invoice.errors)
else
render :index
end
Expand All @@ -60,6 +60,11 @@ def destroy
def issue
@invoice.issue!
redirect resource(@invoice), :message => { :notice => "Invoice has been issued" }
rescue Exception => e
load_column_properties
@activities = @invoice.activities.all(:order => [:created_at.desc])
message[:error] = e.to_s
render :show
end

protected
Expand Down
11 changes: 9 additions & 2 deletions app/controllers/projects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Projects < Application
before :ensure_can_list_projects, :only => [:index]
before :load_project, :only => [:edit, :update, :destroy, :show]
before :load_projects, :only => [:index, :create]
before :load_clients, :only => [:index, :new, :create, :edit, :update]
before :load_clients, :only => [:index, :new, :create]

def index
@project = Project.new :client => Client.get(params[:client_id])
Expand All @@ -15,7 +15,12 @@ def index
@projects.each do |p|
p.has_activities = @projects_with_activities.any? { |pwa| pwa.id == p.id }
end
display @projects, :methods => [:has_activities]

if params[:include_activity_types]
display @projects, :methods => [:has_activities, :available_activity_types]
else
display @projects, :methods => [:has_activities]
end
else
display @projects
end
Expand All @@ -36,13 +41,15 @@ def create
end

def edit
@clients = Client.all
render
end

def update
if @project.update(params[:project]) || !@project.dirty?
redirect resource(@project)
else
@clients = Client.all
render :edit
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/activities_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def calendar_table(options = {}, &block)
cal = %(<table id="#{options[:table_id]}" class="#{options[:table_class]}" border="0" cellspacing="0" cellpadding="0">)
cal << %(<thead><tr class="#{options[:month_name_class]}"><th colspan="7">)
cal << link_to("&laquo; Previous", prev_url, :id => "previous_month")
cal << %(<span class="date">#{Date::MONTHNAMES[options[:month]]} #{options[:year]}</span>)
cal << %(<span class="date" data-current-year="#{options[:year]}" data-current-month="#{options[:month]}">#{Date::MONTHNAMES[options[:month]]} #{options[:year]}</span>)
unless @next_month.nil? && @next_year.nil?
cal << link_to("Next &raquo;", next_url, :id => "next_month")
end
Expand Down
6 changes: 6 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,11 @@ def format_number(number, options = {})
end
end

def smart_errors_format(errors)
message = errors.full_messages.reject { |m| m =~ /integer/ }.join(", ").split(' ')
message.first.capitalize unless message.empty?
message.join(' ')
end

end
end # Merb
2 changes: 1 addition & 1 deletion app/models/activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def role_name
end

def price_as_json
price.as_json
price.as_json if price
end

def price_frozen?
Expand Down
4 changes: 4 additions & 0 deletions app/models/activity_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ def destroy(force = false)
super()
end

def json_hash
{ :id => id, :name => name, :position => position }
end

end
10 changes: 10 additions & 0 deletions app/models/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class Invoice

attr_accessor :new_activities

validates_with_method :activities, :method => :validate_activities

after :save do
unless new_activities.blank?
new_activities.each { |activity| activity.update(:invoice_id => id) }
Expand All @@ -26,6 +28,14 @@ class Invoice
activities.update!(:invoice_id => nil)
end

def validate_activities
if new_activities.blank? || new_activities.all?(&:valid?)
true
else
[false, "Some of activities are invalid (#{new_activities.first.errors.first.first})."]
end
end

def self.pending
all(:issued_at => nil)
end
Expand Down
8 changes: 7 additions & 1 deletion app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,15 @@ def self.with_activities_for(user)
all('activities.user_id' => user.id, :unique => true)
end


# instance methods

def available_activity_types
self.activity_types(:parent => nil).map do |at|
subactivity_types_array = self.activity_types(:parent => at).map(&:json_hash)
at.json_hash.merge({ :available_subactivity_types => subactivity_types_array })
end
end

def calendar_viewable?(user)
user.client == self.client || user.is_admin?
end
Expand Down
10 changes: 10 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class User
include DataMapper::Resource

RECENT_ACTIVITIES_NUM = 3

property :id, Serial
property :name, String, :required => true
Expand Down Expand Up @@ -68,6 +70,14 @@ def self.with_activities_for_client(client)
active.all('activities.project.client_id' => client.id, :unique => true)
end

def recent_projects
self.projects.active.sort_by { |p| self.last_activity_in_project(p).date }.reverse.first(RECENT_ACTIVITIES_NUM)
end

def last_activity_in_project(project)
self.activities.first(:project_id => project.id, :order => [:date.desc])
end

def authenticated?(password)
crypted_password == encrypt(password) && active
end
Expand Down
3 changes: 2 additions & 1 deletion app/views/activities/_activity_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div id="errors" style="display:none"></div>

<%= form_for @activity, :action => @activity.new? ? url(:activities) : resource(@activity), :class => "activity_form" do %>
<%= form_for @activity, :action => @activity.new? ? url(:activities) : resource(@activity), :class => "activity_form #{@activity.new? ? 'dark': ''}" do %>
<fieldset>
<% if @activity.new? %><legend>New activity</legend><% end %>
<% if current_user.is_admin? %>
Expand All @@ -16,6 +16,7 @@
"Recent projects" => @recent_projects.map { |p| [p.id, p.name] },
"Other projects" => @other_projects.map { |p| [p.id, p.name] } } %>
</p>
<%= hidden_field :main_activity_type_id, :value => nil %>
<p<%= @activity.available_main_activity_types.any? ? '' : ' style="display: none"' %>>
<%= select :main_activity_type_id, :label => "Type", :collection => @activity.available_main_activity_types.map { |at| [at.id, at.name] }, :selected => @activity.main_activity_type_id.to_s, :disabled => @activity.available_main_activity_types.empty? %>
</p>
Expand Down
3 changes: 3 additions & 0 deletions app/views/layout/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<head>
<title>Rubytime</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="SHORTCUT ICON" href="<%= url('favicon.ico') %>" />
<link rel="icon" type="image/png" href="<%= url('favicon.png') %>" />
<%= css_include_tag Merb.env?('production') ? 'master.min' : 'master' %>
<%= js_include_tag 'lib/jquery.min.js',
'lib/jquery-ui-1.8.custom.min.js',
Expand All @@ -13,6 +15,7 @@
'application.js',
'lib/rubytime/input-filler.js',
'lib/thickbox',
'indicator.js',
:bundle => :base %>
<%= auto_link %>
<% if session.user %>
Expand Down
6 changes: 5 additions & 1 deletion app/views/users/_user_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
<p>
<%= text_field :email, :label => "Email" %>
</p>
<% unless @user.new? %>
<% if !@user.new? && @user != current_user%>
<p>
<label for="user_admin">Admin?</label>
<%= check_box :admin %>
</p>
<p>
<label for="user_active">Active?</label>
<%= check_box :active %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/_users.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<td class="icons">
<%= link_to_calendar user %>
<%= link_to image_tag("icons/pencil.png", :title => "Edit", :alt => "E"), url(:edit_user, user) %>
<%= link_to image_tag("icons/cross.png", :title => "Remove", :alt => "R"), url(:user, user), :class => "delete_row" %>
<%= link_to image_tag("icons/cross.png", :title => "Remove", :alt => "R"), url(:user, user), :class => "delete_row" unless user == current_user %>
</td>
</tr>
<% end %>
Expand Down
Loading

0 comments on commit 7a1befd

Please sign in to comment.