diff options
-rw-r--r-- | app/assets/javascripts/dashboard.js.coffee | 33 | ||||
-rw-r--r-- | app/assets/javascripts/dispatcher.js.coffee | 2 | ||||
-rw-r--r-- | app/assets/javascripts/issues.js.coffee | 2 | ||||
-rw-r--r-- | app/assets/javascripts/projects_list.js.coffee | 43 | ||||
-rw-r--r-- | app/assets/javascripts/user.js.coffee | 2 | ||||
-rw-r--r-- | app/controllers/application_controller.rb | 4 | ||||
-rw-r--r-- | app/controllers/dashboard/projects_controller.rb | 14 | ||||
-rw-r--r-- | app/controllers/explore/projects_controller.rb | 12 | ||||
-rw-r--r-- | app/controllers/groups_controller.rb | 1 | ||||
-rw-r--r-- | app/controllers/users_controller.rb | 3 | ||||
-rw-r--r-- | app/models/event.rb | 2 | ||||
-rw-r--r-- | app/views/dashboard/_projects_head.html.haml | 4 | ||||
-rw-r--r-- | app/views/dashboard/projects/_projects.html.haml | 4 | ||||
-rw-r--r-- | app/views/explore/projects/_projects.html.haml | 4 | ||||
-rw-r--r-- | app/views/explore/projects/starred.html.haml | 4 | ||||
-rw-r--r-- | app/views/explore/projects/trending.html.haml | 2 | ||||
-rw-r--r-- | app/views/projects/show.atom.builder | 2 | ||||
-rw-r--r-- | app/views/shared/projects/_list.html.haml | 14 |
18 files changed, 90 insertions, 62 deletions
diff --git a/app/assets/javascripts/dashboard.js.coffee b/app/assets/javascripts/dashboard.js.coffee index dc0b9597d1f..0229c588b41 100644 --- a/app/assets/javascripts/dashboard.js.coffee +++ b/app/assets/javascripts/dashboard.js.coffee @@ -1,3 +1,30 @@ -class @Dashboard - constructor: -> - ProjectsList.init() +@Dashboard = + init: -> + this.initSearch() + + initSearch: -> + @timer = null + $("#project-filter-form-field").keyup -> + clearTimeout(@timer) + @timer = setTimeout(Dashboard.filterResults, 500) + + filterResults: => + $('.projects-list-holder').css("opacity", '0.5') + + form = null + form = $("#project-filter-form") + search = $("#project-filter-form-field").val() + project_filter_url = form.attr('action') + '?' + form.serialize() + + $.ajax + type: "GET" + url: form.attr('action') + data: form.serialize() + complete: -> + $('.projects-list-holder').css("opacity", '1.0') + success: (data) -> + $('div.projects-list-holder').replaceWith(data.html) + # Change url so if user reload a page - search results are saved + history.replaceState {page: project_filter_url}, document.title, project_filter_url + dataType: "json" + #uiBox.find("ul.projects-list li.bottom").hide() diff --git a/app/assets/javascripts/dispatcher.js.coffee b/app/assets/javascripts/dispatcher.js.coffee index 2cdf01d874c..d4a2b74b143 100644 --- a/app/assets/javascripts/dispatcher.js.coffee +++ b/app/assets/javascripts/dispatcher.js.coffee @@ -58,7 +58,7 @@ class Dispatcher shortcut_handler = new ShortcutsNavigation() MergeRequests.init() when 'dashboard:show', 'root:show' - new Dashboard() + Dashboard.init() when 'dashboard:activity' new Activities() when 'dashboard:projects:starred' diff --git a/app/assets/javascripts/issues.js.coffee b/app/assets/javascripts/issues.js.coffee index 54e00741424..a0acf3028bf 100644 --- a/app/assets/javascripts/issues.js.coffee +++ b/app/assets/javascripts/issues.js.coffee @@ -45,7 +45,7 @@ filterResults: => form = $("#issue_search_form") - search = $("#projects-list-filter").val() + search = $("#issue_search").val() $('.issues-holder').css("opacity", '0.5') issues_url = form.attr('action') + '?' + form.serialize() diff --git a/app/assets/javascripts/projects_list.js.coffee b/app/assets/javascripts/projects_list.js.coffee index 384b95118c9..ebf7140b7e3 100644 --- a/app/assets/javascripts/projects_list.js.coffee +++ b/app/assets/javascripts/projects_list.js.coffee @@ -1,35 +1,24 @@ -@ProjectsList = - init: -> +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() - this.initSearch() - initSearch: -> - @timer = null - $("#projects-list-filter").keyup -> - clearTimeout(@timer) - @timer = setTimeout(ProjectsList.filterResults, 500) + $(".projects-list-filter").keyup -> + terms = $(this).val() + uiBox = $('div.projects-list-holder') + filterSelector = $(this).data('filter-selector') || 'span.filter-title' - filterResults: => - form = $("#project-list-form") - search = $("#issue_search").val() - uiBox = $('div.projects-list-holder') + if terms == "" || terms == undefined + uiBox.find("ul.projects-list li").show() + else + uiBox.find("ul.projects-list li").each (index) -> + name = $(this).find(filterSelector).text() - $('.projects-list-holder').css("opacity", '0.5') - - project_filter_url = form.attr('action') + '?' + form.serialize() - $.ajax - type: "GET" - url: form.attr('action') - data: form.serialize() - complete: -> - $('.projects-list-holder').css("opacity", '1.0') - success: (data) -> - $('.projects-list-holder').html(data.html) - # Change url so if user reload a page - search results are saved - history.replaceState {page: project_filter_url}, document.title, project_filter_url - dataType: "json" - uiBox.find("ul.projects-list li.bottom").hide() + if name.toLowerCase().search(terms.toLowerCase()) == -1 + $(this).hide() + else + $(this).show() + uiBox.find("ul.projects-list li.bottom").hide() diff --git a/app/assets/javascripts/user.js.coffee b/app/assets/javascripts/user.js.coffee index eb7f7bb26b1..ec4271b092c 100644 --- a/app/assets/javascripts/user.js.coffee +++ b/app/assets/javascripts/user.js.coffee @@ -1,7 +1,7 @@ class @User constructor: -> $('.profile-groups-avatars').tooltip("placement": "top") - ProjectsList.init() + new ProjectsList() $('.hide-project-limit-message').on 'click', (e) -> path = '/' diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c189f498951..48b1f95acb9 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -277,9 +277,9 @@ class ApplicationController < ActionController::Base } end - def view_to_html_string(partial, locals = nil) + def view_to_html_string(partial, locals = {}) render_to_string( - partial: partial, + partial, locals: locals, layout: false, formats: [:html] diff --git a/app/controllers/dashboard/projects_controller.rb b/app/controllers/dashboard/projects_controller.rb index 2f56228ff75..cd3a25866af 100644 --- a/app/controllers/dashboard/projects_controller.rb +++ b/app/controllers/dashboard/projects_controller.rb @@ -24,7 +24,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController end format.json do render json: { - html: view_to_html_string("dashboard/projects/projects", locals: { projects: @projects }) + html: view_to_html_string("dashboard/projects/_projects", locals: { projects: @projects }) } end end @@ -34,6 +34,13 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController @projects = current_user.starred_projects @projects = @projects.includes(:namespace, :forked_from_project, :tags) @projects = @projects.sort(@sort = params[:sort]) + + terms = params['filter_projects'] + + if terms.present? + @projects = @projects.search(terms) + end + @projects = @projects.page(params[:page]).per(PER_PAGE) @last_push = current_user.recent_push @groups = [] @@ -42,8 +49,9 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController format.html format.json do - load_events - pager_json("events/_events", @events.count) + render json: { + html: view_to_html_string("dashboard/projects/projects", locals: { projects: @projects }) + } end end end diff --git a/app/controllers/explore/projects_controller.rb b/app/controllers/explore/projects_controller.rb index 2689bf4f1ec..a5aeaed66c5 100644 --- a/app/controllers/explore/projects_controller.rb +++ b/app/controllers/explore/projects_controller.rb @@ -11,14 +11,14 @@ class Explore::ProjectsController < Explore::ApplicationController end def trending - @projects = TrendingProjectsFinder.new.execute(current_user) - @projects = @projects.non_archived - @projects = @projects.page(params[:page]).per(PER_PAGE) + @trending_projects = TrendingProjectsFinder.new.execute(current_user) + @trending_projects = @trending_projects.non_archived + @trending_projects = @trending_projects.page(params[:page]).per(PER_PAGE) end def starred - @projects = ProjectsFinder.new.execute(current_user) - @projects = @projects.reorder('star_count DESC') - @projects = @projects.page(params[:page]).per(PER_PAGE) + @starred_projects = ProjectsFinder.new.execute(current_user) + @starred_projects = @starred_projects.reorder('star_count DESC') + @starred_projects = @starred_projects.page(params[:page]).per(PER_PAGE) end end diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index ad6b3eae932..90475c17c17 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -41,6 +41,7 @@ class GroupsController < Groups::ApplicationController def show @last_push = current_user.recent_push if current_user @projects = @projects.includes(:namespace) + @projects = @projects.page(params[:page]).per(PER_PAGE) respond_to do |format| format.html diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 280228dbcc0..6055b606086 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -4,8 +4,9 @@ class UsersController < ApplicationController def show @contributed_projects = contributed_projects.joined(@user).reject(&:forked?) - + @projects = PersonalProjectsFinder.new(@user).execute(current_user) + @projects = @projects.page(params[:page]).per(PER_PAGE) @groups = @user.groups.order_id_desc diff --git a/app/models/event.rb b/app/models/event.rb index 4be23a1cf72..9a0bbf50f8b 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -49,7 +49,7 @@ class Event < ActiveRecord::Base scope :code_push, -> { where(action: PUSHED) } scope :in_projects, ->(projects) do - where(project_id: projects.select(:id).reorder(nil)).recent + where(project_id: projects.map(&:id)).recent end scope :with_associations, -> { includes(project: :namespace) } diff --git a/app/views/dashboard/_projects_head.html.haml b/app/views/dashboard/_projects_head.html.haml index ab2da1824c5..911f57f69e4 100644 --- a/app/views/dashboard/_projects_head.html.haml +++ b/app/views/dashboard/_projects_head.html.haml @@ -13,9 +13,9 @@ Explore Projects .nav-controls - = form_tag '', method: :get, class: 'project-list-form', id: 'project-list-form' do |f| + = form_tag request.original_url, method: :get, class: 'project-filter-form', id: 'project-filter-form' do |f| .append-right-10.hidden-xs.hidden-sm - = search_field_tag :filter_projects, params[:filter_projects], placeholder: 'Filter by name...', class: 'projects-list-filter form-control search-text-input', spellcheck: false, id: 'projects-list-filter' + = search_field_tag :filter_projects, params[:filter_projects], placeholder: 'Filter by name...', class: 'project-filter-form-field form-control search-text-input', spellcheck: false, id: 'project-filter-form-field' - if current_user.can_create_project? = link_to new_project_path, class: 'btn btn-new' do = icon('plus') diff --git a/app/views/dashboard/projects/_projects.html.haml b/app/views/dashboard/projects/_projects.html.haml index c08247cd9ac..933a3edd0f0 100644 --- a/app/views/dashboard/projects/_projects.html.haml +++ b/app/views/dashboard/projects/_projects.html.haml @@ -1,6 +1,6 @@ .projects-list-holder - = render 'shared/projects/list', ci: true + = render 'shared/projects/list', projects: @projects, ci: true :javascript - ProjectsList.init() + Dashboard.init() diff --git a/app/views/explore/projects/_projects.html.haml b/app/views/explore/projects/_projects.html.haml index b64a4918761..669079e9521 100644 --- a/app/views/explore/projects/_projects.html.haml +++ b/app/views/explore/projects/_projects.html.haml @@ -1,6 +1,6 @@ -- if @projects.any? +- if projects.any? .public-projects - = render 'shared/projects/list' + = render 'shared/projects/list', projects: projects - else .nothing-here-block No such projects diff --git a/app/views/explore/projects/starred.html.haml b/app/views/explore/projects/starred.html.haml index 0bdd0a57fe6..8450a1394c0 100644 --- a/app/views/explore/projects/starred.html.haml +++ b/app/views/explore/projects/starred.html.haml @@ -7,5 +7,5 @@ = render 'explore/head' = render 'explore/projects/nav' -= render 'projects', projects: @projects -= paginate @projects, theme: 'gitlab' += render 'projects', projects: @starred_projects += paginate @projects, theme: 'gitlab' if @projects diff --git a/app/views/explore/projects/trending.html.haml b/app/views/explore/projects/trending.html.haml index ec461755103..adcda810061 100644 --- a/app/views/explore/projects/trending.html.haml +++ b/app/views/explore/projects/trending.html.haml @@ -7,4 +7,4 @@ = render 'explore/head' = render 'explore/projects/nav' -= render 'projects', projects: @projects += render 'projects', projects: @trending_projects diff --git a/app/views/projects/show.atom.builder b/app/views/projects/show.atom.builder index 2468509242a..9b3d3f069d9 100644 --- a/app/views/projects/show.atom.builder +++ b/app/views/projects/show.atom.builder @@ -4,7 +4,7 @@ xml.feed "xmlns" => "http://www.w3.org/2005/Atom", "xmlns:media" => "http://sear xml.link href: namespace_project_url(@project.namespace, @project, format: :atom, private_token: current_user.try(:private_token)), rel: "self", type: "application/atom+xml" xml.link href: namespace_project_url(@project.namespace, @project), rel: "alternate", type: "text/html" xml.id namespace_project_url(@project.namespace, @project) - xml.updated @events[0].updated_at.xmlschema if @events[0? + xml.updated @events[0].updated_at.xmlschema if @events[0] @events.each do |event| event_to_atom(xml, event) diff --git a/app/views/shared/projects/_list.html.haml b/app/views/shared/projects/_list.html.haml index 80795063f6f..83188e58135 100644 --- a/app/views/shared/projects/_list.html.haml +++ b/app/views/shared/projects/_list.html.haml @@ -8,20 +8,22 @@ - show_last_commit_as_description = false unless local_assigns[:show_last_commit_as_description] == true %ul.projects-list - - if @projects.any? - - @projects.each_with_index do |project, i| + - if projects.any? + - projects.each_with_index do |project, i| - css_class = (i >= projects_limit) ? 'hide' : nil = render "shared/projects/project", project: project, skip_namespace: skip_namespace, avatar: avatar, stars: stars, css_class: css_class, ci: ci, use_creator_avatar: use_creator_avatar, forks: forks, show_last_commit_as_description: show_last_commit_as_description - - if @projects.size > projects_limit + - if projects.size > projects_limit %li.bottom.center .light - #{projects_limit} of #{pluralize(@projects.count, 'project')} displayed. + #{projects_limit} of #{pluralize(projects.count, 'project')} displayed. = link_to '#', class: 'js-expand' do Show all - = paginate @projects, theme: "gitlab" + = paginate projects, theme: "gitlab" if !projects.kind_of?(Array) - else %h3 No projects found - %p.slead Try searching for a different project. + +:javascript + new ProjectsList(); |