Skip to content

Commit

Permalink
Move pulse related code to it's own controller
Browse files Browse the repository at this point in the history
I tried to use Rails resourceful routing, but that woulde create
different routes than we had before: 'project/:project/pulse' instead
of 'project/pulse/:project'.
  • Loading branch information
bgeuken authored and hennevogel committed Dec 6, 2018
1 parent 3c15e4b commit 0e3b6cd
Show file tree
Hide file tree
Showing 21 changed files with 144 additions and 119 deletions.
32 changes: 0 additions & 32 deletions src/api/app/controllers/webui/project_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,38 +95,6 @@ def subprojects
@siblings = @project.siblingprojects
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
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
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

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,47 +45,46 @@
There have been no requests send to this project.
.row
.col
%h3
%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 }
%h3

%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 }
%h3
Collaboration

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

%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 }
%h3#pulse-requests

%h5#pulse-requests
Requests
- if @requests.count > 30
%small.text-muted
( last 30,
= link_to(project_requests_path(@project)) do
view all
)
%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)
= 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
@@ -1,9 +1,9 @@
- if @comments.any?
And
- people = @comments.group(:user_name).count
%b
= pluralize(people.count, 'person')
= pluralize(people.count, 'person')
added
%b
= link_to('#pulse-collaboration') do
= pluralize(@comments.count, 'comment')
in here.
- else
Expand Down
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,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)

Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
.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
= link_to(update_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
= link_to(update_pulse_path(@project, range: 'month'), remote: true, type: :json, class: 'dropdown-item') do
One Month
.row
.col#pulse
Expand All @@ -33,11 +33,11 @@

:javascript
$.ajax({
url: "#{update_project_pulse_path(@project)}",
type:"get",
url: "#{update_pulse_path(@project)}",
type: "get",
});
$( ".dropdown-item" ).click(function() {
$( "#pulse" ).html('<div class="fa-3x"><i class="fas fa-spinner fa-spin"></i></div>')
$(".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')
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
$('#range-header').html("<%= escape_javascript(pulse_period(@range)) %>");
$('#range-text').html("<%= @range.titleize %>");
$('#pulse').html("<%= escape_javascript render partial: 'pulse_list' %>");
$('#pulse').html("<%= escape_javascript render partial: 'pulse_list' %>");
7 changes: 5 additions & 2 deletions src/api/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,6 @@ def self.public_or_about_path?(request)
post 'project/remove_maintained_project/:project' => :remove_maintained_project, constraints: cons
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 All @@ -314,6 +312,11 @@ def self.public_or_about_path?(request)
get 'project/rebuild_time_png/:project/:key' => :rebuild_time_png, constraints: cons, as: :project_rebuild_time_png
end

controller 'webui/projects/pulse' do
get 'project/pulse/:project' => :show, constraints: cons, as: 'project_pulse'
get 'project/pulse/:project/update_pulse' => :update_pulse, constraints: cons, as: 'update_pulse'
end

resources :projects, only: [], param: :name do
resource :public_key, controller: 'webui/projects/public_key', only: [:show], constraints: cons do
member do
Expand Down

0 comments on commit 0e3b6cd

Please sign in to comment.