[PATCH conductor] BZ798574: Separating matching_provider_hardware_profiles action from create
Jan Provaznik
jprovazn at redhat.com
Tue Mar 6 15:22:40 UTC 2012
On 03/02/2012 05:31 PM, ifarkas at redhat.com wrote:
> From: Imre Farkas<ifarkas at redhat.com>
>
> https://bugzilla.redhat.com/show_bug.cgi?id=798574
> ---
> .../controllers/hardware_profiles_controller.rb | 32 ++++++++++---------
> src/app/views/hardware_profiles/_form.html.haml | 3 +-
> src/app/views/hardware_profiles/new.html.haml | 2 +-
> src/config/routes.rb | 1 +
> 4 files changed, 21 insertions(+), 17 deletions(-)
>
> diff --git a/src/app/controllers/hardware_profiles_controller.rb b/src/app/controllers/hardware_profiles_controller.rb
> index db94433..f845654 100644
> --- a/src/app/controllers/hardware_profiles_controller.rb
> +++ b/src/app/controllers/hardware_profiles_controller.rb
> @@ -19,7 +19,7 @@ class HardwareProfilesController< ApplicationController
> before_filter :load_hardware_profiles, :only => [:index, :show]
> before_filter :load_hardware_profile, :only => [:show]
> before_filter :setup_new_hardware_profile, :only => [:new]
> - before_filter :setup_hardware_profile, :only => [:new, :create, :edit, :update]
> + before_filter :setup_hardware_profile, :only => [:new, :create, :matching_provider_hardware_profiles, :edit, :update]
>
> def index
> @title = t('hardware_profiles.hardware_profiles')
> @@ -32,7 +32,7 @@ class HardwareProfilesController< ApplicationController
> format.js do
> if params[:hardware_profile]
> build_hardware_profile(params[:hardware_profile])
> - matching_provider_hardware_profiles
> + find_matching_provider_hardware_profiles
> render :partial => 'matching_provider_hardware_profiles'
> else
> render :partial => 'list'
> @@ -53,7 +53,7 @@ class HardwareProfilesController< ApplicationController
> @tab_captions = [t('hardware_profiles.tab_captions.properties'), t('hardware_profiles.tab_captions.history'), t('hardware_profiles.tab_captions.matching_provider_hwp')]
> @details_tab = params[:details_tab].blank? ? 'properties' : params[:details_tab]
> properties
> - matching_provider_hardware_profiles
> + find_matching_provider_hardware_profiles
> save_breadcrumb(hardware_profile_path(@hardware_profile), @hardware_profile.name)
>
> respond_to do |format|
> @@ -81,19 +81,21 @@ class HardwareProfilesController< ApplicationController
> require_privilege(Privilege::CREATE, HardwareProfile)
>
> build_hardware_profile(params[:hardware_profile])
> - if params[:commit] == 'Save'
> - if @hardware_profile.save
> - redirect_to hardware_profiles_path
> - else
> - params.delete :commit
> - render :action => 'new'
> - end
> + if @hardware_profile.save
> + redirect_to hardware_profiles_path
> else
> - matching_provider_hardware_profiles
> render :action => 'new'
> end
> end
>
> + def matching_provider_hardware_profiles
> + require_privilege(Privilege::CREATE, HardwareProfile)
> +
> + build_hardware_profile(params[:hardware_profile])
> + find_matching_provider_hardware_profiles
> + render :action => 'new'
> + end
> +
> def destroy
> hardware_profile = HardwareProfile.find(params[:id])
> require_privilege(Privilege::MODIFY, hardware_profile)
> @@ -121,7 +123,7 @@ class HardwareProfilesController< ApplicationController
> redirect_to hardware_profile_path(@hardware_profile)
> return
> end
> - matching_provider_hardware_profiles
> + find_matching_provider_hardware_profiles
> end
>
> def update
> @@ -133,7 +135,7 @@ class HardwareProfilesController< ApplicationController
>
> if params[:commit] == "Check Matches"
> require_privilege(Privilege::VIEW, HardwareProfile)
> - matching_provider_hardware_profiles
> + find_matching_provider_hardware_profiles
> render :edit and return
> end
>
> @@ -183,7 +185,7 @@ class HardwareProfilesController< ApplicationController
> :storage => HardwareProfileProperty.new(:name => "storage", :unit => "GB"),
> :architecture => HardwareProfileProperty.new(:name => "architecture", :unit => "label"))
> end
> - matching_provider_hardware_profiles
> + find_matching_provider_hardware_profiles
> end
>
> def properties
> @@ -195,7 +197,7 @@ class HardwareProfilesController< ApplicationController
> end
>
> #TODO Update this method when moving to new HWP Model
> - def matching_provider_hardware_profiles
> + def find_matching_provider_hardware_profiles
> @provider_hwps_header = [
> { :name => t('hardware_profiles.provider_hwp_headers.provider_name'), :sort_attr => "provider.name" },
> { :name => t('hardware_profiles.provider_hwp_headers.hwp_name'), :sort_attr => :name },
> diff --git a/src/app/views/hardware_profiles/_form.html.haml b/src/app/views/hardware_profiles/_form.html.haml
> index 0a0fed8..5b1815c 100644
> --- a/src/app/views/hardware_profiles/_form.html.haml
> +++ b/src/app/views/hardware_profiles/_form.html.haml
> @@ -18,5 +18,6 @@
> = hwpp_form.select("value", ["i386", "x86_64"], {})
> -else
> = hwpp_form.text_field(:value)
> -= hwp_form.submit t('hardware_profiles.form.check_matches'), :class => "submit button", :id => 'check_matches'
> +
> += restful_submit_tag t('hardware_profiles.form.check_matches'), 'matching_provider_hardware_profiles', matching_provider_hardware_profiles_hardware_profiles_path, 'GET', :class => 'button danger', :id => 'check_matches', 'data-none_selected' => t('deployments.flash.error.none_selected')
> = hwp_form.submit t('save'), :class => 'submit button', :id => 'save_button'
> diff --git a/src/app/views/hardware_profiles/new.html.haml b/src/app/views/hardware_profiles/new.html.haml
> index cdb732c..c5b2db8 100644
> --- a/src/app/views/hardware_profiles/new.html.haml
> +++ b/src/app/views/hardware_profiles/new.html.haml
> @@ -12,4 +12,4 @@
> = form_for @hardware_profile, :url => hardware_profiles_path, :html => { :multipart => true } do |hwp_form|
> = render :partial => "form", :locals => { :hwp_form => hwp_form }
>
> - = render :partial => 'matching_provider_hardware_profiles' if params[:commit] == 'Check Matches'
> + = render :partial => 'matching_provider_hardware_profiles' if @matching_hwps.present?&& @matching_hwps.any?
> diff --git a/src/config/routes.rb b/src/config/routes.rb
> index d24f039..e7dd434 100644
> --- a/src/config/routes.rb
> +++ b/src/config/routes.rb
> @@ -137,6 +137,7 @@ Conductor::Application.routes.draw do
> resources :hardware_profiles do
> delete 'multi_destroy', :on => :collection
> post :filter, :on => :collection
> + get :matching_provider_hardware_profiles, :on => :collection
^ maybe it would be better to use POST since you are submitting form anyway
> end
>
> resources :providers do
ACK with one minor not inline
More information about the aeolus-devel
mailing list