<commit_before>angular.module('PaperUI.controllers', [ 'PaperUI.constants' ]).controller('BodyController', function($rootScope, $scope, $http, $location, eventService, toastService, discoveryResultRepository, thingTypeRepository, bindingRepository, restConfig, util) {
    $scope.scrollTop = 0;
    $(window).scroll(function() {
        $scope.$apply(function(scope) {
            $scope.scrollTop = $('body').scrollTop();
        });
    });
    $scope.isBigTitle = function() {
        return $scope.scrollTop < 80 && !$rootScope.simpleHeader;
    }
    $scope.setTitle = function(title) {
        $rootScope.title = title;
    }
    $scope.subtitles = [];
    $scope.setSubtitle = function(args) {
        $scope.subtitles = [];
        $.each(args, function(i, subtitle) {
            $scope.subtitles.push(subtitle);
        })
    }
    $scope.setHeaderText = function(headerText) {
        $scope.headerText = headerText;
    }
    $rootScope.$on('$routeChangeStart', function() {
        $scope.subtitles = [];
        $scope.headerText = null;
    });
    $scope.generateUUID = function() {
        var d = new Date().getTime();
        var uuid = 'xxxxxxxx'.replace(/[x]/g, function(c) {
            var r = (d + Math.random() * 16) % 16 | 0;
            d = Math.floor(d / 16);
            return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);
        });
        return uuid;
    };

    var numberOfInboxEntries = -1, prevAudioUrl = '';
    eventService.onEvent('smarthome/inbox/*/added', function(topic, discoveryResult) {
        toastService.showDefaultToast('New Inbox Entry: ' + discoveryResult.label, 'Show Inbox', 'inbox/search');
    });
    eventService.onEvent('smarthome/webaudio/playurl', function(topic, audioUrl) {
        if (prevAudioUrl !== audioUrl) {
            var context;
            window.AudioContext = window.AudioContext || window.webkitAudioContext;
            if (typeof (window.AudioContext) != "undefined") {
                try {
                    context = new AudioContext();
                    var audioBuffer = null;
                    $http({
                        url : audioUrl,
                        method : 'GET',
                        responseType : 'arraybuffer'
                    }).then(function(response) {
                        context.decodeAudioData(response.data, function(buffer) {
                            audioBuffer = buffer;
                            var source = context.createBufferSource();
                            source.buffer = buffer;
                            source.connect(context.destination);
                            source.onended = function() {
                                context.close();
                            }
                            source.start(0);
                        });
                    });
                } catch (e) {
                    if (context) {
                        context.close();
                    }
                }
            } else {
                angular.element("#audioSink").attr('src', audioUrl);
            }
            prevAudioUrl = audioUrl;
        }
    });
    eventService.onEvent('smarthome/items/*/state', function(topic, stateObject) {

        var itemName = topic.split('/')[2];
        var state = stateObject.value;

        console.log('Item ' + itemName + ' updated: ' + state);

        if ($rootScope.itemUpdates[itemName] + 500 > new Date().getTime()) {
            console.log('Ignoring update for ' + itemName + ', because update was probably triggered through UI.');
            return;
        }

        var changeStateRecursively = function(item) {
            var updateState = true;
            if (item.name === itemName) {
                // ignore ON and OFF update for Dimmer
                if (item.type === 'Dimmer') {
                    if (state === 'ON' || state == 'OFF') {
                        updateState = false;
                    }
                }
                if (item.type === "Number" || item.groupType === "Number") {
                    var parsedValue = Number(state);
                    if (isNaN(parsedValue)) {
                        state = null;
                    } else {
                        state = parsedValue;
                    }
                }
                if (item.type === "Rollershutter") {
                    if (stateObject.type == "Percent" || stateObject.type == "Decimal") {
                        state = parseInt(stateObject.value);
                    }
                }<commit_msg>[PaperUI] fix UNDEF/NULL display (#4408)<commit_after>angular.module('PaperUI.controllers', [ 'PaperUI.constants' ]).controller('BodyController', function($rootScope, $scope, $http, $location, eventService, toastService, discoveryResultRepository, thingTypeRepository, bindingRepository, restConfig, util) {
    $scope.scrollTop = 0;
    $(window).scroll(function() {
        $scope.$apply(function(scope) {
            $scope.scrollTop = $('body').scrollTop();
        });
    });
    $scope.isBigTitle = function() {
        return $scope.scrollTop < 80 && !$rootScope.simpleHeader;
    }
    $scope.setTitle = function(title) {
        $rootScope.title = title;
    }
    $scope.subtitles = [];
    $scope.setSubtitle = function(args) {
        $scope.subtitles = [];
        $.each(args, function(i, subtitle) {
            $scope.subtitles.push(subtitle);
        })
    }
    $scope.setHeaderText = function(headerText) {
        $scope.headerText = headerText;
    }
    $rootScope.$on('$routeChangeStart', function() {
        $scope.subtitles = [];
        $scope.headerText = null;
    });
    $scope.generateUUID = function() {
        var d = new Date().getTime();
        var uuid = 'xxxxxxxx'.replace(/[x]/g, function(c) {
            var r = (d + Math.random() * 16) % 16 | 0;
            d = Math.floor(d / 16);
            return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);
        });
        return uuid;
    };

    var numberOfInboxEntries = -1, prevAudioUrl = '';
    eventService.onEvent('smarthome/inbox/*/added', function(topic, discoveryResult) {
        toastService.showDefaultToast('New Inbox Entry: ' + discoveryResult.label, 'Show Inbox', 'inbox/search');
    });
    eventService.onEvent('smarthome/webaudio/playurl', function(topic, audioUrl) {
        if (prevAudioUrl !== audioUrl) {
            var context;
            window.AudioContext = window.AudioContext || window.webkitAudioContext;
            if (typeof (window.AudioContext) != "undefined") {
                try {
                    context = new AudioContext();
                    var audioBuffer = null;
                    $http({
                        url : audioUrl,
                        method : 'GET',
                        responseType : 'arraybuffer'
                    }).then(function(response) {
                        context.decodeAudioData(response.data, function(buffer) {
                            audioBuffer = buffer;
                            var source = context.createBufferSource();
                            source.buffer = buffer;
                            source.connect(context.destination);
                            source.onended = function() {
                                context.close();
                            }
                            source.start(0);
                        });
                    });
                } catch (e) {
                    if (context) {
                        context.close();
                    }
                }
            } else {
                angular.element("#audioSink").attr('src', audioUrl);
            }
            prevAudioUrl = audioUrl;
        }
    });
    eventService.onEvent('smarthome/items/*/state', function(topic, stateObject) {

        var itemName = topic.split('/')[2];
        var state = stateObject.value;

        console.log('Item ' + itemName + ' updated: ' + state);

        if ($rootScope.itemUpdates[itemName] + 500 > new Date().getTime()) {
            console.log('Ignoring update for ' + itemName + ', because update was probably triggered through UI.');
            return;
        }

        var changeStateRecursively = function(item) {
            var updateState = true;
            if (item.name === itemName) {
                // ignore ON and OFF update for Dimmer
                if (item.type === 'Dimmer') {
                    if (state === 'ON' || state == 'OFF') {
                        updateState = false;
                    }
                }
                if (item.type === "Number" || item.groupType === "Number") {
                    var parsedValue = Number(state);
                    if (!isNaN(parsedValue)) {
                        state = parsedValue;
                    }
                }
                if (item.type === "Rollershutter") {
                    if (stateObject.type == "Percent" || stateObject.type == "Decimal") {
                        state = parseInt(stateObject.value);
                    }
                }
{'fraction_non_alphanumeric': 0.12944805552495317, 'fraction_numerical': 0.005288090778891704, 'mean_word_length': 1.4735694822888283, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '983127', 'n_tokens_mistral': 2405, 'n_tokens_neox': 2285, 'n_words': 451}