diff --git a/client/assets/styles/scss/modals/modals-forms.scss b/client/assets/styles/scss/modals/modals-forms.scss index 6a94fd52c..c23f3ec24 100644 --- a/client/assets/styles/scss/modals/modals-forms.scss +++ b/client/assets/styles/scss/modals/modals-forms.scss @@ -157,6 +157,7 @@ // max-width on buttons > .btn, .btn-wrapped { + @extend %btn-sm; display: block; font-size: 16px; max-width: 360px; diff --git a/client/assets/styles/scss/views/views-new-service.scss b/client/assets/styles/scss/views/views-new-service.scss index a475c86ca..1ba50d754 100644 --- a/client/assets/styles/scss/views/views-new-service.scss +++ b/client/assets/styles/scss/views/views-new-service.scss @@ -44,6 +44,19 @@ } } + // for branch selector + .btn-wrapped { + @extend %btn-md; + display: flex; + flex: 1 1 auto; + justify-content: space-between; + padding-left: 8px; + + .icons-branch { + top: 9px; + } + } + // for the nested compose test file .well > .label { margin-bottom: 0; diff --git a/client/directives/components/fancySelectors/branchSelector/branchSelectorView.jade b/client/directives/components/fancySelectors/branchSelector/branchSelectorView.jade index d4d9bbc7b..0a914b421 100644 --- a/client/directives/components/fancySelectors/branchSelector/branchSelectorView.jade +++ b/client/directives/components/fancySelectors/branchSelector/branchSelectorView.jade @@ -1,4 +1,4 @@ -fancy-select.btn-sm.white.btn-wrapped( +fancy-select.white.btn-wrapped( ng-disabled = "branchFetching || !state.repo.branches.models.length" ng-required = "true" on-update = "onBranchChange" diff --git a/client/directives/components/mirrorDockerfile/addDockerfileDirective.js b/client/directives/components/mirrorDockerfile/addDockerfileDirective.js index 669073f24..0f5069f64 100644 --- a/client/directives/components/mirrorDockerfile/addDockerfileDirective.js +++ b/client/directives/components/mirrorDockerfile/addDockerfileDirective.js @@ -46,13 +46,21 @@ function addDockerfile( MDC.loadDefaultDockerfile($scope.fullRepo, $scope.branchName, path, $scope.fileType); } - fetchRepoDockerfile($scope.fullRepo, $scope.branchName, path) - .then(doesDockerfileExist) - .then(function (file) { - if (file) { - $scope.newDockerfile = $scope.fileName; - } - }); + + function populateNewDockerfile () { + return fetchRepoDockerfile($scope.fullRepo, $scope.branchName, path) + .then(doesDockerfileExist) + .then(function (file) { + if (file) { + $scope.newDockerfile = $scope.fileName; + } else { + // Account for files not found + $scope.newDockerfile = undefined; + } + }); + } + $scope.$watch('branchName', populateNewDockerfile); + populateNewDockerfile(); $scope.$on('dockerfileExistsValidator', function ($event, path, fileType, dockerfile) { if (fileType === 'Dockerfile') { @@ -67,7 +75,7 @@ function addDockerfile( $scope.dockerfile = dockerfile; MDC.state.dockerfile = dockerfile; return; - } + } }); $scope.closeDockerFileInput = function () { diff --git a/client/directives/components/mirrorDockerfile/mirrorDockerfileController.js b/client/directives/components/mirrorDockerfile/mirrorDockerfileController.js index e3fad7b8b..8f7e02264 100644 --- a/client/directives/components/mirrorDockerfile/mirrorDockerfileController.js +++ b/client/directives/components/mirrorDockerfile/mirrorDockerfileController.js @@ -32,31 +32,6 @@ function MirrorDockerfileController( MDC.branchName = MDC.branchName || keypather.get(MDC.repo, 'attrs.default_branch'); MDC.state.configurationMethod = null; - MDC.fetchRepoDockerfiles = function () { - return fetchRepoDockerfiles(MDC.getFullRepo(), MDC.branchName, MDC.newDockerfilePaths) - .then(function (dockerfiles) { - // remove any dead paths by replacing them with the results - MDC.newDockerfilePaths = dockerfiles.map(function (dockerfile) { - return dockerfile.path; - }); - MDC.repo.dockerfiles = dockerfiles; - return dockerfiles; - }) - .catch(errs.handler); - }; - - MDC.fetchRepoDockerComposeFiles = function () { - return fetchRepoDockerfiles(MDC.getFullRepo(), MDC.branchName, MDC.newDockerComposeFilePaths) - .then(function (dockerfiles) { - MDC.newDockerComposeFilePaths = dockerfiles.map(function (dockerfile) { - return dockerfile.path; - }); - MDC.repo.dockerComposeFiles = dockerfiles; - return dockerfiles; - }) - .catch(errs.handler); - }; - MDC.loadDefaultDockerfile = function (repo, branchName, filePath, fileType) { return fetchRepoDockerfile(repo, branchName, filePath) .then(doesDockerfileExist) diff --git a/client/directives/components/newContainer/forms/configureNewServiceView.jade b/client/directives/components/newContainer/forms/configureNewServiceView.jade index 99b1a128e..d9f55e2fa 100644 --- a/client/directives/components/newContainer/forms/configureNewServiceView.jade +++ b/client/directives/components/newContainer/forms/configureNewServiceView.jade @@ -51,11 +51,17 @@ section.grid-block.vertical.modal-body( ) //- form for naming the environment - form.grid-block.vertical.label( + form.grid-block.vertical.label.label-name( name = "NCC.nameForm" ng-include = "'nameNewServiceView'" ) + //- default branch selector + label.grid-block.vertical.label( + ng-if = "NCC.state.dockerFileTab === 'compose' && $root.featureFlags.composeDefaultBranch" + ng-include = "'defaultBranchView'" + ) + .grid-block.vertical.views-kubernetes-setup( ng-if = "NCC.state.dockerFileTab === 'kubernetes'" ng-include = "'kubernetesSetupView'" @@ -72,7 +78,7 @@ section.grid-block.vertical.modal-body( //- form for dockerfile setup .grid-block.vertical.label.views-dockerfile-setup( - branch-name = "NCC.state.repo.attrs.default_branch" + branch-name = "NCC.state.branch.attrs.name" mirror-dockerfile name = "'newContainer'" ng-if = "NCC.state.dockerFileTab !== 'kubernetes'" diff --git a/client/directives/components/newContainer/forms/defaultBranchView.jade b/client/directives/components/newContainer/forms/defaultBranchView.jade new file mode 100644 index 000000000..e64d1a58b --- /dev/null +++ b/client/directives/components/newContainer/forms/defaultBranchView.jade @@ -0,0 +1,8 @@ +.padding-xxs.small.label-sm Initial Branch +.grid-block( + auto-update = "true" + branch-selector + loading-promises-target = "editServerModal" + state = "NCC.state" +) +small.padding-xxs.small Select the first branch you want to add. diff --git a/client/directives/components/newContainer/newContainerController.js b/client/directives/components/newContainer/newContainerController.js index 567915c45..47975f38f 100644 --- a/client/directives/components/newContainer/newContainerController.js +++ b/client/directives/components/newContainer/newContainerController.js @@ -332,7 +332,7 @@ function NewContainerController( if (NCC.state.dockerComposeFile && (!$rootScope.featureFlags.composeNewService || NCC.state.types.stage)) { return createNewCluster( NCC.state.repo.attrs.full_name, - NCC.state.repo.attrs.default_branch, + NCC.state.branch.attrs.name, NCC.state.dockerComposeFile.path, NCC.state.instanceName, currentOrg.github.attrs.id @@ -348,7 +348,7 @@ function NewContainerController( var instanceName = NCC.state.instanceName + '-test'; return createNewCluster( NCC.state.repo.attrs.full_name, - NCC.state.repo.attrs.default_branch, + NCC.state.branch.attrs.name, NCC.state.dockerComposeTestFile.path, instanceName, currentOrg.github.attrs.id, @@ -363,7 +363,7 @@ function NewContainerController( return createNewCluster( NCC.state.repo.attrs.full_name, - NCC.state.repo.attrs.default_branch, + NCC.state.branch.attrs.name, NCC.state.dockerComposeTestFile.path, NCC.state.instanceName, currentOrg.github.attrs.id, @@ -383,17 +383,33 @@ function NewContainerController( }; NCC.canCreateBuild = function () { - return keypather.get(NCC, 'state.instanceName.length') && !keypather.get(NCC, 'nameForm.$invalid') && - !$rootScope.isLoading.newContainerSingleRepo && !$rootScope.isLoading.creatingDockerCompose && (NCC.state.templateSource || - !$scope.$root.featureFlags.composeNewService || NCC.validateDockerComposeBuild()); + var hasInstances = keypather.get(NCC, 'state.instanceName.length'); + var isLoading = $rootScope.isLoading.newContainerSingleRepo || $rootScope.isLoading.creatingDockerCompose; + var isFormValid = !keypather.get(NCC, 'nameForm.$invalid'); + var isTemplate = NCC.state.templateSource; + var isValidCompose = !$scope.$root.featureFlags.composeNewService || NCC.validateDockerComposeBuild(); + return hasInstances && + isFormValid && + !isLoading && + (isTemplate || isValidCompose); }; NCC.validateDockerComposeBuild = function () { - return ((NCC.state.configurationMethod === 'new' || NCC.state.configurationMethod === 'blankDockerfile') || - (NCC.state.configurationMethod === 'dockerfile' && NCC.state.dockerfile) || - (NCC.state.configurationMethod === 'dockerComposeFile' && - ((NCC.state.types.test ? NCC.state.dockerComposeTestFile && NCC.state.testReporter : NCC.state.types.stage) && - (NCC.state.types.stage ? NCC.state.dockerComposeFile : NCC.state.types.test)))); + var isNewBlankDockerfile = ['new', 'blankDockerfile'].includes(NCC.state.configurationMethod); + var isValidDockerfile = NCC.state.configurationMethod === 'dockerfile' && NCC.state.dockerfile; + var isValidComposeFile = false; + if (NCC.state.configurationMethod === 'dockerComposeFile') { + var isValidTestCompose = true, isValidStagingCompose = true; + var hasTestOrStaging = NCC.state.types.test || NCC.state.types.stage; + if (NCC.state.types.test) { + isValidTestCompose = NCC.state.dockerComposeTestFile && NCC.state.testReporter; + } + if (NCC.state.types.stage) { + isValidStagingCompose = NCC.state.dockerComposeFile; + } + isValidComposeFile = hasTestOrStaging && isValidTestCompose && isValidStagingCompose; + } + return isNewBlankDockerfile || isValidDockerfile || isValidComposeFile; }; NCC.isSaving = function () { diff --git a/client/services/featureFlagService.js b/client/services/featureFlagService.js index 17d618fc9..e883ec04f 100644 --- a/client/services/featureFlagService.js +++ b/client/services/featureFlagService.js @@ -14,6 +14,7 @@ function featureFlags( autoIsolationSetup: false, backup: false, cardStatus: false, + composeDefaultBranch: false, composeEditing: false, composeInstance: true, composeNav: true,