Skip to content

Commit

Permalink
Merge pull request Katello#268 from bbuckingham/fork-group_events
Browse files Browse the repository at this point in the history
UI - systems and system groups - allow user to view action results from package and errata panes
  • Loading branch information
ehelms committed Jul 3, 2012
2 parents afae370 + a538005 commit 24c7a78
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 127 deletions.
6 changes: 3 additions & 3 deletions src/app/controllers/system_errata_controller.rb
Expand Up @@ -67,15 +67,15 @@ def install
task = @system.install_errata(errata_ids)

notice _("Errata scheduled for install.")
render :text => task.uuid
render :text => task.id
rescue Exception => error
errors error
render :text => error, :status => :bad_request
end

def status
if params[:uuid]
statuses = @system.tasks.where(:uuid => params[:uuid], :task_type => [:errata_install])
if params[:id]
statuses = @system.tasks.where('task_statuses.id' => params[:id], :task_type => [:errata_install])
else
statuses = @system.tasks.where(:task_type => [:errata_install], :state => [:waiting, :running])
end
Expand Down
6 changes: 3 additions & 3 deletions src/app/controllers/system_group_errata_controller.rb
Expand Up @@ -62,16 +62,16 @@ def install
job = @group.install_errata(errata_ids)

notice _("Errata scheduled for install.")
render :text => job.pulp_id
render :text => job.id
rescue Exception => error
errors error
render :text => error, :status => :bad_request
end

def status
if params[:uuid]
if params[:id]
jobs = @group.refreshed_jobs.joins(:task_statuses).where(
'jobs.pulp_id' => params[:uuid], 'task_statuses.task_type' => [:errata_install])
'jobs.id' => params[:id], 'task_statuses.task_type' => [:errata_install])
else
jobs = @group.refreshed_jobs.joins(:task_statuses).where(
'task_statuses.task_type' => [:errata_install], 'task_statuses.state' => [:waiting, :running])
Expand Down
19 changes: 13 additions & 6 deletions src/app/controllers/system_group_packages_controller.rb
Expand Up @@ -72,7 +72,9 @@ def add
render :text => '' and return
end

render :partial => 'system_groups/packages/items', :locals => {:editable => @group.systems_editable?, :job => job, :include_tr_shading => false}
render :partial => 'system_groups/packages/items', :locals => {:editable => @group.systems_editable?,
:group_id => @group.id, :job => job,
:include_tr_shading => false}
end

def remove
Expand Down Expand Up @@ -102,7 +104,9 @@ def remove
render :text => '' and return
end

render :partial => 'system_groups/packages/items', :locals => {:editable => @group.systems_editable?, :job => job, :include_tr_shading => false}
render :partial => 'system_groups/packages/items', :locals => {:editable => @group.systems_editable?,
:group_id => @group.id, :job => job,
:include_tr_shading => false}
end

def update
Expand Down Expand Up @@ -132,18 +136,21 @@ def update
render :text => '' and return
end

render :partial => 'system_groups/packages/items', :locals => {:editable => @group.systems_editable?, :job => job, :include_tr_shading => false}
render :partial => 'system_groups/packages/items', :locals => {:editable => @group.systems_editable?,
:group_id => @group.id, :job => job,
:include_tr_shading => false}
end

def status
# retrieve the status for the actions initiated by the client
response = []
jobs = @group.refreshed_jobs.where('jobs.pulp_id' => params[:id])
jobs = @group.refreshed_jobs.where('jobs.id' => params[:id])
jobs.each do |job|
status_html = render_to_string(:template => 'system_groups/packages/_status.html.haml', :layout => false,
:locals => {:id => job.pulp_id, :state => job.state, :status_message => job.status_message})
:locals => {:group_id => @group.id, :id => job.id, :state => job.state,
:status_message => job.status_message})

response << {:id => job.pulp_id, :status_html => status_html}
response << {:id => job.id, :status_html => status_html}
end

render :json => response
Expand Down
8 changes: 4 additions & 4 deletions src/app/controllers/system_packages_controller.rb
Expand Up @@ -62,7 +62,7 @@ def add
render :text => '' and return
end

