<commit_before>/**
 * Module for all Metrics Controllers
 */

angular.module('pcApp.metrics.controllers.metric', [
    'pcApp.metrics.services.metric',
    'pcApp.references.services.reference',
    'dialogs.main'
])

.controller('CreateMetric1Controller', ['$scope', '$modal', 'API_CONF', '$http', 'MetricsControllerHelper', '$location', function($scope, $modal, API_CONF, $http, MetricsControllerHelper, $location) {

    $scope.metrics_controller_helper = MetricsControllerHelper;
    $scope.metrics_controller_helper.init();

    $scope.variableIndex = 1;
    $scope.showFunctions = false;

    $scope.toggleFunctions = function() {
        $scope.showFunctions = !$scope.showFunctions;
    }

    $scope.addIndicator = function(indicator) {

        var i = "__" + $scope.variableIndex + "__";
        if (angular.isUndefined($scope.cursorPosVal) || angular.isUndefined($scope.metrics_controller_helper.metricsdata.formula)){
            if(angular.isUndefined($scope.metrics_controller_helper.metricsdata.formula)){
                $scope.metrics_controller_helper.metricsdata.formula = "";
            }
            $scope.metrics_controller_helper.metricsdata.formula = $scope.metrics_controller_helper.metricsdata.formula + i;
            //$("#formula-div").append('<span contentEditable="false" class="indicator-formula indicator-formula-selected">' + indicator.name + '</span>');
            //$("#formula-div").css('height', ($("#formula-div")[0].scrollHeight + 19) +  'px');
        }
        else{
            $scope.metrics_controller_helper.metricsdata.formula = [$scope.metrics_controller_helper.metricsdata.formula.slice(0, $scope.cursorPosVal), i, $scope.metrics_controller_helper.metricsdata.formula.slice($scope.cursorPosVal)].join('');
            //$("#formula-div").append('<span contentEditable="false" class="indicator-formula indicator-formula-selected">'+ indicator.name +'</span>' );
            //$("#formula-div").css('height',($("#formula-div")[0].scrollHeight + 19) + 'px');
            $scope.cursorPosVal = undefined;
        }
        $scope.variableIndex += 1;
        $scope.metrics_controller_helper.metricsdata.variables[i] = {"type": "indicator", "id": indicator.id}
    };

    $scope.getCursorPosition = function(event) {
        var element = event.target;
        $scope.doGetCaretPosition(element);

        /*var caretOffset = 0;
        var doc = element.ownerDocument || element.document;
        var win = doc.defaultView || doc.parentWindow;
        var sel;
        if (typeof win.getSelection != "undefined") {
            sel = win.getSelection();
            if (sel.rangeCount > 0) {
                var range = win.getSelection().getRangeAt(0);
                var preCaretRange = range.cloneRange();
                preCaretRange.selectNodeContents(element);
                preCaretRange.setEnd(range.endContainer, range.endOffset);
                caretOffset = preCaretRange.toString().length;
            }
        } else if ( (sel = doc.selection) && sel.type != "Control") {
            var textRange = sel.createRange();
            var preCaretTextRange = doc.body.createTextRange();
            preCaretTextRange.moveToElementText(element);
            preCaretTextRange.setEndPoint("EndToEnd", textRange);
            caretOffset = preCaretTextRange.text.length;
        }
        $scope.cursorPosVal = caretOffset;
        console.log($scope.cursorPosVal);*/
    };

    $scope.clearErrors = function() {
        $scope.servererror = undefined;
    }


    $scope.doGetCaretPosition = function(oField) {

        var iCaretPos = 0;

        // IE Support
        if (document.selection) {
           oField.focus ();
           var oSel = document.selection.createRange ();
           oSel.moveStart ('character', -oField.value.length);
           iCaretPos = oSel.text.length;
        }

        else if (oField.selectionStart || oField.selectionStart == '0') {
            iCaretPos = oField.selectionStart;
        }
        $scope.cursorPosVal = iCaretPos;
    };

    $scope.submitFormula = function () {

        var url = API_CONF.FORMULA_VALIDATION_URL;

        if ($scope.formulaForm.$valid) {<commit_msg>remove unused code<commit_after>/**
 * Module for all Metrics Controllers
 */

angular.module('pcApp.metrics.controllers.metric', [
    'pcApp.metrics.services.metric',
    'pcApp.references.services.reference',
    'dialogs.main'
])

.controller('CreateMetric1Controller', ['$scope', '$modal', 'API_CONF', '$http', 'MetricsControllerHelper', '$location', function($scope, $modal, API_CONF, $http, MetricsControllerHelper, $location) {

    $scope.metrics_controller_helper = MetricsControllerHelper;
    $scope.metrics_controller_helper.init();

    $scope.variableIndex = 1;
    $scope.showFunctions = false;

    $scope.toggleFunctions = function() {
        $scope.showFunctions = !$scope.showFunctions;
    }

    $scope.addIndicator = function(indicator) {

        var i = "__" + $scope.variableIndex + "__";
        if (angular.isUndefined($scope.cursorPosVal) || angular.isUndefined($scope.metrics_controller_helper.metricsdata.formula)){
            if(angular.isUndefined($scope.metrics_controller_helper.metricsdata.formula)){
                $scope.metrics_controller_helper.metricsdata.formula = "";
            }
            $scope.metrics_controller_helper.metricsdata.formula = $scope.metrics_controller_helper.metricsdata.formula + i;
        }
        else{
            $scope.metrics_controller_helper.metricsdata.formula = [$scope.metrics_controller_helper.metricsdata.formula.slice(0, $scope.cursorPosVal), i, $scope.metrics_controller_helper.metricsdata.formula.slice($scope.cursorPosVal)].join('');
            $scope.cursorPosVal = undefined;
        }
        $scope.variableIndex += 1;
        $scope.metrics_controller_helper.metricsdata.variables[i] = {"type": "indicator", "id": indicator.id}
    };

    $scope.getCursorPosition = function(event) {
        var element = event.target;
        $scope.doGetCaretPosition(element);
    };

    $scope.clearErrors = function() {
        $scope.servererror = undefined;
    }


    $scope.doGetCaretPosition = function(oField) {

        var iCaretPos = 0;

        // IE Support
        if (document.selection) {
           oField.focus ();
           var oSel = document.selection.createRange ();
           oSel.moveStart ('character', -oField.value.length);
           iCaretPos = oSel.text.length;
        }

        else if (oField.selectionStart || oField.selectionStart == '0') {
            iCaretPos = oField.selectionStart;
        }
        $scope.cursorPosVal = iCaretPos;
    };

    $scope.submitFormula = function () {

        var url = API_CONF.FORMULA_VALIDATION_URL;

        if ($scope.formulaForm.$valid) {
{'fraction_non_alphanumeric': 0.13728089556635734, 'fraction_numerical': 0.0030932390631904553, 'mean_word_length': 2.895582329317269, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 8, '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': '6098935', 'n_tokens_mistral': 1992, 'n_tokens_neox': 1915, 'n_words': 286}