On 12/22/2010 03:47 PM, jzigmund(a)redhat.com wrote:
From: Jozef Zigmund<jzigmund(a)redhat.com>
---
src/app/controllers/admin/providers_controller.rb | 113 ++++++++++++++++++++
src/app/views/admin/providers/_form.haml | 14 +++
src/app/views/admin/providers/_list.haml | 19 ++++
src/app/views/admin/providers/_properties.haml | 4 +
src/app/views/admin/providers/edit.haml | 7 ++
src/app/views/admin/providers/index.haml | 3 +-
src/app/views/admin/providers/new.haml | 3 +
src/app/views/admin/providers/show.haml | 5 +
src/config/routes.rb | 3 +-
9 files changed, 169 insertions(+), 2 deletions(-)
create mode 100644 src/app/views/admin/providers/_form.haml
create mode 100644 src/app/views/admin/providers/_history.haml
create mode 100644 src/app/views/admin/providers/_hw_profiles.haml
create mode 100644 src/app/views/admin/providers/_list.haml
create mode 100644 src/app/views/admin/providers/_permissions.haml
create mode 100644 src/app/views/admin/providers/_properties.haml
create mode 100644 src/app/views/admin/providers/_provider_accounts.haml
create mode 100644 src/app/views/admin/providers/_realms.haml
create mode 100644 src/app/views/admin/providers/_services.haml
create mode 100644 src/app/views/admin/providers/edit.haml
create mode 100644 src/app/views/admin/providers/new.haml
create mode 100644 src/app/views/admin/providers/show.haml
diff --git a/src/app/controllers/admin/providers_controller.rb
b/src/app/controllers/admin/providers_controller.rb
index 80a7f28..1836061 100644
--- a/src/app/controllers/admin/providers_controller.rb
+++ b/src/app/controllers/admin/providers_controller.rb
@@ -1,6 +1,119 @@
class Admin::ProvidersController< ApplicationController
before_filter :require_user
+ before_filter :load_providers, :only => [:index, :show]
+
+require 'ruby-debug'
I guess this ^^^ was for debuging only and you can delete it now, right?
def index
end
+
+ def new
+ require_privilege(Privilege::PROVIDER_MODIFY)
+ @provider = Provider.new
+ kick_condor
+ end
+
+ def edit
+ @provider = Provider.find_by_id(params[:id])
+ require_privilege(Privilege::PROVIDER_MODIFY, @provider)
+ end
+
+ def show
+ @provider = Provider.find(params[:id])
+ @url_params = params.clone
+ @tab_captions = ['Properties', 'HW Profiles', 'Realms',
'Provider Accounts', 'Services','History','Permissions']
+ @details_tab = params[:details_tab].blank? ? 'properties' :
params[:details_tab]
+ respond_to do |format|
+ format.js do
+ if @url_params.delete :details_pane
+ render :partial => 'layouts/details_pane' and return
+ end
+ render :partial => @details_tab and return
+ end
+ format.html { render :action => 'show'}
+ end
+ end
+
+ def create
+ require_privilege(Privilege::PROVIDER_MODIFY)
+ @provider = Provider.new(params[:provider])
+ if params[:test_connection]
+ test_connection(@provider)
+ render :action => 'new'
+ else
+ @provider.set_cloud_type!
+ if @provider.save&& @provider.populate_hardware_profiles
+ flash[:notice] = "Provider added."
+ redirect_to admin_providers_path
+ else
+ flash[:notice] = "Cannot add the provider."
+ render :action => "new"
+ end
+ kick_condor
+ end
+ end
+
+ def update
+ require_privilege(Privilege::PROVIDER_MODIFY)
+ @provider = Provider.find_by_id(params[:id])
+ previous_cloud_type = @provider.cloud_type
+ @provider.update_attributes(params[:provider])
+ if params[:test_connection]
+ test_connection(@provider)
+ render :action => 'edit'
+ else
+ @provider.set_cloud_type!
+ if previous_cloud_type != @provider.cloud_type
+ @provider.errors.add :url, "points to a different provider"
+ end
+
+ if @provider.errors.empty? and @provider.save
+ flash[:notice] = "Provider updated."
+ redirect_to admin_providers_path
+ else
+ flash[:notice] = "Cannot update the provider."
+ render :action => 'edit'
+ end
+ kick_condor
+ end
+ end
+
+ def multi_destroy
+ #debugger
This ^^^ is commented out, could you please just delete it?
+ Provider.destroy(params[:provider_selected])
+ redirect_to admin_providers_url
+ end
+
+ def test_connection(provider)
+ #@provider = Provider.find_by_id(params[:id])
+ #if @provider.nil?
+ # @provider = Provider.new(params[:provider])
+ #else
+ # @provider.attributes = params[:provider]
+ #end
Again, commented-out, please delete it.
+ @provider.errors.clear
+ if @provider.connect
+ flash[:notice] = "Successfuly Connected to Provider"
+ else
+ flash[:notice] = "Failed to Connect to Provider"
+ @provider.errors.add :url
+ end
+
+ #if ['new', 'edit'].include? params[:a]
+ # action = params[:a]
+ #end
+
+ #render :action => (action || 'new')
Same here ^^^
+ end
+
+
+ protected
+
+ def load_providers
+ @header = [{ :name => "Provider name", :sort_attr => :name },
+ { :name => "Provider URL", :sort_attr => :name }
+ ]
+ @providers = Provider.list_for_user(@current_user, Privilege::PROVIDER_VIEW)
+ @url_params = params.clone
+ end
end
diff --git a/src/app/views/admin/providers/_form.haml
b/src/app/views/admin/providers/_form.haml
new file mode 100644
index 0000000..fe8c9ca
--- /dev/null
+++ b/src/app/views/admin/providers/_form.haml
@@ -0,0 +1,a14 @@
+= form.error_message_on :name, 'Name'
+= form.error_message_on :url, 'URL'
+%fieldset.clear
+ = form.label :name,'Provider name :'
+ = form.text_field :name, :title => 'provider_name', :value =>
@provider.name, :class => "clear grid_4 alpha"
+%fieldset.clear
+ = form.label :url, 'Provider URL :'
+ = form.text_field :url, :title => 'provider_url', :value =>
@provider.url, :class => "grid_5"
+ (
+ %button.linkbutton.nospace{ :type => 'submit', :value =>
t('.test_connection'), :name => 'test_connection', :id =>
'test_connection' }
+ Test connection
+ )
+ %fieldset.clear
+ = form.submit "Save", :class => "submit formbutton"
diff --git a/src/app/views/admin/providers/_history.haml
b/src/app/views/admin/providers/_history.haml
new file mode 100644
index 0000000..e69de29
diff --git a/src/app/views/admin/providers/_hw_profiles.haml
b/src/app/views/admin/providers/_hw_profiles.haml
new file mode 100644
index 0000000..e69de29
diff --git a/src/app/views/admin/providers/_list.haml
b/src/app/views/admin/providers/_list.haml
new file mode 100644
index 0000000..0735340
--- /dev/null
+++ b/src/app/views/admin/providers/_list.haml
@@ -0,0 +1,19 @@
+- form_tag do
+ = link_to "Create", new_admin_provider_url, :class =>
"button"
+ = restful_submit_tag "Delete", 'destroy',
multi_destroy_admin_providers_path, 'DELETE', :id => 'delete_button'
+
+ %p
+ Select:
+ = link_to "All", @url_params.merge(:select => 'all')
+ %span> ,
+ = link_to "None", @url_params.merge(:select => 'none')
+
+ %table#providers_table
+ = sortable_table_header @header
+ -(a)providers.each do |provider|
+ %tr
+ %td
+ - selected = @url_params[:select] == 'all'
+ %input{:name => "provider_selected[]", :type =>
"checkbox", :value => provider.id, :id =>
"provider_checkbox_#{provider.id}" }
The links "Select All, None" don't currently work. Please append the
following code to the line above:
:checked => selected
(put it at the end of the %input hash)
+ = link_to provider.name, admin_provider_path(provider)
+ %td= provider.url
diff --git a/src/app/views/admin/providers/_permissions.haml
b/src/app/views/admin/providers/_permissions.haml
new file mode 100644
index 0000000..e69de29
diff --git a/src/app/views/admin/providers/_properties.haml
b/src/app/views/admin/providers/_properties.haml
new file mode 100644
index 0000000..163401e
--- /dev/null
+++ b/src/app/views/admin/providers/_properties.haml
@@ -0,0 +1,4 @@
+%h3
+ Properties for
+ = @provider.name
+= link_to "Edit", edit_admin_provider_path(@provider), {:class =>
'button'}
diff --git a/src/app/views/admin/providers/_provider_accounts.haml
b/src/app/views/admin/providers/_provider_accounts.haml
new file mode 100644
index 0000000..e69de29
diff --git a/src/app/views/admin/providers/_realms.haml
b/src/app/views/admin/providers/_realms.haml
new file mode 100644
index 0000000..e69de29
diff --git a/src/app/views/admin/providers/_services.haml
b/src/app/views/admin/providers/_services.haml
new file mode 100644
index 0000000..e69de29
diff --git a/src/app/views/admin/providers/edit.haml
b/src/app/views/admin/providers/edit.haml
new file mode 100644
index 0000000..66864e9
--- /dev/null
+++ b/src/app/views/admin/providers/edit.haml
@@ -0,0 +1,7 @@
+%h3
+ Editing
+ = @provider.name
+ Provider
+
+-form_for @provider, :url => admin_provider_path(@provider), :html => { :method
=> :put } do |f|
+ = render :partial => 'form', :locals => { :form => f, :cancel_path
=> admin_providers_path }
diff --git a/src/app/views/admin/providers/index.haml
b/src/app/views/admin/providers/index.haml
index 589bac8..62ccbc6 100644
--- a/src/app/views/admin/providers/index.haml
+++ b/src/app/views/admin/providers/index.haml
@@ -1 +1,2 @@
-admin/providers/index.haml
+- content_for :list do
+ = render :partial => 'list'
diff --git a/src/app/views/admin/providers/new.haml
b/src/app/views/admin/providers/new.haml
new file mode 100644
index 0000000..516fdb3
--- /dev/null
+++ b/src/app/views/admin/providers/new.haml
@@ -0,0 +1,3 @@
+%h2 Create a new Provider
+- form_for @provider, :url => admin_providers_path do |f|
+ = render :partial => "form", :locals => { :form => f,
:cancel_path => admin_providers_path }
diff --git a/src/app/views/admin/providers/show.haml
b/src/app/views/admin/providers/show.haml
new file mode 100644
index 0000000..0c36221
--- /dev/null
+++ b/src/app/views/admin/providers/show.haml
@@ -0,0 +1,5 @@
+- content_for 'list' do
+ = render :partial => 'list'
+
+- content_for 'details' do
+ = render :partial => 'layouts/details_pane'
diff --git a/src/config/routes.rb b/src/config/routes.rb
index 99af504..2a50133 100644
--- a/src/config/routes.rb
+++ b/src/config/routes.rb
@@ -44,7 +44,8 @@ ActionController::Routing::Routes.draw do |map|
map.connect '/set_layout', :controller => 'application', :action
=> 'set_layout'
map.namespace 'admin' do |r|
- r.resources :hardware_profiles, :pool_families, :providers, :provider_accounts,
:realms, :roles, :settings
+ r.resources :hardware_profiles, :pool_families, :provider_accounts, :realms, :roles,
:settings
+ r.resources :providers, :collection => { :multi_destroy => :delete }
r.resources :users, :collection => { :multi_destroy => :delete }
end
ACK with a few nits:
There are some leftovers from debugging, please remove them. Also, the
"Select all/none" code doesn't work.
I've marked everything inline. When you fix it, feel free to push the code.
Thanks,
Thomas