When viewing enterprise fees, only show those for the enterprise I select

This commit is contained in:
Rohan Mitchell
2013-10-18 14:44:01 +11:00
parent 91f14dcd4c
commit ea17e475a6
4 changed files with 39 additions and 6 deletions

View File

@@ -1,6 +1,17 @@
angular.module('enterprise_fees', [])
.controller('AdminEnterpriseFeesCtrl', ['$scope', '$http', function($scope, $http) {
$http.get('/admin/enterprise_fees.json?include_calculators=1').success(function(data) {
.controller('AdminEnterpriseFeesCtrl', ['$scope', '$http', '$window', function($scope, $http, $window) {
$scope.enterpriseFeesUrl = function() {
var url = '/admin/enterprise_fees.json?include_calculators=1';
var match = $window.location.search.match(/enterprise_id=(\d+)/);
if(match) {
url += "&"+match[0];
}
return url;
};
$http.get($scope.enterpriseFeesUrl()).success(function(data) {
$scope.enterprise_fees = data;
for(i=0; i<3; i++) {

View File

@@ -51,7 +51,14 @@ module Admin
end
def collection
EnterpriseFee.managed_by(spree_current_user).order('enterprise_id', 'fee_type', 'name')
collection = EnterpriseFee.managed_by(spree_current_user).order('enterprise_id', 'fee_type', 'name')
if params.key? :enterprise_id
enterprise = Enterprise.find params[:enterprise_id]
collection = collection.for_enterprise(enterprise)
end
collection
end
end
end

View File

@@ -43,7 +43,7 @@
<%= link_to_with_icon 'icon-chevron-right', 'Payment Methods', spree.admin_payment_methods_path(enterprise_id: enterprise.id) %> (<%= enterprise.payment_methods.count %>)<br />
<%= link_to_with_icon 'icon-plane', 'Shipping Methods', spree.admin_shipping_methods_path(enterprise_id: enterprise.id) %> (<%= enterprise.shipping_methods.count %>)<br />
<%= link_to_with_icon 'icon-money', 'Enterprise Fees', main_app.admin_enterprise_fees_path %> (<%= enterprise.enterprise_fees.count %>)
<%= link_to_with_icon 'icon-money', 'Enterprise Fees', main_app.admin_enterprise_fees_path(enterprise_id: enterprise.id) %> (<%= enterprise.enterprise_fees.count %>)
</td>
</tr>
<% end %>

View File

@@ -128,8 +128,8 @@ feature %q{
let(:enterprise_user) { create_enterprise_user }
let(:distributor1) { create(:distributor_enterprise, name: 'First Distributor') }
let(:distributor2) { create(:distributor_enterprise, name: 'Second Distributor') }
let(:ef1) { create(:enterprise_fee, name: 'One', distributors: [distributor1]) }
let(:ef2) { create(:enterprise_fee, name: 'Two', distributors: [distributor2]) }
let(:ef1) { create(:enterprise_fee, name: 'One', enterprise: distributor1) }
let(:ef2) { create(:enterprise_fee, name: 'Two', enterprise: distributor2) }
before(:each) do
enterprise_user.enterprise_roles.build(enterprise: distributor1).save
@@ -151,5 +151,20 @@ feature %q{
enterprise_fee = EnterpriseFee.find_by_name 'foo'
enterprise_fee.enterprise.should == distributor1
end
it "shows me only enterprise fees for the enterprise I select" do
ef1
ef2
click_link 'Enterprises'
within(".enterprise-#{distributor1.id}") { click_link 'Enterprise Fees' }
page.should have_field 'enterprise_fee_set_collection_attributes_0_name', with: 'One'
page.should_not have_field 'enterprise_fee_set_collection_attributes_1_name', with: 'Two'
click_link 'Enterprises'
within(".enterprise-#{distributor2.id}") { click_link 'Enterprise Fees' }
page.should_not have_field 'enterprise_fee_set_collection_attributes_0_name', with: 'One'
page.should have_field 'enterprise_fee_set_collection_attributes_0_name', with: 'Two'
end
end
end