Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

system groups - UI - allow user to change the env/view for systems in a group #1837

Merged
merged 6 commits into from

2 participants

@bbuckingham
Owner

This PR contains modifications to allow a user to change (via UI) the environment and content view for all users in a system group. This PR also contains changes to the group's system list to show the current env/view associated with each system.

To change the env/view, the user would:

  • go to System Groups -> -> Systems
  • click the 'Edit' link
  • select environment/content view and click 'Save'

Since this will change the values for all systems in the group, the user is presented with a confirmation dialog before proceeding with the change.

As part of these changes, I created 'env_content_view_selector.js' which can hopefully be reused for similar scenarios in the UI (e.g. Systems & Activation Keys create). I've also done some minor refactoring of those other areas to centralized the definition of some strings and view helpers. (Will do any further refactoring to use this common js as part of a separate PR.)

bbuckingham added some commits
@bbuckingham bbuckingham system groups - update system's list to include env and view
Adding a little more info to the system's list.
37263f2
@bbuckingham bbuckingham activation keys / systems - minor refactor to allow for reuse on syst…
…em groups

For content views, we will be updating system groups to allow
the admin to change the env/view for all systems in a group.
This will use a similar env/view widget to what is currently
used in both activation keys and systems.  In preparation for
that, this commit is moving some of the logic to be common.

This commit primarily addresses:
1. moves the definition of 'no content view' - placing it in common_i18n
   and application_helper
2. moves the logic for obtaining the content view select labels
   to application_helper
f3a46a2
@bbuckingham bbuckingham ctivation keys / systems - mv i18n.update_view to _common_i18n partial
Renaming update_view to select_content_view and moving it to
the _common_i18n.html.haml partial.
b524f42
@bbuckingham bbuckingham activation keys - test fix fbbae0c
@bbuckingham bbuckingham system groups - ui - allow user to change env/view for systems in a g…
…roup

This commit contains changes to allow a user to navigate to
a system group and then 'edit' the environment/content view
for all systems in that group.

As part of the change, created env_content_view_selector.js, which
we may be able to leverage in other places in the UI where similar
behavior is used (e.g. activation key & system 'create').
ac176ca
src/app/controllers/system_groups_controller.rb
@@ -39,6 +41,8 @@ def rules
:auto_complete=>any_readable,
:add_systems=> edit_perm,
:remove_systems=>edit_perm,
+ :edit_systems=>edit_systems_perm,
+ :update_systems=>edit_systems_perm,
@daviddavis Owner

In param_rules, you use spaces around your hash rockets, but here you don't. Any reason?

Personally, I prefer spaces around them since it makes it easier to read (and also a space after the lambda keyword).

@bbuckingham Owner

