collab/app/controllers/projects_controller.rb

110 lines
2.9 KiB
Ruby
Raw Normal View History

2010-03-04 06:22:45 +00:00
class ProjectsController < ApplicationController
2010-03-05 06:48:00 +00:00
before_filter :authenticate
2010-03-04 06:22:45 +00:00
# GET /projects
# GET /projects.xml
def index
2010-03-05 06:48:00 +00:00
@projects = Project.active.paginate :per_page => 30, :page => params[:page]
2010-03-04 06:22:45 +00:00
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @projects }
end
end
2010-03-15 15:47:32 +00:00
def join
@project = Project.find(params[:project_id])
@project.users << current_user
if @project.save
flash[:success] = "You have joined #{@project.name}"
else
flash[:error] = "There was a problem joining this project"
end
redirect_to project_path(@project)
end
def leave
@project = Project.find(params[:project_id])
@project.users.delete current_user
if @project.save
flash[:success] = "You have been removed from #{@project.name}"
else
flash[:error] = "There was an error removing you form this project"
end
redirect_to project_path(@project)
end
2010-03-04 06:22:45 +00:00
# GET /projects/1
# GET /projects/1.xml
def show
2010-03-15 15:47:32 +00:00
@project = Project.find(params[:id], :include => [:users, :wall_posts])
2010-03-05 06:48:00 +00:00
@tasks = @project.tasks.parents.paginate(:per_page => 30, :page => params[:page], :include => :tasks)
2010-03-15 15:47:32 +00:00
@wall_posts = @project.wall_posts.paginate(:per_page => 15, :page => params[:post_page])
2010-03-04 06:22:45 +00:00
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @project }
end
end
# GET /projects/new
# GET /projects/new.xml
def new
@project = Project.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @project }
end
end
# GET /projects/1/edit
def edit
@project = Project.find(params[:id])
end
# POST /projects
# POST /projects.xml
def create
@project = Project.new(params[:project])
respond_to do |format|
if @project.save
flash[:notice] = 'Project was successfully created.'
format.html { redirect_to(@project) }
format.xml { render :xml => @project, :status => :created, :location => @project }
else
format.html { render :action => "new" }
format.xml { render :xml => @project.errors, :status => :unprocessable_entity }
end
end
end
# PUT /projects/1
# PUT /projects/1.xml
def update
@project = Project.find(params[:id])
respond_to do |format|
if @project.update_attributes(params[:project])
flash[:notice] = 'Project was successfully updated.'
format.html { redirect_to(@project) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @project.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /projects/1
# DELETE /projects/1.xml
def destroy
@project = Project.find(params[:id])
@project.destroy
respond_to do |format|
format.html { redirect_to(projects_url) }
format.xml { head :ok }
end
end
end