-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #5412 - adding content view deletion ui
- Loading branch information
1 parent
5fc7b85
commit f37f2b5
Showing
5 changed files
with
184 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...app/assets/javascripts/bastion/content-views/deletion/content-view-deletion.controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Copyright 2014 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. | ||
*/ | ||
|
||
/** | ||
* @ngdoc object | ||
* @name Bastion.content-views.controller:ContentViewDeletionController | ||
* | ||
* @requires $scope | ||
* @requires ContentView | ||
* | ||
* @description | ||
* Provides the functionality for deleting Content Views | ||
*/ | ||
angular.module('Bastion.content-views').controller('ContentViewDeletionController', | ||
['$scope', 'ContentView', function ($scope, ContentView) { | ||
|
||
if ($scope.versions === undefined) { | ||
$scope.reloadVersions(); | ||
} | ||
|
||
$scope.delete = function () { | ||
$scope.working = true; | ||
ContentView.remove({id: $scope.contentView.id}, success, failure); | ||
}; | ||
|
||
$scope.conflictingVersions = function () { | ||
return _.reject($scope.versions, function (version) { | ||
return version.environments.length === 0; | ||
}); | ||
}; | ||
|
||
$scope.environmentNames = function (version) { | ||
return _.pluck(version.environments, 'name'); | ||
}; | ||
|
||
function success() { | ||
$scope.removeRow($scope.contentView.id); | ||
$scope.transitionTo('content-views.index'); | ||
$scope.working = false; | ||
} | ||
|
||
function failure(response) { | ||
$scope.$parent.errorMessages = [response.data.displayMessage]; | ||
$scope.working = false; | ||
} | ||
|
||
}] | ||
); |
63 changes: 63 additions & 0 deletions
63
...on/app/assets/javascripts/bastion/content-views/deletion/views/content-view-deletion.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<span page-title ng-model="contentView">{{ 'Remove Content View ' | translate }} {{ contentView.name }}</span> | ||
|
||
<div> | ||
<h3 translate>Delete {{ contentView.name }}</h3> | ||
|
||
<div ng-show="conflictingVersions().length > 0"> | ||
<i class="icon-warning-sign"></i> | ||
<span translate> | ||
{{ contentView.name }} cannot be deleted as one or more Content View Versions are still promoted to a Lifecycle Environment. | ||
Each Content View Version must be removed from their Lifecycle Environments before the Content View can be deleted. | ||
</span> | ||
|
||
<br/><br/> | ||
<table class="table table-striped table-bordered" alch-table="table"> | ||
<thead> | ||
<tr> | ||
<th translate>Version</th> | ||
<th translate>Lifecycle Environments</th> | ||
<th translate>Actions</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr ng-repeat="version in conflictingVersions()"> | ||
<td>{{ version.version }}</td> | ||
<td>{{ environmentNames(version).join(', ') }}</td> | ||
<td> | ||
<a ui-sref="content-views.details.version-deletion.environments({contentViewId: contentView.id, versionId: version.id})"> | ||
<button class="btn btn-default"> | ||
<i class="icon-trash"></i> | ||
<span translate>Remove Version</span> | ||
</button> | ||
</a> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
|
||
<div class="details" ng-show="conflictingVersions().length === 0"> | ||
<p translate> | ||
Are you sure you want to delete Content View "{{ contentView.name }}"? | ||
</p> | ||
|
||
<div ng-show="versions.length > 0"> | ||
<i class="icon-warning-sign"></i> | ||
<span translate translate-n="versions.length" translate-plural=" As part of this deletion, {{ versions.length }} Content View Versions will be deleted."> | ||
As part of this deletion, 1 Content View Version will be deleted. | ||
</span> | ||
</div> | ||
|
||
<br/><br/> | ||
<div class="fr"> | ||
<button ng-disabled="working" class="btn-danger btn-lg" ng-click="delete()" > | ||
<i class="icon-spinner icon-spin" ng-show="working"></i> | ||
<span translate>Delete</span> | ||
</button> | ||
|
||
<a ui-sref="content-views.details.versions" ng-disabled="working" class="btn btn-default btn-lg" translate role="button"> | ||
Cancel | ||
</a> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
engines/bastion/test/content-views/details/deletion/content-view-deletion.controller.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* Copyright 2014 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. | ||
**/ | ||
|
||
describe('Controller: ContentViewDeletionController', function() { | ||
var $scope, | ||
versions, | ||
ContentView; | ||
|
||
beforeEach(module('Bastion.content-views', 'Bastion.test-mocks')); | ||
|
||
beforeEach(inject(function($injector) { | ||
var $controller = $injector.get('$controller'); | ||
|
||
versions = [{version: 1, environments:[{name: "name"}]}, {version: 2, environments: []}]; | ||
ContentView = $injector.get('MockResource').$new(); | ||
|
||
$scope = $injector.get('$rootScope').$new(); | ||
$scope.$stateParams = {contentViewId: 1}; | ||
$scope.contentView = {id: '99'}; | ||
|
||
$scope.reloadVersions = function () { | ||
$scope.versions = versions; | ||
}; | ||
|
||
$controller('ContentViewDeletionController', { | ||
$scope: $scope, | ||
ContentView: ContentView | ||
}); | ||
})); | ||
|
||
it("properly detects conflicting versions", function() { | ||
expect($scope.conflictingVersions()[0]).toBe(versions[0]); | ||
}); | ||
|
||
it("properly extracts environment names", function () { | ||
expect($scope.environmentNames(versions[0])[0]).toBe("name"); | ||
}); | ||
|
||
it("properly deletes the view", function () { | ||
spyOn(ContentView, 'remove'); | ||
$scope.delete(); | ||
expect(ContentView.remove).toHaveBeenCalledWith({id: $scope.contentView.id}, | ||
jasmine.any(Function), jasmine.any(Function)); | ||
}); | ||
}); |