Skip to content

Commit

Permalink
Merge pull request #2302 from mzazrivec/get_rid_of_static_ui_lookup_i…
Browse files Browse the repository at this point in the history
…n_helpers

app helpers: get rid of ui_lookup() with static string argument
  • Loading branch information
martinpovolny authored Oct 6, 2017
2 parents 6a0ec02 + 9309a84 commit f389225
Show file tree
Hide file tree
Showing 30 changed files with 122 additions and 191 deletions.
6 changes: 2 additions & 4 deletions app/helpers/application_helper/button/collect_logs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ class ApplicationHelper::Button::CollectLogs < ApplicationHelper::Button::LogDep

def disabled?
@error_message = if !@record.started?
_('Cannot collect current logs unless the %{server} is started') %
{:server => ui_lookup(:table => 'miq_server')}
_('Cannot collect current logs unless the Server is started')
elsif @record.log_collection_active_recently?
_('Log collection is already in progress for this %{server}') %
{:server => ui_lookup(:table => 'miq_server')}
_('Log collection is already in progress for this Server')
elsif !@record.log_file_depot
_('Log collection requires the Log Depot settings to be configured')
end
Expand Down
3 changes: 1 addition & 2 deletions app/helpers/application_helper/button/iso_datastore_new.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
class ApplicationHelper::Button::IsoDatastoreNew < ApplicationHelper::Button::ButtonNewDiscover
def disabled?
if no_ems_without_iso_datastores?
@error_message = _('No %{providers} are available to create an ISO Datastore on') %
{:providers => ui_lookup(:tables => 'ext_management_system')}
@error_message = _('No Providers are available to create an ISO Datastore on')
end
@error_message.present?
end
Expand Down
3 changes: 1 addition & 2 deletions app/helpers/application_helper/button/storage_delete.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ class ApplicationHelper::Button::StorageDelete < ApplicationHelper::Button::Basi

def disabled?
unless @record.vms_and_templates.empty? && @record.hosts.empty?
@error_message = _('Only %{storage} without VMs and Hosts can be removed') %
{:storage => ui_lookup(:table => 'storage')}
@error_message = _('Only Datastore without VMs and Hosts can be removed')
end
@error_message.present?
end
Expand Down
3 changes: 1 addition & 2 deletions app/helpers/application_helper/button/storage_perf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ class ApplicationHelper::Button::StoragePerf < ApplicationHelper::Button::Basic

def disabled?
unless @record.has_perf_data?
@error_message = _('No Capacity & Utilization data has been collected for this %{storage}') %
{:storage => ui_lookup(:table => 'storage')}
@error_message = _('No Capacity & Utilization data has been collected for this Datastore')
end
@error_message.present?
end
Expand Down
6 changes: 1 addition & 5 deletions app/helpers/application_helper/button/volume_detach.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ def disabled?
if !@record.is_available?(:detach_volume)
@error_message = @record.is_available_now_error_message(:detach_volume)
elsif @record.number_of(:vms) == 0
@error_message = _("%{model} \"%{name}\" is not attached to any %{instances}") % {
:model => ui_lookup(:table => 'cloud_volume'),
:name => @record.name,
:instances => ui_lookup(:tables => 'vm_cloud')
}
@error_message = _("Cloud Volume \"%{name}\" is not attached to any Instances") % {:name => @record.name}
end
@error_message.present?
end
Expand Down
6 changes: 2 additions & 4 deletions app/helpers/application_helper/button/zone_collect_logs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ class ApplicationHelper::Button::ZoneCollectLogs < ApplicationHelper::Button::Lo

def disabled?
@error_message = if !@record.any_started_miq_servers?
_('Cannot collect current logs unless there are started %{servers} in the Zone') %
{:servers => ui_lookup(:tables => 'miq_servers')}
_('Cannot collect current logs unless there are started Servers in the Zone')
elsif !@record.log_file_depot
_('This Zone do not have Log Depot settings configured, collection not allowed')
elsif @record.log_collection_active_recently?
_('Log collection is already in progress for one or more %{servers} in this Zone') %
{:servers => ui_lookup(:tables => 'miq_servers')}
_('Log collection is already in progress for one or more Servers in this Zone')
end
@error_message.present?
end
Expand Down
5 changes: 2 additions & 3 deletions app/helpers/auth_key_pair_cloud_helper/textual_summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ def textual_fingerprint
end

