diff --git a/Project, b/Project, new file mode 100644 index 0000000..e69de29 diff --git a/Task, b/Task, new file mode 100644 index 0000000..e69de29 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 8e93168..fa075d6 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,6 +2,8 @@ # Likewise, all the methods added will be available for all controllers. class ApplicationController < ActionController::Base + before_filter :authenticate + include Clearance::Authentication #helper :all # include all helpers, all the time protect_from_forgery # See ActionController::RequestForgeryProtection for details diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 766b4d1..5cf0b2d 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -1,8 +1,9 @@ class ProjectsController < ApplicationController + before_filter :authenticate # GET /projects # GET /projects.xml def index - @projects = Project.all + @projects = Project.active.paginate :per_page => 30, :page => params[:page] respond_to do |format| format.html # index.html.erb @@ -13,8 +14,8 @@ class ProjectsController < ApplicationController # GET /projects/1 # GET /projects/1.xml def show - @project = Project.find(params[:id]) - + @project = Project.find(params[:id], :include => [:users]) + @tasks = @project.tasks.parents.paginate(:per_page => 30, :page => params[:page], :include => :tasks) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @project } diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000..73f8b0c --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,25 @@ +class UsersController < Clearance::UsersController + + def dashboard + @user = current_user + @projects = @user.projects.active.paginate(:per_page => 30, :page => params[:page]) + end + + def show + @user = User.find_by_short_name(params[:id]) + end + + def inline + + user = current_user + old = user.send(params[:id]) + user.update_attribute(params[:id], params['value']) + if user.save + value = user.send(params[:id]) + else + value = old + end + render :text => value , :layout => false + end + +end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 48f74d7..ae7fc75 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -7,4 +7,5 @@ module ApplicationHelper out << tag(:meta, :name => 'csrf-param', :content => 'authenticity_token') end + end diff --git a/app/models/project.rb b/app/models/project.rb index f8e90d2..75eedc7 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1,4 +1,11 @@ class Project < ActiveRecord::Base has_many :tasks + belongs_to :owner, :class_name => "User", :foreign_key => "owner_id" validates_presence_of :name + has_and_belongs_to_many :users + validates_uniqueness_of :name + + named_scope :archived, :conditions => {:archived => true} + named_scope :active, :conditions => {:archived => false} + end diff --git a/app/models/task.rb b/app/models/task.rb index d7d38a0..314be49 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -1,9 +1,31 @@ class Task < ActiveRecord::Base belongs_to :project has_many :tasks, :foreign_key => :parent - + belongs_to :owner, :class_name => "User", :foreign_key => "owner_id" + belongs_to :assignee, :class_name => "User", :foreign_key => 'assigned_id' + #named scopes named_scope :parents, :conditions => {:parent => nil} - + #validations validates_presence_of :name, :description, :project_id validates_associated :project + validate :assignee_validation, :owner_validation + + def assignee_validation + unless assigned_id.blank? + unless User.exists?(assigned_id) + errors.add :assignee, "Assignee doesn't exist" + end + end + end + + def owner_validation + unless owner_id.blank? + unless User.exists?(owner_id) + errors.add :owner, "Owner doesn't exist" + end + end + end + + + end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000..dbcf911 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,17 @@ +class User < ActiveRecord::Base + include Clearance::User + has_and_belongs_to_many :projects + has_many :owned_projects, :class_name => "Project", :foreign_key => "owner_id" + has_many :owned_tasks, :class_name => "Task", :foreign_key => "owner_id" + has_many :assigned_tasks, :class_name => "Task", :foreign_key => "assigned_id" + validates_uniqueness_of :short_name + validates_presence_of :short_name + validates_format_of :phone, :with => /^[0-9]{3}-[0-9]{3}-[0-9]{4}$/, :if => Proc.new {|user| !user.phone.blank?} + validates_format_of :mobile, :with => /^[0-9]{3}-[0-9]{3}-[0-9]{4}$/, :if => Proc.new {|user| !user.mobile.blank?} + + def gravatar(size = 48) + hash = Digest::MD5.hexdigest email + "http://www.gravatar.com/avatar/#{hash}.jpg?s=#{size}" + end + +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index a2e3ec8..fa75efa 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -7,13 +7,18 @@ <%= stylesheet_link_tag 'scaffold', 'style' %>
- +