move notes login to one controller
This commit is contained in:
parent
81092c0198
commit
215a01f63c
15 changed files with 55 additions and 46 deletions
|
@ -95,18 +95,6 @@ class ApplicationController < ActionController::Base
|
|||
redirect_to @project unless @project.repo_exists? && @project.has_commits?
|
||||
end
|
||||
|
||||
def respond_with_notes
|
||||
if params[:last_id] && params[:first_id]
|
||||
@notes = @notes.where("id >= ?", params[:first_id])
|
||||
elsif params[:last_id]
|
||||
@notes = @notes.where("id > ?", params[:last_id])
|
||||
elsif params[:first_id]
|
||||
@notes = @notes.where("id < ?", params[:first_id])
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def no_cache_headers
|
||||
response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
|
||||
response.headers["Pragma"] = "no-cache"
|
||||
|
|
|
@ -29,16 +29,9 @@ class CommitsController < ApplicationController
|
|||
|
||||
git_not_found! and return unless @commit
|
||||
|
||||
@notes = project.commit_notes(@commit).fresh.limit(20)
|
||||
@note = @project.build_commit_note(@commit)
|
||||
|
||||
@comments_allowed = true
|
||||
@line_notes = project.commit_line_notes(@commit)
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.js { respond_with_notes }
|
||||
end
|
||||
end
|
||||
|
||||
def compare
|
||||
|
|
|
@ -49,7 +49,6 @@ class IssuesController < ApplicationController
|
|||
end
|
||||
|
||||
def show
|
||||
@notes = @issue.notes.inc_author.order("created_at DESC").limit(20)
|
||||
@note = @project.notes.new(:noteable => @issue)
|
||||
|
||||
@commits = if @issue.branch_name && @project.repo.heads.map(&:name).include?(@issue.branch_name)
|
||||
|
@ -61,7 +60,7 @@ class IssuesController < ApplicationController
|
|||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.js { respond_with_notes }
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -39,7 +39,6 @@ class MergeRequestsController < ApplicationController
|
|||
git_not_found! and return
|
||||
end
|
||||
|
||||
@notes = @merge_request.notes.inc_author.order("created_at DESC").limit(20)
|
||||
@note = @project.notes.new(:noteable => @merge_request)
|
||||
|
||||
@commits = @project.repo.
|
||||
|
@ -52,7 +51,7 @@ class MergeRequestsController < ApplicationController
|
|||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.js { respond_with_notes }
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -9,6 +9,23 @@ class NotesController < ApplicationController
|
|||
|
||||
respond_to :js
|
||||
|
||||
def index
|
||||
@notes = case params[:target_type]
|
||||
when "commit"
|
||||
then project.commit_notes(project.commit((params[:target_id]))).fresh.limit(20)
|
||||
when "wall"
|
||||
then project.common_notes.order("created_at DESC").fresh.limit(20)
|
||||
when "issue"
|
||||
then project.issues.find(params[:target_id]).notes.inc_author.order("created_at DESC").limit(20)
|
||||
when "merge_request"
|
||||
then project.merge_requests.find(params[:target_id]).notes.inc_author.order("created_at DESC").limit(20)
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.js { respond_with_notes }
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@note = @project.notes.new(params[:note])
|
||||
@note.author = current_user
|
||||
|
@ -34,4 +51,17 @@ class NotesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def respond_with_notes
|
||||
if params[:last_id] && params[:first_id]
|
||||
@notes = @notes.where("id >= ?", params[:first_id])
|
||||
elsif params[:last_id]
|
||||
@notes = @notes.where("id > ?", params[:last_id])
|
||||
elsif params[:first_id]
|
||||
@notes = @notes.where("id < ?", params[:first_id])
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -82,14 +82,10 @@ class ProjectsController < ApplicationController
|
|||
|
||||
def wall
|
||||
return render_404 unless @project.wall_enabled
|
||||
|
||||
@note = Note.new
|
||||
@notes = @project.common_notes.order("created_at DESC")
|
||||
@notes = @notes.fresh.limit(20)
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.js { respond_with_notes }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue