Commit a58c6e9a authored by Douwe Maan's avatar Douwe Maan

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
parents 68cb24c4 4bc1e040
@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()
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
......
......@@ -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'
......
- if project.gitlab_ci_project
- ci_project = project.gitlab_ci_project
- last_commit = ci_project.last_commit
%tr
- last_commit = project.last_commit
%tr
%td
= link_to [:ci, ci_project] do
= ci_project.name
= link_to [:ci, project] do
= 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
- if project.last_commit_date
= time_ago_in_words project.last_commit_date
ago
- else
No builds yet
%td
- if ci_project.public
- if 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'
= project.commits.count
.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
- 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
......@@ -21,10 +12,6 @@
%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
= paginate @projects, theme: 'gitlab'
- else
= render 'public'
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
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment