mirror of
https://github.com/portainer/portainer.git
synced 2025-08-08 15:25:22 +02:00
fix(UI) check image name when build image EE-3010 (#7409)
* EE-3010 check image name when build image
This commit is contained in:
parent
f2d93654f5
commit
2574f223b4
2 changed files with 41 additions and 14 deletions
|
@ -1,5 +1,6 @@
|
|||
angular.module('portainer.docker').controller('BuildImageController', BuildImageController);
|
||||
|
||||
/* @ngInject */
|
||||
function BuildImageController($scope, $async, $window, ModalService, BuildService, Notifications, HttpRequestHelper) {
|
||||
$scope.state = {
|
||||
BuildType: 'editor',
|
||||
|
@ -9,7 +10,7 @@ function BuildImageController($scope, $async, $window, ModalService, BuildServic
|
|||
};
|
||||
|
||||
$scope.formValues = {
|
||||
ImageNames: [{ Name: '' }],
|
||||
ImageNames: [{ Name: '', Valid: false, Unique: true }],
|
||||
UploadFile: null,
|
||||
DockerFileContent: '',
|
||||
URL: '',
|
||||
|
@ -27,19 +28,38 @@ function BuildImageController($scope, $async, $window, ModalService, BuildServic
|
|||
$scope.state.isEditorDirty = false;
|
||||
});
|
||||
|
||||
$scope.checkName = function (name) {
|
||||
const parts = name.split('/');
|
||||
$scope.checkName = function (index) {
|
||||
var item = $scope.formValues.ImageNames[index];
|
||||
item.Valid = true;
|
||||
item.Unique = true;
|
||||
if (item.Name !== '') {
|
||||
// Check unique
|
||||
$scope.formValues.ImageNames.forEach((element, idx) => {
|
||||
if (idx != index && element.Name == item.Name) {
|
||||
item.Valid = false;
|
||||
item.Unique = false;
|
||||
}
|
||||
});
|
||||
if (!item.Valid) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Validation
|
||||
const parts = item.Name.split('/');
|
||||
const repository = parts[parts.length - 1];
|
||||
const repositoryRegExp = RegExp('^[a-z0-9-_]{2,255}(:[A-Za-z0-9-_.]{1,128})?$');
|
||||
return repositoryRegExp.test(repository);
|
||||
item.Valid = repositoryRegExp.test(repository);
|
||||
};
|
||||
|
||||
$scope.addImageName = function () {
|
||||
$scope.formValues.ImageNames.push({ Name: '' });
|
||||
$scope.formValues.ImageNames.push({ Name: '', Valid: false, Unique: true });
|
||||
};
|
||||
|
||||
$scope.removeImageName = function (index) {
|
||||
$scope.formValues.ImageNames.splice(index, 1);
|
||||
for (var i = 0; i < $scope.formValues.ImageNames.length; i++) {
|
||||
$scope.checkName(i);
|
||||
}
|
||||
};
|
||||
|
||||
function buildImageBasedOnBuildType(method, names) {
|
||||
|
@ -103,8 +123,7 @@ function BuildImageController($scope, $async, $window, ModalService, BuildServic
|
|||
return false;
|
||||
}
|
||||
for (var i = 0; i < $scope.formValues.ImageNames.length; i++) {
|
||||
var item = $scope.formValues.ImageNames[i];
|
||||
if (!$scope.checkName(item.Name)) {
|
||||
if (!$scope.formValues.ImageNames[i].Valid) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue