<commit_before>/**
 * Author: <NAME>
 * Date: 10/14/14
 * Time: 2:18 PM
 */

'use strict';

angular.module('registryApp.cliche')
    .controller('JsonEditorCtrl', ['$scope', '$rootScope', '$modalInstance', '$timeout', '$document', 'options', 'SchemaValidator', '$http', 'Globals', function ($scope, $rootScope, $modalInstance, $timeout, $document, options, SchemaValidator, $http, Globals) {

        $scope.view = {};
        $scope.view.user = options.user;

        $scope.view.urlImport = false;

        //$scope.mirror = null;

        $scope.$watch('view.urlImport', function (n, o) {
            if (o !== n) {
                $scope.view.error = '';
            }
        });

        // TODO: make this pretty, use directive which will serve as general purpose codemirror container
        var timeoutId = $timeout(function () {

            $scope.mirror = CodeMirror($document[0].querySelector('.codemirror-editor'), {
                lineNumbers: true,
                value: '',
                mode: {name: 'javascript', json: true},
                theme: 'mbo',
                lineWrapping: true
            });

        }, 100);

        /**
         * Check if json is valid
         *
         * @param str
         * @returns {boolean}
         */
        var isJsonString = function (str) {

            try {
                JSON.parse(str);
                return true;
            } catch (e) {
                return false;
            }

        };

        /**
         * Do the app import
         */
        $scope.import = function () {

            if ($scope.view.urlImport) {
                if (!$scope.urlImport.url.$invalid) {

                    $scope.view.error = '';

                    $http.post(Globals.apiUrls.brood + 'import', {url: $scope.view.url}).then(function (response) {
                        var data = response.message;
                        $scope.view.validating = false;

                        if (typeof data === 'object') {
                            validateJson(JSON.stringify(data));
                        } else {
                            try {
                                var test = JSON.parse(data);
                                validateJson(data);
                            } catch (e) {
                                $rootScope.$broadcast('httpError', {message: 'Error while parsinf json response'});
                            }
                        }

                    }, function (trace) {
                        $scope.view.validating = false;
                    });
                } else {
                    $scope.view.error = 'You must provide valid url';
                }

            } else {
                validateJson($scope.mirror.getValue());<commit_msg>Fixin avengers import wf from url initiative<commit_after>/**
 * Author: <NAME>
 * Date: 10/14/14
 * Time: 2:18 PM
 */

'use strict';

angular.module('registryApp.cliche')
    .controller('JsonEditorCtrl', ['$scope', '$rootScope', '$modalInstance', '$timeout', '$document', 'options', 'SchemaValidator', '$http', 'Globals', function ($scope, $rootScope, $modalInstance, $timeout, $document, options, SchemaValidator, $http, Globals) {

        $scope.view = {};
        $scope.view.user = options.user;

        $scope.view.urlImport = false;

        //$scope.mirror = null;

        $scope.$watch('view.urlImport', function (n, o) {
            if (o !== n) {
                $scope.view.error = '';
            }
        });

        // TODO: make this pretty, use directive which will serve as general purpose codemirror container
        var timeoutId = $timeout(function () {

            $scope.mirror = CodeMirror($document[0].querySelector('.codemirror-editor'), {
                lineNumbers: true,
                value: '',
                mode: {name: 'javascript', json: true},
                theme: 'mbo',
                lineWrapping: true
            });

        }, 100);

        /**
         * Check if json is valid
         *
         * @param str
         * @returns {boolean}
         */
        var isJsonString = function (str) {

            try {
                JSON.parse(str);
                return true;
            } catch (e) {
                return false;
            }

        };

        /**
         * Do the app import
         */
        $scope.import = function () {

            if ($scope.view.urlImport) {
                if (!$scope.urlImport.url.$invalid) {

                    $scope.view.error = '';

                    $http.post(Globals.apiUrls.brood + 'import', {url: $scope.view.url}).then(function (response) {

                        if (!response.data) {
                            $rootScope.$broadcast('httpError', {message: 'Something has gone wrong, summon the avengers.'});
                            return false;
                        }

                        var data = response.data.message;
                        $scope.view.validating = false;

                        if (typeof data === 'object') {
                            validateJson(JSON.stringify(data));
                        } else {
                            try {
                                var test = JSON.parse(data);
                                validateJson(data);
                            } catch (e) {
                                $rootScope.$broadcast('httpError', {message: 'Error while parsing json response'});
                            }
                        }

                    }, function (trace) {
                        $scope.view.validating = false;
                    });
                } else {
                    $scope.view.error = 'You must provide valid url';
                }

            } else {
                validateJson($scope.mirror.getValue());
{'fraction_non_alphanumeric': 0.1279807857265397, 'fraction_numerical': 0.004460456338994682, 'mean_word_length': 1.2116843702579667, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '818360', 'n_tokens_mistral': 1529, 'n_tokens_neox': 1416, 'n_words': 324}