Skip to content

Commit

Permalink
fixes #5412 - adding content view deletion ui
Browse files Browse the repository at this point in the history
  • Loading branch information
jlsherrill committed Apr 25, 2014
1 parent 5fc7b85 commit f37f2b5
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ angular.module('Bastion.content-views').config(['$stateProvider', function ($sta
controller: 'ContentViewVersionDeletionConfirmController',
templateUrl: 'content-views/deletion/views/version-deletion-confirm.html'
})
.state('content-views.details.deletion', {
collapsed: true,
url: '/delete',
controller: 'ContentViewDeletionController',
templateUrl: 'content-views/deletion/views/content-view-deletion.html'
})
.state('content-views.details.repositories', {
abstract: true,
collapsed: true,
Expand Down
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;
}

}]
);
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>
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h2 class="col-sm-6" ng-show="contentView.composite" translate>Composite Content
<span translate>Clone View</span>
</a>

<button ng-hide="true" class="btn btn-default" ui-sref="content-views.index">
<button class="btn btn-default" ui-sref="content-views.details.deletion">
<i class="icon-trash"></i>
{{ "Remove View" | translate }}
</button>
Expand Down Expand Up @@ -81,7 +81,7 @@ <h2 class="col-sm-6" ng-show="contentView.composite" translate>Composite Content
</a>
</li>

<li ng-class="{active: isState('content-views.details.info')}">
<li ng-class="{active: isState('content-views.details.info') || isState('content-views.details.deletion')}">
<a ui-sref="content-views.details.info" translate>
Details
</a>
Expand Down
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));
});
});

0 comments on commit f37f2b5

Please sign in to comment.