Skip to content

Commit

Permalink
Merge pull request #6265 from dmarcoux/show_staging_projects_on_stagi…
Browse files Browse the repository at this point in the history
…ng_workflow_page

Show staging projects on staging workflow page
  • Loading branch information
bgeuken committed Nov 19, 2018
2 parents 9cff063 + 2fcc4f1 commit 4fc35e0
Show file tree
Hide file tree
Showing 13 changed files with 255 additions and 58 deletions.
13 changes: 13 additions & 0 deletions src/api/app/assets/stylesheets/webui2/collapse-component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[data-toggle="collapse"] {
&[aria-expanded="false"] {
.collapser {
display: none;
}
}

&[aria-expanded="true"] {
.expander {
display: none;
}
}
}
91 changes: 86 additions & 5 deletions src/api/app/assets/stylesheets/webui2/staging-workflow.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,91 @@ ul .table-list-group-item {
background-color: transparent;
}

.collapse-link[aria-expanded="false"] .less{
display: none;
}
#staging-projects-datatable {
td {
span.badge {
font-size: inherit;
font-weight: inherit;
}

&.project {
> span.badge {
@extend .w-100;
}

span.badge {
&.state-unacceptable {
@extend .badge-dark;
}

&.state-acceptable {
@extend .badge-success;
}

&.state-testing {
@extend .badge-info;
}

&.state-building {
@extend .badge-warning;

span {
@extend .text-dark;
}
}

&.state-failed {
@extend .badge-danger;
}

&.state-review {
@extend .badge-secondary;
}

&.state-empty {
@extend .badge-light;
@extend .border;

span {
@extend .text-dark;
}
}
}
}

&.requests {
@extend .w-50;

a.request {
@extend .text-white;
padding: 0 0.125rem 0.25rem;

&:hover {
text-decoration: none;
}

span.badge {
&.state-ready {
@extend .badge-success;
}

&.state-review {
@extend .badge-warning;
}

.collapse-link[aria-expanded="true"] .more{
display: none;
&.state-obsolete {
@extend .badge-info;
}

&.state-untracked {
@extend .badge-dark;
}
}
}

a, div.collapse, div.collapsing {
float: left;
}
}
}
}
3 changes: 2 additions & 1 deletion src/api/app/assets/stylesheets/webui2/webui2.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@
@import 'diff';
@import 'package-show';
@import 'staging-workflow';
@import 'repositories';
@import 'collapse-component';

html {
overflow-y: scroll !important;
}
@import 'repositories';
2 changes: 2 additions & 0 deletions src/api/app/controllers/webui/staging/workflows_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def create

def show
@project = @staging_workflow.project
@staging_projects = @staging_workflow.staging_projects.includes(:staged_requests).reject { |project| project.overall_state == :empty }
@unassigned_requests = @staging_workflow.unassigned_requests.first(5)
@more_unassigned_requests = @staging_workflow.unassigned_requests.count - @unassigned_requests.size
@ready_requests = @staging_workflow.ready_requests.first(5)
Expand All @@ -44,6 +45,7 @@ def edit
authorize @staging_workflow

@project = @staging_workflow.project
@staging_projects = @staging_workflow.staging_projects.includes(:staged_requests)
end

def destroy
Expand Down
86 changes: 86 additions & 0 deletions src/api/app/helpers/webui/staging/workflow_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
module Webui::Staging::WorkflowHelper
def build_progress(staging_project)
final = to_build = 0

staging_project.building_repositories.each do |repository|
to_build += repository[:tobuild]
final += repository[:final]
end

total = to_build + final

return 100 if total == 0
# if we have building repositories, make sure we don't exceed 99
[final * 100 / total, 99].min
end

def review_progress(staging_project)
staged_requests_numbers = staging_project.staged_requests.pluck(:number)
total = Review.where(bs_request: staging_project.staged_requests).size
missing = staging_project.missing_reviews.count { |missing_review| staged_requests_numbers.include?(missing_review[:request]) }

100 - missing * 100 / total
end

def testing_progress(staging_project)
notdone = allchecks = 0

