<commit_before>"use strict";
var deployService = soajsApp.components;
deployService.service('deploySrv', ['ngDataApi', '$timeout', '$modal', function (ngDataApi, $timeout, $modal) {

	function injectCatalogInputs(formConfig, recipes, opts){
		var mainLevel = opts.mainLevel;
		var subLevel = opts.subLevel;
		var initialCount = opts.initialCount;
		var type = opts.type;

		formConfig.entries[mainLevel].entries[subLevel].onAction = function(id, data, form){

			//reset form entries
			form.entries[mainLevel].entries.length = initialCount;

			//append the custom catalog inputs
			recipes.forEach(function(oneRecipe){
				if(oneRecipe.type === type &&  oneRecipe._id === data){
					if(oneRecipe.recipe.deployOptions.image.override){
						//append images
						form.entries[mainLevel].entries.push({
							'name': '_ci_' + type + "ImagePrefix",
							'label': "Image Prefix",
							'type': 'text',
							'value': oneRecipe.recipe.deployOptions.image.prefix,
							'fieldMsg': "Override the image prefix if you want"
						});
						form.formData['_ci_' + type + "ImagePrefix"] = oneRecipe.recipe.deployOptions.image.prefix;

						form.entries[mainLevel].entries.push({
							'name': '_ci_' + type + "ImageName",
							'label': "Image Name",
							'type': 'text',
							'value': oneRecipe.recipe.deployOptions.image.name,
							'fieldMsg': "Override the image name if you want"
						});
						form.formData['_ci_' + type + "ImageName"] = oneRecipe.recipe.deployOptions.image.name;

						form.entries[mainLevel].entries.push({
							'name': '_ci_' + type + "ImageTag",
							'label': "Image Tag",
							'type': 'text',
							'value': oneRecipe.recipe.deployOptions.image.tag,
							'fieldMsg': "Override the image tag if you want"
						});
						form.formData['_ci_' + type + "ImageTag"] = oneRecipe.recipe.deployOptions.image.tag;
					}

					//append inputs whose type is userInput
					for(var envVariable in oneRecipe.recipe.buildOptions.env){
						if(oneRecipe.recipe.buildOptions.env[envVariable].type === 'userInput'){

							//push a new input for this variable
							var newInput = {
								'name': '_ci_' + type + "_" + envVariable,
								'label': oneRecipe.recipe.buildOptions.env[envVariable].label || envVariable,
								'type': 'text',
								'value': oneRecipe.recipe.buildOptions.env[envVariable].default || '',
								'fieldMsg': oneRecipe.recipe.buildOptions.env[envVariable].fieldMsg
							};

							if(!oneRecipe.recipe.buildOptions.env[envVariable].default || oneRecipe.recipe.buildOptions.env[envVariable].default === ''){
								newInput.required = true;
							}

							form.entries[mainLevel].entries.push(newInput);
							form.formData['_ci_' + type + "_" + envVariable] = oneRecipe.recipe.buildOptions.env[envVariable].default || '';
						}
					}

					if(oneRecipe.recipe.deployOptions.specifyGitConfiguration && opts.deployment && opts.deployment.type === 'environment'){
						var newInput = {
							'name': 'branch',
							'label': 'Branch',
							'type': 'select',
							'value': [],
							'fieldMsg': 'Select a branch to deploy from',
							'required': true
						};

		                opts.deployment.data.branches.forEach(function (oneBranch) {
		                    delete oneBranch.commit.url;
			                newInput.value.push({'v': oneBranch, 'l': oneBranch.name});
		                });
						form.entries[mainLevel].entries.push(newInput);
					}
				}
			});
		};
	}

    /**
     * Deploy New Environment controller + Nginx
     * @param currentScope
     */
    function deployEnvironment(currentScope) {
        var formConfig = angular.copy(environmentsConfig.form.deploy);
        var kubeConfig = environmentsConfig.deployer.kubernetes;
        var envCode = currentScope.envCode;

        currentScope.isKubernetes = (currentScope.envDeployer.selected.split('.')[1] === "kubernetes");
        if (currentScope.isKubernetes) {
            formConfig.entries[0].entries[0].value = [
                {l: 'Deployment', v: 'deployment', 'selected': true},
                {l: 'Daemonset', v: 'daemonset'}
            ];

            formConfig.entries[1].entries[0].value = [
                {l: 'Deployment', v: 'deployment', 'selected': true},
                {l: 'Daemonset', v: 'daemonset'}
            ];
	        formConfig.entries[0].entries.splice(3, 0,
		        {
			        'name': 'nginxCpuLimit',
			        'label': 'CPU Limit Per Instance for Nginx',
			        'type': 'number',
			        'placeholder': '100m or 0.1',
			        'fieldMsg': 'Set a custom CPU limit for Nginx instances',
			        'required': true
		        }
	        );
	        formConfig.entries[1].entries.splice(3, 0,
		        {
			        'name': 'ctrlCpuLimit',
			        'label': 'CPU Limit Per Instance for Controller',
			        'type': 'number',
			        'placeholder': '100m or 0.1',
			        'fieldMsg': 'Set a custom CPU limit for controller instances',
			        'required': true
		        }
	        );
        }

        formConfig.entries[0].entries[0].onAction = function (id, data, form) {
            if (data === 'global' || data === 'daemonset') {
                form.entries[0].entries[1].disabled = true;
                form.entries[0].entries[1].required = false;
            }
            else {
                delete form.entries[0].entries[1].disabled;
                form.entries[0].entries[1].required = true;
            }
        };

        formConfig.entries[1].entries[0].onAction = function (id, data, form) {
            if (data === 'global' || data === 'daemonset') {
                form.entries[1].entries[1].disabled = true;
                form.entries[1].entries[1].required = false;
            }
            else {
                delete form.entries[1].entries[1].disabled;
                form.entries[1].entries[1].required = true;
            }
        };

        getControllerBranches(currentScope, function (branchInfo) {
            getCatalogRecipes(currentScope, function (recipes) {
                // adding available recipes to form
                recipes.forEach(function (oneRecipe) {
                    if (oneRecipe.type === 'soajs' && oneRecipe.subtype === 'service') {
                        formConfig.entries[1].entries[3].value.push({ l: oneRecipe.name, v: oneRecipe._id });
	                    injectCatalogInputs(formConfig, recipes, {
		                    mainLevel : 1,
	                        subLevel: 3,
	                        initialCount: 4,
	                        type: 'soajs',
		                    deployment: {
		                    	type: "environment",
			                    data: branchInfo
		                    }
	                    });
                    }
                    else if (oneRecipe.type === 'nginx') {
                        formConfig.entries[0].entries[3].value.push({ l: oneRecipe.name, v: oneRecipe._id });
	                    injectCatalogInputs(formConfig, recipes, {
		                    mainLevel : 0,
		                    subLevel: 3,
		                    initialCount: 4,
		                    type: 'nginx'
	                    });
                    }
                });

                var options = {
                    timeout: $timeout,
                    form: formConfig,
                    name: 'deployEnv',
                    label: translation.deployEnvironment[LANG] + ' ' + envCode,
                    actions: [
                        {
                            'type': 'submit',
                            'label': translation.submit[LANG],
                            'btn': 'primary',
                            'action': function (formData) {
                                if ((!formData.controllers || formData.controllers < 1) && (formData.controllerDeploymentMode === 'replicated' || formData.controllerDeploymentMode === 'deployment')) {
                                    $timeout(function () {
                                        alert(translation.youMustChooseLeastControllerDeployEnvironment[LANG]);
                                    }, 100);<commit_msg>minor update.<commit_after>"use strict";
var deployService = soajsApp.components;
deployService.service('deploySrv', ['ngDataApi', '$timeout', '$modal', function (ngDataApi, $timeout, $modal) {

	function injectCatalogInputs(formConfig, recipes, opts){
		var mainLevel = opts.mainLevel;
		var subLevel = opts.subLevel;
		var initialCount = opts.initialCount;
		var type = opts.type;

		formConfig.entries[mainLevel].entries[subLevel].onAction = function(id, data, form){

			//reset form entries
			form.entries[mainLevel].entries.length = initialCount;

			//append the custom catalog inputs
			recipes.forEach(function(oneRecipe){
				if(oneRecipe.type === type &&  oneRecipe._id === data){
					if(oneRecipe.recipe.deployOptions.image.override){
						//append images
						form.entries[mainLevel].entries.push({
							'name': '_ci_' + type + "ImagePrefix",
							'label': "Image Prefix",
							'type': 'text',
							'value': oneRecipe.recipe.deployOptions.image.prefix,
							'fieldMsg': "Override the image prefix if you want"
						});
						form.formData['_ci_' + type + "ImagePrefix"] = oneRecipe.recipe.deployOptions.image.prefix;

						form.entries[mainLevel].entries.push({
							'name': '_ci_' + type + "ImageName",
							'label': "Image Name",
							'type': 'text',
							'value': oneRecipe.recipe.deployOptions.image.name,
							'fieldMsg': "Override the image name if you want"
						});
						form.formData['_ci_' + type + "ImageName"] = oneRecipe.recipe.deployOptions.image.name;

						form.entries[mainLevel].entries.push({
							'name': '_ci_' + type + "ImageTag",
							'label': "Image Tag",
							'type': 'text',
							'value': oneRecipe.recipe.deployOptions.image.tag,
							'fieldMsg': "Override the image tag if you want"
						});
						form.formData['_ci_' + type + "ImageTag"] = oneRecipe.recipe.deployOptions.image.tag;
					}

					//append inputs whose type is userInput
					for(var envVariable in oneRecipe.recipe.buildOptions.env){
						if(oneRecipe.recipe.buildOptions.env[envVariable].type === 'userInput'){

							//push a new input for this variable
							var newInput = {
								'name': '_ci_' + type + "_" + envVariable,
								'label': oneRecipe.recipe.buildOptions.env[envVariable].label || envVariable,
								'type': 'text',
								'value': oneRecipe.recipe.buildOptions.env[envVariable].default || '',
								'fieldMsg': oneRecipe.recipe.buildOptions.env[envVariable].fieldMsg
							};

							if(!oneRecipe.recipe.buildOptions.env[envVariable].default || oneRecipe.recipe.buildOptions.env[envVariable].default === ''){
								newInput.required = true;
							}

							form.entries[mainLevel].entries.push(newInput);
							form.formData['_ci_' + type + "_" + envVariable] = oneRecipe.recipe.buildOptions.env[envVariable].default || '';
						}
					}

					if(oneRecipe.recipe.deployOptions.specifyGitConfiguration && opts.deployment && opts.deployment.type === 'environment'){
						var newInput = {
							'name': 'branch',
							'label': 'Branch',
							'type': 'select',
							'value': [],
							'fieldMsg': 'Select a branch to deploy from',
							'required': true
						};

		                opts.deployment.data.branches.forEach(function (oneBranch) {
		                    delete oneBranch.commit.url;
			                newInput.value.push({'v': oneBranch, 'l': oneBranch.name});
		                });
						form.entries[mainLevel].entries.push(newInput);
					}
				}
			});
		};
	}

    /**
     * Deploy New Environment controller + Nginx
     * @param currentScope
     */
    function deployEnvironment(currentScope) {
        var formConfig = angular.copy(environmentsConfig.form.deploy);
        var kubeConfig = environmentsConfig.deployer.kubernetes;
        var envCode = currentScope.envCode;

        currentScope.isKubernetes = (currentScope.envDeployer.selected.split('.')[1] === "kubernetes");
        if (currentScope.isKubernetes) {
            formConfig.entries[0].entries[0].value = [
                {l: 'Deployment', v: 'deployment', 'selected': true},
                {l: 'Daemonset', v: 'daemonset'}
            ];

            formConfig.entries[1].entries[0].value = [
                {l: 'Deployment', v: 'deployment', 'selected': true},
                {l: 'Daemonset', v: 'daemonset'}
            ];
	        formConfig.entries[0].entries.splice(3, 0,
		        {
			        'name': 'nginxCpuLimit',
			        'label': 'CPU Limit Per Instance for Nginx',
			        'type': 'number',
			        'placeholder': '100m or 0.1',
			        'fieldMsg': 'Set a custom CPU limit for Nginx instances',
			        'required': true
		        }
	        );
	        formConfig.entries[1].entries.splice(3, 0,
		        {
			        'name': 'ctrlCpuLimit',
			        'label': 'CPU Limit Per Instance for Controller',
			        'type': 'number',
			        'placeholder': '100m or 0.1',
			        'fieldMsg': 'Set a custom CPU limit for controller instances',
			        'required': true
		        }
	        );
        }

        formConfig.entries[0].entries[0].onAction = function (id, data, form) {
            if (data === 'global' || data === 'daemonset') {
                form.entries[0].entries[1].disabled = true;
                form.entries[0].entries[1].required = false;
            }
            else {
                delete form.entries[0].entries[1].disabled;
                form.entries[0].entries[1].required = true;
            }
        };

        formConfig.entries[1].entries[0].onAction = function (id, data, form) {
            if (data === 'global' || data === 'daemonset') {
                form.entries[1].entries[1].disabled = true;
                form.entries[1].entries[1].required = false;
            }
            else {
                delete form.entries[1].entries[1].disabled;
                form.entries[1].entries[1].required = true;
            }
        };

        getControllerBranches(currentScope, function (branchInfo) {
            getCatalogRecipes(currentScope, function (recipes) {
                // adding available recipes to form
                recipes.forEach(function (oneRecipe) {
	                var index = 3;
	                if(currentScope.isKubernetes){
		                index = 4;
	                }
                    if (oneRecipe.type === 'soajs' && oneRecipe.subtype === 'service') {
                        formConfig.entries[1].entries[index].value.push({ l: oneRecipe.name, v: oneRecipe._id });
	                    injectCatalogInputs(formConfig, recipes, {
		                    mainLevel : 1,
	                        subLevel: 3,
	                        initialCount: 4,
	                        type: 'soajs',
		                    deployment: {
		                    	type: "environment",
			                    data: branchInfo
		                    }
	                    });
                    }
                    else if (oneRecipe.type === 'nginx') {
                        formConfig.entries[0].entries[index].value.push({ l: oneRecipe.name, v: oneRecipe._id });
	                    injectCatalogInputs(formConfig, recipes, {
		                    mainLevel : 0,
		                    subLevel: 3,
		                    initialCount: 4,
		                    type: 'nginx'
	                    });
                    }
                });

                var options = {
                    timeout: $timeout,
                    form: formConfig,
                    name: 'deployEnv',
                    label: translation.deployEnvironment[LANG] + ' ' + envCode,
                    actions: [
                        {
                            'type': 'submit',
                            'label': translation.submit[LANG],
                            'btn': 'primary',
                            'action': function (formData) {
                                if ((!formData.controllers || formData.controllers < 1) && (formData.controllerDeploymentMode === 'replicated' || formData.controllerDeploymentMode === 'deployment')) {
                                    $timeout(function () {
                                        alert(translation.youMustChooseLeastControllerDeployEnvironment[LANG]);
                                    }, 100);
{'fraction_non_alphanumeric': 0.13302416402245545, 'fraction_numerical': 0.006712228459848669, 'mean_word_length': 1.7967576791808875, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3013960', 'n_tokens_mistral': 5437, 'n_tokens_neox': 4408, 'n_words': 856}