<commit_before>function DeployWizard($scope, $notification, $translate, resourcesService) {
    var step = 0;
    var nextClicked = false;
    $scope.name='wizard';

    var  validTemplateSelected = function() {
        if($scope.selectedTemplates().length <= 0){
            showError($translate.instant("label_wizard_select_app"));
            return false;
        }else{
            resetError();
        }

        return true;
    };

    var validDeploymentID = function() {
        if($scope.install.deploymentId === undefined || $scope.install.deploymentId === ""){
            showError($translate.instant("label_wizard_deployment_id"));
            return false;
        }else{
            resetError();
        }

        return true;
    };

    var validTemplateUpload = function(){
        var uploadedFiles = $("#new_template_filename_wizard")[0].files;
        if(uploadedFiles.length === 0){
            showError($translate.instant("template_error"));
            return false;
        }else{
            var data = new FormData();
            $.each(uploadedFiles, function(key, value){
                data.append("tpl", value);
            });
            resourcesService.add_app_template(data, function(data){
                resourcesService.get_app_templates(false, function(templatesMap) {
                    var templates = [];
                    for (var key in templatesMap) {
                        var template = templatesMap[key];
                        template.Id = key;
                        templates[templates.length] = template;
                    }
                    $scope.templates.data = templates;
                });
            });
            resetError();
            return true;
        }
    };

    var resetStepPage = function() {
        step = 0;

        $scope.install = {
            selected: {
                pool: 'default'
            },
            templateSelected: function(template) {
                if (template.depends) {
                    $scope.install.selected[template.depends] = true;
                }
            },
            templateDisabled: function(template) {
                if (template.disabledBy) {
                    return $scope.install.selected[template.disabledBy];
                }
                return false;
            }
        };

        resourcesService.get_app_templates(false, function(templatesMap) {
            var templates = [];
            for (var key in templatesMap) {
                var template = templatesMap[key];
                template.Id = key;
                templates[templates.length] = template;
            }

            if($scope.templates.data.length === 0){
                $scope.steps.unshift({
                    content: '/static/partials/wizard-modal-add-template.html',
                    label: 'template_add',
                    validate: validTemplateUpload
                });
            }

            $scope.step_page = $scope.steps[step].content;
        });
    };

    var showError = function(message){
        $("#deployWizardNotificationsContent").html(message);
        $("#deployWizardNotifications").removeClass("hide");
    };

    var resetError = function(){
        $("#deployWizardNotifications").html("");
        $("#deployWizardNotifications").addClass("hide");
    };

    $scope.steps = [
        {
            content: '/static/partials/wizard-modal-2.html',
            label: 'label_step_select_app',
            validate: validTemplateSelected
        },
        {
            content: '/static/partials/wizard-modal-3.html',
            label: 'label_step_select_pool' },
        {
            content: '/static/partials/wizard-modal-4.html',
            label: 'label_step_deploy',
            validate: validDeploymentID
        }
    ];

    $scope.install = {
        selected: {
            pool: 'default'
        },
        templateSelected: function(template) {
            if (template.depends) {
                $scope.install.selected[template.depends] = true;
            }
        },
        templateDisabled: function(template) {
            if (template.disabledBy) {
                return $scope.install.selected[template.disabledBy];
            }
            return false;
        }
    };

    $scope.selectedTemplates = function() {
        var templates = [];
        for (var i=0; i < $scope.templates.data.length; i++) {
            var template = $scope.templates.data[i];
            if ($scope.install.selected[template.Id]) {
                templates[templates.length] = template;
            }
        }
        return templates;
    };

    $scope.getTemplateRequiredResources = function(template){
        var ret = {CPUCommitment:0, RAMCommitment:0};

        // if Services, iterate and sum up their commitment values
        if(template.Services){
            for (var i=0; i<template.Services.length; ++i){
                if(template.Services[i].CPUCommitment) ret.CPUCommitment += template.Services[i].CPUCommitment;
                if(template.Services[i].RAMCommitment) ret.RAMCommitment += template.Services[i].RAMCommitment;
            }
        }

        return ret;
    };

    $scope.addHostStart = function() {
        $scope.newHost = {};
        $scope.step_page = '/static/partials/wizard-modal-addhost.html';
    };

    $scope.addHostCancel = function() {
        $scope.step_page = $scope.steps[step].content;
    };

    $scope.addHostFinish = function() {
        $scope.newHost.Name = $scope.newHost.IPAddr;
        $scope.newHost.ID = 'fakefakefake';
        $scope.newHost.selected = true;
        $scope.detected_hosts.push($scope.newHost);
        $scope.step_page = $scope.steps[step].content;
    };<commit_msg>recursively calculate app cpu and ram commitment<commit_after>function DeployWizard($scope, $notification, $translate, resourcesService) {
    var step = 0;
    var nextClicked = false;
    $scope.name='wizard';

    var  validTemplateSelected = function() {
        if($scope.selectedTemplates().length <= 0){
            showError($translate.instant("label_wizard_select_app"));
            return false;
        }else{
            resetError();
        }

        return true;
    };

    var validDeploymentID = function() {
        if($scope.install.deploymentId === undefined || $scope.install.deploymentId === ""){
            showError($translate.instant("label_wizard_deployment_id"));
            return false;
        }else{
            resetError();
        }

        return true;
    };

    var validTemplateUpload = function(){
        var uploadedFiles = $("#new_template_filename_wizard")[0].files;
        if(uploadedFiles.length === 0){
            showError($translate.instant("template_error"));
            return false;
        }else{
            var data = new FormData();
            $.each(uploadedFiles, function(key, value){
                data.append("tpl", value);
            });
            resourcesService.add_app_template(data, function(data){
                resourcesService.get_app_templates(false, function(templatesMap) {
                    var templates = [];
                    for (var key in templatesMap) {
                        var template = templatesMap[key];
                        template.Id = key;
                        templates[templates.length] = template;
                    }
                    $scope.templates.data = templates;
                });
            });
            resetError();
            return true;
        }
    };

    var resetStepPage = function() {
        step = 0;

        $scope.install = {
            selected: {
                pool: 'default'
            },
            templateSelected: function(template) {
                if (template.depends) {
                    $scope.install.selected[template.depends] = true;
                }
            },
            templateDisabled: function(template) {
                if (template.disabledBy) {
                    return $scope.install.selected[template.disabledBy];
                }
                return false;
            }
        };

        resourcesService.get_app_templates(false, function(templatesMap) {
            var templates = [];
            for (var key in templatesMap) {
                var template = templatesMap[key];
                template.Id = key;
                templates[templates.length] = template;
            }

            if($scope.templates.data.length === 0){
                $scope.steps.unshift({
                    content: '/static/partials/wizard-modal-add-template.html',
                    label: 'template_add',
                    validate: validTemplateUpload
                });
            }

            $scope.step_page = $scope.steps[step].content;
        });
    };

    var showError = function(message){
        $("#deployWizardNotificationsContent").html(message);
        $("#deployWizardNotifications").removeClass("hide");
    };

    var resetError = function(){
        $("#deployWizardNotifications").html("");
        $("#deployWizardNotifications").addClass("hide");
    };

    $scope.steps = [
        {
            content: '/static/partials/wizard-modal-2.html',
            label: 'label_step_select_app',
            validate: validTemplateSelected
        },
        {
            content: '/static/partials/wizard-modal-3.html',
            label: 'label_step_select_pool' },
        {
            content: '/static/partials/wizard-modal-4.html',
            label: 'label_step_deploy',
            validate: validDeploymentID
        }
    ];

    $scope.install = {
        selected: {
            pool: 'default'
        },
        templateSelected: function(template) {
            if (template.depends) {
                $scope.install.selected[template.depends] = true;
            }
        },
        templateDisabled: function(template) {
            if (template.disabledBy) {
                return $scope.install.selected[template.disabledBy];
            }
            return false;
        }
    };

    $scope.selectedTemplates = function() {
        var templates = [];
        for (var i=0; i < $scope.templates.data.length; i++) {
            var template = $scope.templates.data[i];
            if ($scope.install.selected[template.Id]) {
                templates[templates.length] = template;
            }
        }
        return templates;
    };

    $scope.getTemplateRequiredResources = function(template){
        var ret = {CPUCommitment:0, RAMCommitment:0};

        // if Services, iterate and sum up their commitment values
        if(template.Services){
            // recursively calculate cpu and ram commitments
            (function calcCommitment(services){
                services.forEach(function(service){
                    // CPUCommitment should be equal to max number of
                    // cores needed by any service
                    ret.CPUCommitment = Math.max(ret.CPUCommitment, service.CPUCommitment);
                    // RAMCommitment should be a sum of all ram needed
                    // by all services
                    ret.RAMCommitment += service.RAMCommitment;

                    // recurse!
                    if(service.Services) calcCommitment(service.Services);
                });
            })(template.Services);
        }

        return ret;
    };

    $scope.addHostStart = function() {
        $scope.newHost = {};
        $scope.step_page = '/static/partials/wizard-modal-addhost.html';
    };

    $scope.addHostCancel = function() {
        $scope.step_page = $scope.steps[step].content;
    };

    $scope.addHostFinish = function() {
        $scope.newHost.Name = $scope.newHost.IPAddr;
        $scope.newHost.ID = 'fakefakefake';
        $scope.newHost.selected = true;
        $scope.detected_hosts.push($scope.newHost);
        $scope.step_page = $scope.steps[step].content;
    };
{'fraction_non_alphanumeric': 0.11798128342245989, 'fraction_numerical': 0.002088903743315508, 'mean_word_length': 1.651528577758086, 'pattern_counts': {'":': 0, '<': 8, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7647774', 'n_tokens_mistral': 3138, 'n_tokens_neox': 3014, 'n_words': 526}