Skip to content

Commit

Permalink
filters - adapting for new panel ajax code
Browse files Browse the repository at this point in the history
  • Loading branch information
jlsherrill committed Oct 31, 2011
1 parent 722b087 commit 7bbd53d
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 32 deletions.
29 changes: 19 additions & 10 deletions src/app/controllers/filters_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,12 @@ def index
@product_hash[prod.id] = {:name=>prod.name, :repos=>repos, :id=>prod.id}
}

@filters = Filter.readable(current_organization).search_for(params[:search]).order('pulp_id desc').
limit(current_user.page_size)

render "index"
end

def items
start = params[:offset]
@filters = Filter.readable(current_organization).search_for(params[:search]).order('pulp_id desc').
limit(current_user.page_size).offset(start)
render_panel_items @providers, @panel_options
render_panel_items(Filter.readable(current_organization).order('lower(pulp_id)'), @panel_options,
params[:search], params[:offset])
end

def auto_complete_products_repos
Expand Down Expand Up @@ -92,6 +87,11 @@ def update
end
@filter.save!
notice _("Package Filter '#{@filter.name}' has been updated.")

if not Filter.where(:id => @filter.id).search_for(params[:search]).include?(@filter)
notice _("'#{@filter["name"]}' no longer matches the current search criteria."), { :level => :message, :synchronous_request => true }
end

render :text=>to_ret
rescue Exception=>e
errors e
Expand All @@ -111,8 +111,16 @@ def new
def create
@filter = Filter.create!(params[:filter].merge({:organization_id=>current_organization.id}))
notice N_("Filter #{@filter.name} created successfully.")
render :partial=>"common/list_item", :locals=>{:item=>@filter, :initial_action=>"packages", :accessor=>"id", :columns=>['name'], :name=>controller_display_name}

if !Filter.where(:id => @filter.id).search_for(params[:search]).include?(@filter)

notice _("'#{@filter.name}' did not meet the current search criteria and is not being shown."),
{ :level => 'message', :synchronous_request => false }
render :json => { :no_match => true }
else
render :partial=>"common/list_item", :locals=>{:item=>@filter, :initial_action=>"packages", :accessor=>"id",
:columns=>['name'], :name=>controller_display_name}
end

rescue Exception=> e
errors e
render :text=>e, :status=>500
Expand Down Expand Up @@ -189,7 +197,8 @@ def panel_options
:name => controller_display_name,
:ajax_scroll=>items_filters_path(),
:enable_create=> Filter.creatable?(current_organization),
:initial_action=>:packages
:initial_action=>:packages,
:ajax_load=>true
}
end

Expand Down
2 changes: 0 additions & 2 deletions src/app/views/filters/_packages.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
= javascript :provider

= content_for :title do
#{@filter.name}

Expand Down
1 change: 0 additions & 1 deletion src/app/views/filters/_products.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
= javascript :provider

:javascript
KT.filters.set_current_filter($.parseJSON('#{escape_javascript(objectify(@filter).to_json)}'));
Expand Down
18 changes: 10 additions & 8 deletions src/app/views/filters/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@

.grid_16
= help_tip_button
= help_tip(_("Package Filters allow you to blacklist packages from being promoted into subsequent environments. " + |
"Simply create a filter and add either a package name or regular expression to the filter. " + |
"You can associate the filter with entire products or individual repositories within any product.")) |

.grid_16#main
= two_panel(@filters, @panel_options)

= javascript :edit, :form, :filters
= include_common_i18n
= include_editable_i18n
Expand All @@ -19,11 +29,3 @@

});

.grid_16
= help_tip_button
= help_tip(_("Package Filters allow you to blacklist packages from being promoted into subsequent environments. " + |
"Simply create a filter and add either a package name or regular expression to the filter. " + |
"You can associate the filter with entire products or individual repositories within any product.")) |

.grid_16#main
= two_panel(@filters, @panel_options)
12 changes: 2 additions & 10 deletions src/public/javascripts/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,10 @@
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
*/

$(document).ready(function() {


$('#new_filter').live('submit', function(e) {
// disable submit to avoid duplicate clicks
$('input[id^=filter_save]').attr("disabled", true);
KT.panel.list.registerPage('filters', { create : 'new_filter' });

e.preventDefault();
$(this).ajaxSubmit({success:KT.filters.success_create , error:KT.filters.failure_create});
});


$(document).ready(function() {

$("#container").delegate("#remove_packages", 'click', function(e){
KT.filters.remove_packages();
Expand Down
25 changes: 24 additions & 1 deletion src/spec/controllers/filters_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@

describe "GET items" do
it "requests filters using search criteria" do

get :items
response.should be_success
assigns(:items)
end
end

Expand Down Expand Up @@ -191,7 +193,7 @@
@organization = new_test_org
@testuser = User.create!(:username=>"TestUser", :password=>"foobar")
@filter = Filter.create!(:name => 'filter1', :organization => @organization)

@filter2 = Filter.create!(:name=>'filter2', :organization => @organization)
end
describe "GET index" do
let(:action) {:index}
Expand All @@ -206,6 +208,27 @@
it_should_behave_like "protected action"
end


describe "GET items" do
let(:action) {:items}
let(:req) {get 'items' }
let(:authorized_user) do
user_with_permissions { |u| u.can(:read, :filters, nil, @organization) }
end
let(:unauthorized_user) do
user_without_permissions
end
let(:on_success) do
assigns(:items).should_not include @filter2
assigns(:items).should include @filter
end


it_should_behave_like "protected action"
end



describe "PUT update" do
let(:action) {:update}
let(:req) {put 'update', {:id=> @filter.id}}
Expand Down

0 comments on commit 7bbd53d

Please sign in to comment.