Skip to content

Commit

Permalink
[webui] Faster incident display
Browse files Browse the repository at this point in the history
  • Loading branch information
saschpe committed Jan 10, 2012
1 parent b33b606 commit 781c5b9
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 101 deletions.
43 changes: 10 additions & 33 deletions src/webui/app/controllers/project_controller.rb
Expand Up @@ -24,7 +24,6 @@ class NoChangesError < Exception; end
before_filter :require_login, :only => [:save_new, :toggle_watch, :delete, :new]
before_filter :require_available_architectures, :only => [:add_repository, :add_repository_from_default_list,
:edit_repository, :update_target]
before_filter :require_maintenance_incidents, :only => [:show, :maintenance_incidents]
prepend_before_filter :lockout_spiders, :only => [:requests]

def index
Expand Down Expand Up @@ -274,6 +273,7 @@ def show
end if @packages

@nr_releasetargets = 0
@open_maintenance_incidents = @project.maintenance_incidents('open')
@project.each_repository do |repo|
@nr_releasetargets += 1 if repo.has_element?('releasetarget')
end
Expand Down Expand Up @@ -1366,7 +1366,15 @@ def remove_maintained_project
end

def maintenance_incidents
#TODO: This method won't scale long!
@incidents = @project.maintenance_incidents(params[:type] || 'open')
end

def list_incidents
if @spider_bot || !request.xhr?
render :text => 'no ajax', :status => 400 and return
end
incidents = @project.maintenance_incidents(params[:type] || 'open')
render :partial => 'shared/incidents', :locals => { :incidents => incidents }
end

private
Expand Down Expand Up @@ -1426,37 +1434,6 @@ def require_project
#TODO: Prepare incident-related data
end

def require_maintenance_incidents
@maintenance_incidents, @open_maintenance_incidents = [], 0
return if @spider_bot
Collection.find(:what => "project", :predicate => "starts-with(@name,'#{params[:project]}:') and @kind='maintenance_incident'").each do |project|
has_releasetarget, has_trigger_maintenance = false, false
project.each_repository do |repo|
if repo.has_element?('releasetarget')
has_releasetarget = true
has_trigger_maintenance = repo.releasetarget.has_attribute?('trigger') && repo.releasetarget.trigger == 'maintenance'
end
end
state = ""
if has_releasetarget
if has_trigger_maintenance
@open_maintenance_incidents += 1
state = "open"
else
state = "closed"
end
end
begin
#TODO: We may want to have a PatchInfo model (with API support):
patchinfo = ActiveXML::Base.new(frontend.get_source(:project => project.value(:name), :package => 'patchinfo', :filename => '_patchinfo'))
rescue ActiveXML::Transport::Error, ActiveXML::ParseError => e
patchinfo = nil
end
packages = find_cached(Package, :all, :project => project.value(:name), :expires_in => 30.seconds)
@maintenance_incidents << {:project => project, :patchinfo => patchinfo, :state => state, :packages => packages}
end
end

def load_requests
if @spider_bot
@requests = [] and return
Expand Down
96 changes: 30 additions & 66 deletions src/webui/app/views/project/maintenance_incidents.html.erb
Expand Up @@ -7,72 +7,36 @@

<%= javascript_include_tag 'jquery.tablesorter' %>
<% content_for :head_javascript do %>
function updateIncidentDisplay() {
$('#spinner').show();
$.ajax({
url: '<%= url_for(:controller => :project, :action => :list_incidents, :project => @project) %>',
data: {
'type': $('#incident_type_select')[0].value,
},
success: function(data) {
$('#incident_display').html(data);
/*if (data.indexOf('No incidents') == -1) {
incident_count = $('#incident_table tbody').children().length;
$('#incident_count').html('(' + incident_count.toString() + ')');
} else {
$('#incident_count').html('');
}*/
$('#spinner').hide();
}
});
}
<% end %>
<% content_for :ready_function do %>
<%= "updateIncidentDisplay();" unless defined?(@incidents) %>
<% end %>

<p>
Display
<%= select_tag("incident_type_select", options_for_select(['all', 'open', 'closed'], 'open')) %>
maintenance incidents:
<%= image_tag('ajax-loader.gif', :id => "spinner", :class => "hidden") %>
Display <%= select_tag("incident_type_select", options_for_select(['open', 'closed'], 'open'), :onchange => "updateIncidentDisplay();") %>
maintenance incidents: <%= image_tag('ajax-loader.gif', :id => "spinner", :class => "hidden") %>
</p>

