summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-09-24 07:32:29 +0000
committerDouwe Maan <douwe@gitlab.com>2015-09-24 07:32:29 +0000
commita58c6e9a9561ffbb3d16a3a9a45bd90a34735b50 (patch)
tree337d55fce3c4a66ced6215d05cab3cb09f15c48e
parent68cb24c4393b2c4e40700ba05039ed1412adcd64 (diff)
parent4bc1e040d4b7d73bd7afb3dbb95c87983eef2b04 (diff)
downloadgitlab-ce-a58c6e9a9561ffbb3d16a3a9a45bd90a34735b50.tar.gz
Merge branch 'cleanup-ci-dashboard' into 'master'
Cleanup ci dashboard Part of #2594. Based on !1403 * remove rendering GitLab projects with not enabled CI on CI dashboard * remove enabling CI for projects from CI dashboard (now its done by simply pushing `.gitlab-ci.yml`) * simplify the projects query for CI dashboard See merge request !1405
-rw-r--r--app/assets/javascripts/ci/pager.js.coffee42
-rw-r--r--app/controllers/ci/projects_controller.rb45
-rw-r--r--app/models/ci/project.rb1
-rw-r--r--app/views/ci/projects/_project.html.haml61
-rw-r--r--app/views/ci/projects/_search.html.haml7
-rw-r--r--app/views/ci/projects/index.html.haml39
-rw-r--r--lib/ci/project_list_builder.rb21
-rw-r--r--spec/controllers/ci/projects_controller_spec.rb50
8 files changed, 47 insertions, 219 deletions
diff --git a/app/assets/javascripts/ci/pager.js.coffee b/app/assets/javascripts/ci/pager.js.coffee
deleted file mode 100644
index 226fbd654ab..00000000000
--- a/app/assets/javascripts/ci/pager.js.coffee
+++ /dev/null
@@ -1,42 +0,0 @@
-@CiPager =
- init: (@url, @limit = 0, preload, @disable = false) ->
- if preload
- @offset = 0
- @getItems()
- else
- @offset = @limit
- @initLoadMore()
-
- getItems: ->
- $(".loading").show()
- $.ajax
- type: "GET"
- url: @url
- data: "limit=" + @limit + "&offset=" + @offset
- complete: =>
- $(".loading").hide()
- success: (data) =>
- CiPager.append(data.count, data.html)
- dataType: "json"
-
- append: (count, html) ->
- if count > 1
- $(".content-list").append html
- if count == @limit
- @offset += count
- else
- @disable = true
-
- initLoadMore: ->
- $(document).unbind('scroll')
- $(document).endlessScroll
- bottomPixels: 400
- fireDelay: 1000
- fireOnce: true
- ceaseFire: ->
- CiPager.disable
-
- callback: (i) =>
- unless $(".loading").is(':visible')
- $(".loading").show()
- CiPager.getItems()
diff --git a/app/controllers/ci/projects_controller.rb b/app/controllers/ci/projects_controller.rb
index 40b61edb0a9..250a2e79313 100644
--- a/app/controllers/ci/projects_controller.rb
+++ b/app/controllers/ci/projects_controller.rb
@@ -1,12 +1,10 @@
module Ci
class ProjectsController < Ci::ApplicationController
- PROJECTS_BATCH = 100
-
before_action :authenticate_user!, except: [:build, :badge, :index, :show]
before_action :authenticate_public_page!, only: :show
- before_action :project, only: [:build, :integration, :show, :badge, :edit, :update, :destroy, :toggle_shared_runners, :dumped_yaml]
- before_action :authorize_access_project!, except: [:build, :badge, :index, :show, :new, :create, :disabled]
- before_action :authorize_manage_project!, only: [:edit, :integration, :update, :destroy, :toggle_shared_runners, :dumped_yaml]
+ before_action :project, only: [:build, :show, :badge, :edit, :update, :destroy, :toggle_shared_runners, :dumped_yaml]
+ before_action :authorize_access_project!, except: [:build, :badge, :index, :show, :new, :disabled]
+ before_action :authorize_manage_project!, only: [:edit, :update, :destroy, :toggle_shared_runners, :dumped_yaml]
before_action :authenticate_token!, only: [:build]
before_action :no_cache, only: [:badge]
skip_before_action :check_enable_flag!, only: [:disabled]
@@ -18,23 +16,15 @@ module Ci
end
def index
- @limit, @offset = (params[:limit] || PROJECTS_BATCH).to_i, (params[:offset] || 0).to_i
- @page = @offset == 0 ? 1 : (@offset / @limit + 1)
+ @projects = Ci::Project.all
if current_user
- @projects = ProjectListBuilder.new.execute(current_user, params[:search])
-
- @projects = @projects.page(@page).per(@limit)
-
- @total_count = @projects.size
+ @projects = @projects.where(gitlab_id: current_user.authorized_projects.pluck(:id))
end
- respond_to do |format|
- format.json do
- pager_json("ci/projects/index", @total_count)
- end
- format.html
- end
+ @projects = @projects.search(params[:search]) if params[:search].present?
+ @projects = @projects.includes(:last_commit).order('ci_commits.created_at DESC')
+ @projects = @projects.page(params[:page]).per(40)
end
def show
@@ -45,25 +35,6 @@ module Ci
@commits = @commits.page(params[:page]).per(20)
end
- def integration
- end
-
- def create
- project_data = OpenStruct.new(JSON.parse(params["project"]))
-
- unless can?(current_user, :admin_project, ::Project.find(project_data.id))
- return redirect_to ci_root_path, alert: 'You have to have at least master role to enable CI for this project'
- end
-
- @project = Ci::CreateProjectService.new.execute(current_user, project_data)
-
- if @project.persisted?
- redirect_to ci_project_path(@project, show_guide: true), notice: 'Project was successfully created.'
- else
- redirect_to :back, alert: 'Cannot save project'
- end
- end
-
def edit
end
diff --git a/app/models/ci/project.rb b/app/models/ci/project.rb
index 37fbcc287bb..a52e28615f7 100644
--- a/app/models/ci/project.rb
+++ b/app/models/ci/project.rb
@@ -41,6 +41,7 @@ module Ci
has_many :events, dependent: :destroy, class_name: 'Ci::Event'
has_many :variables, dependent: :destroy, class_name: 'Ci::Variable'
has_many :triggers, dependent: :destroy, class_name: 'Ci::Trigger'
+ has_one :last_commit, -> { order 'ci_commits.created_at DESC' }, class_name: 'Ci::Commit'
# Project services
has_many :services, dependent: :destroy, class_name: 'Ci::Service'
diff --git a/app/views/ci/projects/_project.html.haml b/app/views/ci/projects/_project.html.haml
index 844b6677b3d..58022de9bc1 100644
--- a/app/views/ci/projects/_project.html.haml
+++ b/app/views/ci/projects/_project.html.haml
@@ -1,37 +1,24 @@
-- if project.gitlab_ci_project
- - ci_project = project.gitlab_ci_project
- - last_commit = ci_project.last_commit
- %tr
- %td
- = link_to [:ci, ci_project] do
- = ci_project.name
- %td
- - if last_commit
- = ci_status_with_icon(last_commit.status)
- = commit_link(last_commit)
- &middot;
- - if ci_project.last_commit_date
- = time_ago_in_words ci_project.last_commit_date
- ago
- - else
- No builds yet
- %td
- - if ci_project.public
- %i.fa.fa-globe
- Public
- - else
- %i.fa.fa-lock
- Private
- %td
- = ci_project.commits.count
-- else
- %tr.light
- %td
- = project.name_with_namespace
- %td
- %small Not added to CI
- %td
- %td
- = form_tag ci_projects_path do
- = hidden_field_tag :project, project.to_json(methods: [:name_with_namespace, :path_with_namespace, :ssh_url_to_repo])
- = submit_tag 'Add project to CI', class: 'btn btn-default btn-sm'
+- last_commit = project.last_commit
+%tr
+ %td
+ = link_to [:ci, project] do
+ = project.name
+ %td
+ - if last_commit
+ = ci_status_with_icon(last_commit.status)
+ = commit_link(last_commit)
+ &middot;
+ - if project.last_commit_date
+ = time_ago_in_words project.last_commit_date
+ ago
+ - else
+ No builds yet
+ %td
+ - if project.public
+ %i.fa.fa-globe
+ Public
+ - else
+ %i.fa.fa-lock
+ Private
+ %td
+ = project.commits.count
diff --git a/app/views/ci/projects/_search.html.haml b/app/views/ci/projects/_search.html.haml
index 4ab43a403f7..a956ed4c0bc 100644
--- a/app/views/ci/projects/_search.html.haml
+++ b/app/views/ci/projects/_search.html.haml
@@ -1,11 +1,6 @@
.search
- = form_tag "#", method: :get, class: 'ci-search-form' do |f|
+ = form_tag ci_root_path, method: :get, class: 'ci-search-form' do |f|
.input-group
= search_field_tag "search", params[:search], placeholder: "Search", class: "search-input form-control"
.input-group-addon
%i.fa.fa-search
-
-:coffeescript
- $('.ci-search-form').submit ->
- CiPager.init "#{ci_projects_path}" + "?search=" + query, #{Ci::ProjectsController::PROJECTS_BATCH}, false
- false
diff --git a/app/views/ci/projects/index.html.haml b/app/views/ci/projects/index.html.haml
index 2b618d61f79..046095a3c12 100644
--- a/app/views/ci/projects/index.html.haml
+++ b/app/views/ci/projects/index.html.haml
@@ -1,30 +1,17 @@
- if current_user
- - if @offset > 0
- = render @projects
- - else
- .gray-content-block.top-block
- = render "search"
- .projects
- .gray-content-block.clearfix.light.second-block
- .pull-left.fetch-status
- - if params[:search].present?
- by keyword: "#{params[:search]}",
- #{@total_count} projects
-
- .wide-table-holder
- %table.table.projects-table.content-list
- %thead
- %tr
- %th Project Name
- %th Last commit
- %th Access
- %th Commits
-
- = render @projects
- %p.text-center.hide.loading
- %i.fa.fa-refresh.fa-spin
- :coffeescript
- CiPager.init "#{ci_projects_path}", #{Ci::ProjectsController::PROJECTS_BATCH}, false
+ .gray-content-block.top-block
+ = render "search"
+ .projects
+ .wide-table-holder
+ %table.table.projects-table.content-list
+ %thead
+ %tr
+ %th Project Name
+ %th Last commit
+ %th Access
+ %th Commits
+ = render @projects
+ = paginate @projects, theme: 'gitlab'
- else
= render 'public'
diff --git a/lib/ci/project_list_builder.rb b/lib/ci/project_list_builder.rb
deleted file mode 100644
index da26f9a9f47..00000000000
--- a/lib/ci/project_list_builder.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-module Ci
- class ProjectListBuilder
- def execute(current_user, search = nil)
- projects = current_user.authorized_projects
- projects = projects.search(search) if search
-
- projects.
- joins("LEFT JOIN ci_projects ON projects.id = ci_projects.gitlab_id
- LEFT JOIN #{last_commit_subquery} AS last_commit ON #{Ci::Project.table_name}.id = last_commit.project_id").
- reorder("ci_projects.id is NULL ASC,
- CASE WHEN last_commit.committed_at IS NULL THEN 1 ELSE 0 END,
- last_commit.committed_at DESC")
- end
-
- private
-
- def last_commit_subquery
- "(SELECT project_id, MAX(committed_at) committed_at FROM #{Ci::Commit.table_name} GROUP BY project_id)"
- end
- end
-end
diff --git a/spec/controllers/ci/projects_controller_spec.rb b/spec/controllers/ci/projects_controller_spec.rb
deleted file mode 100644
index 3e579f9a7d6..00000000000
--- a/spec/controllers/ci/projects_controller_spec.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-require "spec_helper"
-
-describe Ci::ProjectsController do
- before do
- @project = FactoryGirl.create :ci_project
- end
-
- describe "POST /projects" do
- let(:project_dump) { OpenStruct.new({ id: @project.gitlab_id }) }
-
- let(:user) do
- create(:user)
- end
-
- before do
- sign_in(user)
- end
-
- it "creates project" do
- post :create, { project: JSON.dump(project_dump.to_h) }.with_indifferent_access
-
- expect(response.code).to eq('302')
- expect(assigns(:project)).not_to be_a_new(Ci::Project)
- end
-
- it "shows error" do
- post :create, { project: JSON.dump(project_dump.to_h) }.with_indifferent_access
-
- expect(response.code).to eq('302')
- expect(flash[:alert]).to include("You have to have at least master role to enable CI for this project")
- end
- end
-
- describe "GET /gitlab" do
- let(:user) do
- create(:user)
- end
-
- before do
- sign_in(user)
- end
-
- it "searches projects" do
- xhr :get, :index, { search: "str", format: "json" }.with_indifferent_access
-
- expect(response).to be_success
- expect(response.code).to eq('200')
- end
- end
-end