def textual_vms
label = ui_lookup(:tables => "vm_cloud")
num = @record.number_of(:vms)
h = {:label => label, :icon => "pficon pficon-virtual-machine", :value => num}
h = {:label => _("Instances"), :icon => "pficon pficon-virtual-machine", :value => num}
if num > 0 && role_allows?(:feature => "vm_show_list")
h[:link] = url_for_only_path(:action => 'show', :id => @record, :display => 'instances')
h[:title] = _("Show all %{label}") % {:label => label}
h[:title] = _("Show all Instances")
end
h
end
Expand Down
10 changes: 4 additions & 6 deletions app/helpers/availability_zone_helper/textual_summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,21 @@ def textual_group_availability_zone_totals
#

def textual_cloud_volumes
label = ui_lookup(:tables => "cloud_volume")
num = @record.number_of(:cloud_volumes)
h = {:label => label, :icon => "pficon pficon-volume", :value => num}
h = {:label => _('Cloud Volumes'), :icon => "pficon pficon-volume", :value => num}
if num > 0 && role_allows?(:feature => "cloud_volume_show_list")
h[:link] = url_for_only_path(:action => 'show', :id => @record, :display => 'cloud_volumes')
h[:title] = _("Show all %{label}") % {:label => label}
h[:title] = _("Show all Cloud Volumes")
end
h
end

def textual_instances
label = ui_lookup(:tables => "vm_cloud")
num = @record.number_of(:vms)
h = {:label => label, :icon => "pficon pficon-virtual-machine", :value => num}
h = {:label => _('Instances'), :icon => "pficon pficon-virtual-machine", :value => num}
if num > 0 && role_allows?(:feature => "vm_show_list")
h[:link] = url_for_only_path(:action => 'show', :id => @record, :display => 'instances')
h[:title] = _("Show all %{label}") % {:label => label}
h[:title] = _("Show all Instances")
end
h
end
Expand Down
5 changes: 2 additions & 3 deletions app/helpers/cloud_network_helper/textual_summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ def textual_parent_ems_cloud
end

def textual_instances
label = ui_lookup(:tables => "vm_cloud")
num = @record.number_of(:vms)
h = {:label => label, :icon => "pficon pficon-virtual-machine", :value => num}
h = {:label => _('Instances'), :icon => "pficon pficon-virtual-machine", :value => num}
if num > 0 && role_allows?(:feature => "vm_show_list")
h[:link] = url_for_only_path(:action => 'show', :id => @record, :display => 'instances')
h[:title] = _("Show all %{label}") % {:label => label}
h[:title] = _('Show all Instances')
end
h
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,19 @@ def textual_ems

def textual_cloud_tenant
cloud_tenant = @record.cloud_tenant if @record.respond_to?(:cloud_tenant)
label = ui_lookup(:table => "cloud_tenant")
h = {:label => label, :icon => "pficon pficon-cloud-tenant", :value => (cloud_tenant.nil? ? "None" : cloud_tenant.name)}
h = {:label => _('Cloud Tenant'), :icon => "pficon pficon-cloud-tenant", :value => (cloud_tenant.nil? ? "None" : cloud_tenant.name)}
if cloud_tenant && role_allows?(:feature => "cloud_tenant_show")
h[:title] = _("Show this Cloud Object Store's parent %{parent}") % {:parent => label}
h[:title] = _("Show this Cloud Object Store's parent Cloud Tenant")
h[:link] = url_for_only_path(:controller => 'cloud_tenant', :action => 'show', :id => cloud_tenant)
end
h
end

