Skip to content

Commit

Permalink
Merge pull request #6446 from hennevogel/feature/bootstrap-pulse
Browse files Browse the repository at this point in the history
Refactor and adopt pulse to bootstrap
  • Loading branch information
bgeuken committed Dec 6, 2018
2 parents cdba459 + 51030dd commit 39b6bea
Show file tree
Hide file tree
Showing 23 changed files with 370 additions and 8 deletions.
49 changes: 49 additions & 0 deletions src/api/app/assets/stylesheets/webui2/pulse.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#pulse {
.request-state-new {
color: $obs_blue;
}

.request-state-review {
color: $obs_yellow;
}

.request-state-accepted {
color: $obs_green;
}

.request-state-declined {
color: $red;
}

.request-state-revoked {
color: $dark;
}

.request-state-superseded {
color: $orange;
}

.progress-state-new {
background-color: $obs_blue;
}

.progress-state-review {
background-color: $obs_yellow;
}

.progress-state-accepted {
background-color: $obs_green;
}

.progress-state-declined {
background-color: $red;
}

.progress-state-revoked {
background-color: $dark;
}

.progress-state-superseded {
background-color: $orange;
}
}
1 change: 1 addition & 0 deletions src/api/app/assets/stylesheets/webui2/webui2.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
@import 'project-package-show-grid';
@import 'user';
@import 'watchlist';
@import 'pulse';

html {
overflow-y: scroll !important;
Expand Down
6 changes: 1 addition & 5 deletions src/api/app/controllers/webui/project_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Webui::ProjectController < Webui::WebuiController
:status, :maintained_projects,
:add_maintained_project_dialog, :add_maintained_project, :remove_maintained_project,
:maintenance_incidents, :unlock_dialog, :unlock, :save_person, :save_group, :remove_role,
:move_path, :save_prjconf, :clear_failed_comment, :pulse]
:move_path, :save_prjconf, :clear_failed_comment, :pulse, :update_pulse]

# TODO: check if get_by_name or set_by_name is used for save_prjconf
before_action :set_project_by_name, only: [:save_prjconf]
Expand Down Expand Up @@ -96,10 +96,6 @@ def subprojects
switch_to_webui2
end

def pulse
@pulse = @project.project_log_entries.page(params[:page])
end

def new
@project = Project.new
@project.name = params[:name] if params[:name]
Expand Down
39 changes: 39 additions & 0 deletions src/api/app/controllers/webui/projects/pulse_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module Webui
module Projects
class PulseController < WebuiController
before_action :set_project

def show
switch_to_webui2
@pulse = @project.project_log_entries.page(params[:page])
end

def update_pulse
@range = params[:range] == 'month' ? 'month' : 'week'
case @range
when 'month'
range = 1.month.ago..Date.tomorrow
else
range = 1.week.ago..Date.tomorrow
end

pulse = @project.project_log_entries.where(datetime: range).order(datetime: :asc)
@builds = pulse.where(event_type: [:build_fail, :build_success])
@new_packages = pulse.where(event_type: :create_package)
@deleted_packages = pulse.where(event_type: :delete_package)
@branches = pulse.where(event_type: :branch_command)
@commits = pulse.where(event_type: :commit)
@updates = pulse.where(event_type: :version_change)
@comments = pulse.where(event_type: [:comment_for_package, :comment_for_project])
@project_changes = pulse.where(event_type: [:update_project, :update_project_config])

@requests = @project.target_of_bs_requests.where(updated_at: range).order(updated_at: :desc)
# group by state, sort by value...
@requests_by_state = @requests.group(:state).count.sort_by { |_, v| -v }.to_h
# transpose to percentages
@requests_by_percentage = @requests_by_state.each_with_object({}) { |(k, v), hash| hash[k] = (v * 100.0 / @requests_by_state.values.sum).round.to_s } if @requests_by_state.any?
switch_to_webui2
end
end
end
end
10 changes: 10 additions & 0 deletions src/api/app/helpers/webui/project_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ module Webui::ProjectHelper

