<commit_before>angular.module('PaperUI.services', [ 'PaperUI.constants' ]).config(function($httpProvider) {
    var language = localStorage.getItem('language');
    if (language) {
        $httpProvider.defaults.headers.common['Accept-Language'] = language;
    }
    $httpProvider.interceptors.push(function($q, $injector) {
        return {
            'responseError' : function(rejection) {
                $injector.get('toastService').showErrorToast('ERROR: ' + rejection.status + ' - ' + rejection.statusText);
                return $q.reject(rejection);
            }
        };
    });
}).factory('eventService', function($resource, $log, restConfig) {

    var callbacks = [];
    var eventSrc;

    var initializeEventService = function() {

        eventSrc = new EventSource(restConfig.eventPath)
        $log.debug('Initializing event service.')

        eventSrc.addEventListener('error', function(event) {
            if (eventSrc.readyState === 2) { // CLOSED
                $log.debug('Event connection broken. Trying to reconnect in 5 seconds.');
                setTimeout(initializeEventService, 5000);
            }
        });
        eventSrc.addEventListener('message', function(event) {
            var data = JSON.parse(event.data);
            $log.debug('Event received: ' + data.topic + ' - ' + data.payload);
            $.each(callbacks, function(index, element) {
                if (data.topic.match(element.topic)) {
                    element.callback(data.topic, JSON.parse(data.payload));
                }
            });
        });
    }
    initializeEventService();

    return new function() {
        this.onEvent = function(topic, callback) {
            var topicRegex = topic.replace('/', '\/').replace('*', '.*');
            callbacks.push({
                topic : topicRegex,
                callback : callback
            });
        }
    };
}).factory('toastService', function($mdToast, $rootScope) {
    return new function() {
        var self = this;
        this.showToast = function(id, text, actionText, actionUrl) {
            var toast = $mdToast.simple().content(text);
            if (actionText) {
                toast.action(actionText);
                toast.hideDelay(6000);
            } else {
                toast.hideDelay(3000);
            }
            toast.position('bottom right');
            $mdToast.show(toast).then(function(value) {
                if (value == "ok") {
                    $rootScope.$location.path(actionUrl);
                }
            });
        }
        this.showDefaultToast = function(text, actionText, actionUrl) {
            self.showToast('default', text, actionText, actionUrl);
        }
        this.showErrorToast = function(text, actionText, actionUrl) {
            self.showToast('error', text, actionText, actionUrl);
        }
        this.showSuccessToast = function(text, actionText, actionUrl) {
            self.showToast('success', text, actionText, actionUrl);
        }
    };
}).factory('configService', function(itemService, thingService, $filter, itemRepository) {
    return {
        getRenderingModel : function(configParameters, configGroups) {
            var parameters = [];
            var indexArray = [];
            if (!configGroups) {
                configGroups = [];
            }
            configGroups.push({
                "name" : "_default",
                "label" : "Others"
            });

            for (var j = 0; j < configGroups.length; j++) {
                indexArray[configGroups[j].name] = j;
            }
            if (!configParameters) {
                return parameters;
            }
            var groupsList = [];
            for (var j = 0; j < configGroups.length; j++) {
                groupsList[j] = {};
                groupsList[j].parameters = [];
            }
            var thingList;
            for (var i = 0; i < configParameters.length; i++) {
                var parameter = configParameters[i];

                var group = [];
                if (!parameter.groupName) {
                    parameter.groupName = "_default";
                }
                group = $filter('filter')(configGroups, {
                    name : parameter.groupName
                }, true);

                if (parameter.context) {
                    if (parameter.context.toUpperCase() === 'ITEM') {
                        parameter.element = 'select';
                    } else if (parameter.context.toUpperCase() === 'DATE') {
                        parameter.element = 'date';
                    } else if (parameter.context.toUpperCase() === 'THING') {
                        parameter.element = 'select';
                        thingList = thingList === undefined ? thingService.getAll() : thingList;
                        parameter.options = thingList;
                    } else if (parameter.context.toUpperCase() === 'COLOR' || parameter.context.toUpperCase() === 'TIME') {
                        parameter.element = 'input';
                        parameter.input = "TEXT";
                        parameter.inputType = parameter.context;
                    } else if (parameter.context.toUpperCase() === 'SCRIPT') {
                        parameter.element = 'textarea';
                        parameter.inputType = 'text';
                        parameter.label = parameter.label && parameter.label.length > 0 ? parameter.label : 'Script';
                    }
                } else if (parameter.type.toUpperCase() === 'TEXT') {
                    if (parameter.options && parameter.options.length > 0) {
                        parameter.element = 'select';<commit_msg>default text field if there is no widget for context (#1708)<commit_after>angular.module('PaperUI.services', [ 'PaperUI.constants' ]).config(function($httpProvider) {
    var language = localStorage.getItem('language');
    if (language) {
        $httpProvider.defaults.headers.common['Accept-Language'] = language;
    }
    $httpProvider.interceptors.push(function($q, $injector) {
        return {
            'responseError' : function(rejection) {
                $injector.get('toastService').showErrorToast('ERROR: ' + rejection.status + ' - ' + rejection.statusText);
                return $q.reject(rejection);
            }
        };
    });
}).factory('eventService', function($resource, $log, restConfig) {

    var callbacks = [];
    var eventSrc;

    var initializeEventService = function() {

        eventSrc = new EventSource(restConfig.eventPath)
        $log.debug('Initializing event service.')

        eventSrc.addEventListener('error', function(event) {
            if (eventSrc.readyState === 2) { // CLOSED
                $log.debug('Event connection broken. Trying to reconnect in 5 seconds.');
                setTimeout(initializeEventService, 5000);
            }
        });
        eventSrc.addEventListener('message', function(event) {
            var data = JSON.parse(event.data);
            $log.debug('Event received: ' + data.topic + ' - ' + data.payload);
            $.each(callbacks, function(index, element) {
                if (data.topic.match(element.topic)) {
                    element.callback(data.topic, JSON.parse(data.payload));
                }
            });
        });
    }
    initializeEventService();

    return new function() {
        this.onEvent = function(topic, callback) {
            var topicRegex = topic.replace('/', '\/').replace('*', '.*');
            callbacks.push({
                topic : topicRegex,
                callback : callback
            });
        }
    };
}).factory('toastService', function($mdToast, $rootScope) {
    return new function() {
        var self = this;
        this.showToast = function(id, text, actionText, actionUrl) {
            var toast = $mdToast.simple().content(text);
            if (actionText) {
                toast.action(actionText);
                toast.hideDelay(6000);
            } else {
                toast.hideDelay(3000);
            }
            toast.position('bottom right');
            $mdToast.show(toast).then(function(value) {
                if (value == "ok") {
                    $rootScope.$location.path(actionUrl);
                }
            });
        }
        this.showDefaultToast = function(text, actionText, actionUrl) {
            self.showToast('default', text, actionText, actionUrl);
        }
        this.showErrorToast = function(text, actionText, actionUrl) {
            self.showToast('error', text, actionText, actionUrl);
        }
        this.showSuccessToast = function(text, actionText, actionUrl) {
            self.showToast('success', text, actionText, actionUrl);
        }
    };
}).factory('configService', function(itemService, thingService, $filter, itemRepository) {
    return {
        getRenderingModel : function(configParameters, configGroups) {
            var parameters = [];
            var indexArray = [];
            if (!configGroups) {
                configGroups = [];
            }
            configGroups.push({
                "name" : "_default",
                "label" : "Others"
            });

            for (var j = 0; j < configGroups.length; j++) {
                indexArray[configGroups[j].name] = j;
            }
            if (!configParameters) {
                return parameters;
            }
            var groupsList = [];
            for (var j = 0; j < configGroups.length; j++) {
                groupsList[j] = {};
                groupsList[j].parameters = [];
            }
            var thingList;
            for (var i = 0; i < configParameters.length; i++) {
                var parameter = configParameters[i];

                var group = [];
                if (!parameter.groupName) {
                    parameter.groupName = "_default";
                }
                group = $filter('filter')(configGroups, {
                    name : parameter.groupName
                }, true);

                if (parameter.context) {
                    if (parameter.context.toUpperCase() === 'ITEM') {
                        parameter.element = 'select';
                    } else if (parameter.context.toUpperCase() === 'DATE') {
                        parameter.element = 'date';
                    } else if (parameter.context.toUpperCase() === 'THING') {
                        parameter.element = 'select';
                        thingList = thingList === undefined ? thingService.getAll() : thingList;
                        parameter.options = thingList;
                    } else if (parameter.context.toUpperCase() === 'COLOR' || parameter.context.toUpperCase() === 'TIME') {
                        parameter.element = 'input';
                        parameter.input = "TEXT";
                        parameter.inputType = parameter.context;
                    } else if (parameter.context.toUpperCase() === 'SCRIPT') {
                        parameter.element = 'textarea';
                        parameter.inputType = 'text';
                        parameter.label = parameter.label && parameter.label.length > 0 ? parameter.label : 'Script';
                    } else {
                        parameter.element = 'input';
                        parameter.inputType = 'text';
                    }
                } else if (parameter.type.toUpperCase() === 'TEXT') {
                    if (parameter.options && parameter.options.length > 0) {
                        parameter.element = 'select';
{'fraction_non_alphanumeric': 0.1283777950444617, 'fraction_numerical': 0.003626003626003626, 'mean_word_length': 1.6054880791722896, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '6346412', 'n_tokens_mistral': 2958, 'n_tokens_neox': 2800, 'n_words': 554}