def textual_cloud_object_store_objects
label = ui_lookup(:tables => "cloud_object_store_object")
num = @record.number_of(:cloud_object_store_objects)
h = {:label => label, :icon => "ff ff-cloud-object-store", :value => num}
h = {:label => _('Cloud Object Store Objects'), :icon => "ff ff-cloud-object-store", :value => num}
if num > 0 && role_allows?(:feature => "cloud_object_store_object_show_list")
h[:title] = _("Show this Cloud Object Store's child %{children}") % {:children => label}
h[:title] = _("Show this Cloud Object Store's child Cloud Object Store Objects")
h[:link] = url_for_only_path(:action => 'show', :id => @record, :display => 'cloud_object_store_objects')
end
h
Expand Down
10 changes: 4 additions & 6 deletions app/helpers/cloud_object_store_object_helper/textual_summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,23 @@ def textual_etag

def textual_cloud_tenant
cloud_tenant = @record.cloud_tenant if @record.respond_to?(:cloud_tenant)
label = ui_lookup(:table => "cloud_tenant")
h = {:label => label, :icon => "pficon pficon-cloud-tenant", :value => (cloud_tenant.nil? ? "None" : cloud_tenant.name)}
h = {:label => _('Cloud Tenant'), :icon => "pficon pficon-cloud-tenant", :value => (cloud_tenant.nil? ? "None" : cloud_tenant.name)}
if cloud_tenant && role_allows?(:feature => "cloud_tenant_show")
h[:title] = _("Show this Cloud Object's parent %{parent}") % {:parent => label}
h[:title] = _("Show this Cloud Object's parent Cloud Tenant")
h[:link] = url_for_only_path(:controller => 'cloud_tenant', :action => 'show', :id => cloud_tenant)
end
h
end

def textual_cloud_object_store_container
object_store_container = @record.cloud_object_store_container if @record.respond_to?(:cloud_object_store_container)
label = ui_lookup(:table => "cloud_object_store_container")
h = {
:label => label,
:label => _('Cloud Object Store Container'),
:icon => "ff ff-cloud-object-store",
:value => (object_store_container.nil? ? "None" : object_store_container.key)
}
if object_store_container && role_allows?(:feature => "cloud_object_store_container_show")
h[:title] = _("Show this Cloud Object's parent %{parent}") % {:parent => label}
h[:title] = _("Show this Cloud Object's parent Cloud Object Store Container")
h[:link] = url_for_only_path(:controller => 'cloud_object_store_container',
:action => 'show',
:id => object_store_container)
Expand Down
5 changes: 2 additions & 3 deletions app/helpers/cloud_subnet_helper/textual_summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,11 @@ def textual_parent_ems_cloud
end

def textual_instances
label = ui_lookup(:tables => "vm_cloud")
num = @record.number_of(:vms)
h = {:label => label, :icon => "pficon pficon-virtual-machine", :value => num}
h = {:label => _('Instances'), :icon => "pficon pficon-virtual-machine", :value => num}
if num > 0 && role_allows?(:feature => "vm_show_list")
h[:link] = url_for_only_path(:action => 'show', :id => @record, :display => 'instances')
h[:title] = _("Show all %{label}") % {:label => label}
h[:title] = _("Show all Instances")
end
h
end
Expand Down
15 changes: 6 additions & 9 deletions app/helpers/cloud_tenant_helper/textual_summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,21 @@ def textual_group_quotas
# Items
#
def textual_instances
label = ui_lookup(:tables => "vm_cloud")
num = @record.number_of(:vms)
h = {:label => label, :icon => "pficon pficon-virtual-machine", :value => num}
h = {:label => _('Instances'), :icon => "pficon pficon-virtual-machine", :value => num}
if num > 0 && role_allows?(:feature => "vm_show_list")
h[:link] = url_for_only_path(:action => 'show', :id => @record, :display => 'instances')
h[:title] = _("Show all %{label}") % {:label => label}
h[:title] = _("Show all Instances")
end
h
end

def textual_images
label = ui_lookup(:tables => "template_cloud")
num = @record.number_of(:miq_templates)
h = {:label => label, :icon => "pficon pficon-virtual-machine", :value => num}
h = {:label => _('Images'), :icon => "pficon pficon-virtual-machine", :value => num}
if num > 0 && role_allows?(:feature => "miq_template_show_list")
h[:link] = url_for_only_path(:action => 'show', :id => @record, :display => 'images')
h[:title] = _("Show all %{label}") % {:label => label}
h[:title] = _("Show all Images")
end
h
end
Expand Down Expand Up @@ -81,12 +79,11 @@ def textual_cloud_volume_snapshots
end

