From: Imre Farkas <ifarkas(a)redhat.com>
---
.../provider_priority_groups_controller.rb | 97 ++++++++++++++++++++
.../views/provider_priority_groups/_form.html.haml | 55 +++++++++++
.../views/provider_priority_groups/edit.html.haml | 15 +++
.../views/provider_priority_groups/index.html.haml | 40 ++++++++
.../views/provider_priority_groups/new.html.haml | 15 +++
5 files changed, 222 insertions(+)
create mode 100644 src/app/controllers/provider_priority_groups_controller.rb
create mode 100644 src/app/views/provider_priority_groups/_form.html.haml
create mode 100644 src/app/views/provider_priority_groups/edit.html.haml
create mode 100644 src/app/views/provider_priority_groups/index.html.haml
create mode 100644 src/app/views/provider_priority_groups/new.html.haml
diff --git a/src/app/controllers/provider_priority_groups_controller.rb
b/src/app/controllers/provider_priority_groups_controller.rb
new file mode 100644
index 0000000..b4fe019
--- /dev/null
+++ b/src/app/controllers/provider_priority_groups_controller.rb
@@ -0,0 +1,97 @@
+#
+# Copyright 2012 Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#
http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+class ProviderPriorityGroupsController < ApplicationController
+
+ before_filter :require_user
+ before_filter :load_pool
+ before_filter :load_providers, :only => [:new, :create, :edit, :update]
+
+ def index
+ @strategy = ProviderSelection::Base.find_strategy_by_name(params[:name])
+ @priority_groups = @pool.provider_priority_groups
+ end
+
+ def new
+ @priority_group = ProviderPriorityGroup.new
+ end
+
+ def create
+ @priority_group = ProviderPriorityGroup.new(params[:provider_priority_group])
+ @priority_group.pool = @pool
+
+ unless @priority_group.save
+ render :new
+ return
+ end
+
+ if params[:provider_ids].present?
+ selected_providers = Provider.find(params[:provider_ids])
+ @priority_group.providers = selected_providers
+ end
+
+ if params[:provider_account_ids].present?
+ selected_provider_accounts = ProviderAccount.find(params[:provider_account_ids])
+ @priority_group.add_provider_accounts(selected_provider_accounts)
+ end
+
+ redirect_to
pool_provider_selection_provider_priority_groups_path((a)priority_group.pool),
+ :notice => t('provider_priority_groups.flash.created')
+ end
+
+ def edit
+ @priority_group = ProviderPriorityGroup.find(params[:id])
+ end
+
+ def update
+ @priority_group = ProviderPriorityGroup.find(params[:id])
+
+ unless @priority_group.update_attributes!(params[:provider_priority_group])
+ render :edit
+ return
+ end
+
+ if params[:provider_ids].present?
+ selected_providers = Provider.find(params[:provider_ids])
+ @priority_group.providers = selected_providers
+ end
+
+ @priority_group.provider_accounts.clear
+ if params[:provider_account_ids].present?
+ selected_provider_accounts = ProviderAccount.find(params[:provider_account_ids])
+ @priority_group.add_provider_accounts(selected_provider_accounts)
+ end
+
+ redirect_to
pool_provider_selection_provider_priority_groups_path((a)priority_group.pool),
+ :notice => t('provider_priority_groups.flash.updated')
+ end
+
+ def destroy
+ @pool.provider_priority_groups.find(params[:id]).destroy
+ redirect_to :back, :notice => t('provider_priority_groups.flash.deleted')
+ end
+
+ private
+
+ def load_pool
+ @pool = Pool.find(params[:pool_id])
+ end
+
+ def load_providers
+ @providers = Provider.list_for_user(current_session, current_user, Privilege::USE)
+ end
+
+end
diff --git a/src/app/views/provider_priority_groups/_form.html.haml
b/src/app/views/provider_priority_groups/_form.html.haml
new file mode 100644
index 0000000..c72918a
--- /dev/null
+++ b/src/app/views/provider_priority_groups/_form.html.haml
@@ -0,0 +1,55 @@
+.priority-group
+ - if @priority_group.errors.any?
+ = render 'layouts/error_messages', :object => @priority_group
+
+ %fieldset
+ .field
+ = form.label :name
+ .input
+ = form.text_field :name
+ .field
+ = form.label :score
+ .input
+ = form.text_field :score
+
+ - @providers.each do |provider|
+ .provider
+
+ %header
+ %h3.name
+ = check_box_tag("provider_ids[]", provider.id,
@priority_group.include?(provider), :class => 'provider-checkbox')
+ = provider.name
+
+ .provider-accounts-table
+ = filter_table(provider_accounts_header(:with_checkbox_placeholder => true,
:without_alert => true), provider.provider_accounts, {:without_form => true}) do
|account|
+ %tr{:class => cycle('nostripe','stripe')}
+ %td{:class => 'checkbox'}
+ = check_box_tag("provider_account_ids[]", account.id,
@priority_group.include?(account), :class => 'provider-account-checkbox')
+ %td= link_to(account.name, provider_provider_account_path(account.provider,
account))
+ %td= account.credentials_hash['username']
+ %td= account.provider.name
+ %td= account.provider.provider_type.name
+ %td= account.priority
+ %td{:class => 'center'}= number_to_percentage
account.quota.percentage_used, :precision => 0
+ %td{:class => 'center'}= account.quota.maximum_running_instances
|| t('provider_accounts.properties.unlimited')
+
+:javascript
+ $(document).ready(function() {
+ $(".priority-group .provider h3.name").live("click",
function(event) {
+ var $providerCheckbox = $(this).find('input.provider-checkbox');
+ var providerAccountCheckboxes =
$(this).parents('.provider').find('input.provider-account-checkbox')
+
+ $.each(providerAccountCheckboxes, function(index, providerAccountCheckbox) {
+ $(providerAccountCheckbox).prop('checked',
$providerCheckbox.prop('checked'));
+ });
+ });
+
+ $(".priority-group .provider
.provider-account-checkbox").live("click", function(event) {
+ var $providerAccountCheckbox = $(this);
+
+ if ($providerAccountCheckbox.prop('checked') == false) {
+ var $providerCheckbox =
$(this).parents('.provider').find('input.provider-checkbox')
+ $providerCheckbox.prop('checked', false);
+ }
+ });
+ });
diff --git a/src/app/views/provider_priority_groups/edit.html.haml
b/src/app/views/provider_priority_groups/edit.html.haml
new file mode 100644
index 0000000..092a45e
--- /dev/null
+++ b/src/app/views/provider_priority_groups/edit.html.haml
@@ -0,0 +1,15 @@
+= render :partial => 'layouts/admin_nav'
+
+%header.page-header
+ .obj_actions
+ .return_to
+ = t(:return_to)
+ = link_to t('provider_priority_groups.edit.back', :pool => @pool.name),
pool_provider_selection_provider_priority_groups_path(@pool)
+ %h1.no-icon= t('provider_priority_groups.edit.title')
+
+%section.content-section
+ .content
+ = form_for @priority_group, :url =>
pool_provider_selection_provider_priority_group_path(@pool) do |form|
+ = render :partial => 'form', :locals => { :form => form }
+ %fieldset.options
+ = form.submit(t('provider_priority_groups.edit.save'), :class =>
"submit button pill")
\ No newline at end of file
diff --git a/src/app/views/provider_priority_groups/index.html.haml
b/src/app/views/provider_priority_groups/index.html.haml
new file mode 100644
index 0000000..8a4eab2
--- /dev/null
+++ b/src/app/views/provider_priority_groups/index.html.haml
@@ -0,0 +1,40 @@
+= render :partial => 'layouts/admin_nav'
+
+%header.page-header
+ .obj_actions
+ .return_to
+ = t(:return_to)
+ = link_to t('provider_selection.edit_stategy.strategies', :pool =>
@pool.name), pool_provider_selection_path(@pool)
+ %h1.no-icon= t('provider_selection.show.provider_selection')
+
+%section.content-section
+ %header
+ .section-controls
+ = link_to(t('provider_priority_groups.index.add_new'),
new_pool_provider_selection_provider_priority_group_path(@pool), :class => 'button
pill')
+ %h2= t('provider_selection.show.edit_strategy', :name => 'Stict
Order')
+ .content
+ .priority-group
+
+ - @priority_groups.each do |priority_group|
+ .provider
+ %header
+ %h3.name
+ %p= priority_group.name
+
+ .score
+ != "(#{ProviderPriorityGroup.human_attribute_name(:score)}:
#{priority_group.score})"
+
+ .button-group
+ = link_to(t('edit'),
edit_pool_provider_selection_provider_priority_group_path(priority_group.pool,
priority_group), :class => "button pill")
+ = link_to(t('delete'),
pool_provider_selection_provider_priority_group_path(priority_group.pool, priority_group),
:method => :delete, :confirm =>
t('provider_priority_groups.index.confirm_delete'), :class => "button pill
danger")
+
+ .provider-accounts-table
+ = filter_table(provider_accounts_header(:without_checkbox => true,
:without_alert => true), priority_group.all_provider_accounts, {:without_form =>
true}) do |account|
+ %tr{:class => cycle('nostripe','stripe')}
+ %td= link_to account.name,
provider_provider_account_path(account.provider, account)
+ %td= account.credentials_hash['username']
+ %td= account.provider.name
+ %td= account.provider.provider_type.name
+ %td= account.priority
+ %td{:class => 'center'}= number_to_percentage
account.quota.percentage_used, :precision => 0
+ %td{:class => 'center'}=
account.quota.maximum_running_instances or
t('provider_accounts.properties.unlimited')
diff --git a/src/app/views/provider_priority_groups/new.html.haml
b/src/app/views/provider_priority_groups/new.html.haml
new file mode 100644
index 0000000..0acdd97
--- /dev/null
+++ b/src/app/views/provider_priority_groups/new.html.haml
@@ -0,0 +1,15 @@
+= render :partial => 'layouts/admin_nav'
+
+%header.page-header
+ .obj_actions
+ .return_to
+ = t(:return_to)
+ = link_to t('provider_priority_groups.new.back', :pool => @pool.name),
pool_provider_selection_provider_priority_groups_path(@pool)
+ %h1.no-icon= t('provider_priority_groups.new.title')
+
+%section.content-section
+ .content
+ = form_for @priority_group, :url =>
pool_provider_selection_provider_priority_groups_path(@pool) do |form|
+ = render :partial => 'form', :locals => { :form => form }
+ %fieldset.options
+ = form.submit(t('provider_priority_groups.new.create'), :class =>
'submit button pill')
\ No newline at end of file
--
1.7.10.4