From: Imre Farkas <ifarkas(a)redhat.com>
---
.../controllers/provider_selections_controller.rb | 43 +++++++++++++++++++---
src/app/helpers/provider_selections_helper.rb | 7 +++-
.../provider_selections/edit_strategy.html.haml | 16 ++++++++
src/config/locales/en.yml | 6 +++
src/config/routes.rb | 2 +
.../provider_selection/provider_selection.rb | 2 +-
6 files changed, 68 insertions(+), 8 deletions(-)
create mode 100644 src/app/views/provider_selections/edit_strategy.html.haml
diff --git a/src/app/controllers/provider_selections_controller.rb
b/src/app/controllers/provider_selections_controller.rb
index 27ea5f8..e6b173b 100644
--- a/src/app/controllers/provider_selections_controller.rb
+++ b/src/app/controllers/provider_selections_controller.rb
@@ -18,25 +18,27 @@ class ProviderSelectionsController < ApplicationController
before_filter :require_user
before_filter :set_view_path
+ before_filter :load_pool
+ before_filter :require_privileged_user_for_modify, :except => :show
def show
- @pool = Pool.find(params[:pool_id])
+ require_privilege(Privilege::VIEW, @pool)
+
@environment = @pool.pool_family
@available_strategies = ProviderSelection::Base.strategies
end
def toggle_strategy
- pool = Pool.find(params[:pool_id])
strategy = ProviderSelection::Base.find_strategy_by_name(params[:strategy_name])
- if pool.provider_selection_strategies.exists?(:name => strategy.name)
- provider_selection_strategy =
pool.provider_selection_strategies.find_by_name(strategy.name)
+ if @pool.provider_selection_strategies.exists?(:name => strategy.name)
+ provider_selection_strategy =
@pool.provider_selection_strategies.find_by_name(strategy.name)
provider_selection_strategy.enabled = !provider_selection_strategy.enabled
else
provider_selection_strategy =
ProviderSelectionStrategy.new(:name => strategy.name,
:enabled => true,
- :pool => pool)
+ :pool => @pool)
end
if provider_selection_strategy.save
@@ -60,6 +62,29 @@ class ProviderSelectionsController < ApplicationController
end
end
+ def edit_strategy
+ @strategy = ProviderSelection::Base.find_strategy_by_name(params[:strategy_name])
+ @provider_selection_strategy =
@pool.provider_selection_strategies.find_by_name((a)strategy.name)
+ @config =
@strategy.base_klass.properties[:config_klass].new(@provider_selection_strategy.config)
+ @edit_partial = @strategy.base_klass.properties[:edit_partial]
+ end
+
+ def save_strategy_options
+ @strategy = ProviderSelection::Base.find_strategy_by_name(params[:strategy_name])
+ @config = @strategy.base_klass.properties[:config_klass].new(params[:config])
+
+ if @config.valid?
+ @provider_selection_strategy =
@pool.provider_selection_strategies.find_by_name((a)strategy.name)
+ @provider_selection_strategy.update_attributes(:config => @config.to_hash)
+
+ redirect_to pool_provider_selection_path(@pool),
+ :notice =>
t('provider_selection.flash.config_successfully_saved', :strategy_name =>
@strategy.translated_name)
+ else
+ @edit_partial = @strategy.base_klass.properties[:edit_partial]
+ render :edit_strategy
+ end
+ end
+
private
def set_view_path
@@ -68,4 +93,12 @@ class ProviderSelectionsController < ApplicationController
end
end
+ def load_pool
+ @pool = Pool.find(params[:pool_id])
+ end
+
+ def require_privileged_user_for_modify
+ require_privilege(Privilege::MODIFY, @pool)
+ end
+
end
\ No newline at end of file
diff --git a/src/app/helpers/provider_selections_helper.rb
b/src/app/helpers/provider_selections_helper.rb
index 1e1dc4f..3868a9d 100644
--- a/src/app/helpers/provider_selections_helper.rb
+++ b/src/app/helpers/provider_selections_helper.rb
@@ -27,8 +27,11 @@ module ProviderSelectionsHelper
def strategy_actions(strategy)
provider_selection_strategy =
@pool.provider_selection_strategies.find_by_name(strategy.name)
if provider_selection_strategy.present? &&
provider_selection_strategy.enabled
- if strategy.klass.properties.has_key?(:edit_path)
- strategy_edit_path = send(strategy.klass.properties[:edit_path])
+ if strategy.base_klass.properties.has_key?(:edit_path)
+ strategy_edit_path = send(strategy.base_klass.properties[:edit_path])
+ link_to(t('provider_selection.show.configure'), strategy_edit_path,
:class => 'configure_strategy_button')
+ elsif strategy.base_klass.properties.has_key?(:config_klass)
+ strategy_edit_path = edit_strategy_pool_provider_selection_path(@pool,
strategy.name)
link_to(t('provider_selection.show.configure'), strategy_edit_path,
:class => 'configure_strategy_button')
end
end
diff --git a/src/app/views/provider_selections/edit_strategy.html.haml
b/src/app/views/provider_selections/edit_strategy.html.haml
new file mode 100644
index 0000000..47d1a8e
--- /dev/null
+++ b/src/app/views/provider_selections/edit_strategy.html.haml
@@ -0,0 +1,16 @@
+= render :partial => 'layouts/admin_nav'
+
+%header.page-header
+ .obj_actions
+ .return_to
+ = t(:return_to)
+ = link_to t('provider_selection.edit_strategy.back_to_strategies', :pool
=> @pool.name), pool_provider_selection_path(@pool)
+ %h1.no-icon= t('provider_selection.edit_strategy.edit', :strategy_name =>
@strategy.translated_name)
+
+%section.content-section
+ .content#priority-group-form
+ = form_for @config, :as => :config, :builder =>
ApplicationHelper::FormBuilderWithRequiredFields,
+ :url => save_strategy_options_pool_provider_selection_path(@pool,
@strategy.name) do |form|
+ = render :partial => @edit_partial, :locals => { :form => form }
+ %fieldset.options
+ = form.submit(t('save'), :class => "submit button pill")
\ No newline at end of file
diff --git a/src/config/locales/en.yml b/src/config/locales/en.yml
index 88c16e6..44687b3 100644
--- a/src/config/locales/en.yml
+++ b/src/config/locales/en.yml
@@ -587,6 +587,7 @@ en:
properties:
properties: Properties for %{pool}
header_show:
+ header_show:
pool_name: "%{name} Pool"
flash:
notice:
@@ -628,11 +629,15 @@ en:
environment: "Environment: %{environment}"
edit_strategy: "Edit %{name} Strategy"
configure: "Configure"
+ edit_strategy:
+ edit: "Edit %{strategy_name} strategy"
+ back_to_strategies: "Provider Selection Strategies for Pool: %{pool}"
flash:
successfully_enabled: "Successfully enabled %{strategy_name} strategy"
successfully_disabled: "Successfully disabled %{strategy_name} strategy"
failed_to_enable: "Failed to enable %{strategy_name} strategy"
failed_to_disable: "Failed to disable %{strategy_name} strategy"
+ config_successfully_saved: "Successfully updated %{strategy_name}
strategy"
hardware_profiles:
hardware: Hardware
hardware_profile: Hardware Profile
@@ -1311,6 +1316,7 @@ en:
provider_priority_groups:
index:
add_new: Add new
+ edit_strict_order_strategy: 'Edit Strict Order Strategy'
confirm_delete: "Are you sure you want to delete this priority group?"
provider_account_name: "Account Name"
provider_account_username: "Username"
diff --git a/src/config/routes.rb b/src/config/routes.rb
index 7d7704e..acbe46c 100644
--- a/src/config/routes.rb
+++ b/src/config/routes.rb
@@ -103,6 +103,8 @@ Conductor::Application.routes.draw do
resources :provider_priority_groups, :except => [:show]
match ':strategy_name/toggle', :to =>
'provider_selections#toggle_strategy', :as => 'toggle_strategy'
+ match ':strategy_name/edit', :to =>
'provider_selections#edit_strategy', :as => 'edit_strategy'
+ match ':strategy_name/save_strategy_options', :to =>
'provider_selections#save_strategy_options', :as =>
'save_strategy_options'
end
end
diff --git a/src/vendor/provider_selection/provider_selection.rb
b/src/vendor/provider_selection/provider_selection.rb
index 8048488..945282c 100644
--- a/src/vendor/provider_selection/provider_selection.rb
+++ b/src/vendor/provider_selection/provider_selection.rb
@@ -22,7 +22,7 @@ Dir['vendor/provider_selection/strategies/*/'].each do |path|
end
# Register view path
-#ProviderSelection::Base.add_view_path(File.expand_path(File.join('vendor',
'provider_selection', 'views')))
+ProviderSelection::Base.add_view_path(File.expand_path(File.join('vendor',
'provider_selection', 'views')))
# Extend I18n.load_path
#I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'config',
'locales', '*.yml')]
--
1.7.11.2