Skip to content
This repository has been archived by the owner on Sep 18, 2018. It is now read-only.

Commit

Permalink
Merge pull request #18 from abenari/repo-show
Browse files Browse the repository at this point in the history
Add some ui elements
  • Loading branch information
ohadlevy committed Jul 29, 2013
2 parents 216b793 + 168bdf0 commit ca1c3e0
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 12 deletions.
9 changes: 8 additions & 1 deletion app/controllers/content/products_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Content
class ProductsController < ::ApplicationController
include Foreman::Controller::AutoCompleteSearch
before_filter :find_by_name, :only => %w{show edit update destroy}
before_filter :find_by_name, :only => %w{show edit update destroy sync}

def index
@products = Product.search_for(params[:search], :order => params[:order]).paginate(:page => params[:page])
Expand Down Expand Up @@ -31,6 +31,13 @@ def update
end
end

def sync
@product.sync
process_success(:success_msg => _("Successfully started sync for %s") % @product.name)
rescue => e
process_error(:error_msg => _("Failed to start sync for %s") % @product.name)
end

def destroy
if @product.destroy
process_success
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/content/providers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ class ProvidersController < ::ApplicationController
before_filter :find_by_name, :only => %w{show edit update destroy}

def index
@providers = Provider.search_for(params[:search], :order => params[:order]).paginate(:page => params[:page])
@providers = Provider.search_for(params[:search], :order => params[:order]).
paginate(:page => params[:page]).includes(:repositories)
end

def new
Expand Down
11 changes: 9 additions & 2 deletions app/controllers/content/repositories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ def update
end
end

def show
@details = @repository.retrieve_with_details
@sync_history = @repository.sync_history
rescue
redirect_back_or_to(edit_repository_path)
end

def destroy
if @repository.destroy
process_success
Expand All @@ -42,9 +49,9 @@ def destroy

def sync
@repository.sync
process_success(:success_msg => _("Successfully started sync for %s") % @repository.name)
process_success(:success_msg => _("Successfully started sync for %s") % @repository.to_label)
rescue => e
process_error(:error_msg => _("Failed to start sync for %s") % @repository.name)
process_error(:error_msg => _("Failed to start sync for %s") % @repository.to_label)
end
end
end
56 changes: 56 additions & 0 deletions app/helpers/content/repositories_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
module Content
module RepositoriesHelper

def sync_status repo
status = repo.sync_status
status = if status && status.first
status.first[:state]
else
details = repo.retrieve_with_details
details[:importers][0][:last_sync] if details && details[:importers] && details[:importers][0]
end
"#{time_ago_in_words(status)} ago" rescue status
rescue
'-'
end

def last_publish details
return '' unless details[:distributors] && details[:distributors].first && published = details[:distributors].first[:last_publish]
"#{time_ago_in_words published} ago" rescue ''
end

def last_sync details
return '' unless details[:importers] && details[:importers].first && synced = details[:importers].first[:last_sync]
"#{time_ago_in_words synced} ago" rescue ''
end

def sync_history_times history
return {} unless history && history.first && summary = history.first['summary']
return {} unless summary[:comps]
{
:comps => summary[:comps][:time_total_sec],
:errata => summary[:errata][:errata_time_total_sec],
:packages => summary[:packages][:time_total_sec]
}
end

def sync_history_metrics history
return {} unless history && last = history.first
{
:updated => last[:updated_count],
:removed => last[:removed_count],
:added => last[:added_count]
}
end

def sync_history_status history
return {} unless history && last = history.first
{
'result' => last[:result],
'message' => last[:error_message] || last['summary']['error'],
'completed' => ("#{time_ago_in_words(last[:completed])} ago" rescue '')
}
end

end
end
18 changes: 15 additions & 3 deletions app/models/content/orchestration/pulp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,22 @@ def sync
Runcible::Resources::Repository.sync(pulp_id)
end

def retrieve_with_details
return unless pulp? && pulp_id
initialize_pulp
Runcible::Resources::Repository.retrieve(pulp_id, {:details => true})
end

def sync_status
initialize_pulp if pulp?
status = Runcible::Extensions::Repository.sync_status(pulp_id) if pulp? && pulp_id
status.first ? status.first[:state] : ''
return unless pulp? && pulp_id
initialize_pulp
Runcible::Extensions::Repository.sync_status(pulp_id)
end

def sync_history
return unless pulp? && pulp_id
initialize_pulp
Runcible::Extensions::Repository.sync_history(pulp_id)
end

protected
Expand Down
5 changes: 5 additions & 0 deletions app/models/content/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ class Product < ActiveRecord::Base
validates :name, :presence => true
validates_with Validators::NameFormat, :attributes => :name
scoped_search :on => :name
scoped_search :in => :repositories, :on => :name, :rename => :repository, :complete_value => :true
scoped_search :in => :provider, :on => :name, :rename => :provider, :complete_value => :true

def sync
self.repositories.map{ |repo| repo.sync }
end
end
end
3 changes: 2 additions & 1 deletion app/models/content/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ class Repository < ActiveRecord::Base
:message => (_("Please select content type from one of the following: %s") % TYPES.join(', '))

scoped_search :on => [:name, :enabled], :complete_value => :true
scoped_search :in => :architectures, :on => :name, :rename => :architecture, :complete_value => :true
scoped_search :in => :architecture, :on => :name, :rename => :architecture, :complete_value => :true
scoped_search :in => :operatingsystems, :on => :name, :rename => :os, :complete_value => :true
scoped_search :in => :product, :on => :name, :rename => :product, :complete_value => :true