<% if @maintenance_incidents.blank? %>
<p>No incidents.</p>
<% else %>
<table cellspacing="1" id="incident_table" class="tablesorter" style="width: 95%">
<thead>
<tr>
<th style="width: 1%">Incident</th>
<th style="width: 40%">Summary</th>
<th style="width: 1%">Category</th>
<th style="width: 1%">Rating</th>
<th style="width: 1%">Patchinfo</th>
<th style="width: 1%">Packages</th>
</tr>
</thead>
<tbody>
<% @maintenance_incidents.each do |incident| %>
<% project, patchinfo, packages = incident[:project], incident[:patchinfo], incident[:packages] %>
<tr class="incident <%= incident[:state] %>_incident">
<td><%= link_to(short_incident_name(@project, project), :action => 'show', :project => project.name) %></td>
<td><%= project.title %></td>
<% if patchinfo %>
<td><%= patchinfo.category %> </td>
<td><%= raw colored_rating(patchinfo.rating) %></td>
<td><%= link_to(image_tag('icons/accept.png', :alt => 'View patchinfo', :title => 'View patchinfo'), :controller => 'patchinfo', :action => 'show', :project => project.name, :package => 'patchinfo', :file => '_patchinfo') %></td>
<% else %>
<td>-</td>
<td>-</td>
<td><%= link_to(image_tag('icons/exclamation.png', :alt => 'Create patchinfo', :title => 'Create patchinfo'), :controller => 'patchinfo', :action => 'new_patchinfo', :project => project.name, :package => 'patchinfo') %></td>
<% end %>
<td>
<% if packages && packages.count > "1" %>
<%= link_to(image_tag('icons/accept.png', :alt => "Has #{packages.count} packages", :title => "Has #{packages.count} packages"), :action => 'packages', :project => project.name) %>
<% else %>
<%= link_to(image_tag('icons/exclamation.png', :alt => 'Has no packages', :title => 'Has no packages'), :action => 'show', :project => project.name) %>
<% end %>
<% buildresult_css_id = "incident_#{valid_xml_id(project.name)}_results" %>
<%# link_to(image_tag('icons/information.png', :alt => 'Build results', :title => 'Build results', :id => buildresult_css_id), :action => :show, :project => project) %>
<!-- <% javascript_tag do %>
setup_buildresult_tooltip('<%= buildresult_css_id %>', '<%= url_for :controller => 'project', :action => 'buildresult', :project => project %>');
<% end %> -->
</td>
</tr>
<% end %>
</tbody>
</table>
<% javascript_tag do %>
$('#incident_table').tablesorter({ widgets: ['zebra'], sortList: [[0,0]], headers: {5: {sorter: false}} });

function updateIncidentDisplay() {
incident_state = $('#incident_type_select option:selected').attr('value');
if (incident_state == "all") {
$('.incident').show();
} else {
$('.incident').hide();
$('.' + incident_state + '_incident').show();
}
}
$('#incident_type_select').change(updateIncidentDisplay);
updateIncidentDisplay();
<% end %>
<% end %>
<div id="incident_display">
<%= render(:partial => 'shared/incidents', :locals => { :incidents => @incidents }) unless not defined?(@incidents) %>
</div>
4 changes: 2 additions & 2 deletions src/webui/app/views/project/show.html.erb
Expand Up @@ -14,12 +14,12 @@
<ul class="clean_list">
<% if @is_maintenance_project %>
<li>
<% if @open_maintenance_incidents == 0 %>
<% if @open_maintenance_incidents %>
<%= image_tag 'icons/accept.png' %>
<% else %>
<%= image_tag 'icons/exclamation.png' %>
<% end %>
<%= @open_maintenance_incidents %> <%= link_to "open incident#{@open_maintenance_incidents == 1 ? '' : 's'}", :action => 'maintenance_incidents', :project => @project %>
<%= @open_maintenance_incidents.length %> <%= link_to "open incident#{@open_maintenance_incidents.length == 1 ? '' : 's'}", :action => 'maintenance_incidents', :project => @project %>
</li>
<li>
<% if @maintained_projects.length == 0 %>
Expand Down
49 changes: 49 additions & 0 deletions src/webui/app/views/shared/_incidents.html.erb
@@ -0,0 +1,49 @@
<% incident_table_id ||= 'incident_table' %>
<% if incidents.blank? %>
<p>No incidents.</p>
<% else %>
<table cellspacing="1" id="<%= incident_table_id %>" class="tablesorter" style="width: 95%">
<thead>
<tr>
<th style="width: 1%">Incident</th>
<th style="width: 40%">Summary</th>
<th style="width: 1%">Category</th>
<th style="width: 1%">Rating</th>
<th style="width: 1%">Patchinfo</th>
<th style="width: 1%">Packages</th>
</tr>
</thead>
<tbody>
<% incidents.each do |incident| %>
<% patchinfo, packages = incident.patchinfo(), incident.packages() %>
<tr>
<td><%= link_to(short_incident_name(@project, incident), :action => 'show', :project => incident.value('name')) %></td>
<td><%= incident.value('title') %></td>
<% if patchinfo %>
<td><%= patchinfo.category %> </td>
<td><%= raw colored_rating(patchinfo.rating) %></td>
<td><%= link_to(image_tag('icons/accept.png', :alt => 'View patchinfo', :title => 'View patchinfo'), :controller => 'patchinfo', :action => 'show', :project => incident.value('name'), :package => 'patchinfo', :file => '_patchinfo') %></td>
<% else %>
<td>-</td>
<td>-</td>
<td><%= link_to(image_tag('icons/exclamation.png', :alt => 'Create patchinfo', :title => 'Create patchinfo'), :controller => 'patchinfo', :action => 'new_patchinfo', :project => incident.value('name'), :package => 'patchinfo') %></td>
<% end %>
<td>
<% if packages.length > 1 %>
<%= link_to(image_tag('icons/accept.png', :alt => "Has #{packages.length} packages", :title => "Has #{packages.count} packages"), :action => 'packages', :project => incident.value('name')) %>
<% else %>
<%= link_to(image_tag('icons/exclamation.png', :alt => 'Has no packages', :title => 'Has no packages'), :action => 'show', :project => incident.value('name')) %>
<% end %>
<% buildresult_css_id = "incident_#{valid_xml_id(incident.value('name'))}_results" %>
<%# link_to(image_tag('icons/information.png', :alt => 'Build results', :title => 'Build results', :id => buildresult_css_id), :action => :show, :project => project) %>
<!-- <% javascript_tag do %>
setup_buildresult_tooltip('<%= buildresult_css_id %>', '<%= url_for :controller => 'project', :action => 'buildresult', :project => incident.value('name') %>');
<% end %> -->
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>

0 comments on commit 781c5b9

Please sign in to comment.