diff --git a/app/assets/images/ajax-loader.gif b/app/assets/images/ajax-loader.gif index 0ca7ada9..c97ec6ea 100644 Binary files a/app/assets/images/ajax-loader.gif and b/app/assets/images/ajax-loader.gif differ diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index b1e95736..31046379 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -21,6 +21,6 @@ $(function(){ $('select#tag').selectmenu({style:'popup', width:200}); }); -function updatePage(){ - $.ajax({type: "GET", url: location.href, dataType: "script"}); +function updatePage(data){ + $.ajax({type: "GET", url: location.href, data: data, dataType: "script"}); } diff --git a/app/assets/javascripts/note.js b/app/assets/javascripts/note.js new file mode 100644 index 00000000..71279fc4 --- /dev/null +++ b/app/assets/javascripts/note.js @@ -0,0 +1,65 @@ +var NoteList = { + +first_id: 0, +last_id: 0, +resource_name: null, + +init: + function(resource_name, first_id, last_id) { + this.resource_name = resource_name; + this.first_id = first_id; + this.last_id = last_id; + this.initRefresh(); + this.initLoadMore(); + }, + +getOld: + function() { + $('.loading').show(); + $.ajax({ + type: "GET", + url: location.href, + data: "first_id=" + this.first_id, + complete: function(){ $('.loading').hide()}, + dataType: "script"}); + }, + +append: + function(id, html) { + this.first_id = id; + $("#notes-list").append(html); + this.initLoadMore(); + }, + +prepend: + function(id, html) { + this.last_id = id; + $("#notes-list").prepend(html); + }, + +getNew: + function() { + // refersh notes list + $.ajax({ + type: "GET", + url: location.href, + data: "last_id=" + this.last_id, + dataType: "script"}); + }, + +initRefresh: + function() { + // init timer + var int = setInterval("NoteList.getNew()", 20000); + }, + +initLoadMore: + function() { + $(window).bind('scroll', function(){ + if($(window).scrollTop() == $(document).height() - $(window).height()){ + $(window).unbind('scroll'); + NoteList.getOld(); + } + }); + } +} diff --git a/app/assets/stylesheets/projects.css.scss b/app/assets/stylesheets/projects.css.scss index 4e4bcccc..766138ee 100644 --- a/app/assets/stylesheets/projects.css.scss +++ b/app/assets/stylesheets/projects.css.scss @@ -421,31 +421,6 @@ input.ssh_project_url { list-style:none; margin:0px; padding:0px; - - li { - display:list-item; - padding:8px; - margin:0px; - background: #F7FBFC; - border-top: 1px solid #E2EAEE; - - &:first-child { - border-top: none; - } - &:nth-child(2n+1) { - background: white; - } - p { - margin-bottom: 4px; - font-size: 13px; - color:#111; - } - } - cite { - &.ago { - color:#666; - } - } } .notes_count { @@ -460,14 +435,6 @@ input.ssh_project_url { right: 6px; top: 6px; } -.note_author { - float:left; - width:60px; -} -.note_content { - float:left; - width:650px; -} .issue_notes { .note_content { @@ -556,8 +523,7 @@ input.ssh_project_url { } .commit, -.message, -#notes-list{ +.message{ .author { background: #eaeaea; color: #333; @@ -574,7 +540,7 @@ input.ssh_project_url { font-size:14px; } -.wall_page { +#new_note { #note_note { height:25px; } @@ -719,3 +685,11 @@ table.highlighttable pre{ .project-refs-select { width:200px; } + +body.project-page #notes-list .note {padding: 10px; border-bottom: 1px solid #eee; overflow: hidden; display: block;} +body.project-page #notes-list .note {padding: 10px; border-bottom: 1px solid #eee; overflow: hidden; display: block;} +body.project-page #notes-list .note img{float: left; margin-right: 10px;} +body.project-page #notes-list .note span.note-title{display: block;} +body.project-page #notes-list .note span.note-title{margin-bottom: 10px} +body.project-page #notes-list .note span.note-author{color: #999; font-weight: normal; font-style: italic;} +body.project-page #notes-list .note span.note-author strong{font-weight: bold; font-style: normal;} diff --git a/app/assets/stylesheets/style.scss b/app/assets/stylesheets/style.scss index 97be566f..29e6058d 100755 --- a/app/assets/stylesheets/style.scss +++ b/app/assets/stylesheets/style.scss @@ -292,7 +292,7 @@ body.login-page{background-color: #f1f1f1; padding-top: 10%} /* General */ #container{background-color: white; overflow: hidden;} -/*#container{margin: auto; width: 980px; border: 1px solid rgba(0,0,0,.22); border-top: 0; box-shadow: 0 0 0px 4px rgba(0,0,0,.04)}*/ +body.collapsed #container{margin: auto; width: 980px; border: 1px solid rgba(0,0,0,.22); border-top: 0; box-shadow: 0 0 0px 4px rgba(0,0,0,.04)} diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 6d0edace..070def96 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,7 @@ class ApplicationController < ActionController::Base before_filter :authenticate_user! + before_filter :view_style + protect_from_forgery helper_method :abilities, :can? @@ -73,4 +75,12 @@ class ApplicationController < ActionController::Base def require_non_empty_project redirect_to @project unless @project.repo_exists? end + + def view_style + if params[:view_style] == "collapsed" + cookies[:view_style] = "collapsed" + elsif params[:view_style] == "fluid" + cookies[:view_style] = "" + end + end end diff --git a/app/controllers/commits_controller.rb b/app/controllers/commits_controller.rb index 79b97ed7..f6af56f8 100644 --- a/app/controllers/commits_controller.rb +++ b/app/controllers/commits_controller.rb @@ -28,12 +28,15 @@ class CommitsController < ApplicationController def show @commit = project.repo.commits(params[:id]).first - @notes = project.notes.where(:noteable_id => @commit.id, :noteable_type => "Commit") + @notes = project.notes.where(:noteable_id => @commit.id, :noteable_type => "Commit").order("created_at DESC").limit(20) @note = @project.notes.new(:noteable_id => @commit.id, :noteable_type => "Commit") - respond_to do |format| - format.html # show.html.erb - format.js + respond_to do |format| + format.html + format.js do + @notes = @notes.where("id > ?", params[:last_id]) if params[:last_id] + @notes = @notes.where("id < ?", params[:first_id]) if params[:first_id] + end end end end diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 71c559a1..b6fd85b8 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -35,8 +35,16 @@ class IssuesController < ApplicationController end def show - @notes = @issue.notes.order("created_at ASC") + @notes = @issue.notes.order("created_at DESC").limit(20) @note = @project.notes.new(:noteable => @issue) + + respond_to do |format| + format.html + format.js do + @notes = @notes.where("id > ?", params[:last_id]) if params[:last_id] + @notes = @notes.where("id < ?", params[:first_id]) if params[:first_id] + end + end end def create diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index e046add3..067245c4 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -86,13 +86,15 @@ class ProjectsController < ApplicationController def wall @note = Note.new @notes = @project.common_notes.order("created_at DESC") + @notes = @notes.fresh.limit(20) - @notes = case params[:view] - when "week" then @notes.since((Date.today - 7.days).at_beginning_of_day) - when "all" then @notes.all - when "day" then @notes.since(Date.today.at_beginning_of_day) - else @notes.fresh.limit(10) - end + respond_to do |format| + format.html + format.js do + @notes = @notes.where("id > ?", params[:last_id]) if params[:last_id] + @notes = @notes.where("id < ?", params[:first_id]) if params[:first_id] + end + end end # diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 3aa40c99..70984804 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -4,6 +4,14 @@ module ApplicationHelper "http://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(user_email)}?s=40&d=identicon" end + def body_class(default_class = nil) + main = content_for(:body_class).blank? ? + default_class : + content_for(:body_class) + + [main, cookies[:view_style]].join(" ") + end + def commit_name(project, commit) if project.commit.id == commit.id "master" diff --git a/app/views/commits/index.html.haml b/app/views/commits/index.html.haml index 7999b94c..b9650145 100644 --- a/app/views/commits/index.html.haml +++ b/app/views/commits/index.html.haml @@ -12,7 +12,7 @@ \/ %a{:href => "#"}= params[:path].split("/").join(" / ") -.right= render "projects/refs" +.right= render :partial => "projects/refs", :locals => { :destination => project_commits_path(@project) } %div{:id => dom_id(@project)} = render "commits" diff --git a/app/views/commits/show.js.haml b/app/views/commits/show.js.haml index 9831bb29..ee31c0b8 100644 --- a/app/views/commits/show.js.haml +++ b/app/views/commits/show.js.haml @@ -1,8 +1 @@ --#:plain - $("#side-commit-preview").remove(); - var side = $("
"); - side.html("#{escape_javascript(render "commits/show")}"); - $("##{dom_id(@project)}").parent().append(side); - $("##{dom_id(@project)}").addClass("span-14"); -:plain - $("#notes-list").html("#{escape_javascript(render(:partial => 'notes/notes_list'))}"); += render "notes/load" diff --git a/app/views/issues/show.html.haml b/app/views/issues/show.html.haml index 371a8033..8267a850 100644 --- a/app/views/issues/show.html.haml +++ b/app/views/issues/show.html.haml @@ -1,14 +1,12 @@ %h2 = "Issue ##{@issue.id} - #{html_escape(@issue.title)}" .left.width-65p - -#= simple_format html_escape(@issue.content) .issue_notes= render "notes/notes" + + .loading{ :style => "display:none;"} + %center= image_tag "ajax-loader.gif" .right.width-30p .span-8 - - if @issue.closed - %center.success Closed - - else - %center.error Open %table.round-borders %tr %td Title: @@ -54,4 +52,3 @@ = link_to 'Edit', edit_project_issue_path(@project, @issue), :class => "lbutton positive", :remote => true .right= link_to 'Destroy', [@project, @issue], :confirm => 'Are you sure?', :method => :delete, :class => "lbutton delete-issue negative", :id => "destroy_issue_#{@issue.id}" .clear - diff --git a/app/views/issues/show.js.haml b/app/views/issues/show.js.haml index ae2ff32c..ee31c0b8 100644 --- a/app/views/issues/show.js.haml +++ b/app/views/issues/show.js.haml @@ -1,2 +1 @@ -:plain - $("#notes-list").html("#{escape_javascript(render(:partial => 'notes/notes_list'))}"); += render "notes/load" diff --git a/app/views/layouts/_head_panel.html.erb b/app/views/layouts/_head_panel.html.erb index a64aa3b5..6db1d389 100644 --- a/app/views/layouts/_head_panel.html.erb +++ b/app/views/layouts/_head_panel.html.erb @@ -1,19 +1,29 @@
-

- GITLAB

-
- <%= link_to profile_path, :class => "pic" do %> - <%= image_tag gravatar_icon(current_user.email) %> - <% end %> - <%= link_to profile_path, :class => "username" do %> - <%= current_user.name %> - <% end %> - <%= link_to 'Logout', destroy_user_session_path, :class => "logout", :method => :delete %> +

+ GITLAB +

+ + + +
- - <% if current_user %> <%= javascript_tag do %> $(function() { diff --git a/app/views/layouts/admin.html.haml b/app/views/layouts/admin.html.haml index 8df7881c..e02dbe04 100644 --- a/app/views/layouts/admin.html.haml +++ b/app/views/layouts/admin.html.haml @@ -9,7 +9,7 @@ = javascript_tag do REQ_URI = "#{request.env["REQUEST_URI"]}"; REQ_REFFER = "#{request.env["HTTP_REFERER"]}"; - %body{ :class => content_for?(:body_class) ? yield(:body_class) : 'project-page', :id => yield(:boyd_id)} + %body{ :class => body_class('project-page'), :id => yield(:boyd_id)} #container = render :partial => "layouts/flash" = render :partial => "layouts/head_panel" diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index eedbf116..030f1999 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -13,7 +13,7 @@ = javascript_tag do REQ_URI = "#{request.env["REQUEST_URI"]}"; REQ_REFFER = "#{request.env["HTTP_REFERER"]}"; - %body{ :class => yield(:body_class), :id => yield(:boyd_id)} + %body{ :class => body_class, :id => yield(:boyd_id)} #container = render :partial => "layouts/flash" = render :partial => "layouts/head_panel" diff --git a/app/views/layouts/profile.html.haml b/app/views/layouts/profile.html.haml index a33d9d5d..2fd30dcd 100644 --- a/app/views/layouts/profile.html.haml +++ b/app/views/layouts/profile.html.haml @@ -9,7 +9,7 @@ = javascript_tag do REQ_URI = "#{request.env["REQUEST_URI"]}"; REQ_REFFER = "#{request.env["HTTP_REFERER"]}"; - %body{ :class => content_for?(:body_class) ? yield(:body_class) : 'project-page', :id => yield(:boyd_id)} + %body{ :class => body_class('project-page'), :id => yield(:boyd_id)} #container = render :partial => "layouts/flash" = render :partial => "layouts/head_panel" diff --git a/app/views/layouts/project.html.haml b/app/views/layouts/project.html.haml index f8d8221a..ee6581ec 100644 --- a/app/views/layouts/project.html.haml +++ b/app/views/layouts/project.html.haml @@ -9,7 +9,7 @@ = javascript_tag do REQ_URI = "#{request.env["REQUEST_URI"]}"; REQ_REFFER = "#{request.env["HTTP_REFERER"]}"; - %body{ :class => content_for?(:body_class) ? yield(:body_class) : 'project-page', :id => yield(:boyd_id)} + %body{ :class => body_class('project-page'), :id => yield(:boyd_id)} #container = render :partial => "layouts/flash" = render :partial => "layouts/head_panel" diff --git a/app/views/notes/_load.js.haml b/app/views/notes/_load.js.haml new file mode 100644 index 00000000..f560f0bd --- /dev/null +++ b/app/views/notes/_load.js.haml @@ -0,0 +1,10 @@ +- unless @notes.blank? + + - if params[:last_id] + :plain + NoteList.prepend(#{@notes.first.id}, "#{escape_javascript(render(:partial => 'notes/notes_list'))}"); + + - if params[:first_id] + :plain + NoteList.append(#{@notes.last.id}, "#{escape_javascript(render(:partial => 'notes/notes_list'))}"); + diff --git a/app/views/notes/_notes.html.haml b/app/views/notes/_notes.html.haml index e7cc2360..4a5c3aab 100644 --- a/app/views/notes/_notes.html.haml +++ b/app/views/notes/_notes.html.haml @@ -1,12 +1,8 @@ -- if controller.action_name == "wall" - %ul#notes-list= render "notes/notes_list" - -- else - %ul#notes-list= render "notes/notes_list" - %br - %br - - if can? current_user, :write_note, @project - = render "notes/form" +- if can? current_user, :write_note, @project + = render "notes/form" +.clear +%hr +%ul#notes-list= render "notes/notes_list" :javascript $('.delete-note').live('ajax:success', function() { @@ -20,8 +16,11 @@ $("#submit_note").removeAttr("disabled"); }) -- if ["issues", "projects"].include?(controller.controller_name) - :javascript - $(function(){ - var int =self.setInterval("updatePage()", 20000); + $(function(){ + $("#note_note").live("click", function(){ + $(this).css("height", "100px"); + $('.attach_holder').show(); }); + + NoteList.init("wall", #{@notes.last.try(:id) || 0}, #{@notes.first.try(:id) || 0}); + }); diff --git a/app/views/notes/_show.html.haml b/app/views/notes/_show.html.haml index 187d0a3c..5d766291 100644 --- a/app/views/notes/_show.html.haml +++ b/app/views/notes/_show.html.haml @@ -1,17 +1,17 @@ -%li{:id => dom_id(note)} - %div.note_author - = image_tag gravatar_icon(note.author.email), :class => "left", :width => 40, :style => "padding-right:5px;" - %div.note_content.left +%li{:id => dom_id(note), :class => "note"} + = image_tag gravatar_icon(note.author.email), :class => "left", :width => 40, :style => "padding-right:5px;" + %div.note-author + %strong= note.author_name + %cite + = time_ago_in_words(note.updated_at) + ago + - if(note.author_id == current_user.id) || can?(current_user, :admin_note, @project) + = link_to 'Remove', [@project, note], :confirm => 'Are you sure?', :method => :delete, :remote => true, :class => "lbutton delete-note right negative" + + %div.note-title = markdown(note.note) - if note.attachment.url Attachment: = link_to note.attachment_identifier, note.attachment.url, :target => "_blank" - %br - %span.author= note.author.name - %cite.ago - = time_ago_in_words(note.updated_at) - ago %br - - if(note.author_id == current_user.id) || can?(current_user, :admin_note, @project) - = link_to 'Remove', [@project, note], :confirm => 'Are you sure?', :method => :delete, :remote => true, :class => "lbutton delete-note right negative" .clear diff --git a/app/views/notes/create.js.haml b/app/views/notes/create.js.haml index a04130e8..cf804493 100644 --- a/app/views/notes/create.js.haml +++ b/app/views/notes/create.js.haml @@ -1,8 +1,8 @@ - if @note.valid? :plain $("#new_note .errors").remove(); - updatePage(); $('#note_note').val(""); + NoteList.prepend(#{@note.id}, "#{escape_javascript(render :partial => "notes/show", :locals => {:note => @note})}"); - else :plain $("#new_note").replaceWith("#{escape_javascript(render('form'))}"); diff --git a/app/views/projects/_refs.html.haml b/app/views/projects/_refs.html.haml index f7712d3d..60b17c7f 100644 --- a/app/views/projects/_refs.html.haml +++ b/app/views/projects/_refs.html.haml @@ -1,4 +1,4 @@ -= form_tag project_commits_path(@project), :method => :get, :class => "project-refs-form" do += form_tag destination, :method => :get, :class => "project-refs-form" do = select_tag "ref", grouped_options_refs, :onchange => "this.form.submit();", :class => "project-refs-select" diff --git a/app/views/projects/_tree.html.haml b/app/views/projects/_tree.html.haml index f70bbb7a..8fdf72f0 100644 --- a/app/views/projects/_tree.html.haml +++ b/app/views/projects/_tree.html.haml @@ -17,7 +17,7 @@ \/ = link_to truncate(part, :length => 40), tree_file_project_path(@project, :path => part_path, :commit_id => @commit.try(:id), :branch => @branch, :tag => @tag), :remote => :true   - .right= render "projects/refs" + .right= render :partial => "projects/refs", :locals => { :destination => tree_project_path(@project) } .clear #tree-content-holder diff --git a/app/views/projects/wall.html.haml b/app/views/projects/wall.html.haml index 63c9613a..4f0ec41e 100644 --- a/app/views/projects/wall.html.haml +++ b/app/views/projects/wall.html.haml @@ -1,29 +1,6 @@ %div.wall_page - - if can? current_user, :write_note, @project - = render "notes/form" - .right - = form_tag wall_project_path(@project), :method => :get do - .span-2 - = radio_button_tag :view, "recent", (params[:view] || "recent") == "recent", :onclick => "this.form.submit()", :id => "recent_view" - = label_tag "recent_view","Recent" - .span-2 - = radio_button_tag :view, "day", params[:view] == "day", :onclick => "this.form.submit()", :id => "day_view" - = label_tag "day_view","Today" - .span-2 - = radio_button_tag :view, "week", params[:view] == "week", :onclick => "this.form.submit()", :id => "week_view" - = label_tag "week_view","Week" - .span-2 - = radio_button_tag :view, "all", params[:view] == "all", :onclick => "this.form.submit()", :id => "all_view" - = label_tag "all_view","All" - .clear - %br - %hr -= render "notes/notes" + = render "notes/notes" + +.loading{ :style => "display:none;"} + %center= image_tag "ajax-loader.gif" -:javascript - $(function(){ - $("#note_note").live("click", function(){ - $(this).css("height", "100px"); - $('.attach_holder').show(); - }); - }); diff --git a/app/views/projects/wall.js.haml b/app/views/projects/wall.js.haml index ae2ff32c..ee31c0b8 100644 --- a/app/views/projects/wall.js.haml +++ b/app/views/projects/wall.js.haml @@ -1,2 +1 @@ -:plain - $("#notes-list").html("#{escape_javascript(render(:partial => 'notes/notes_list'))}"); += render "notes/load"