From 65105ff3bbe66363d4c922913dbc8c9514f1485c Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 4 Mar 2015 17:22:55 -0800 Subject: [PATCH] Improve projects list * Add search filtering for group projects * Show all user projects on dashboard * Refactor projects list into one view * Hide big list of projects with 'Show all' button --- app/assets/javascripts/dashboard.js.coffee | 17 +--------- app/assets/javascripts/dispatcher.js.coffee | 6 +++- .../javascripts/projects_list.js.coffee | 24 ++++++++++++++ app/assets/javascripts/user.js.coffee | 1 + app/controllers/dashboard_controller.rb | 8 ++--- app/views/dashboard/_projects.html.haml | 19 ++---------- app/views/groups/_projects.html.haml | 31 ++++++------------- .../{dashboard => shared}/_project.html.haml | 14 ++++++--- app/views/shared/_projects_list.html.haml | 17 ++++++++++ app/views/users/_projects.html.haml | 20 ++++-------- 10 files changed, 77 insertions(+), 80 deletions(-) create mode 100644 app/assets/javascripts/projects_list.js.coffee rename app/views/{dashboard => shared}/_project.html.haml (56%) create mode 100644 app/views/shared/_projects_list.html.haml diff --git a/app/assets/javascripts/dashboard.js.coffee b/app/assets/javascripts/dashboard.js.coffee index 6ef5a539b8f..3bdb9469d06 100644 --- a/app/assets/javascripts/dashboard.js.coffee +++ b/app/assets/javascripts/dashboard.js.coffee @@ -1,22 +1,7 @@ class @Dashboard constructor: -> @initSidebarTab() - - $(".dash-filter").keyup -> - terms = $(this).val() - uiBox = $(this).parents('.panel').first() - if terms == "" || terms == undefined - uiBox.find(".dash-list li").show() - else - uiBox.find(".dash-list li").each (index) -> - name = $(this).find(".filter-title").text() - - if name.toLowerCase().search(terms.toLowerCase()) == -1 - $(this).hide() - else - $(this).show() - - + new ProjectsList() initSidebarTab: -> key = "dashboard_sidebar_filter" diff --git a/app/assets/javascripts/dispatcher.js.coffee b/app/assets/javascripts/dispatcher.js.coffee index 591a3749a93..bf94fa3aaa0 100644 --- a/app/assets/javascripts/dispatcher.js.coffee +++ b/app/assets/javascripts/dispatcher.js.coffee @@ -62,9 +62,13 @@ class Dispatcher shortcut_handler = new ShortcutsNavigation() when 'projects:commits:show' shortcut_handler = new ShortcutsNavigation() - when 'groups:show', 'projects:show' + when 'projects:show' new Activities() shortcut_handler = new ShortcutsNavigation() + when 'groups:show' + new Activities() + shortcut_handler = new ShortcutsNavigation() + new ProjectsList() when 'groups:members' new GroupMembers() new UsersSelect() diff --git a/app/assets/javascripts/projects_list.js.coffee b/app/assets/javascripts/projects_list.js.coffee new file mode 100644 index 00000000000..c0e36d1ccc5 --- /dev/null +++ b/app/assets/javascripts/projects_list.js.coffee @@ -0,0 +1,24 @@ +class @ProjectsList + constructor: -> + $(".projects-list .js-expand").on 'click', (e) -> + e.preventDefault() + list = $(this).closest('.projects-list') + list.find("li").show() + list.find("li.bottom").hide() + + $(".projects-list-filter").keyup -> + terms = $(this).val() + uiBox = $(this).closest('.panel') + if terms == "" || terms == undefined + uiBox.find(".projects-list li").show() + else + uiBox.find(".projects-list li").each (index) -> + name = $(this).find(".filter-title").text() + + if name.toLowerCase().search(terms.toLowerCase()) == -1 + $(this).hide() + else + $(this).show() + uiBox.find(".projects-list li.bottom").hide() + + diff --git a/app/assets/javascripts/user.js.coffee b/app/assets/javascripts/user.js.coffee index 8a2e2421c2e..d0d81f96921 100644 --- a/app/assets/javascripts/user.js.coffee +++ b/app/assets/javascripts/user.js.coffee @@ -1,3 +1,4 @@ class @User constructor: -> $('.profile-groups-avatars').tooltip("placement": "top") + new ProjectsList() diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 4930029e165..8f06a673584 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -5,15 +5,11 @@ class DashboardController < ApplicationController before_filter :event_filter, only: :show def show - # Fetch only 30 projects. - # If user needs more - point to Dashboard#projects page - @projects_limit = 30 - + @projects_limit = 20 @groups = current_user.authorized_groups.order_name_asc @has_authorized_projects = @projects.count > 0 @projects_count = @projects.count - @projects = @projects.includes(:namespace).limit(@projects_limit) - + @projects = @projects.includes(:namespace) @last_push = current_user.recent_push @publicish_project_count = Project.publicish(current_user).count diff --git a/app/views/dashboard/_projects.html.haml b/app/views/dashboard/_projects.html.haml index 0596738342f..3634b2bfd7b 100644 --- a/app/views/dashboard/_projects.html.haml +++ b/app/views/dashboard/_projects.html.haml @@ -1,25 +1,10 @@ .panel.panel-default .panel-heading.clearfix .input-group - = search_field_tag :filter_projects, nil, placeholder: 'Filter by name', class: 'dash-filter form-control' + = search_field_tag :filter_projects, nil, placeholder: 'Filter by name', class: 'projects-list-filter form-control' - if current_user.can_create_project? .input-group-addon.dash-new-project = link_to new_project_path do %strong New project - %ul.well-list.dash-list - - projects.each do |project| - %li.project-row - = render "project", project: project - - - if projects.blank? - %li - .nothing-here-block There are no projects here. - - if @projects_count > @projects_limit - %li.bottom - %span.light - #{@projects_limit} of #{pluralize(@projects_count, 'project')} displayed. - .pull-right - = link_to projects_dashboard_path do - Show all - %i.fa.fa-angle-right + = render 'shared/projects_list', projects: @projects, projects_limit: 20 diff --git a/app/views/groups/_projects.html.haml b/app/views/groups/_projects.html.haml index b505760fa8f..0dfd398f54d 100644 --- a/app/views/groups/_projects.html.haml +++ b/app/views/groups/_projects.html.haml @@ -1,23 +1,10 @@ .panel.panel-default - .panel-heading - Projects (#{projects.count}) - - if can? current_user, :create_projects, @group - .panel-head-actions - = link_to new_project_path(namespace_id: @group.id), class: "btn btn-new" do - %i.fa.fa-plus - New project - %ul.well-list - - if projects.blank? - .nothing-here-block This group has no projects yet - - projects.each do |project| - %li.project-row - = link_to project_path(project), class: dom_class(project) do - .dash-project-avatar - = project_icon(project, alt: '', class: 'avatar s40') - .dash-project-access-icon - = visibility_level_icon(project.visibility_level) - %span.str-truncated - %span.project-name - = project.name - %span.arrow - %i.fa.fa-angle-right + .panel-heading.clearfix + .input-group + = search_field_tag :filter_projects, nil, placeholder: 'Filter by name', class: 'projects-list-filter form-control' + - if current_user.can_create_project? + .input-group-addon.dash-new-project + = link_to new_project_path(namespace_id: @group.id) do + %strong New project + + = render 'shared/projects_list', projects: @projects, projects_limit: 20 diff --git a/app/views/dashboard/_project.html.haml b/app/views/shared/_project.html.haml similarity index 56% rename from app/views/dashboard/_project.html.haml rename to app/views/shared/_project.html.haml index fa9179cb249..d9ae0459862 100644 --- a/app/views/dashboard/_project.html.haml +++ b/app/views/shared/_project.html.haml @@ -1,6 +1,7 @@ = link_to project_path(project), class: dom_class(project) do - .dash-project-avatar - = project_icon(project, alt: '', class: 'avatar project-avatar s40') + - if avatar + .dash-project-avatar + = project_icon(project, alt: '', class: 'avatar project-avatar s40') .dash-project-access-icon = visibility_level_icon(project.visibility_level) %span.str-truncated @@ -10,5 +11,10 @@ \/ %span.project-name.filter-title = project.name - %span.arrow - %i.fa.fa-angle-right + - if stars + %span.pull-right.light + %i.fa.fa-star + = project.star_count + - else + %span.arrow + %i.fa.fa-angle-right diff --git a/app/views/shared/_projects_list.html.haml b/app/views/shared/_projects_list.html.haml new file mode 100644 index 00000000000..4c58092af44 --- /dev/null +++ b/app/views/shared/_projects_list.html.haml @@ -0,0 +1,17 @@ +- projects_limit = 20 unless local_assigns[:projects_limit] +- avatar = true unless local_assigns[:avatar] == false +- stars = false unless local_assigns[:stars] == true +%ul.well-list.projects-list + - projects.each_with_index do |project, i| + %li{class: (i >= projects_limit) ? 'project-row hide' : 'project-row'} + = render "shared/project", project: project, avatar: avatar, stars: stars + - if projects.blank? + %li + .nothing-here-block There are no projects here. + - if projects.count > projects_limit + %li.bottom + %span.light + #{projects_limit} of #{pluralize(projects.count, 'project')} displayed. + %span + = link_to '#', class: 'js-expand' do + Show all diff --git a/app/views/users/_projects.html.haml b/app/views/users/_projects.html.haml index c925a48f550..6c7779be30e 100644 --- a/app/views/users/_projects.html.haml +++ b/app/views/users/_projects.html.haml @@ -1,21 +1,13 @@ - if @contributed_projects.present? .panel.panel-default .panel-heading Projects contributed to - %ul.well-list - - @contributed_projects.sort_by(&:star_count).reverse.each do |project| - %li - = link_to_project project - %span.pull-right.light - %i.fa.fa-star - = project.star_count + = render 'shared/projects_list', + projects: @contributed_projects.sort_by(&:star_count).reverse, + projects_limit: 5, stars: true, avatar: false - if @projects.present? .panel.panel-default .panel-heading Personal projects - %ul.well-list - - @projects.sort_by(&:star_count).reverse.each do |project| - %li - = link_to_project project - %span.pull-right.light - %i.fa.fa-star - = project.star_count + = render 'shared/projects_list', + projects: @projects.sort_by(&:star_count).reverse, + projects_limit: 10, stars: true, avatar: false