# Note: The status_reports are defined via a has many through relation. Since within the
# status report context the bs request relation is polymorphic, we have to call
# includes with the polymorphic name ('checkable').
staging_project.status_reports.includes(:checkable).each do |report|
notdone += report.checks.where(state: 'pending').size
allchecks += report.checks.size + report.missing_checks.size
end

return 100 if allchecks == 0
100 - notdone * 100 / allchecks
end

def progress(staging_project)
case staging_project.overall_state
when :building
link_to project_monitor_url(staging_project.name) do
"#{build_progress(staging_project)} %"
end
when :review
"#{review_progress(staging_project)} %"
when :testing
"#{testing_progress(staging_project)} %"
end
end

def requests(staging_project)
number_of_requests = staging_project.classified_requests.size

return 'None' if number_of_requests == 0

requests_visible_by_default = 10
requests_links = staging_project.classified_requests.map do |request|
css = 'ready'
css = 'review' if request[:missing_reviews].present?
css = 'obsolete' if request[:state].in?(BsRequest::OBSOLETE_STATES)

link_to(request_show_path(request[:number]), class: 'request') do
content_tag(:span, request[:package], class: "badge state-#{css}")
end
end

if number_of_requests <= requests_visible_by_default
return safe_join(requests_links)
end

output = safe_join(requests_links[0, requests_visible_by_default])

output += link_to('#', class: 'collapsed', 'data-toggle': 'collapse', href: ".collapse-#{staging_project.id}",
role: 'button', aria: { expanded: 'false', controls: "collapse-#{staging_project.id}" }) do
safe_join([
content_tag(:i, nil, class: 'fas fa-chevron-up collapser text-secondary ml-1 mr-1'),
content_tag(:i, nil, class: 'fas fa-chevron-down expander text-secondary ml-1 mr-1')
])
end
output + content_tag(:div, class: "collapse collapse-#{staging_project.id}") do
safe_join(requests_links[requests_visible_by_default..-1])
end
end
end
15 changes: 15 additions & 0 deletions src/api/app/models/staging/staging_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ def staging_identifier
name[/.*:Staging:(.*)/, 1]
end

def classified_requests
requests = (requests_to_review | staged_requests.includes(:reviews)).map do |request|
{
number: request.number,
state: request.state,
package: request.first_target_package,
request_type: request.bs_request_actions.first.type,
missing_reviews: missing_reviews.select { |review| review[:request] == request.number },
tracked: requests_to_review.include?(request)
}
end

requests.sort_by { |request| request[:package] }
end

def untracked_requests
requests_to_review - staged_requests
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
= project.name
%span.badge{ class: "state-#{staging_project.overall_state}" }
%span.badge.badge-light
-# TODO: Link to the staging project show page
= link_to(staging_project.staging_identifier, project_show_path(staging_project.staging_identifier))
%span
%br
= staging_project.overall_state
%br
= progress(staging_project)
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Placeholder for the content
= requests(staging_project)
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
:ruby
max_problems = 5
project_class = project.name.tr(':', '_')
project_class = staging_project.name.tr(':', '_')
item_project_class = 'hidden-item-' + project_class

- if project.problems.empty?
- if staging_project.problems.empty?
.text-center
%i.fas.fa-check-circle.fa-2x.text-success
- else
%ul.list-group.list-group-flush
= render partial: 'problems_item', locals: { project: project, index: 0...max_problems }
= render partial: 'problems_item', locals: { staging_project: staging_project, index: 0...max_problems }

- length = project.problems.length
- length = staging_project.problems.length
- if length > max_problems
%span.collapse{ 'id': item_project_class }
= render partial: 'problems_item', locals: { project: project, index: max_problems..-1 }
= render partial: 'problems_item', locals: { staging_project: staging_project, index: max_problems..-1 }

