From 586c53ea0594a327b346c6fed38528a1f508c9e1 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sat, 5 Nov 2011 13:59:43 +0200 Subject: [PATCH 1/4] fixed notes loading/paging --- app/assets/javascripts/note.js | 24 ++++++++++++++++++++++- app/controllers/application_controller.rb | 12 ++++++++++++ app/controllers/commits_controller.rb | 5 +---- app/controllers/issues_controller.rb | 5 +---- app/controllers/projects_controller.rb | 5 +---- app/views/notes/_load.js.haml | 11 +++++++++-- 6 files changed, 47 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/note.js b/app/assets/javascripts/note.js index 71279fc4..7acc81e5 100644 --- a/app/assets/javascripts/note.js +++ b/app/assets/javascripts/note.js @@ -31,6 +31,15 @@ append: this.initLoadMore(); }, +replace: + function(fid, lid, html) { + this.first_id = fid; + this.last_id = lid; + $("#notes-list").html(html); + this.initLoadMore(); + }, + + prepend: function(id, html) { this.last_id = id; @@ -47,10 +56,23 @@ getNew: dataType: "script"}); }, +refresh: + function() { + // refersh notes list + $.ajax({ + type: "GET", + url: location.href, + data: "first_id=" + this.first_id + "&last_id=" + this.last_id, + dataType: "script"}); + }, + + + initRefresh: function() { // init timer - var int = setInterval("NoteList.getNew()", 20000); + var intNew = setInterval("NoteList.getNew()", 15000); + var intRefresh = setInterval("NoteList.refresh()", 90000); }, initLoadMore: diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 070def96..5c25d7d6 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -83,4 +83,16 @@ class ApplicationController < ActionController::Base cookies[:view_style] = "" end 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 end diff --git a/app/controllers/commits_controller.rb b/app/controllers/commits_controller.rb index f6af56f8..fa0d0b57 100644 --- a/app/controllers/commits_controller.rb +++ b/app/controllers/commits_controller.rb @@ -33,10 +33,7 @@ class CommitsController < ApplicationController 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 + format.js { respond_with_notes } end end end diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index b6fd85b8..7ff1ccb3 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -40,10 +40,7 @@ class IssuesController < ApplicationController 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 + format.js { respond_with_notes } end end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 067245c4..ef7eb921 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -90,10 +90,7 @@ class ProjectsController < ApplicationController 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 + format.js { respond_with_notes } end end diff --git a/app/views/notes/_load.js.haml b/app/views/notes/_load.js.haml index f560f0bd..c7ec9ed3 100644 --- a/app/views/notes/_load.js.haml +++ b/app/views/notes/_load.js.haml @@ -1,10 +1,17 @@ - unless @notes.blank? - - if params[:last_id] + - if params[:last_id] && params[:first_id] + :plain + NoteList.replace(#{@notes.last.id}, #{@notes.first.id}, "#{escape_javascript(render(:partial => 'notes/notes_list'))}"); + + + - elsif params[:last_id] :plain NoteList.prepend(#{@notes.first.id}, "#{escape_javascript(render(:partial => 'notes/notes_list'))}"); - - if params[:first_id] + - elsif params[:first_id] :plain NoteList.append(#{@notes.last.id}, "#{escape_javascript(render(:partial => 'notes/notes_list'))}"); + - else + :plain From 5eecbfdb10f97a216b585e7bddcbbd68f71f6ccc Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sat, 5 Nov 2011 14:26:06 +0200 Subject: [PATCH 2/4] commit paging fixes --- app/assets/javascripts/commits.js | 48 +++++++++++++++++++++++++ app/controllers/commits_controller.rb | 5 +-- app/views/commits/_commits.html.haml | 1 - app/views/commits/index.html.haml | 12 ++++++- app/views/commits/index.js.erb | 2 -- app/views/commits/index.js.haml | 3 ++ app/views/layouts/application.html.haml | 11 ++---- 7 files changed, 68 insertions(+), 14 deletions(-) delete mode 100644 app/views/commits/index.js.erb create mode 100644 app/views/commits/index.js.haml diff --git a/app/assets/javascripts/commits.js b/app/assets/javascripts/commits.js index a62e9330..bef7ed74 100644 --- a/app/assets/javascripts/commits.js +++ b/app/assets/javascripts/commits.js @@ -7,3 +7,51 @@ $(document).ready(function(){ } }); }); + + + +var CommitsList = { + +ref:null, +limit:0, +offset:0, + +init: + function(ref, limit) { + this.ref=ref; + this.limit=limit; + this.offset=limit; + this.initLoadMore(); + $('.loading').show(); + }, + +getOld: + function() { + $('.loading').show(); + $.ajax({ + type: "GET", + url: location.href, + data: "limit=" + this.limit + "&offset=" + this.offset + "&ref=" + this.ref, + complete: function(){ $('.loading').hide()}, + dataType: "script"}); + }, + +append: + function(count, html) { + $("#commits_list").append(html); + if(count > 0) { + this.offset += count; + this.initLoadMore(); + } + }, + +initLoadMore: + function() { + $(window).bind('scroll', function(){ + if($(window).scrollTop() == $(document).height() - $(window).height()){ + $(window).unbind('scroll'); + CommitsList.getOld(); + } + }); + } +} diff --git a/app/controllers/commits_controller.rb b/app/controllers/commits_controller.rb index fa0d0b57..79703cf1 100644 --- a/app/controllers/commits_controller.rb +++ b/app/controllers/commits_controller.rb @@ -13,11 +13,12 @@ class CommitsController < ApplicationController load_refs # load @branch, @tag & @ref @repo = project.repo + limit, offset = (params[:limit] || 20), (params[:offset] || 0) if params[:path] - @commits = @repo.log(@ref, params[:path], :max_count => params[:limit] || 100, :skip => params[:offset] || 0) + @commits = @repo.log(@ref, params[:path], :max_count => limit, :skip => offset) else - @commits = @repo.commits(@ref, params[:limit] || 100, params[:offset] || 0) + @commits = @repo.commits(@ref, limit, offset) end respond_to do |format| diff --git a/app/views/commits/_commits.html.haml b/app/views/commits/_commits.html.haml index 9761c65f..2d393993 100644 --- a/app/views/commits/_commits.html.haml +++ b/app/views/commits/_commits.html.haml @@ -22,4 +22,3 @@ %strong= commit.author_name = time_ago_in_words(commit.committed_date) ago -= more_commits_link if @commits.size > 99 diff --git a/app/views/commits/index.html.haml b/app/views/commits/index.html.haml index b9650145..0dfb2cff 100644 --- a/app/views/commits/index.html.haml +++ b/app/views/commits/index.html.haml @@ -15,4 +15,14 @@ .right= render :partial => "projects/refs", :locals => { :destination => project_commits_path(@project) } %div{:id => dom_id(@project)} - = render "commits" + #commits_list= render "commits" +.clear +.loading{ :style => "display:none;"} + %center= image_tag "ajax-loader.gif" + + + +:javascript + $(function(){ + CommitsList.init("#{@ref}", 20); + }); diff --git a/app/views/commits/index.js.erb b/app/views/commits/index.js.erb deleted file mode 100644 index 94daa396..00000000 --- a/app/views/commits/index.js.erb +++ /dev/null @@ -1,2 +0,0 @@ -$("#more-commits-link").remove(); -$('#<%= dom_id(@project)%>').append('<%= escape_javascript(render("commits")) %>'); diff --git a/app/views/commits/index.js.haml b/app/views/commits/index.js.haml new file mode 100644 index 00000000..39b7108c --- /dev/null +++ b/app/views/commits/index.js.haml @@ -0,0 +1,3 @@ +:plain + CommitsList.append(#{@commits.count}, "#{escape_javascript(render(:partial => 'commits/commits'))}"); + diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 030f1999..9022ecb1 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -2,11 +2,7 @@ %html %head %title - GitLab #{" - #{@project.name}" if @project && !@project.new_record?} - -#= stylesheet_link_tag 'blueprint/screen', :media => "screen, projection" - -#= stylesheet_link_tag 'blueprint/print', :media => "print" - -#= stylesheet_link_tag 'blueprint/plugins/buttons/screen', :media => "screen, projection" - -#= stylesheet_link_tag 'blueprint/plugins/link-icons/screen', :media => "screen, projection" + GitLab = stylesheet_link_tag "application" = javascript_include_tag "application" = csrf_meta_tags @@ -17,6 +13,5 @@ #container = render :partial => "layouts/flash" = render :partial => "layouts/head_panel" - %div{ :id => "main", :role => "main", :class => "container_4" } - = render :partial => "layouts/page_title" - = yield + = render :partial => "layouts/page_title" + = yield From 31a9d6531dcbfc72babf3da52d17cde61b4bcc04 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sat, 5 Nov 2011 14:45:52 +0200 Subject: [PATCH 3/4] commits notes under diff. tab removed --- app/assets/stylesheets/projects.css.scss | 7 ++++--- app/views/commits/show.html.haml | 24 +++++------------------- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/app/assets/stylesheets/projects.css.scss b/app/assets/stylesheets/projects.css.scss index 766138ee..0e1ad931 100644 --- a/app/assets/stylesheets/projects.css.scss +++ b/app/assets/stylesheets/projects.css.scss @@ -52,7 +52,8 @@ background: #eee; } .diff_file_content { - overflow-x: scroll; + overflow:auto; + overflow-y:hidden; background:#fff; color:#333; font-size: 12px; @@ -174,9 +175,9 @@ a { .old_line, .new_line { background:#ECECEC; color:#777; - width:15px; + width:30px; float:left; - padding: 0px 10px; + padding: 0px 5px; border-right: 1px solid #ccc; } } diff --git a/app/views/commits/show.html.haml b/app/views/commits/show.html.haml index 3bd9145e..b42b23de 100644 --- a/app/views/commits/show.html.haml +++ b/app/views/commits/show.html.haml @@ -1,5 +1,5 @@ %h3 - = "[ #{@commit.committer} ] #{truncate(@commit.safe_message)}" + = "[ #{@commit.author_name} ] #{truncate(@commit.safe_message, :length => 70)}" -#= link_to 'Back', project_commits_path(@project), :class => "button" %table.round-borders %tr @@ -8,12 +8,9 @@ %tr %td Author %td= @commit.author_name - %tr - %td Commiter - %td= @commit.committer %tr %td Commited Date - %td= @commit.committed_date + %td= @commit.committed_date.stamp("21 Aug 2011, 11:15pm") %tr %td Message %td @@ -24,18 +21,7 @@ %td= link_to 'Browse Code', tree_project_path(@project, :commit_id => @commit.id) .clear -#tabs - %ul - %li - %a{ :href => "#tabs-1" } Diff - %li - %a{ :href => "#tabs-2" } Comments - %span{ :class => "notes_count" }= @notes.count - %hr - #tabs-1 - = render "commits/diff" - #tabs-2 - = render "notes/notes" +%br -:javascript - $(function() { $( "#tabs" ).tabs(); }); += render "commits/diff" += render "notes/notes" From 0499759204449a78ead1950c06fbab4dacfa84f2 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sat, 5 Nov 2011 15:31:54 +0200 Subject: [PATCH 4/4] issues & fixed layout --- app/assets/stylesheets/projects.css.scss | 42 +++++------------------ app/controllers/application_controller.rb | 6 ++++ app/views/issues/_show.html.haml | 14 ++++---- app/views/issues/index.html.haml | 10 +++--- app/views/issues/show.html.haml | 23 ++++++------- spec/requests/commits_notes_spec.rb | 1 - 6 files changed, 38 insertions(+), 58 deletions(-) diff --git a/app/assets/stylesheets/projects.css.scss b/app/assets/stylesheets/projects.css.scss index 0e1ad931..c4b5de8a 100644 --- a/app/assets/stylesheets/projects.css.scss +++ b/app/assets/stylesheets/projects.css.scss @@ -163,10 +163,6 @@ table.round-borders { padding:20px; } -//body { - //background: #eaeaea; -//} - a { color: #111; } @@ -232,43 +228,15 @@ input.ssh_project_url { text-align:center; } -.day-commits-table li.commit { - cursor:pointer; - - &:hover { - @include hover-color; - } -} - -/* -#FFF6BF -#FFD324 -*/ -#tree-slider tr.tree-item { - cursor:pointer; - - &:hover { - @include hover-color; - td { - @include hover-color; - } - } -} #projects-list .project { height:50px; } +#tree-slider .tree-item, #projects-list .project, #snippets-table .snippet, #issues-table .issue{ cursor:pointer; - - &:hover { - @include hover-color; - td { - @include hover-color; - } - } } .clear { @@ -563,6 +531,7 @@ input.ssh_project_url { @include round-borders-all(4px); padding:2px 4px; border:none; + text-shadow:none; &.high { background: #D12F19; @@ -687,6 +656,13 @@ table.highlighttable pre{ width:200px; } +.issues_filter { + margin-top:10px; + .left { + margin-right:15px; + } +} + 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;} diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5c25d7d6..782612c0 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -82,6 +82,12 @@ class ApplicationController < ActionController::Base elsif params[:view_style] == "fluid" cookies[:view_style] = "" end + + @view_mode = if cookies[:view_style] == "collapsed" + :fixed + else + :fluid + end end def respond_with_notes diff --git a/app/views/issues/_show.html.haml b/app/views/issues/_show.html.haml index 94cc03d1..05208d09 100644 --- a/app/views/issues/_show.html.haml +++ b/app/views/issues/_show.html.haml @@ -4,10 +4,11 @@ = image_tag "move.png" , :class => [:handle, :left] %td = image_tag gravatar_icon(issue.assignee.email), :class => "left", :width => 40, :style => "padding:0 5px;" - = truncate issue.assignee.name, :lenght => 20 + = issue.assignee.name %td ##{issue.id} %td - = truncate(html_escape(issue.title), :length => 60) + = truncate(html_escape(issue.title), :length => 200) + %br %br - if issue.critical %span.tag.high critical @@ -27,7 +28,8 @@ - else = check_box_tag "closed", 1, issue.closed, :disabled => true %td - - if can?(current_user, :admin_issue, @project) || issue.author == current_user - = link_to 'Edit', edit_project_issue_path(@project, issue), :class => "lbutton positive", :remote => true - - if can?(current_user, :admin_issue, @project) || issue.author == current_user - = link_to 'Destroy', [@project, issue], :confirm => 'Are you sure?', :method => :delete, :remote => true, :class => "lbutton delete-issue negative", :id => "destroy_issue_#{issue.id}" + - if @view_mode == :fluid + - if can?(current_user, :admin_issue, @project) || issue.author == current_user + = link_to 'Edit', edit_project_issue_path(@project, issue), :class => "lbutton positive", :remote => true + - if can?(current_user, :admin_issue, @project) || issue.author == current_user + = link_to 'Destroy', [@project, issue], :confirm => 'Are you sure?', :method => :delete, :remote => true, :class => "lbutton delete-issue negative", :id => "destroy_issue_#{issue.id}" diff --git a/app/views/issues/index.html.haml b/app/views/issues/index.html.haml index a70c65d4..21e455b9 100644 --- a/app/views/issues/index.html.haml +++ b/app/views/issues/index.html.haml @@ -7,18 +7,18 @@ = hidden_field_tag :project_id, @project.id, { :id => 'project_id' } = search_field_tag :issue_search, nil, { :placeholder => 'Search', :class => 'issue_search' } - .right + .right.issues_filter = form_tag project_issues_path(@project), :method => :get do - .span-2 + .left = radio_button_tag :f, 0, (params[:f] || "0") == "0", :onclick => "this.form.submit()", :id => "open_issues", :class => "status" = label_tag "open_issues","Open" - .span-2 + .left = radio_button_tag :f, 2, params[:f] == "2", :onclick => "this.form.submit()", :id => "closed_issues", :class => "status" = label_tag "closed_issues","Closed" - .span-2 + .left = radio_button_tag :f, 3, params[:f] == "3", :onclick => "this.form.submit()", :id => "my_issues", :class => "status" = label_tag "my_issues","To Me" - .span-2 + .left = radio_button_tag :f, 1, params[:f] == "1", :onclick => "this.form.submit()", :id => "all_issues", :class => "status" = label_tag "all_issues","All" diff --git a/app/views/issues/show.html.haml b/app/views/issues/show.html.haml index 8267a850..dc4ab338 100644 --- a/app/views/issues/show.html.haml +++ b/app/views/issues/show.html.haml @@ -1,5 +1,9 @@ %h2 - = "Issue ##{@issue.id} - #{html_escape(@issue.title)}" + %strong + Issue + = "##{@issue.id}" + – + = html_escape(@issue.title) .left.width-65p .issue_notes= render "notes/notes" @@ -8,14 +12,6 @@ .right.width-30p .span-8 %table.round-borders - %tr - %td Title: - %td - = truncate html_escape(@issue.title) - %tr - %td Project - %td - %strong= @issue.project.name %tr %td Author: %td @@ -39,7 +35,7 @@ %tr %td Closed? %td - - if can? current_user, :write_issue, @project + - if can? current_user, :write_issue, @issue = form_for([@project, @issue]) do |f| = f.check_box :closed, :onclick => "$(this).parent().submit();" = hidden_field_tag :status_only, true @@ -47,8 +43,9 @@ = check_box_tag "closed", 1, @issue.closed, :disabled => true - - if can?(current_user, :admin_issue, @issue) + - if can?(current_user, :write_issue, @issue) .clear - = 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}" + %br + = 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/spec/requests/commits_notes_spec.rb b/spec/requests/commits_notes_spec.rb index c424f4fc..69a492e9 100644 --- a/spec/requests/commits_notes_spec.rb +++ b/spec/requests/commits_notes_spec.rb @@ -12,7 +12,6 @@ describe "Issues" do describe "add new note", :js => true do before do visit project_commit_path(project, commit) - click_link "Comments" # notes tab fill_in "note_note", :with => "I commented this commit" click_button "Add note" end