Allow adding cpid to null product version

This will be used for associated a CPID to the product with no
specific version in mind.

Change-Id: I419a6bb18cde8f31088d25cf8d9113dde7a4bc1f
This commit is contained in:
Paul Van Eck 2017-02-15 11:52:12 -08:00
parent f1ed8079ec
commit 3e6bfbab71
5 changed files with 64 additions and 6 deletions

View File

@ -7,6 +7,7 @@
<strong>Name:</strong> {{ctrl.product.name}}<br />
<strong>Product ID:</strong> {{ctrl.id}}<br />
<strong>Description:</strong> {{ctrl.product.description}}<br />
<span ng-if="ctrl.nullVersion.cpid"><strong>CPID:</strong> {{ctrl.nullVersion.cpid}}<br /></span>
<strong>Publicity:</strong> {{ctrl.product.public ? 'Public' : 'Private'}}<br />
<strong>Vendor Name:</strong> <a ui-sref="vendor({vendorID: ctrl.vendor.id})">{{ctrl.vendor.name}}</a><br />
<div ng-if="ctrl.productProperties">

View File

@ -7,6 +7,7 @@
<strong>Name:</strong> {{ctrl.product.name}}<br />
<strong>Product ID:</strong> {{ctrl.id}}<br />
<strong>Description:</strong> {{ctrl.product.description}}<br />
<span ng-if="ctrl.nullVersion.cpid"><strong>CPID:</strong> {{ctrl.nullVersion.cpid}}<br /></span>
<strong>Publicity:</strong> {{ctrl.product.public ? 'Public' : 'Private'}}<br />
<strong>Vendor Name:</strong> <a ui-sref="vendor({vendorID: ctrl.vendor.id})">{{ctrl.vendor.name}}</a><br />
<div ng-if="ctrl.productProperties">

View File

@ -42,6 +42,20 @@
</div>
</div>
<div><small><a ng-click="modal.addField()"><span class="glyphicon glyphicon-plus"></span>&nbsp;Add new property</a></small></div>
<br />
<div ng-if="modal.productVersion.id">
<label for="name">Product CPID</label>
<small>
<span class="text-muted glyphicon glyphicon-info-sign"
title="You can optionally associate a cloud provider ID to this product. This is used to automatically associate uploaded test results to the product.">
</span>
</small>
<input type="text"
class="form-control"
id="cpid"
ng-model="modal.productVersion.cpid">
<br />
</div>
</div>
<div ng-show="modal.showError" class="alert alert-danger" role="alert">
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>

View File

@ -112,6 +112,14 @@
ctrl.productVersionsRequest = $http.get(content_url).success(
function(data) {
ctrl.productVersions = data;
// Determine the null version.
for (var i = 0; i < data.length; i++) {
if (data[i].version === null) {
ctrl.nullVersion = data[i];
break;
}
}
}
).error(function(error) {
ctrl.showError = true;
@ -310,6 +318,9 @@
resolve: {
product: function () {
return ctrl.product;
},
version: function () {
return ctrl.nullVersion;
}
}
});
@ -383,7 +394,8 @@
.controller('ProductEditModalController', ProductEditModalController);
ProductEditModalController.$inject = [
'$uibModalInstance', '$http', '$state', 'product', 'refstackApiUrl'
'$uibModalInstance', '$http', '$state', 'product',
'version', 'refstackApiUrl'
];
/**
@ -391,7 +403,7 @@
* This controls the modal that allows editing a product.
*/
function ProductEditModalController($uibModalInstance, $http,
$state, product, refstackApiUrl) {
$state, product, version, refstackApiUrl) {
var ctrl = this;
@ -403,6 +415,8 @@
ctrl.product = product;
ctrl.productName = product.name;
ctrl.productProperties = [];
ctrl.productVersion = angular.copy(version);
ctrl.originalCpid = version ? version.cpid : null;
parseProductProperties();
@ -434,9 +448,29 @@
if (ctrl.productName != ctrl.product.name) {
content.name = ctrl.product.name;
}
// Request for product detail updating.
$http.put(url, content).success(function() {
ctrl.showSuccess = true;
$state.reload();
// Request for product version CPID update if it has changed.
if (ctrl.productVersion &&
ctrl.originalCpid !== ctrl.productVersion.cpid) {
url = url + '/versions/' + ctrl.productVersion.id;
content = {'cpid': ctrl.productVersion.cpid};
$http.put(url, content).success(function() {
ctrl.showSuccess = true;
ctrl.originalCpid = ctrl.productVersion.cpid;
$state.reload();
}).error(function(error) {
ctrl.showError = true;
ctrl.error = error.detail;
});
}
else {
ctrl.showSuccess = true;
$state.reload();
}
}).error(function(error) {
ctrl.showError = true;
ctrl.error = error.detail;

View File

@ -1478,7 +1478,9 @@ describe('Refstack controllers', function () {
describe('ProductEditModalController', function() {
var ctrl, modalInstance, state;
var fakeProduct = {'name': 'Foo', 'description': 'Bar', 'id': '1234',
'properties': {'key1': 'value1'}};
'properties': {'key1': 'value1'}};
var fakeVersion = {'version': null, 'product_id': '1234',
'cpid': null, 'id': 'asdf'};
beforeEach(inject(function ($controller) {
modalInstance = {
@ -1489,7 +1491,8 @@ describe('Refstack controllers', function () {
};
ctrl = $controller('ProductEditModalController',
{$uibModalInstance: modalInstance, $state: state,
product: fakeProduct}
product: fakeProduct,
version: fakeVersion}
);
}));
@ -1510,9 +1513,14 @@ describe('Refstack controllers', function () {
'name': 'Foo1', 'description': 'Bar',
'properties': {'key1': 'value1'}
};
var verContent = {'cpid': 'abc'};
$httpBackend.expectPUT(
fakeApiUrl + '/products/1234', expectedContent)
.respond(200, '');
$httpBackend.expectPUT(
fakeApiUrl + '/products/1234/versions/asdf', verContent)
.respond(200, '');
ctrl.productVersion.cpid = 'abc';
ctrl.product.name = 'Foo1';
ctrl.saveChanges();
$httpBackend.flush();