- number = length - max_problems
%li.list-group-item.table-list-group-item
%a.collapse-link{ 'data-toggle': 'collapse', href: "##{item_project_class}", 'aria-expanded': 'false' }
%span.more See #{number} more
%span.less See #{number} less
%a{ 'data-toggle': 'collapse', href: "##{item_project_class}", 'aria-expanded': 'false' }
%span.expander See #{number} more
%span.collapser See #{number} less
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- project.problems[index].each do |name, states|
- staging_project.problems[index].each do |name, states|
%li.list-group-item.table-list-group-item
= link_to("#{name}:", package_show_path(package: name, project: project))
= link_to("#{name}:", package_show_path(package: name, project: staging_project))
- states.each do |state, values|
= state
= surround '(', ')' do
Expand All @@ -12,5 +12,5 @@
- else
= link_to(value[:arch], package_live_build_log_path(package: name,
repository: value[:repository],
project: project,
project: staging_project,
arch: value[:arch]))
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
%table.table.table-striped.table-bordered.table-sm.dt-responsive.w-100#staging-projects-datatable
%thead
%tr.text-center
%th Staging Project
%th Requests
%th Problems
- if display_actions_column
%th Actions
%tbody
- staging_projects.each do |staging_project|
%tr
%td.project
= render partial: 'overall_state', locals: { staging_project: staging_project }
%td.requests
= render partial: 'packages_list', locals: { staging_project: staging_project }
%td
= render partial: 'problems', locals: { staging_project: staging_project }
- if display_actions_column
%td.text-center
= link_to('#', data: { toggle: 'modal', target: "#confirm-modal-#{staging_project.id}" }, title: "Delete #{staging_project}") do
%i.fas.fa-times-circle.text-danger

= render partial: 'delete_staging_project_modal', locals: { staging_workflow: staging_workflow, staging_project: staging_project }

- content_for :ready_function do
$('#staging-projects-datatable').DataTable({ responsive: true });
22 changes: 2 additions & 20 deletions src/api/app/views/webui2/webui/staging/workflows/edit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,8 @@
.card-body
%h3= @pagetitle

%table.table.table-striped.table-bordered.table-sm.dt-responsive.w-100
%thead
%tr.text-center
%th Staging Project
%th Requests
%th Actions

%tbody
- @staging_workflow.staging_projects.each do |staging_project|
%tr
%td
= render partial: 'overall_state', locals: { project: staging_project }
%td
= render partial: 'packages_list', locals: { project: staging_project }
%td.text-center
= link_to('#', data: { toggle: 'modal', target: "#confirm-modal-#{staging_project.id}" }, title: "Delete #{staging_project}") do
%i.fas.fa-times-circle.text-danger

= render partial: 'delete_staging_project_modal', locals: { staging_workflow: @staging_workflow, staging_project: staging_project }

= render(partial: 'staging_projects_table',
locals: { staging_workflow: @staging_workflow, staging_projects: @staging_projects, display_actions_column: true })

= link_to('#', class: 'nav-link', data: { toggle: 'modal', target: '#create-staging-projects-modal' }) do
%i.fas.fa-plus-circle.text-success
Expand Down
21 changes: 2 additions & 19 deletions src/api/app/views/webui2/webui/staging/workflows/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,8 @@

%hr

%table.table.table-striped.table-bordered.table-sm.dt-responsive.w-100#staging-projects-datatable
%thead
%tr.text-center
%th Project
%th Requests
%th Problems

%tbody
- @staging_workflow.staging_projects.each do |staging_project|
%tr
%td
= render partial: 'overall_state', locals: { project: staging_project }
%td
= render partial: 'packages_list', locals: { project: staging_project }
%td.broken-packages
= render partial: 'problems', locals: { project: staging_project }
= render(partial: 'staging_projects_table',
locals: { staging_workflow: @staging_workflow, staging_projects: @staging_projects, display_actions_column: false })

%ul.list-inline
%li.list-inline-item
Expand All @@ -43,6 +29,3 @@
ready_requests: @ready_requests, more_ready_requests: @more_ready_requests,
ignored_requests: @ignored_requests, more_ignored_requests: @more_ignored_requests,
project: @project }

- content_for :ready_function do
$('#staging-projects-datatable').DataTable({ responsive: true });

0 comments on commit 4fc35e0

Please sign in to comment.