mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Admin can delete enterprise relationships
This commit is contained in:
@@ -4,8 +4,12 @@ Admin.controller "AdminEnterpriseRelationshipsCtrl", ($scope, $http, EnterpriseR
|
||||
|
||||
$scope.create = ->
|
||||
$http.post('/admin/enterprise_relationships', {enterprise_relationship: {parent_id: $scope.parent_id, child_id: $scope.child_id}}).success (data, status) =>
|
||||
$scope.EnterpriseRelationships.enterprise_relationships.unshift({parent_name: data.parent_name, child_name: data.child_name})
|
||||
$scope.EnterpriseRelationships.enterprise_relationships.unshift(data)
|
||||
$scope.errors = ""
|
||||
|
||||
.error (response, status) =>
|
||||
$scope.errors = response.errors
|
||||
|
||||
$scope.delete = (enterprise_relationship) ->
|
||||
if confirm("Are you sure?")
|
||||
$scope.EnterpriseRelationships.delete enterprise_relationship
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
Admin.factory 'EnterpriseRelationships', (enterprise_relationships) ->
|
||||
Admin.factory 'EnterpriseRelationships', ($http, enterprise_relationships) ->
|
||||
new class EnterpriseRelationships
|
||||
constructor: ->
|
||||
@enterprise_relationships = enterprise_relationships
|
||||
|
||||
delete: (er) ->
|
||||
ers = @enterprise_relationships
|
||||
$http.delete('/admin/enterprise_relationships/' + er.id).success (data) ->
|
||||
ers.splice ers.indexOf(er), 1
|
||||
|
||||
@@ -14,5 +14,11 @@ module Admin
|
||||
render status: 400, json: {errors: @enterprise_relationship.errors.full_messages.join(', ')}
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@enterprise_relationship = EnterpriseRelationship.find params[:id]
|
||||
@enterprise_relationship.destroy
|
||||
render nothing: true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -27,3 +27,5 @@
|
||||
%tr{"ng-repeat" => "enterprise_relationship in EnterpriseRelationships.enterprise_relationships"}
|
||||
%td {{ enterprise_relationship.parent_name }}
|
||||
%td {{ enterprise_relationship.child_name }}
|
||||
%td.actions
|
||||
%a.delete-enterprise-relationship.icon-trash.no-text{'ng-click' => 'delete(enterprise_relationship)'}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
object @enterprise_relationship
|
||||
|
||||
attributes :parent_id, :child_id
|
||||
attributes :id, :parent_id, :child_id
|
||||
|
||||
node :parent_name do |enterprise_relationship|
|
||||
enterprise_relationship.parent.name
|
||||
|
||||
@@ -22,8 +22,8 @@ feature %q{
|
||||
|
||||
# Then I should see the relationships
|
||||
within('table#enterprise-relationships') do
|
||||
page.should have_table_row [e1.name, e2.name]
|
||||
page.should have_table_row [e3.name, e4.name]
|
||||
page.should have_table_row [e1.name, e2.name, '']
|
||||
page.should have_table_row [e3.name, e4.name, '']
|
||||
end
|
||||
end
|
||||
|
||||
@@ -37,7 +37,7 @@ feature %q{
|
||||
select 'Two', from: 'enterprise_relationship_child_name'
|
||||
click_button 'Create'
|
||||
|
||||
page.should have_table_row [e1.name, e2.name]
|
||||
page.should have_table_row [e1.name, e2.name, '']
|
||||
EnterpriseRelationship.where(parent_id: e1, child_id: e2).should be_present
|
||||
end
|
||||
|
||||
@@ -60,5 +60,17 @@ feature %q{
|
||||
end
|
||||
|
||||
|
||||
scenario "deleting a relationship"
|
||||
scenario "deleting a relationship" do
|
||||
e1 = create(:enterprise, name: 'One')
|
||||
e2 = create(:enterprise, name: 'Two')
|
||||
er = create(:enterprise_relationship, parent: e1, child: e2)
|
||||
|
||||
visit admin_enterprise_relationships_path
|
||||
page.should have_table_row [e1.name, e2.name, '']
|
||||
|
||||
first("a.delete-enterprise-relationship").click
|
||||
|
||||
page.should_not have_table_row [e1.name, e2.name, '']
|
||||
EnterpriseRelationship.where(id: er.id).should be_empty
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user