def textual_cloud_object_store_containers
label = ui_lookup(:tables => "cloud_object_store_container")
num = @record.number_of(:cloud_object_store_containers)
h = {:label => label, :icon => "ff ff-cloud-object-store", :value => num}
h = {:label => _('Cloud Object Store Containers'), :icon => "ff ff-cloud-object-store", :value => num}
if num > 0 && role_allows?(:feature => "cloud_object_store_container_show_list")
h[:link] = url_for_only_path(:action => 'show', :id => @record, :display => 'cloud_object_store_containers')
h[:title] = _("Show all %{models}") % {:models => label}
h[:title] = _("Show all Cloud Object Store Containers")
end
h
end
Expand Down
5 changes: 2 additions & 3 deletions app/helpers/cloud_volume_backup_helper/textual_summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ def textual_ems_storage

def textual_cloud_tenant
cloud_tenant = @record.try(:cloud_tenant)
label = ui_lookup(:table => "cloud_tenants")
h = {:label => label, :icon => "pficon pficon-cloud-tenant", :value => (cloud_tenant.try(:name) || _("None"))}
h = {:label => _('Cloud Tenants'), :icon => "pficon pficon-cloud-tenant", :value => (cloud_tenant.try(:name) || _("None"))}
if cloud_tenant && role_allows?(:feature => "cloud_tenant_show")
h[:title] = _("Show this Backup's %{parent}") % {:parent => label}
h[:title] = _("Show this Backup's Cloud Tenants")
h[:link] = url_for_only_path(:controller => 'cloud_tenant', :action => 'show', :id => cloud_tenant)
end
h
Expand Down
32 changes: 12 additions & 20 deletions app/helpers/cloud_volume_helper/textual_summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,75 +35,67 @@ def textual_ems

def textual_availability_zone
availability_zone = @record.availability_zone
label = ui_lookup(:table => "availability_zone")
h = {
:label => label,
:label => _('Availability Zone'),
:icon => "pficon pficon-zone",
:value => (availability_zone.nil? ? _("None") : availability_zone.name)
}
if availability_zone && role_allows?(:feature => "availability_zone_show")
h[:title] = _("Show this Volume's %{availability_zone}") % {:availability_zone => label}
h[:title] = _("Show this Volume's Availability Zone")
h[:link] = url_for_only_path(:controller => 'availability_zone', :action => 'show', :id => availability_zone)
end
h
end

def textual_base_snapshot
base_snapshot = @record.base_snapshot if @record.respond_to?(:base_snapshot)
label = ui_lookup(:table => "base_snapshot")
h = {
:label => label,
:label => _('Base Snapshot'),
:icon => "fa fa-camera",
:value => (base_snapshot.nil? ? _("None") : base_snapshot.name)
}
if base_snapshot && role_allows?(:feature => "cloud_volume_snapshot_show")
h[:title] = _("Show this Volume's %{parent}") % {:parent => label}
h[:title] = _("Show this Volume's Base Snapshot")
h[:link] = url_for_only_path(:controller => 'cloud_volume_snapshot', :action => 'show', :id => base_snapshot)
end
h
end

def textual_cloud_tenant
cloud_tenant = @record.cloud_tenant if @record.respond_to?(:cloud_tenant)
label = ui_lookup(:table => "cloud_tenants")
h = {:label => label, :icon => "pficon pficon-cloud-tenant", :value => (cloud_tenant.nil? ? _("None") : cloud_tenant.name)}
h = {:label => _('Cloud Tenants'), :icon => "pficon pficon-cloud-tenant", :value => (cloud_tenant.nil? ? _("None") : cloud_tenant.name)}
if cloud_tenant && role_allows?(:feature => "cloud_tenant_show")
h[:title] = _("Show this Volume's %{cloud_tenant}") % {:cloud_tenant => label}
h[:title] = _("Show this Volume's Cloud Tenants")
h[:link] = url_for_only_path(:controller => 'cloud_tenant', :action => 'show', :id => cloud_tenant)
end
h
end