The only reason was to be consistent within the blocks of code where the lines were added. That said, I can create a commit to change the code, but will change it throughout the controller to be consistent (i.e. not just the lines I added with this PR).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/public/javascripts/env_content_view_selector.js
((8 lines not shown))
+ including the implied warranties of MERCHANTABILITY,
+ NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
+ have received a copy of GPLv2 along with this software; if not, see
+ http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+ */
+KT.env_content_view_selector = (function(){
+ var settings,
+
+ initialize = function(params) {
+ /**
+ * params:
+ * override_save // (default: true) if false, perform save on form submit
+ * override_cancel // (default: true) if false, perform cancel when cancel button clicked
+ * cv_change_cb() // callback function to perform custom logic after user selects content view
+ * save_success_cb() // callback function to perform custom logic after a successful save
+ * save_error_cb // callback function to perform custom logic after an unsuccessful save
@daviddavis Owner

Why no parens?

@bbuckingham Owner

Unintentional, will add.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/public/javascripts/env_content_view_selector.js
((1 lines not shown))
+/**
+ Copyright 2013 Red Hat, Inc.
+
+ This software is licensed to you under the GNU General Public
+ License as published by the Free Software Foundation; either version
+ 2 of the License (GPLv2) or (at your option) any later version.
+ There is NO WARRANTY for this software, express or implied,
+ including the implied warranties of MERCHANTABILITY,
+ NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
+ have received a copy of GPLv2 along with this software; if not, see
+ http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+ */
+KT.env_content_view_selector = (function(){
+ var settings,
+
+ initialize = function(params) {
@daviddavis Owner

Why is this indented?

@bbuckingham Owner

No particular reason. It may have been from ide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@daviddavis
Owner

Good job. ACK pending some minor comments.

@bbuckingham bbuckingham system groups - address style comments from pull request 1837 review
Addresses a few minor style comments from 1837:
- spacing around => in controller
- spacing after lambda in controller
- inclusion of () on selector callback function
- indentation in *selector.js
e036360
@daviddavis
Owner

ACK

@bbuckingham
Owner

I have a need to get this code in to master and another branch. Since tests are passing and I've gotten an ACK, I am going to proceed with merging. If, however, folks have any additional comments, feel free to send them to me and I'll get them incorporated.

@bbuckingham bbuckingham merged commit 7af81a5 into Katello:master
@komidore64 komidore64 referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 3, 2013
  1. @bbuckingham

    system groups - update system's list to include env and view

    bbuckingham authored
    Adding a little more info to the system's list.
  2. @bbuckingham

    activation keys / systems - minor refactor to allow for reuse on syst…

    bbuckingham authored
    …em groups
    
    For content views, we will be updating system groups to allow
    the admin to change the env/view for all systems in a group.
    This will use a similar env/view widget to what is currently
    used in both activation keys and systems.  In preparation for
    that, this commit is moving some of the logic to be common.
    
    This commit primarily addresses:
    1. moves the definition of 'no content view' - placing it in common_i18n
       and application_helper
    2. moves the logic for obtaining the content view select labels
       to application_helper
  3. @bbuckingham

    ctivation keys / systems - mv i18n.update_view to _common_i18n partial

    bbuckingham authored
    Renaming update_view to select_content_view and moving it to
    the _common_i18n.html.haml partial.
  4. @bbuckingham
  5. @bbuckingham

    system groups - ui - allow user to change env/view for systems in a g…

    bbuckingham authored
    …roup
    
    This commit contains changes to allow a user to navigate to
    a system group and then 'edit' the environment/content view
    for all systems in that group.
    
    As part of the change, created env_content_view_selector.js, which
    we may be able to leverage in other places in the UI where similar
    behavior is used (e.g. activation key & system 'create').
  6. @bbuckingham

    system groups - address style comments from pull request 1837 review

    bbuckingham authored
    Addresses a few minor style comments from 1837:
    - spacing around => in controller
    - spacing after lambda in controller
    - inclusion of () on selector callback function
    - indentation in *selector.js
This page is out of date. Refresh to see the latest.
Showing with 427 additions and 104 deletions.
  1. +0 −15 src/app/controllers/activation_keys_controller.rb
  2. +82 −52 src/app/controllers/system_groups_controller.rb
  3. +0 −3  src/app/helpers/activation_keys_helper.rb
  4. +20 −0 src/app/helpers/application_helper.rb
  5. +0 −4 src/app/helpers/systems_helper.rb
  6. +3 −1 src/app/views/activation_keys/_edit.html.haml
  7. +2 −1  src/app/views/activation_keys/_new.html.haml
  8. +1 −8 src/app/views/activation_keys/index.html.haml
  9. +3 −1 src/app/views/common/_common_i18n.html.haml
  10. +32 −0 src/app/views/system_groups/_edit_systems.html.haml
  11. +4 −0 src/app/views/system_groups/_system_item.html.haml
  12. +9 −0 src/app/views/system_groups/_systems.html.haml
  13. +2 −1  src/app/views/system_groups/index.html.haml
  14. +0 −7 src/app/views/systems/_new.html.haml
  15. +1 −0  src/config/assets.yml
  16. +2 −0  src/config/routes.rb
  17. +2 −3 src/public/javascripts/activation_key.js
  18. +179 −0 src/public/javascripts/env_content_view_selector.js
  19. +35 −5 src/public/javascripts/system_groups.js
  20. +2 −2 src/public/javascripts/systems.js
  21. +46 −1 src/spec/controllers/system_groups_controller_spec.rb
  22. +2 −0  src/spec/views/activation_keys/_new.html.haml_spec.rb
View
15 src/app/controllers/activation_keys_controller.rb
@@ -183,15 +183,6 @@ def new
setup_environment_selector(current_organization, accessible_envs)
@environment = first_env_in_path(accessible_envs)
- @content_view_labels = [[no_content_view, '']]
- if @environment
- @content_view_labels += ContentView.readable(@organization).non_default.
- in_environment(@environment).collect {|cv| [cv.name, cv.id]}
- else
- @content_view_labels = []
- end
- @selected_content_view = no_content_view
-
render :partial => "new", :locals => {:activation_key => activation_key,
:accessible_envs => accessible_envs}
end
@@ -201,18 +192,12 @@ def edit
accessible_envs = current_organization.environments
setup_environment_selector(current_organization, accessible_envs)
- content_view_labels = [[no_content_view, '']]
- content_view_labels += ContentView.readable(@organization).non_default.
- in_environment(@activation_key.environment).collect {|cv| [cv.name, cv.id]}
- selected_content_view = @activation_key.content_view.nil? ? no_content_view : @activation_key.content_view_id
products = @activation_key.content_view ? @activation_key.content_view.products(@environment) : @environment.products
render :partial => "edit", :locals => {:activation_key => @activation_key,
:editable => ActivationKey.manageable?(current_organization),
:name => controller_display_name,
:accessible_envs => accessible_envs,
- :content_view_labels => content_view_labels,
- :selected_content_view => selected_content_view,
:products => products
}
end
View
134 src/app/controllers/system_groups_controller.rb
@@ -12,34 +12,38 @@
class SystemGroupsController < ApplicationController
- before_filter :panel_options, :only=>[:index, :items, :create, :copy]
- before_filter :find_group, :only=>[:edit, :update, :destroy, :destroy_systems, :systems,
- :show, :add_systems, :remove_systems, :copy]
+ before_filter :panel_options, :only => [:index, :items, :create, :copy]
+ before_filter :find_group, :only => [:edit, :update, :destroy, :destroy_systems, :systems,
+ :show, :add_systems, :remove_systems, :edit_systems,
+ :update_systems, :copy]
before_filter :authorize
def rules
- any_readable = lambda{current_organization && SystemGroup.any_readable?(current_organization)}
- read_perm = lambda{@group.readable?}
- edit_perm = lambda{@group.editable?}
- create_perm = lambda{SystemGroup.creatable?(current_organization)}
- destroy_perm = lambda{@group.deletable?}
- destroy_systems_perm = lambda{@group.systems_deletable?}
+ any_readable = lambda {current_organization && SystemGroup.any_readable?(current_organization)}
+ read_perm = lambda {@group.readable?}
+ edit_perm = lambda {@group.editable?}
+ create_perm = lambda {SystemGroup.creatable?(current_organization)}
+ destroy_perm = lambda {@group.deletable?}
+ destroy_systems_perm = lambda {@group.systems_deletable?}
+ edit_systems_perm = lambda {@group.systems_editable?}
{
- :index=>any_readable,
- :items=>any_readable,
+ :index => any_readable,
+ :items => any_readable,
:new => create_perm,
- :create=>create_perm,
- :copy=>create_perm,
- :edit=>read_perm,
+ :create => create_perm,
+ :copy => create_perm,
+ :edit => read_perm,
:systems => read_perm,
- :update=>edit_perm,
- :destroy=>destroy_perm,
- :destroy_systems=>destroy_systems_perm,
- :show=>read_perm,
- :auto_complete=>any_readable,
- :add_systems=> edit_perm,
- :remove_systems=>edit_perm,
- :validate_name=>any_readable
+ :update => edit_perm,
+ :destroy => destroy_perm,
+ :destroy_systems => destroy_systems_perm,
+ :show => read_perm,
+ :auto_complete => any_readable,
+ :add_systems => edit_perm,
+ :remove_systems => edit_perm,
+ :edit_systems => edit_systems_perm,
+ :update_systems => edit_systems_perm,
+ :validate_name => any_readable
}
end
@@ -48,7 +52,8 @@ def param_rules
:create => {:system_group => [:name, :description, :max_systems]},
:update => {:system_group => [:name, :description, :max_systems]},
:add_systems => [:system_ids, :id],
- :remove_systems => [:system_ids, :id]
+ :remove_systems => [:system_ids, :id],
+ :update_systems => {:system_group => [:environment_id, :content_view_id]}
}
end
@@ -66,15 +71,15 @@ def new
end
def create
- @group = SystemGroup.create!(params[:system_group].merge({:organization_id=>current_organization.id}))
+ @group = SystemGroup.create!(params[:system_group].merge({:organization_id => current_organization.id}))
notify.success _("System Group %s created successfully.") % @group.name
if !search_validate(SystemGroup, @group.id, params[:search])
notify.message _("'%s' did not meet the current search criteria and is not being shown.") % @group.name
render :json => { :no_match => true }
else
respond_to do |format|
- format.html {render :partial => "system_groups/list_group", :locals=>{:item=>@group, :accessor=>"id",
- :name=>controller_display_name}}
+ format.html {render :partial => "system_groups/list_group", :locals => {:item => @group, :accessor => "id",
+ :name => controller_display_name}}
format.json {render :json => @group}
end
end
@@ -93,17 +98,18 @@ def copy
notify.success _("System Group %{new_group} created successfully as a copy of system group %{group}.") % {:new_group => new_group.name, :group => @group.name}
- render :partial => "system_groups/list_group", :locals=>{:item=>new_group, :accessor=>"id", :name=>controller_display_name}
+ render :partial => "system_groups/list_group", :locals=> {:item => new_group, :accessor => "id",
+ :name => controller_display_name}
end
def edit
- render :partial => "edit", :locals => {:filter => @group, :name=>controller_display_name,
- :editable=>@group.editable?
- }
+ render :partial => "edit", :locals => {:filter => @group, :name => controller_display_name,
+ :editable => @group.editable?
+ }
end
def show
- render :partial => "system_groups/list_group", :locals=>{:item=>@group, :accessor=>"id", :name=>controller_display_name}
+ render :partial => "system_groups/list_group", :locals => {:item => @group, :accessor => "id", :name => controller_display_name}
end
def update
@@ -128,13 +134,13 @@ def update
:asynchronous => false
end
- render :text=>to_ret
+ render :text => to_ret
end
def destroy
@group.destroy
notify.success _("System Group %s deleted.") % @group.name
- render :partial => "common/list_remove", :locals => {:id=>params[:id], :name=>controller_display_name}
+ render :partial => "common/list_remove", :locals => {:id => params[:id], :name => controller_display_name}
end
def destroy_systems
@@ -149,14 +155,15 @@ def destroy_systems
notify.success _("Deleted System Group %{group} and it's %{count} systems.") % {:group => @group.name, :count => system_names.length.to_s},
:details => system_names.join("\n")
- render :partial => "common/list_remove.js", :locals => {:id=>params[:id], :name=>controller_display_name}
+ render :partial => "common/list_remove.js", :locals => {:id => params[:id], :name => controller_display_name}
end
def items
ids = SystemGroup.readable(current_organization).collect{|s| s.id}
render_panel_direct(SystemGroup, @panel_options, params[:search], params[:offset], [:name_sort, :asc],
- {:default_field => :name, :load=>true, :filter=>[{:id=>ids},{:organization_id=>[current_organization.id]}]})
+ {:default_field => :name, :load => true, :filter => [{:id => ids},
+ {:organization_id => [current_organization.id]}]})
end
def panel_options
@@ -166,43 +173,66 @@ def panel_options
:titles => [_('Name')],
:create => _('System Group'),
:name => controller_display_name,
- :ajax_scroll=>items_system_groups_path(),
- :enable_create=> SystemGroup.creatable?(current_organization),
- :initial_action=>:systems,
+ :ajax_scroll => items_system_groups_path(),
+ :enable_create => SystemGroup.creatable?(current_organization),
+ :initial_action =>:systems,
:list_partial => 'system_groups/list_groups',
- :ajax_load=>true,
- :search_class=>SystemGroup
+ :ajax_load => true,
+ :search_class => SystemGroup
}
end
def systems
@system_joins = @group.system_system_groups.sort_by{|a| a.system.name}
render :partial => "systems",
- :locals => {:filter => @group, :name=>controller_display_name, :editable=>@group.editable?,
- :systems_deletable=>@group.systems_deletable?}
+ :locals => {:filter => @group, :name => controller_display_name, :editable => @group.editable?,
+ :systems_deletable => @group.systems_deletable?}
end
def add_systems
ids = params[:system_ids].collect{|s| s.to_i} - @group.system_ids #ignore dups
- systems = System.readable(current_organization).where(:id=>ids)
+ systems = System.readable(current_organization).where(:id => ids)
@group.system_ids = (@group.system_ids + systems.collect{|s| s.id}).uniq
@group.save!
- system_joins = @group.system_system_groups.where(:system_id=>ids)
+ system_joins = @group.system_system_groups.where(:system_id => ids)
notify.success _("Successfully added system[s] to group '%s'.") % @group.name
- render :partial=>'system_item', :collection=>system_joins, :as=>:system,
- :locals=>{:editable=>@group.editable?}
+ render :partial => 'system_item', :collection => system_joins, :as => :system,
+ :locals => {:editable => @group.editable?}
end
def remove_systems
- systems = System.readable(current_organization).where(:id=>params[:system_ids]).collect{|s| s.id}
+ systems = System.readable(current_organization).where(:id => params[:system_ids]).collect{|s| s.id}
@group.system_ids = (@group.system_ids - systems).uniq
@group.save!
notify.success _("Successfully removed system[s] from group '%s'.") % @group.name
- render :text=>''
+ render :text => ''
+ end
+
+ def edit_systems
+ accessible_envs = current_organization.environments
+ setup_environment_selector(current_organization, accessible_envs)
+ @organization = current_organization
+ @environment = first_env_in_path(accessible_envs)
+
+ render :partial => "edit_systems",
+ :locals => {:filter => @group, :accessible_envs => accessible_envs}
+ end
+
+ def update_systems
+ unless params[:system_group].blank?
+ @group.systems.each do|system|
+ system.update_attributes!(params[:system_group])
+ end
+ end
+
+ notify.success _("Successfully updated environment and content view for all systems in group %{group}") %
+ {:group => @group.name}
+
+ render :text => ''
end
def auto_complete
@@ -214,11 +244,11 @@ def auto_complete
string query
end
filter :term, {:organization_id => org.id}
- filter :terms, {:id=>SystemGroup.editable(org).collect{|g| g.id}}
+ filter :terms, {:id => SystemGroup.editable(org).collect{|g| g.id}}
end
- render :json=>groups.map{|s| {:label=>s.name, :value=>s.name, :id=>s.id}}
+ render :json => groups.map{|s| {:label => s.name, :value => s.name, :id => s.id}}
rescue Tire::Search::SearchRequestFailed => e
- render :json=>Util::Support.array_with_total
+ render :json => Util::Support.array_with_total
end
def controller_display_name
@@ -227,7 +257,7 @@ def controller_display_name
def validate_name
name = params[:term]
- render :json=>SystemGroup.search("name:#{name}").count
+ render :json => SystemGroup.search("name:#{name}").count
end
def find_group
View
3  src/app/helpers/activation_keys_helper.rb
@@ -11,7 +11,4 @@
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
module ActivationKeysHelper
- def no_content_view
- _("No Content View")
- end
end
View
20 src/app/helpers/application_helper.rb
@@ -278,4 +278,24 @@ def kt_form_for(object, options = {}, &block)
options[:builder] = KatelloFormBuilder
form_for(object, options, &block)
end
+
+ def no_content_view
+ _("No Content View")
+ end
+
+ def content_view_select_labels(organization, environment)
+ labels = [[no_content_view, '']]
+ if environment
+ labels += ContentView.readable(organization).non_default.
+ in_environment(environment).collect {|cv| [cv.name, cv.id]}
+ else
+ labels = []
+ end
+ labels
+ end
+
+ def selected_content_view(content_view)
+ content_view.nil? ? no_content_view : content_view.id
+ end
+
end
View
4 src/app/helpers/systems_helper.rb
@@ -52,10 +52,6 @@ def content_view_select(org, env)
{:tabindex => 2})
end
- def no_content_view
- _('Select Content View')
- end
-
def system_content_view_opts
keys = {}
ContentView.readable(current_organization).non_default.each do |view|
View
4 src/app/views/activation_keys/_edit.html.haml
@@ -59,7 +59,9 @@
%label #{_("Content View")}:
.grid_10.la
- if editable
- = select_tag 'activation_key[content_view_id]', options_for_select(content_view_labels, selected_content_view)
+ = select_tag 'activation_key[content_view_id]',
+ options_for_select(content_view_select_labels(@organization, @activation_key.environment),
+ selected_content_view(@activation_key.content_view))
- else
= @content_view.nil? ? no_content_view : @content_view.name
View
3  src/app/views/activation_keys/_new.html.haml
@@ -23,7 +23,8 @@
- if Katello.config.katello?
= form.field :content_view_id, :label => _("Content View"), :wrapper => {:id => "content_views"}, :grid => [2,7] do
- = select_tag 'activation_key[content_view_id]', options_for_select(@content_view_labels, @selected_content_view),
+ = select_tag 'activation_key[content_view_id]',
+ options_for_select(content_view_select_labels(@organization, @environment), no_content_view),
:tabindex => auto_tab_index
= form.field :usage_limit, :label => _("Usage Limit"), :grid => [2,7] do
View
9 src/app/views/activation_keys/index.html.haml
@@ -14,11 +14,4 @@
= two_panel(@activation_keys, @panel_options)
%div#environment_edit_dialog
-= javascript :activation_key
-
-= javascript do
- :plain
- localize({
- "noContentView": '#{no_content_view}',
- "update_view": '#{escape_javascript(_('Select a Content View'))}'
- });
+= javascript :activation_key
View
4 src/app/views/common/_common_i18n.html.haml
@@ -35,5 +35,7 @@
"description": '#{escape_javascript(_('Description'))}',
"import_in_progress": function(m){ return '#{escape_javascript(_("Import in progress (%M)"))}'.replace("%M", m);},
"current_default_org" : '#{escape_javascript(_('This is your default organization.'))}',
- "make_default_org" : '#{escape_javascript(_('Make this your default organization.'))}'
+ "make_default_org" : '#{escape_javascript(_('Make this your default organization.'))}',
+ "no_content_view" : '#{no_content_view}',
+ "select_content_view": '#{escape_javascript(_('Select a View'))}'
});
View
32 src/app/views/system_groups/_edit_systems.html.haml
@@ -0,0 +1,32 @@
+= content_for :title do
+ = _("Edit Systems' Environment and Content View")
+
+= content_for :subcontent do
+
+ = form_tag update_systems_system_group_path(@group.id), :id => 'update_form',
+ :method => :put, :class => 'env_content_view_selector' do
+
+ = hidden_field_tag 'system_group[environment_id]', @environment.id, :id => :environment_id
+
+ %fieldset
+ .grid_2.ra
+ %label #{_('Choose Environment:')}
+
+ .grid_10.la
+ = environment_selector(:path_widget_class => "grid_7",
+ :path_entries_class => "grid_7", :library_clickable => false,
+ :accessible_envs => accessible_envs,
+ :url_content_views_proc => url_content_views_proc)
+
+ %fieldset
+ .grid_2.ra
+ %label #{_('Content View:')}
+
+ .grid_10.la
+ = select_tag 'system_group[content_view_id]',
+ options_for_select(content_view_select_labels(@organization, @environment), no_content_view),
+ :id => :content_view_id
+
+ = submit_tag _('Save'), :class => 'submit dialogbutton', :id=>"save_button"
+
+= render :template => "layouts/tupane_layout"
View
4 src/app/views/system_groups/_system_item.html.haml
@@ -4,4 +4,8 @@
%input.system_checkbox{:type=>:checkbox, 'data-id'=>system.system.id ,:disabled=>('disabled' if !@group.editable?)}
= system.system.name
%td
+ = system.system.environment.name
+ %td
+ = system.system.content_view.try(:name)
+ %td
= system.created_at
View
9 src/app/views/system_groups/_systems.html.haml
@@ -31,12 +31,21 @@
%input#add_system_input_id{:type=>'hidden'}
%input{:type=>'text', :id=>'add_system_input', :size=>'30', :placeholder => help_text, :title => help_text, :tabindex => auto_tab_index}
%input#add_system.button{:style => 'padding-left: 10px;', :value=>_("Add"), :type=>:button, :tabindex => auto_tab_index}
+
%table#systems_table.filter_table.list
%thead.header
%tr
+ %td{:colspan => 4}
+ %a.subpanel_element{"data-url" => edit_systems_system_group_path(@group.id)}
+ = _("Edit Details for All Systems")
+ %tr
%th
= _("Name")
%th
+ = _("Environment")
+ %th
+ = _("Content View")
+ %th
= _("Added")
%tbody
%tr.empty_row{:class=>(:hidden if !@system_joins.empty?)}
View
3  src/app/views/system_groups/index.html.haml
@@ -6,7 +6,8 @@
"delete_system_group_confirm": '#{escape_javascript(_('Are you sure you want to delete the system group?'))}',
"delete_systems_confirm": '#{escape_javascript(_('Do you also want to delete the systems in the system group?'))}',
"delete_systems_warning": '#{escape_javascript(_('This will completely remove those systems.'))}',
- "delete_system_group_continue": '#{escape_javascript(_('No, only delete the system group.'))}'
+ "delete_system_group_continue": '#{escape_javascript(_('No, only delete the system group.'))}',
+ "change_systems_confirm": '#{escape_javascript(_('Are you sure you want to change all systems in the group?'))}'
});
.grid_16
View
7 src/app/views/systems/_new.html.haml
@@ -52,11 +52,4 @@
= content_for :content do
#{_("You need to create an environment for this org before you can create a system.")}
-= javascript do
- :plain
- localize({
- "noContentView": '#{no_content_view}',
- "update_view": '#{escape_javascript(_('Select a View'))}'
- });
-
= render :template => "layouts/tupane_layout"
View
1  src/config/assets.yml
@@ -133,6 +133,7 @@ javascripts:
- public/javascripts/packages.js
- public/javascripts/package_actions.js
- public/javascripts/auto_complete.js
+ - public/javascripts/env_content_view_selector.js
system_subscriptions:
- public/javascripts/system_subscriptions.js
system_packages:
View
2  src/config/routes.rb
@@ -48,6 +48,8 @@
post :add_systems
post :remove_systems
delete :destroy_systems
+ get :edit_systems
+ put :update_systems
end
resources :events, :controller => "system_group_events", :only => [:index, :show] do
collection do
View
5 src/public/javascripts/activation_key.js
@@ -263,7 +263,7 @@ KT.activation_key = (function($) {
var opt_template = KT.utils.template("<option value='<%= key %>'><%= text %></option>");
// create an html option list using the response
- options += opt_template({key: "", text: i18n.noContentView});
+ options += opt_template({key: "", text: i18n.no_content_view});
$.each(response, function(key, item) {
options += opt_template({key: item.id, text: item.name});
});
@@ -297,12 +297,11 @@ KT.activation_key = (function($) {
highlight_input("#activation_key_content_view_id", add_highlight);
};
highlight_input = function(element_id, add_highlight) {
- var text = element_id.match(/template/) ? "update_template" : "update_view";
var select_input = $(element_id);
if (add_highlight) {
if( !select_input.next('span').hasClass('highlight_input_text')) {
select_input.addClass('highlight_input');
- select_input.after('<span class ="highlight_input_text">' + i18n[text] + '</span>');
+ select_input.after('<span class ="highlight_input_text">' + i18n.select_content_view + '</span>');
}
} else {
select_input.removeClass('highlight_input');
View
179 src/public/javascripts/env_content_view_selector.js
@@ -0,0 +1,179 @@
+/**
+ Copyright 2013 Red Hat, Inc.
+
+ This software is licensed to you under the GNU General Public
+ License as published by the Free Software Foundation; either version
+ 2 of the License (GPLv2) or (at your option) any later version.
+ There is NO WARRANTY for this software, express or implied,
+ including the implied warranties of MERCHANTABILITY,
+ NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
+ have received a copy of GPLv2 along with this software; if not, see
+ http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+ */
+KT.env_content_view_selector = (function(){
+ var settings,
+
+ initialize = function(params) {
+ /**
+ * params:
+ * override_save // (default: true) if false, perform save on form submit
+ * override_cancel // (default: true) if false, perform cancel when cancel button clicked
+ * cv_change_cb() // callback function to perform custom logic after user selects content view
+ * save_success_cb() // callback function to perform custom logic after a successful save
+ * save_error_cb() // callback function to perform custom logic after an unsuccessful save
+ * cancel_success_cb() // callback function to perform custom logic after a successful cancel
+ * cancel_success_cb() // callback function to perform custom logic after an unsuccessful cancel
+ */
+ var pane = $(".env_content_view_selector");
+ if (pane.length === 0){
+ return;
+ }
+
+ settings = params;
+ disable_buttons();
+
+ //Set the callback on the environment selector
+ env_select.click_callback = function(env_id) {
+ save_selected_environment(env_id);
+ get_content_views();
+ };
+
+ $('#content_view_id').unbind('change');
+ $('#content_view_id').change(function() {
+ highlight_content_views(false);
+ enable_buttons();
+
+ if (settings.cv_change_cb) {
+ settings.cv_change_cb();
+ }
+ });
+
+ if (settings.override_save === false) {
+ $('#update_form').unbind('submit');
+ $('#update_form').submit(function(e) {
+ e.preventDefault();
+ save($(this));
+ });
+ }
+
+ if (settings.override_cancel === true) {
+ $('#cancel_button').unbind('click');
+ $('#cancel_button').click(function(e) {
+ e.preventDefault();
+ cancel($(this));
+ });
+ }
+ },
+ disable_buttons = function() {
+ $('#cancel_button').attr("disabled","disabled");
+ $('input[id^=save_button]').attr("disabled","disabled");
+ },
+ enable_buttons = function() {
+ $('#cancel_key').removeAttr('disabled');
+ $('input[id^=save_button]').removeAttr('disabled');
+ },
+ save = function(data) {
+ disable_buttons();
+
+ data.ajaxSubmit({
+ success: function(data) {
+ highlight_content_views(false);
+ enable_buttons();
+ if (settings.save_success_cb) {
+ settings.save_success_cb();
+ }
+ }, error: function(e) {
+ highlight_content_views(false);
+ enable_buttons();
+ if (settings.save_error_cb) {
+ settings.save_error_cb();
+ }
+ }});
+ },
+ cancel = function(data) {
+ var url = $('#cancel_button').attr('data-url');
+ if (url !== undefined) {
+ disable_buttons();
+
+ $.ajax({
+ type: "GET",
+ url: url,
+ cache: false,
+ success: function(response) {
+ $('.panel-content').html(response);
+ if (settings.cancel_success_cb) {
+ settings.cancel_success_cb();
+ }
+ },
+ error: function(data) {
+ initialize_edit();
+ if (settings.cancel_error_cb) {
+ settings.cancel_error_cb();
+ }
+ }
+ });
+ } else {
+ if (settings.cancel_success_cb) {
+ settings.cancel_success_cb();
+ }
+ }
+ },
+ save_selected_environment = function(env_id) {
+ // save the id of the env selected
+ $("#environment_id").attr('value', env_id);
+ },
+ get_content_views = function() {
+ // this function will retrieve the views associated with a given environment and
+ // update the views box with the results
+ var url = $('.path_link.active').attr('data-content_views_url');
+ if (url !== undefined) {
+ disable_buttons();
+ $.ajax({
+ type: "GET",
+ url: url,
+ cache: false,
+ success: function(response) {
+ // update the appropriate content on the page
+ var options = '';
+ var opt_template = KT.utils.template("<option value='<%= key %>'><%= text %></option>");
+
+ // create an html option list using the response
+ options += opt_template({key: "", text: i18n.no_content_view});
+ $.each(response, function(key, item) {
+ options += opt_template({key: item.id, text: item.name});
+ });
+
+ $("#content_view_id").html(options);
+
+ if (response.length > 0) {
+ highlight_content_views(true);
+ }
+ enable_buttons();
+ },
+ error: function(data) {
+ enable_buttons();
+ }
+ });
+ }
+ },
+ highlight_content_views = function(add_highlight) {
+ highlight_input("#content_view_id", add_highlight);
+ },
+ highlight_input = function(element_id, add_highlight) {
+ var select_input = $(element_id);
+ if (add_highlight) {
+ if( !select_input.next('span').hasClass('highlight_input_text')) {
+ select_input.addClass('highlight_input');
+ select_input.after('<span class ="highlight_input_text">' + i18n.select_content_view + '</span>');
+ }
+ } else {
+ select_input.removeClass('highlight_input');
+ $('.highlight_input_text').remove();
+ }
+ };
+ return {
+ initialize: initialize,
+ save: save,
+ cancel: cancel
+ }
+})();
View
40 src/public/javascripts/system_groups.js
@@ -21,9 +21,10 @@ $(document).ready(function() {
KT.menu.hoverMenu(item, { top : '75px' });
});
- KT.system_groups.init();
+ KT.system_groups.initialize();
KT.system_groups.new_setup();
KT.system_groups.details_setup();
+ KT.system_groups.env_content_view_setup();
});
});
@@ -152,7 +153,7 @@ KT.system_groups = (function(){
}
});
},
- init = function(){
+ initialize = function(){
$('.pane_action.remove').bind('click', prompt_to_destroy_group);
},
prompt_to_destroy_group = function(e) {
@@ -359,15 +360,44 @@ KT.system_groups = (function(){
var url = add ? KT.routes.add_systems_system_group_path(grp_id) :
KT.routes.remove_systems_system_group_path(grp_id);
$.post(url, {'system_ids':sys_ids}, cb).error(error_cb);
+ },
+ env_content_view_setup = function(){
+ var pane = $(".env_content_view_selector");
+ if (pane.length === 0){
+ return;
+ }
+
+ KT.env_content_view_selector.initialize(
+ {
+ save_success_cb: updated_env_content_view,
+ override_save: true
+ }
+ );
+
+ $('#update_form').unbind('submit');
+ $('#update_form').submit(function(e) {
+ var form = $(this);
+ e.preventDefault();
+ KT.common.customConfirm({
+ message: i18n.change_systems_confirm,
+ yes_callback: function(){
+ KT.env_content_view_selector.save(form);
+ }
+ });
+ });
+ },
+ updated_env_content_view = function (){
+ KT.panel.panelAjax('', KT.routes.systems_system_group_path($('#system_group_systems').data('id')) ,$('#panel'));
+ KT.panel.closeSubPanel($('#subpanel'));
};
return {
- init: init,
+ initialize: initialize,
new_setup: new_setup,
details_setup: details_setup,
systems_setup: systems_setup,
+ env_content_view_setup: env_content_view_setup,
add_system : add_system,
refresh_list_item: refresh_list_item
}
-})();
-
+})();
View
4 src/public/javascripts/systems.js
@@ -418,7 +418,7 @@ KT.systems_page = (function() {
var opt_template = KT.utils.template("<option value='<%= key %>'><%= text %></option>");
// create an html option list using the response
- options += opt_template({key: "", text: i18n.noContentView});
+ options += opt_template({key: "", text: i18n.no_content_view});
$.each(response, function(key, item) {
options += opt_template({key: item.id, text: item.name});
});
@@ -438,7 +438,7 @@ KT.systems_page = (function() {
if( !select_input.next('span').hasClass('highlight_input_text')) {
select_input.addClass('highlight_input');
select_input.after('<span class ="highlight_input_text">' +
- i18n["update_view"] + '</span>');
+ i18n.select_content_view + '</span>');
}
} else {
select_input.removeClass('highlight_input');
View
47 src/spec/controllers/system_groups_controller_spec.rb
@@ -328,6 +328,51 @@
end
end
- end
+ describe "GET edit_systems" do
+ let(:action) {:edit_systems}
+ let(:req) { get :edit_systems, :id => @group.id}
+ let(:authorized_user) do
+ user_with_permissions { |u| u.can(:update_systems, :system_groups, @group.id, @org) }
+ end
+ let(:unauthorized_user) do
+ user_without_permissions
+ end
+ it_should_behave_like "protected action"
+
+ it "should render edit_systems partial" do
+ get :edit_systems, :id => @group.id
+ response.should be_success
+ response.should render_template(:partial => '_edit_systems')
+ end
+ end
+
+ describe "PUT update_systems" do
+ let(:action) {:update_systems}
+ let(:req) { put :update_systems, :id => @group.id}
+ let(:authorized_user) do
+ user_with_permissions { |u| u.can(:update_systems, :system_groups, @group.id, @org) }
+ end
+ let(:unauthorized_user) do
+ user_without_permissions
+ end
+ it_should_behave_like "protected action"
+
+
+ it "should update systems successfully" do
+ Resources::Candlepin::Consumer.stub!(:get).and_return({:uuid => uuid, :owner => {:key => uuid}})
+
+ next_environment = KTEnvironment.create!(:name => "TEST", :label => "TEST", :prior => @environment,
+ :organization => @org)
+ @group.systems = [@system]
+ @group.save
+ controller.should notify.success
+ put :update_systems, :id => @group.id, :system_group=>{:environment_id => next_environment.id}
+
+ response.should be_success
+ @system.reload.environment.should == next_environment
+ end
+ end
+
+ end
end
View
2  src/spec/views/activation_keys/_new.html.haml_spec.rb
@@ -13,6 +13,7 @@
require 'spec_helper'
describe "activation_keys/_new.html.haml" do
+
before(:each) do
@environment = assign(:environment, stub_model(KTEnvironment,
:name => "dev").as_new_record)
@@ -27,6 +28,7 @@
@content_view_labels = []
@selected_content_view = "No Content View"
view.stub!(:environment_selector)
+ view.stub!(:content_view_select_labels).and_return([])
render :partial => "new", :locals => {:accessible_envs => [@environment]}
end
Something went wrong with that request. Please try again.