From: Martyn Taylor <mtaylor(a)redhat.com>
---
.../admin/hardware_profiles_controller.rb | 8 +++++++-
src/app/models/hardware_profile.rb | 4 ++++
src/app/models/hardware_profile_property.rb | 13 +++++++++++++
3 files changed, 24 insertions(+), 1 deletions(-)
diff --git a/src/app/controllers/admin/hardware_profiles_controller.rb
b/src/app/controllers/admin/hardware_profiles_controller.rb
index 783c0e8..a3ff77a 100644
--- a/src/app/controllers/admin/hardware_profiles_controller.rb
+++ b/src/app/controllers/admin/hardware_profiles_controller.rb
@@ -178,7 +178,13 @@ class Admin::HardwareProfilesController < ApplicationController
end
def load_hardware_profiles
- @hardware_profiles = HardwareProfile.all(:conditions => 'provider_id IS
NULL')
+ sort_order = params['order_field'].nil? ? "name" :
params['order_field']
+ if sort_order == "name"
+ @hardware_profiles = HardwareProfile.all(:order => sort_order, :conditions =>
'provider_id IS NULL')
+ else
+ @hardware_profiles = HardwareProfile.all(:conditions => 'provider_id IS
NULL')
+ @hardware_profiles.sort! {|x,y| x.get_property_map[sort_order].sort_value(true)
<=> y.get_property_map[sort_order].sort_value(true)}
+ end
end
def load_hardware_profile
diff --git a/src/app/models/hardware_profile.rb b/src/app/models/hardware_profile.rb
index 9cfc770..836717e 100644
--- a/src/app/models/hardware_profile.rb
+++ b/src/app/models/hardware_profile.rb
@@ -83,6 +83,10 @@ class HardwareProfile < ActiveRecord::Base
validates_associated :cpu
validates_associated :architecture
+ def get_property_map
+ return {'memory' => memory, 'cpu' => cpu,
'architecture' => architecture, 'storage' => storage}
+ end
+
def provider_hardware_profile?
!provider.nil?
end
diff --git a/src/app/models/hardware_profile_property.rb
b/src/app/models/hardware_profile_property.rb
index f38d394..41ad7aa 100644
--- a/src/app/models/hardware_profile_property.rb
+++ b/src/app/models/hardware_profile_property.rb
@@ -127,5 +127,18 @@ class HardwareProfileProperty < ActiveRecord::Base
"undefined"
end
end
+
+ def sort_value(ascending)
+ case kind
+ when "fixed"
+ return value
+ when range
+ return ascending ? range_from : range_to
+ when
+ entries = (property_enum_entries.map { |enum| enum.value }).sort!
+ return ascending ? entries.first : entries.last
+ end
+ end
+
end
--
1.7.4
Show replies by date