def textual_cloud_volume_snapshots
label = ui_lookup(:tables => "cloud_volume_snapshots")
num = @record.number_of(:cloud_volume_snapshots)
h = {:label => label, :icon => "fa fa-camera", :value => num}
h = {:label => _('Cloud Volume Snapshots'), :icon => "fa fa-camera", :value => num}
if num > 0 && role_allows?(:feature => "cloud_volume_snapshot_show_list")
label = ui_lookup(:tables => "cloud_volume_snapshots")
h[:title] = _("Show all %{models}") % {:models => label}
h[:title] = _("Show all Cloud Volume Snapshots")
h[:link] = url_for_only_path(:action => 'show', :id => @record, :display => 'cloud_volume_snapshots')
end
h
end

def textual_cloud_volume_backups
label = ui_lookup(:tables => "cloud_volume_backup")
num = @record.number_of(:cloud_volume_backups)
h = {:label => label, :icon => "pficon pficon-volume", :value => num}
h = {:label => _('Cloud Volume Backups'), :icon => "pficon pficon-volume", :value => num}
if num > 0 && role_allows?(:feature => "cloud_volume_backup_show_list")
label = ui_lookup(:tables => "cloud_volume_backups")
h[:title] = _("Show all %{models}") % {:models => label}
h[:title] = _("Show all Cloud Volume Backups")
h[:link] = url_for_only_path(:action => 'show', :id => @record, :display => 'cloud_volume_backups')
end
h
end

def textual_attachments
label = ui_lookup(:tables => "vm_cloud")
num = @record.number_of(:attachments)
h = {:label => label, :icon => "pficon pficon-virtual-machine", :value => num}
h = {:label => _('Instances'), :icon => "pficon pficon-virtual-machine", :value => num}
if num > 0 && role_allows?(:feature => "vm_show_list")
h[:title] = _("Show all attached %{models}") % {:models => label}
h[:title] = _("Show all attached Instances")
h[:link] = url_for_only_path(:action => 'show', :id => @record, :display => 'instances')
end
h
Expand Down
11 changes: 4 additions & 7 deletions app/helpers/cloud_volume_snapshot_helper/textual_summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ def textual_size
end

def textual_based_volumes
label = ui_lookup(:table => "based_volumes")
num = @record.total_based_volumes
h = {:label => label, :icon => "pficon pficon-volume", :value => num}
h = {:label => _('Cloud Volumes Based on Snapshot'), :icon => "pficon pficon-volume", :value => num}
if num > 0 && role_allows?(:feature => "cloud_volume_show_list")
label = ui_lookup(:table => "cloud_volumes")
h[:title] = _("Show all %{volumes} based on this Snapshot.") % {:volumes => label}
h[:title] = _("Show all Cloud Volumes based on this Snapshot.")
h[:link] = url_for_only_path(:action => 'show', :id => @record, :display => 'based_volumes')
end
h
Expand All @@ -41,10 +39,9 @@ def textual_ems

def textual_cloud_tenant
cloud_tenant = @record.cloud_tenant if @record.respond_to?(:cloud_tenant)
label = ui_lookup(:table => "cloud_tenants")
h = {:label => label, :icon => "pficon pficon-cloud-tenant", :value => (cloud_tenant.nil? ? _("None") : cloud_tenant.name)}
h = {:label => _('Cloud Tenants'), :icon => "pficon pficon-cloud-tenant", :value => (cloud_tenant.nil? ? _("None") : cloud_tenant.name)}
if cloud_tenant && role_allows?(:feature => "cloud_tenant_show")
h[:title] = _("Show this Snapshot's %{parent}") % {:parent => label}
h[:title] = _("Show this Snapshot's Cloud Tenants")
h[:link] = url_for_only_path(:controller => 'cloud_tenant', :action => 'show', :id => cloud_tenant)
end
h
Expand Down
Loading

0 comments on commit f389225

Please sign in to comment.