Skip to content

Commit

Permalink
Refactor and adopt pulse to bootstrap
Browse files Browse the repository at this point in the history
This was some basic functionality. A bit extended now to give
some more information about what is happening in a Project.
  • Loading branch information
hennevogel committed Dec 6, 2018
1 parent 7919c5f commit cef8f37
Show file tree
Hide file tree
Showing 17 changed files with 318 additions and 1 deletion.
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
30 changes: 29 additions & 1 deletion 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,9 +96,37 @@ def subprojects
end

def pulse
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(&:last).reverse.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

def new
@project = Project.new
@project.name = params[:name] if params[:name]
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
91 changes: 91 additions & 0 deletions src/api/app/views/webui2/webui/project/_pulse_list.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
.row
.col
%p
During this period
= render partial: 'pulse_list_commits'
%p
= render partial: 'pulse_list_builds'
= render partial: 'pulse_list_new'
= render partial: 'pulse_list_changes'
%p
= render partial: 'pulse_list_branches'
= render partial: 'pulse_list_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
%h3
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 }
%h3
Project Changes
%hr
%ul.list-unstyled
- @project_changes.each do |log_entry|
%li
= render partial: 'pulse_list_entry', locals: { log_entry: log_entry }
%h3
Collaboration
%hr
%ul.list-unstyled
- @branches.each do |log_entry|
%li
= render partial: 'pulse_list_entry', locals: { log_entry: log_entry }
- @comments.each do |log_entry|
%li
= render partial: 'pulse_list_entry', locals: { log_entry: log_entry }
%h3#pulse-requests
Requests
%hr
.row
- @requests.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)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- if @branches.any?
Packages from this project have been
%b
branched
= pluralize(@branches.count, 'time')
- else
No one branched packages from this project.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
- if @builds.any?
- builds = @builds.group(:event_type).count
There
- # FIXME: 'has' does not have an inflection and
- # 'has'.pluralize(builds.values.sum, plural: 'have')
- # does not work...
- if builds.values.sum > 1
have
- else
has
been
%b
= 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?
- people = @comments.group(:user_name).count
%b
= pluralize(people.count, 'person')
added
%b
= 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,20 @@
- if @commits.any?
- people = @commits.group(:user_name).count
%b
= pluralize(people.count, 'person')
added
%b
= pluralize(@commits.count, 'commit')
to packages in this project.
- if @updates.any?
Out of those commits,
= pluralize(@updates.count, 'was a', plural: 'where')
version #{'update'.pluralize(@updates.count)}.
- top_committer = @commits.group(:user_name).count.max_by { |_, v| v }
= top_committer.first
was the busiest commiter with
%b
#{pluralize(top_committer.second, 'commit')}.
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)
15 changes: 15 additions & 0 deletions src/api/app/views/webui2/webui/project/_pulse_list_new.html.haml
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 @@
#{Time.zone.today.strftime('%B, %e')} – #{Time.zone.today.prev_month.strftime('%B, %e')}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#{Time.zone.today.strftime('%B, %e')} – #{Time.zone.today.prev_week.strftime('%B, %e')}
43 changes: 43 additions & 0 deletions src/api/app/views/webui2/webui/project/pulse.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
- @pagetitle = "Pulse for #{@project}"

.card
= render(partial: 'tabs', locals: { project: @project })

.card-body
.row
.col-8.mb-3
%h3#range-header
= render partial: 'range_month'
.col
.dropdown.float-right
%button.btn.btn-secondary.dropdown-toggle#period-dropdown{ 'aria-expanded': 'false',
'aria-haspopup': 'true',
'data-toggle': 'dropdown',
type: 'button' }
Period: One
%span#range-text
Week
.dropdown-menu{ 'aria-labelledby': 'dropdownMenuButton' }
%h6.dropdown-header
Period to display:
= link_to(update_project_pulse_path(@project), remote: true, type: :json, class: 'dropdown-item') do
One Week
= link_to(update_project_pulse_path(@project, range: 'month'), remote: true, type: :json, class: 'dropdown-item') do
One Month
.row
.col#pulse
.row
.col.text-center
%i.fas.fa-spinner.fa-spin.fa-3x


:javascript
$.ajax({
url: "#{update_project_pulse_path(@project)}",
type:"get",
});
$( ".dropdown-item" ).click(function() {
$( "#pulse" ).html('<div class="fa-3x"><i class="fas fa-spinner fa-spin"></i></div>')
// FIXME: No idea why this is needed, maybe remote links are not covered by bootstrap?
$('#period-dropdown').dropdown('toggle')
});
3 changes: 3 additions & 0 deletions src/api/app/views/webui2/webui/project/update_pulse.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$('#range-header').html("<%= escape_javascript render partial: "range_#{@range}" %>");
$('#range-text').html("<%= @range.titleize %>");
$('#pulse').html("<%= escape_javascript render partial: 'pulse_list' %>");
1 change: 1 addition & 0 deletions src/api/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ def self.public_or_about_path?(request)
get 'project/maintenance_incidents/:project' => :maintenance_incidents, constraints: cons, as: :project_maintenance_incidents
get 'project/list_incidents/:project' => :list_incidents, constraints: cons
get 'project/pulse/:project' => :pulse, constraints: cons, as: :project_pulse
get 'project/update_pulse/:project' => :update_pulse, constraints: cons, as: :update_project_pulse
get 'project/unlock_dialog' => :unlock_dialog
post 'project/unlock' => :unlock
end
Expand Down

0 comments on commit cef8f37

Please sign in to comment.