protected

def pulse_period(range)
start = if range == 'month'
Time.zone.today.prev_month.strftime('%B, %e')
else
Time.zone.today.prev_week.strftime('%B, %e')
end

"#{Time.zone.today.strftime('%B, %e')}#{start}"
end

def show_status_comment(comment, package, firstfail, comments_to_clear)
status_comment_html = ''.html_safe
if comment
Expand Down
13 changes: 13 additions & 0 deletions src/api/app/helpers/webui/request_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,26 @@ module Webui::RequestHelper
'superseded' => 'red'
}.freeze

STATE_BOOTSTRAP_ICONS = {
'new' => 'fa-code-branch',
'review' => 'fa-search',
'accepted' => 'fa-check',
'declined' => 'fa-hand-paper',
'revoked' => 'fa-eraser',
'superseded' => 'fa-plus'
}.freeze

AVAILABLE_TYPES = ['all', 'submit', 'delete', 'add_role', 'change_devel', 'maintenance_incident', 'maintenance_release'].freeze
AVAILABLE_STATES = ['new or review', 'new', 'review', 'accepted', 'declined', 'revoked', 'superseded'].freeze

def request_state_color(state)
STATE_COLORS[state.to_s] || ''
end

def request_bootstrap_icon(state)
STATE_BOOTSTRAP_ICONS[state.to_s] || ''
end

