diff --git a/app/assets/javascripts/note.js b/app/assets/javascripts/note.js index 831150ffbdb616adf103157e5cdee8917c96351a..77f9c9cfc01d9a016d2fc1f9456f798e08662e57 100644 --- a/app/assets/javascripts/note.js +++ b/app/assets/javascripts/note.js @@ -1,15 +1,20 @@ var NoteList = { +notes_path: null, +target_params: null, +target_id: 0, +target_type: null, first_id: 0, last_id: 0, -resource_name: null, disable:false, init: - function(resource_name, first_id, last_id) { - this.resource_name = resource_name; - this.first_id = first_id; - this.last_id = last_id; + function(tid, tt, path) { + this.notes_path = path + ".js"; + this.target_id = tid; + this.target_type = tt; + this.target_params = "&target_type=" + this.target_type + "&target_id=" + this.target_id + this.refresh(); this.initRefresh(); this.initLoadMore(); }, @@ -19,8 +24,8 @@ getOld: $('.loading').show(); $.ajax({ type: "GET", - url: location.href, - data: "first_id=" + this.first_id, + url: this.notes_path, + data: "first_id=" + this.first_id + this.target_params, complete: function(){ $('.loading').hide()}, dataType: "script"}); }, @@ -56,8 +61,8 @@ getNew: // refersh notes list $.ajax({ type: "GET", - url: location.href, - data: "last_id=" + this.last_id, + url: this.notes_path, + data: "last_id=" + this.last_id + this.target_params, dataType: "script"}); }, @@ -66,8 +71,8 @@ refresh: // refersh notes list $.ajax({ type: "GET", - url: location.href, - data: "first_id=" + this.first_id + "&last_id=" + this.last_id, + url: this.notes_path, + data: "first_id=" + this.first_id + "&last_id=" + this.last_id + this.target_params, dataType: "script"}); }, diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2365449707c9b47526c3b6dccb3ae30415cc1ba1..ff00208cff1619bac76ee4eeb5489016c695fc77 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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" diff --git a/app/controllers/commits_controller.rb b/app/controllers/commits_controller.rb index 5ddce3c0df84458b9c8f06049afedca02e6889dc..0d36957c43f50d448752f4a2c82ea0709a52090e 100644 --- a/app/controllers/commits_controller.rb +++ b/app/controllers/commits_controller.rb @@ -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 diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 36c9c8f6c513d926af88f7b9f97b772139053991..02e738d57131c125d0ce5d0d6d5ed6ac8f6feeeb 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -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 diff --git a/app/controllers/merge_requests_controller.rb b/app/controllers/merge_requests_controller.rb index 6c9cc0cfee7c2a62cd7faadd82ccf9fae9fc92c4..3ae259403780f856f36b3846800f950f3430c170 100644 --- a/app/controllers/merge_requests_controller.rb +++ b/app/controllers/merge_requests_controller.rb @@ -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 diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index 19c8571705d876e904d5fe8eedee7bf1c7c194d4..327985ef6682b9ffda47987344322b26d8b13529 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -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 diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 3b59a895a376cfbfcea2a08d8e52fd2f2914c8e8..26eabe5f94fb29961a7e99a121e71ca68deecc9b 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -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 diff --git a/app/views/commits/show.html.haml b/app/views/commits/show.html.haml index 0d0c629da7f0b934f1f638242a6aa5233ab2c7fd..5f055c285761e02f9d28c9e850204c7452d506b6 100644 --- a/app/views/commits/show.html.haml +++ b/app/views/commits/show.html.haml @@ -21,7 +21,7 @@ %p.cgray Showing #{pluralize(@commit.diffs.count, "changed file")} = render "commits/diffs", :diffs => @commit.diffs -= render "notes/notes" += render "notes/notes", :tid => @commit.id, :tt => "commit" = render "notes/per_line_form" diff --git a/app/views/issues/show.html.haml b/app/views/issues/show.html.haml index 170d6831fb44badd21394c6c7bb6b3ced370a613..ace1d1e369e05cd0038ae689067548ccc09a7c18 100644 --- a/app/views/issues/show.html.haml +++ b/app/views/issues/show.html.haml @@ -41,5 +41,5 @@ %div= simple_format @issue.title -.issue_notes= render "notes/notes" +.issue_notes= render "notes/notes", :tid => @issue.id, :tt => "issue" diff --git a/app/views/merge_requests/show.html.haml b/app/views/merge_requests/show.html.haml index 0a07f0bc6ae016c8bc2eb1af67c57d82a61b29f2..4acc748e94c3e5d120d44b74656416fbbf97870c 100644 --- a/app/views/merge_requests/show.html.haml +++ b/app/views/merge_requests/show.html.haml @@ -63,7 +63,7 @@ %img{:src => "/assets/ajax-loader-facebook.gif", :class => "dashboard-loader"} .merge-request-notes - .merge_request_notes= render "notes/notes" + .merge_request_notes= render "notes/notes", :tid => @merge_request.id, :tt => "merge_request" .loading{ :style => "display:none;"} %center= image_tag "ajax-loader.gif" .clear diff --git a/app/views/notes/_notes.html.haml b/app/views/notes/_notes.html.haml index 4a5c3aab353bc1c7dd0d2094d1c3d01a1cd0486b..fb589c3238f722fe0cf790700ef04a068cada7df 100644 --- a/app/views/notes/_notes.html.haml +++ b/app/views/notes/_notes.html.haml @@ -2,7 +2,7 @@ = render "notes/form" .clear %hr -%ul#notes-list= render "notes/notes_list" +%ul#notes-list :javascript $('.delete-note').live('ajax:success', function() { @@ -22,5 +22,5 @@ $('.attach_holder').show(); }); - NoteList.init("wall", #{@notes.last.try(:id) || 0}, #{@notes.first.try(:id) || 0}); + NoteList.init("#{tid}", "#{tt}", "#{project_notes_path(@project)}"); }); diff --git a/app/views/issues/show.js.haml b/app/views/notes/index.js.haml similarity index 100% rename from app/views/issues/show.js.haml rename to app/views/notes/index.js.haml diff --git a/app/views/projects/wall.html.haml b/app/views/projects/wall.html.haml index 4f0ec41ee92e555a2a2d0d87306bacc5e2c85e63..f6c59e47a2341986fe76e6de5b87eb9225eb2d13 100644 --- a/app/views/projects/wall.html.haml +++ b/app/views/projects/wall.html.haml @@ -1,5 +1,5 @@ %div.wall_page - = render "notes/notes" + = render "notes/notes", :tid => nil, :tt => "wall" .loading{ :style => "display:none;"} %center= image_tag "ajax-loader.gif" diff --git a/app/views/projects/wall.js.haml b/app/views/projects/wall.js.haml deleted file mode 100644 index ee31c0b8d3c1c8112471bbee240b14ef816f01ac..0000000000000000000000000000000000000000 --- a/app/views/projects/wall.js.haml +++ /dev/null @@ -1 +0,0 @@ -= render "notes/load" diff --git a/config/routes.rb b/config/routes.rb index 653ec0892663d8e89db4d56194fdcfddb3065d9b..0f380095d395e5ad6f8dcf220765ddf298d94281 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -121,7 +121,7 @@ Gitlab::Application.routes.draw do get :search end end - resources :notes, :only => [:create, :destroy] + resources :notes, :only => [:index, :create, :destroy] end root :to => "projects#index" end