diff --git a/refstack-ui/app/components/products/cloud.html b/refstack-ui/app/components/products/cloud.html
index bf812d6c..e85220c6 100644
--- a/refstack-ui/app/components/products/cloud.html
+++ b/refstack-ui/app/components/products/cloud.html
@@ -7,6 +7,7 @@
Name: {{ctrl.product.name}}
Product ID: {{ctrl.id}}
Description: {{ctrl.product.description}}
+ CPID: {{ctrl.nullVersion.cpid}}
Publicity: {{ctrl.product.public ? 'Public' : 'Private'}}
Vendor Name: {{ctrl.vendor.name}}
diff --git a/refstack-ui/app/components/products/distro.html b/refstack-ui/app/components/products/distro.html
index ec12d380..12ab93e6 100644
--- a/refstack-ui/app/components/products/distro.html
+++ b/refstack-ui/app/components/products/distro.html
@@ -7,6 +7,7 @@
Name: {{ctrl.product.name}}
Product ID: {{ctrl.id}}
Description: {{ctrl.product.description}}
+
CPID: {{ctrl.nullVersion.cpid}}
Publicity: {{ctrl.product.public ? 'Public' : 'Private'}}
Vendor Name: {{ctrl.vendor.name}}
diff --git a/refstack-ui/app/components/products/partials/productEditModal.html b/refstack-ui/app/components/products/partials/productEditModal.html
index f49e3522..cd1e7459 100644
--- a/refstack-ui/app/components/products/partials/productEditModal.html
+++ b/refstack-ui/app/components/products/partials/productEditModal.html
@@ -42,6 +42,20 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/refstack-ui/app/components/products/productController.js b/refstack-ui/app/components/products/productController.js
index 3d7695b5..ab70b419 100644
--- a/refstack-ui/app/components/products/productController.js
+++ b/refstack-ui/app/components/products/productController.js
@@ -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;
}
}
});
@@ -385,7 +396,8 @@
.controller('ProductEditModalController', ProductEditModalController);
ProductEditModalController.$inject = [
- '$uibModalInstance', '$http', '$state', 'product', 'refstackApiUrl'
+ '$uibModalInstance', '$http', '$state', 'product',
+ 'version', 'refstackApiUrl'
];
/**
@@ -393,7 +405,7 @@
* This controls the modal that allows editing a product.
*/
function ProductEditModalController($uibModalInstance, $http,
- $state, product, refstackApiUrl) {
+ $state, product, version, refstackApiUrl) {
var ctrl = this;
@@ -405,6 +417,8 @@
ctrl.product = angular.copy(product);
ctrl.productName = product.name;
ctrl.productProperties = [];
+ ctrl.productVersion = angular.copy(version);
+ ctrl.originalCpid = version ? version.cpid : null;
parseProductProperties();
@@ -436,9 +450,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;
diff --git a/refstack-ui/tests/unit/ControllerSpec.js b/refstack-ui/tests/unit/ControllerSpec.js
index e8610634..77f77889 100644
--- a/refstack-ui/tests/unit/ControllerSpec.js
+++ b/refstack-ui/tests/unit/ControllerSpec.js
@@ -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();