def new_or_update_request(row)
if row.target_package_id || row.request_type != 'submit'
row.request_type
Expand Down
3 changes: 2 additions & 1 deletion src/api/app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module Event
'Event::UpdateProjectConfig',
'Event::UpdateProject'].freeze
PACKAGE_CLASSES = ['Event::BranchCommand',
'Event::Build',
'Event::BuildSuccess',
'Event::BuildFail',
'Event::CommentForPackage',
'Event::Commit',
'Event::CreatePackage',
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/views/webui/project/_tabs.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<%= tab 'attribute', 'Attributes', :controller => '/webui/attribute', :project => @project, :action => 'index' %>
<%= tab 'meta', "Meta", :controller => '/webui/projects/meta', :action => :show %>
<%= tab 'status', 'Status', :controller => '/webui/project', :action => :status unless @project.defines_remote_instance? || @is_maintenance_project %>
<%= tab 'pulse', 'Pulse', :controller => '/webui/project', :action => :pulse %>
<%= tab 'pulse', 'Pulse', :controller => '/webui/projects/pulse', :action => :show %>
<% end -%>
</ul>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
.row
.col
%p
During this period
= render partial: 'pulse_list_commits', locals: { commits: commits, updates: updates }
%p
= render partial: 'pulse_list_builds', locals: { builds: builds }
= render partial: 'pulse_list_new', locals: { new_packages: new_packages, deleted_packages: deleted_packages }
= render partial: 'pulse_list_changes', locals: { project_changes: project_changes }
%p
= render partial: 'pulse_list_branches', locals: { branches: branches }
= render partial: 'pulse_list_comments', locals: { comments: comments }

.col
.card
.card-header
Requests
.card-body
- if requests.any?
.row
.col
.progress
-# haml-lint:disable InlineStyles
- requests_by_percentage.each do |state, percentage|
%div{ title: "#{requests_by_state[state]} #{state} requests",
class: "progress-bar progress-state-#{state}",
'aria-valuemax': '100', 'aria-valuemin': '0', 'aria-valuenow': percentage,
role: 'progressbar', style: "width: #{percentage}%" }
-# haml-lint:enable InlineStyles
%p
= link_to('#pulse-requests') do
= requests_by_state.values.sum
active requests
.row
- requests_by_state.each_key do |state|
.col.border.text-center
%p.fa-3x
%i{ class: "fa #{request_bootstrap_icon(state)} request-state-#{state}" }
%p
= pluralize(requests_by_state[state], 'request')
%br
in #{state}
- else
= link_to(project_requests_path(project)) do
There have been no requests send to this project.
.row
.col
%h5#pulse-packages
Package Changes
%hr
%ul.list-unstyled
- (commits + new_packages + deleted_packages + updates).sort_by(&:datetime).reverse_each do |log_entry|
%li
= render partial: 'pulse_list_entry', locals: { log_entry: log_entry, project: project }

%h5#pulse-project
Project Changes
%hr
%ul.list-unstyled
- project_changes.each do |log_entry|
%li
= render partial: 'pulse_list_entry', locals: { log_entry: log_entry, project: project }

%h5#pulse-builds
Builds
%hr
%ul.list-unstyled
- builds.each do |log_entry|
%li
= render partial: 'pulse_list_entry', locals: { log_entry: log_entry, project: project }

%h5#pulse-collaboration
Collaboration
%hr
%ul.list-unstyled
- (branches + comments).sort_by(&:datetime).reverse_each.each do |log_entry|
%li
= render partial: 'pulse_list_entry', locals: { log_entry: log_entry, project: project }

%h5#pulse-requests
Requests
- if requests.count > 30
%small.text-muted
( last 30,
= link_to(project_requests_path(project)) do
view all
)
%hr
= render partial: 'pulse_list_requests', locals: { requests: requests }

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- if branches.any?
People
= link_to('#pulse-collaboration') do
branched
#{pluralize(branches.count, 'package')}.
- else
No one branched packages from this project.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
- if builds.any?
- builds = builds.group(:event_type).count
There
-# 'has' does not have an inflection and the String
version of pluralize does not know about the plural
option like, that's why this is an if...
'has'.pluralize(builds.values.sum, plural: 'have')
= builds.values.sum > 1 ? 'have' : 'has'
been
= link_to('#pulse-builds') do
= builds.values.sum
builds
of which
%b.text-danger
= builds['build_fail']
failed
and
%b.text-success
= builds['build_success']
succeeded
\.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- if project_changes.any?
And the project setup has been changed
#{pluralize(project_changes.count, 'time')}.
- else
And no one touched the project setup.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- if comments.any?
And
- people = comments.group(:user_name).count
= pluralize(people.count, 'person')
added
= link_to('#pulse-collaboration') do
= pluralize(comments.count, 'comment')
in here.
- else
And no one commented in here.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
- if commits.any?
- people = commits.group(:user_name).count
%b
= pluralize(people.count, 'person')
added
= link_to('#pulse-packages') do
= pluralize(commits.count, 'commit')
to packages in this project.
- if updates.any?
Out of those commits,
= pluralize(updates.count, 'was a', plural: 'were')
version #{'update'.pluralize(updates.count)}.
- top_committer = commits.group(:user_name).count.max_by { |_, v| v }
%span{ title: "with #{pluralize(top_committer.second, 'commit')}" }
= top_committer.first
was the busiest commiter, hooray!
- else
no one committed anything.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
= log_entry.event_type.camelcase.prepend('Event::').constantize.description
- if log_entry.package_name
(#{link_to(log_entry.package_name, package_show_path(project.name, log_entry.package_name))})
- if log_entry.user_name
by #{link_to(log_entry.user_name, user_show_path(log_entry.user_name))}
= fuzzy_time(log_entry.datetime)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
There was
- if new_packages.any?
%b.text-success
= new_packages.count
= 'package'.pluralize(new_packages.count)
created
- else
no package created
- if deleted_packages.any?
and
%b.text-danger
= deleted_packages.count
deleted.
- else
\.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.row
- @requests.take(30).each do |request|
%dt.col-1
%span{ class: "badge progress-state-#{request.state} text-light" }
= request.state.to_s
%dd.col-11
= link_to(request_show_path(request.number)) do
= request.number
(#{truncate(request.description)})
- if request.request_history_elements.any?
= request.request_history_elements.last.description.gsub('Request', '')
- else
was created
by
= link_to(user_show_path(request.creator)) do
= request.creator
= fuzzy_time(request.updated_at)

0 comments on commit 39b6bea

Please sign in to comment.