# architecture_id is nil for noarch repositories.
scope :for_host, lambda { |host| includes({ :product => :environments }).
Expand Down
7 changes: 6 additions & 1 deletion app/views/content/products/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@
<tr>
<th><%= sort :name, :as => s_("Name") %></th>
<th><%= _("Description") %></th>
<th><%= _("Repositories") %></th>
<th></th>
</tr>
<% @products.each do |product| %>
<tr>
<td><%= link_to_if_authorized(h(product.name), hash_for_edit_product_path(:id => product.name)) %></td>
<td><%= product.description %></td>
<td><%= link_to product.repositories.count, repositories_path(:search => "product=#{product.name}") %></td>
<td align="right">
<%= display_delete_if_authorized hash_for_product_path(:id => product.name), :confirm => "Delete #{product.name}?" %>
<%= action_buttons(
display_link_if_authorized(_("Synchronize"), hash_for_sync_product_path(product), :method => :put),
display_delete_if_authorized(hash_for_product_path(product), :confirm => "Delete #{product.name}?")
)%>
</td>
</tr>
<% end %>
Expand Down
7 changes: 4 additions & 3 deletions app/views/content/repositories/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@
<th><%= sort :name, :as => s_("Name") %></th>
<th><%= _("Product") %></th>
<th><%= _("Operating system") %></th>
<th><%= _("Sync status") %></th>
<th><%= _("Last sync status") %></th>
<th><%= _("Content type") %></th>
<th></th>
</tr>
<% @repositories.each do |repository| %>
<tr>
<td><%= link_to_if_authorized(h(repository.name), hash_for_edit_repository_path(repository)) %></td>
<td><%= link_to_if_authorized(h(repository.name), hash_for_repository_path(repository)) %></td>
<td><%= repository.product %></td>
<td><%= repository.operatingsystems.map(&:to_label).to_sentence %></td>
<td><%= repository.sync_status %></td>
<td><%= sync_status repository %></td>
<td><%= repository.content_type %></td>
<td align="right">
<%= action_buttons(
display_link_if_authorized(_("Edit"), hash_for_edit_repository_path(repository)),
display_link_if_authorized(_("Synchronize"), hash_for_sync_repository_path(repository), :method => :put),
display_delete_if_authorized(hash_for_repository_path(repository), :confirm => "Delete #{repository.name}?")
)%>
Expand Down
98 changes: 98 additions & 0 deletions app/views/content/repositories/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<% javascript 'charts' %>
<% title @repository.to_label %>
<%= title_actions(button_group(
link_to_if_authorized(_("Edit"), hash_for_edit_repository_path(@repository)),
link_to_if_authorized(_("Synchronize"), hash_for_sync_repository_path(@repository), :method => :put)
)) %>
<div class="row">
<div class="span12">
<table class="table table-bordered table-striped">
<tr>
<th><%= _('Repository details') %></th>
<th></th>
</tr>
<tr>
<td> <%= _("Name") %> </td>
<td> <%= @repository.to_label %> </td>
</tr>
<tr>
<td> <%= _("Description") %> </td>
<td> <%= @repository.description %> </td>
</tr>
<tr>
<td> <%= _("Feed") %> </td>
<td> <%= @repository.feed %> </td>
</tr>
<tr>
<td> <%= _("Content type") %> </td>
<td> <%= @repository.content_type %> </td>
</tr>
<tr>
<td> <%= _("Architecture") %> </td>
<td> <%= @repository.architecture %> </td>
</tr>
<tr>
<td> <%= _("Enabled") %> </td>
<td> <%= @repository.enabled %> </td>
</tr>
<tr>
<td> <%= _("Unprotected") %> </td>
<td> <%= @repository.unprotected %> </td>
</tr>
<tr>
<td> <%= _("Full path") %> </td>
<td> <%= @repository.full_path %> </td>
</tr>
</table>
</div>
</div>
<div class="row-fluid">
<div class="stats-well span4">
<h4 class="ca" ><%= _('Last Update Metrics') -%></h4>
<div style="margin-top:50px;padding-bottom: 40px;">
<%= flot_pie_chart("metrics" ,_("Last Update Metrics"), sync_history_times(@sync_history), :class => "statistics-pie small")%>
</div>
</div>
<div class="stats-well span4">
<h4 class="ca" ><%= _('Update Summary') -%></h4>
<%= flot_bar_chart("status" ,"", _("Number of packages"), sync_history_metrics(@sync_history), :class => "statistics-bar")%>
</div>

<div class="span4">
<table class="table table-bordered table-striped">
<tr>
<th><%= _('Repository Counters') %></th>
<th></th>
</tr>
<% @details[:content_unit_counts].each do |name, value| -%>
<tr>
<td> <%= name.humanize %> </td>
<td> <%= value %> </td>
</tr>
<% end -%>
<tr>
<td> <%= _("Last published") %> </td>
<td> <%= last_publish @details %> </td>
</tr>
<tr>
<td> <%= _("Last synchronized") %> </td>
<td> <%= last_sync @details %> </td>
</tr>
</table>
</div>
<div class="span4">
<table class="table table-bordered table-striped">
<tr>
<th><%= _('Last Sync') %></th>
<th></th>
</tr>
<% sync_history_status(@sync_history).each do |name, value| -%>
<tr>
<td> <%= name.humanize %> </td>
<td> <%= value %> </td>
</tr>
<% end -%>
</table>
</div>
</div>
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
collection do
get 'auto_complete_search'
end
member do
put :sync
end
end

resources :repositories do
Expand Down

0 comments on commit ca1c3e0

Please sign in to comment.