<commit_before>define(['qvangular', 'qlik'], function(qva, qlik) {

    var app = qlik.currApp();

    qva.directive('exportTableButton', ['qlikService', function(qlikService){
        return {
            restrict: 'E',
            template: '<div class="exportButtonContainer" ng-show="canExportData && !hideButton">' +
                '<button ng-click="exportData()"><span class="lui-icon lui-icon--download"></span></button></div>',
            scope: {
                tab: '=',
                hideButton: '='
            },
            link: function(scope){
                scope.table, scope.data;
                scope.canExportData = false;
                scope.hideButton = scope.hideButton || false;

                app.getObject(scope.tab.objectid).then(function(model){
                    return qlikService.getAllDataRows(model);
                }).then(function(data){
                    if(data instanceof Array && data.length > 0){
                        scope.canExportData = true;
                        scope.data = data;
                    }
                });

                scope.exportData = function() {
                    var csvContent = 'data:text/csv;charset=utf-8,';
                    var dataString, encodeUri;

                    scope.data.forEach(function(dataArray, index){
                        dataArray = dataArray.map(function(cell){ return cell.qText; });
                        dataString = dataArray.join(',');
                        csvContent += (index < scope.data.length) ? dataString + '\n' : dataString;
                    });

                    triggerDownload(csvContent);
                }
            }
        }
    }]);

    /** PRIVATE FUNCTIONS */
    function getHypercubeData(hypercube){
        return hypercube.qHyperCube.qDataPages[0].qMatrix.map(function(row) {
            return row.map(function(cell){ return cell.qText; })
        });
    }

    function triggerDownload(csvContent){
        var encodedUri = encodeURI(csvContent);
        var link = document.createElement('a');

        link.setAttribute('href', encodedUri)
        link.setAttribute('download', 'data.csv');
        document.body.appendChild(link);
        link.click();
    }
})
<commit_msg>Hide the export button by default<commit_after>define(['qvangular', 'qlik'], function(qva, qlik) {

    var app = qlik.currApp();

    qva.directive('exportTableButton', ['qlikService', function(qlikService){
        return {
            restrict: 'E',
            template: '<div class="exportButtonContainer" ng-show="canExportData && !hideButton">' +
                '<button ng-click="exportData()"><span class="lui-icon lui-icon--download"></span></button></div>',
            scope: {
                tab: '=',
                hideButton: '='
            },
            link: function(scope){
                scope.table, scope.data;
                scope.canExportData = false;
                scope.hideButton = scope.hideButton || true;

                app.getObject(scope.tab.objectid).then(function(model){
                    return qlikService.getAllDataRows(model);
                }).then(function(data){
                    if(data instanceof Array && data.length > 0){
                        scope.canExportData = true;
                        scope.data = data;
                    }
                });

                scope.exportData = function() {
                    var csvContent = 'data:text/csv;charset=utf-8,';
                    var dataString, encodeUri;

                    scope.data.forEach(function(dataArray, index){
                        dataArray = dataArray.map(function(cell){ return cell.qText; });
                        dataString = dataArray.join(',');
                        csvContent += (index < scope.data.length) ? dataString + '\n' : dataString;
                    });

                    triggerDownload(csvContent);
                }
            }
        }
    }]);

    /** PRIVATE FUNCTIONS */
    function getHypercubeData(hypercube){
        return hypercube.qHyperCube.qDataPages[0].qMatrix.map(function(row) {
            return row.map(function(cell){ return cell.qText; })
        });
    }

    function triggerDownload(csvContent){
        var encodedUri = encodeURI(csvContent);
        var link = document.createElement('a');

        link.setAttribute('href', encodedUri)
        link.setAttribute('download', 'data.csv');
        document.body.appendChild(link);
        link.click();
    }
})

{'fraction_non_alphanumeric': 0.13000221092195446, 'fraction_numerical': 0.0013265531726730046, 'mean_word_length': 1.6518171160609614, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3362792', 'n_tokens_mistral': 1216, 'n_tokens_neox': 1137, 'n_words': 193}