render :text => task.uuid
render :text => task.id
end

def remove
Expand Down Expand Up @@ -99,7 +99,7 @@ def remove
render :text => '' and return
end

render :text => task.uuid
render :text => task.id
end

def update
Expand All @@ -118,7 +118,7 @@ def update
{:s => @system['name'], :p => params[:package]}
end

render :text => task.uuid
render :text => task.id
end

def packages
Expand Down Expand Up @@ -193,7 +193,7 @@ def more_packages

def status
# retrieve the status for the package actions initiated by the client
statuses = @system.tasks.where(:uuid => params[:uuid],
statuses = @system.tasks.where(:id => params[:id],
:task_type => [:package_install, :package_update, :package_remove,
:package_group_install, :package_group_remove])
render :json => statuses
Expand Down
4 changes: 4 additions & 0 deletions src/app/views/system_groups/errata/_index.html.haml
@@ -1,3 +1,5 @@
= javascript :system_events

= javascript do
-if editable
:plain
Expand Down Expand Up @@ -29,6 +31,8 @@
#{_("Applied")}
= content_for :content do
%input.events{:type => "hidden", 'data-url' => status_system_group_events_path(@group.id)}

#errata_container{ "data-parent_id" => @group.id }
%table.filter_table.ajaxScroll
%thead
Expand Down
5 changes: 4 additions & 1 deletion src/app/views/system_groups/packages/_index.html.haml
@@ -1,3 +1,5 @@
= javascript :system_events

= javascript do
= render :partial => 'common/package_actions_i18n'

Expand All @@ -16,6 +18,7 @@
= render :partial => "system_groups/tupane_header"

= content_for :content do
%input.events{:type => "hidden", 'data-url' => status_system_group_events_path(@group.id)}

#packages_container{ "data-parent_id" => @group.id }
= form_tag system_group_packages_path(@group.id), :id => "system_content_action_form", :method => "post", :remote => true do
Expand Down Expand Up @@ -58,5 +61,5 @@
%a
#{_("Name")}
%tbody
= render :partial => 'system_groups/packages/items', :locals => {:editable => editable, :include_tr_shading => true}, :collection => jobs, :as => :job
= render :partial => 'system_groups/packages/items', :locals => {:editable => editable, :include_tr_shading => true, :group_id => @group.id}, :collection => jobs, :as => :job
4 changes: 2 additions & 2 deletions src/app/views/system_groups/packages/_items.html.haml
Expand Up @@ -13,11 +13,11 @@
%tr.package{:class => "#{shading}"}
%td{'data-name' => "#{name}"}
#{name}
= render :partial => 'system_groups/packages/status', :locals => {:id => job.pulp_id, :state => state, :status_message => status_message}
= render :partial => 'system_groups/packages/status', :locals => {:group_id => group_id, :id => job.id, :state => state, :status_message => status_message}

- unless task.parameters[:groups].blank?
- task.parameters[:groups].each do |name|
%tr.group{:class => "#{shading}"}
%td{'data-name' => "#{name}"}
#{name}
= render :partial => 'system_groups/packages/status', :locals => {:id => job.pulp_id, :state => state, :status_message => status_message}
= render :partial => 'system_groups/packages/status', :locals => {:group_id => group_id, :id => job.id, :state => state, :status_message => status_message}
3 changes: 2 additions & 1 deletion src/app/views/system_groups/packages/_status.html.haml
@@ -1,4 +1,5 @@
%td.fr.status{'data-pending-action-id' => (id if state == :running)}
- if state == :running
= image_tag("embed/icons/spinner.gif")
= status_message
%a.event_status.subpanel_element{"data-url"=>system_group_event_path(group_id, id)}
= status_message
6 changes: 3 additions & 3 deletions src/app/views/system_packages/_package_items.html.haml
Expand Up @@ -8,7 +8,7 @@
- unless t.parameters.nil? or t.parameters[:packages].nil?
- t.parameters[:packages].each do |pkg_name|

%tr{:class => row_shading + ' content_package', 'data-uuid' => t.uuid}
%tr{:class => row_shading + ' content_package', 'data-pending-action-id' => t.id}
%td
%td.package_name
#{pkg_name}
Expand All @@ -23,7 +23,7 @@
- unless t.parameters.nil? or t.parameters[:groups].nil?
- t.parameters[:groups].each do |group_name|

%tr{:class => row_shading + ' content_group', 'data-uuid' => t.uuid}
%tr{:class => row_shading + ' content_group', 'data-pending-action-id' => t.id}
%td
%td.package_name
#{group_name}
Expand All @@ -42,4 +42,4 @@
#{p.nvrea}
%td.package_action_status
-#%td
-#TODO: installed date
-#TODO: installed date
74 changes: 47 additions & 27 deletions src/public/javascripts/system_errata.js
Expand Up @@ -19,6 +19,7 @@ KT.system.errata = function() {
load_more = undefined,
task_list = {},
actions_updater,
parent_id = undefined, // e.g. system id, system group id
items_url = undefined,
install_url = undefined,
status_url = undefined,
Expand All @@ -33,18 +34,18 @@ KT.system.errata = function() {
// This component is shared by the systems and system groups pages; however, some of the behavior is
// different depending on the page. For example, the URLs to interact with the server.
errata_for = page;
var id = errata_container.data('parent_id');
parent_id = errata_container.data('parent_id');
if (page === 'system') {
items_url = KT.routes.items_system_errata_path(id);
install_url = KT.routes.install_system_errata_path(id);
status_url = KT.routes.status_system_errata_path(id);
items_url = KT.routes.items_system_errata_path(parent_id);
install_url = KT.routes.install_system_errata_path(parent_id);
status_url = KT.routes.status_system_errata_path(parent_id);
update_function = update_status_for_system;
KT.tipsy.custom.tooltip($('.tipsy-icon.errata-info'));
} else {
// errata_for === 'system_group'
items_url = KT.routes.items_system_group_errata_path(id);
install_url = KT.routes.install_system_group_errata_path(id);
status_url = KT.routes.status_system_group_errata_path(id);
items_url = KT.routes.items_system_group_errata_path(parent_id);
install_url = KT.routes.install_system_group_errata_path(parent_id);
status_url = KT.routes.status_system_group_errata_path(parent_id);
update_function = update_status_for_group;
KT.tipsy.custom.tooltip($('.tipsy-icon.systems, .tipsy-icon.errata-info'));
}
Expand Down Expand Up @@ -73,7 +74,7 @@ KT.system.errata = function() {
actions_updater = $.PeriodicalUpdater(status_url, {
method: 'get',
type: 'json',
data: function() {return {uuid: Object.keys(task_list)};},
data: function() {return {id: Object.keys(task_list)};},
global: false,
minTimeout: timeout,
maxTimeout: timeout
Expand Down Expand Up @@ -143,22 +144,31 @@ KT.system.errata = function() {
actions_updater.restart();
}
task_list[data] = errata_ids;
if(errata_for === 'system') {
set_status(errata_ids, 'installing', undefined);
} else {
set_status(errata_ids, 'installing', KT.routes.system_group_event_path(parent_id, data));
}
});
},
update_status_for_system = function(data){
var i = 0, length = data.length,
task;
var i = 0, length = data.length, task, url = undefined;

for(i; i < length; i += 1){
task = data[i];
url = KT.routes.system_event_path(parent_id, task.id);

if( task['state'] === 'finished' ){
set_status(task_list[task['uuid']], 'finished');
delete task_list[task['uuid']];
set_status(task_list[task['id']], 'finished', url);
delete task_list[task['id']];
} else if( task['state'] === 'running' ){
if( !task_list.hasOwnProperty(task['uuid']) ){
task_list[task['uuid']] = task['parameters']['errata_ids'];
set_status(task['parameters']['errata_ids'], 'installing');
if( !task_list.hasOwnProperty(task['id']) ){
task_list[task['id']] = task['parameters']['errata_ids'];
set_status(task['parameters']['errata_ids'], 'installing', url);
}
} else if( task['state'] === 'error' ){
set_status(task_list[task['id']], 'failed', url);
delete task_list[task['id']];
}
}

Expand All @@ -167,11 +177,13 @@ KT.system.errata = function() {
}
},
update_status_for_group = function(data){
var i = 0, num_jobs = data.length, job, num_tasks, task;
var i = 0, num_jobs = data.length, job, num_tasks, task, url = undefined;

for(i; i < num_jobs; i += 1){
job = data[i];
num_tasks = job.tasks.length;
url = KT.routes.system_group_event_path(parent_id, job.id);

var j = 0, running = 0, error = 0;
for(j; j < num_tasks; j += 1){
task = job.tasks[j];
Expand All @@ -183,18 +195,18 @@ KT.system.errata = function() {
}
if (running > 0) {
// still have a task running... status should remain installing
if( !task_list.hasOwnProperty(job.pulp_id) ){
task_list[job.pulp_id] = job['parameters']['errata_ids'];
set_status(job['parameters']['errata_ids'], 'installing');
if( !task_list.hasOwnProperty(job.id) ){
task_list[job.id] = job['parameters']['errata_ids'];
set_status(task_list[job.id], 'installing', url);
}
} else if (error > 0) {
// no tasks are still running, but at least 1 error was encountered
set_status(task_list[job.pulp_id], 'failed');
delete task_list[job.pulp_id];
set_status(task_list[job.id], 'failed', url);
delete task_list[job.id];
} else {
// looks like all tasks completed...
set_status(task_list[job.pulp_id], 'finished');
delete task_list[job.pulp_id];
set_status(task_list[job.id], 'finished', url);
delete task_list[job.id];
}
}

Expand Down Expand Up @@ -236,7 +248,7 @@ KT.system.errata = function() {
$('#list-spinner').hide();
}
},
set_status = function(errata_ids, status){
set_status = function(errata_ids, status, url){
var rows = get_rows(errata_ids),
errata_row, i, length;

Expand All @@ -246,18 +258,26 @@ KT.system.errata = function() {
errata_row = rows[i];

if( status === 'installing' ){
errata_row.find('.errata_status_text').html(i18n.installing);
errata_row.find('.errata_status_text').html(get_status_block(i18n.installing, url));
errata_row.find('img').show();
} else if( status === 'finished' ){
errata_row.find('img').hide();
errata_row.find('.errata_status_text').html(i18n.install_finished);
errata_row.find('.errata_status_text').html(get_status_block(i18n.install_finished, url));
} else if ( status === 'failed' ) {
errata_row.find('img').hide();
errata_row.find('.errata_status_text').html(i18n.install_error)
errata_row.find('.errata_status_text').html(get_status_block(i18n.install_error, url));
}
errata_row.find('.errata_status').show();
}
},
get_status_block = function(status, url){
if(url === undefined) {
return status;
} else {
var html = '<a data-url="' + url + '" class="subpanel_element">' + status + '</a>';
return html;
}
},
get_rows = function(errata_ids){
var i = 0,
length = errata_ids.length,
Expand Down
6 changes: 3 additions & 3 deletions src/public/javascripts/system_events.js
Expand Up @@ -128,9 +128,6 @@ KT.events = function() {
}

updateLoadedSummary();
if(($('.event_name[data-pending-task-id]').length > 0) || ($('.event_name[data-pending-job-id]').length > 0)) {
startUpdater();
}

var search_button = $('#event_filter_button'),
search_field = $('#event_search_filter'),
Expand Down Expand Up @@ -159,6 +156,9 @@ KT.events = function() {
});
});
}
if(($('.event_name[data-pending-task-id]').length > 0) || ($('.event_name[data-pending-job-id]').length > 0)) {
startUpdater();
}
},
updateLoadedSummary = function() {
var more_size = page_size;
Expand Down

0 comments on commit 24c7a78

Please sign in to comment.