From 5ff87be8a9ecc73a64182584558871fef772b276 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Tue, 10 Sep 2013 23:03:00 +0600 Subject: [PATCH] [#277] profile projects --- app/assets/javascripts/application.js | 29 ++++++++++ app/assets/javascripts/extra/tracker.js | 28 ++-------- app/assets/stylesheets/design/profile.scss | 53 ++++++++++--------- app/controllers/groups/profile_controller.rb | 19 ++++++- .../platforms/products_controller.rb | 2 +- app/controllers/users/profile_controller.rb | 21 +++++++- app/views/shared/_profile.html.haml | 15 +++--- app/views/shared/_profile_projects.html.haml | 26 +++++---- 8 files changed, 121 insertions(+), 72 deletions(-) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 1672028d3..9946b1663 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -100,4 +100,33 @@ $(document).ready(function() { updateTime(); setInterval( updateTime, 15000 ); + + window.updatePagination = function(link) { + var page = parseInt($('.pagination .current').text()); + if (link.hasClass('next_page')) { + page += 1; + } else { + if (link.hasClass('previous_page')) { + page -= 1; + } else { + page = link.text(); + } + } + $('.pagination .current').html(page); + }; + + window.isSearchUser = null; + window.search_items = function(path, fdata, dom) { + if (window.isSearchUser != null) { window.isSearchUser.abort(); } + window.isSearchUser = $.ajax({ + type: 'GET', + url: path, + data: fdata, + success: function(data) { + dom.html(data); + updateTime(); + } + }); + return false; + } }); diff --git a/app/assets/javascripts/extra/tracker.js b/app/assets/javascripts/extra/tracker.js index 94fe055d7..072e1fcdf 100644 --- a/app/assets/javascripts/extra/tracker.js +++ b/app/assets/javascripts/extra/tracker.js @@ -18,18 +18,7 @@ $(document).ready(function() { }); $("#table1.issues-table .pagination a").live('click', function() { - var a = $(this); - var page = parseInt($('.pagination .current').text()); - if (a.hasClass('next_page')) { - page += 1; - } else { - if (a.hasClass('previous_page')) { - page -= 1; - } else { - page = a.text(); - } - } - $('.pagination .current').html(page); + updatePagination($(this)); return send_index_tracker_request('GET'); }); @@ -116,18 +105,11 @@ $(document).ready(function() { return false; }; - var isSearchUser = null; $('#search_user').on('keyup', function() { - if (isSearchUser != null) { isSearchUser.abort(); } - isSearchUser = $.ajax({ - type: 'GET', - url: $('#search_user_path').attr('path'), - data: $(this).serialize(), - success: function(data){ - $('#manage_issue_users_list').html(data); - } - }); - return false; + path = $('#search_user_path').attr('path'); + data = $(this).serialize(); + dom = $('#manage_issue_users_list'); + return search_items(path, data, dom); }); $('.users-search-popup .header .icon-remove-circle').live('click', function() { diff --git a/app/assets/stylesheets/design/profile.scss b/app/assets/stylesheets/design/profile.scss index 1c351ac40..f47c63c88 100644 --- a/app/assets/stylesheets/design/profile.scss +++ b/app/assets/stylesheets/design/profile.scss @@ -40,32 +40,32 @@ hr.profile_line { float: left; margin: 15px 10px; width: 837px; - } - div.search div.pic { - background: url("/assets/search-button.png") repeat scroll 0 0 transparent; - float: left; - height: 22px; - width: 24px; - } - div.search div.field { - float: left; - margin: -1px 0 0; - } - - div.search div.field input { - background: none repeat scroll 0 0 transparent; - border: medium none; - font-family: Arial; - font-size: 12px; - height: 18px; - padding: 2px 0 0; - width: 132px; - } - div.search div.field input.gray { - color: #CFCFCF; - } - div.search div.field input.black { - color: #333333; + div.pic { + background: url("/assets/search-button.png") repeat scroll 0 0 transparent; + float: left; + height: 22px; + width: 24px; + } + div.field { + float: left; + margin: -1px 0 0; + width: 750px; + input { + background: none repeat scroll 0 0 transparent; + border: medium none; + font-family: Arial; + font-size: 12px; + height: 18px; + padding: 2px 0 0; + width: 700px; + } + input.gray { + color: #CFCFCF; + } + input.black { + color: #333333; + } + } } table { border: none; @@ -74,6 +74,7 @@ hr.profile_line { width: 844px; th { padding-left: 10px; + min-width: 411px; .project-link { margin-top: 5px; } diff --git a/app/controllers/groups/profile_controller.rb b/app/controllers/groups/profile_controller.rb index 266c528b1..94312ebff 100644 --- a/app/controllers/groups/profile_controller.rb +++ b/app/controllers/groups/profile_controller.rb @@ -10,8 +10,19 @@ class Groups::ProfileController < Groups::BaseController end def show + @path, page = group_path, params[:page].to_i @projects = @group.projects.opened.search(params[:search]).recent - .paginate(:page => params[:page], :per_page => 24) + if params[:projects] == 'show' + if params[:visibility] != 'hidden' + @projects = @projects.opened + @hidden = true + else + @projects = @projects.by_visibilities('hidden').accessible_by(current_ability, :read) + end + render :partial => 'shared/profile_projects', :layout => nil, :locals => {:projects => paginate_projects(page)} + else + @projects = paginate_projects(page) + end end def new @@ -53,4 +64,10 @@ class Groups::ProfileController < Groups::BaseController Relation.by_actor(current_user).by_target(@group).destroy_all redirect_to groups_path end + + protected + + def paginate_projects(page) + @projects.paginate(:page => (page>0 ? page : nil), :per_page => 24) + end end diff --git a/app/controllers/platforms/products_controller.rb b/app/controllers/platforms/products_controller.rb index 1bf862f5e..9f22988d4 100644 --- a/app/controllers/platforms/products_controller.rb +++ b/app/controllers/platforms/products_controller.rb @@ -54,7 +54,7 @@ class Platforms::ProductsController < Platforms::BaseController def autocomplete_project items = Project.accessible_by(current_ability, :membered) .search(params[:term]).limit(20) - items.select! {|e| e.repo.branches.count > 0} + #items.select! {|e| e.repo.branches.count > 0} render :json => items.map{ |p| { :id => p.id, diff --git a/app/controllers/users/profile_controller.rb b/app/controllers/users/profile_controller.rb index b19d1b047..dba36ad44 100644 --- a/app/controllers/users/profile_controller.rb +++ b/app/controllers/users/profile_controller.rb @@ -3,7 +3,24 @@ class Users::ProfileController < Users::BaseController skip_before_filter :authenticate_user!, :only => :show if APP_CONFIG['anonymous_access'] def show - @projects = @user.projects.opened.search(params[:search]).recent - .paginate(:page => params[:page], :per_page => 24) + @path = user_path + @projects = @user.projects.search(params[:search]).recent + if params[:projects] == 'show' + if params[:visibility] != 'hidden' + @projects = @projects.opened + @hidden = true + else + @projects = @projects.by_visibilities('hidden').accessible_by(current_ability, :read) + end + render :partial => 'shared/profile_projects', :layout => nil, :locals => {:projects => paginate_projects(page)} + else + @projects = paginate_projects(page) + end + end + + protected + + def paginate_projects(page) + @projects.paginate(:page => (page>0 ? page : nil), :per_page => 24) end end diff --git a/app/views/shared/_profile.html.haml b/app/views/shared/_profile.html.haml index 1c87bbe62..9fdcc553a 100644 --- a/app/views/shared/_profile.html.haml +++ b/app/views/shared/_profile.html.haml @@ -8,6 +8,7 @@ - [group.description , t('activerecord.attributes.group.description')] - max_length = 35 += hidden_field_tag :profile_path, @profile_path .row .span3.profile .avatar= image_tag avatar_url(user || group, :big), :alt => (user || group).uname @@ -44,14 +45,10 @@ .span12.sub-menu %nav %ul - %li= link_to t('layout.projects.public'), '#', :class => "public-projects #{@public ? 'active' : ''}" - %li= link_to t('layout.projects.private'), '#', :class => "private-projects #{!@public ? 'active' : ''}" + %li= link_to t('layout.projects.public'), '#', :class => "public-projects #{!@hidden ? 'active' : ''}" + %li= link_to t('layout.projects.private'), '#', :class => "private-projects #{@hidden ? 'active' : ''}" .search .pic - .field= text_field_tag 'query', @query, :placeholder => t('layout.find_project') - - %table.profile-table - %tbody= render 'shared/profile_projects', :projects => projects -%br -= will_paginate projects - + .field= text_field_tag :query_projects, @query, :placeholder => t('layout.find_project') + .both + .profile-table= render 'shared/profile_projects', :projects => projects diff --git a/app/views/shared/_profile_projects.html.haml b/app/views/shared/_profile_projects.html.haml index 3762c49a7..c832cadab 100644 --- a/app/views/shared/_profile_projects.html.haml +++ b/app/views/shared/_profile_projects.html.haml @@ -1,11 +1,17 @@ - pr_groups = projects.in_groups(2) -- pr_groups[0].each_with_index do |project, ind| - %tr{:class => ind.odd? ? 'odd' : 'even'} - - [project, pr_groups[1][ind]].each do |project| - %th - - if project.present? - .project-link= link_to project.name, project - .row-fluid - = datetime_moment project.updated_at, :class => :span3 - - commits_count = project.total_commits_count - .span3= "#{commits_count > 10000 ? '10000+' : commits_count} #{commits_pluralize(commits_count)}" +%table + %tbody + - pr_groups[0].each_with_index do |project, ind| + %tr{:class => ind.odd? ? 'odd' : 'even'} + - [project, pr_groups[1][ind]].each do |project| + %th + - if project.present? + .project-link= link_to short_message(project.name, 60), project, :title => project.name + .both + .row-fluid + = datetime_moment project.updated_at, :class => :span3 + - commits_count = project.total_commits_count + .span3= "#{commits_count > 10000 ? '10000+' : commits_count} #{commits_pluralize(commits_count)}" +%br +%div{:style => 'margin: 10px;'}= will_paginate projects +