<commit_before>/// <reference path='../../all.d.ts' />


module odh {
    'use strict';
    interface IField {
        name: string;
        alias: string;
    }

    interface IExpression {
        foreignKey: IField;
        joinField: IField;
        joinTable: any;
        operation: any;
    }
    export class OdhQLController {

        public query:string;
        public columns:string[];
        public rows:{};
        public submitted:boolean = false;
        public documents:Object[];
        public odhqlInputString = '';
        public selected;
        public manualEdit:boolean = false;
        public joinOperations:{
            none: {}
            union: {}
            join: {}
        };
        public tableParams:any;
        public alerts:Object[] = [];

        constructor(private $http:ng.IHttpService, private $state:ng.ui.IStateService, private $scope:any,
                    private ToastService:odh.utils.ToastService, private $window:ng.IWindowService, private $upload,
                    private UrlService:odh.utils.UrlService, private FileGroupService:main.FileGroupService,
                    private DocumentService:main.DocumentService,
                    private $log:ng.ILogService, private ngTableParams, public $filter:ng.IFilterService,
                    private $auth:any) {

            this.tableParams = new ngTableParams({
                page: 1,            // show first page
                count: 10,           // count per page
                limit: 10
            }, {
                counts: [10, 25, 50, 100],
                total: 0, // length of data
                getData: ($defer, params) => {
                    DocumentService.getList(params.url()).then(result => {
                        console.log(params);
                        params.total(result.count);
                        $defer.resolve(result.results);
                    });
                }
            });

            this.selected = {
                items: [],
                fields: {},
                expression: {},
                unionTargets: [],
                joinTargets: [],
                remove: (item) => {
                    var index = this.selected.items.indexOf(item);
                    if (index > -1) {
                        this.selected.items.splice(index, 1);
                    }
                    this.selected.fields[item.uniqueid] = [];
                }

                ,
                add: (item) => {
                    if (this.selected.items.indexOf(item) === -1) {
                        item.uniqueid = 'ODH' + item.id;
                        this.selected.expression[item.uniqueid] = {};
                        this.selected.items.push(item);
                        this.selected.expression[item.uniqueid].operation = this.joinOperations.none;
                    }
                }
                ,
                getItem: (item) => {
                    for (var i = 0; i < this.selected.items.length; i++) {
                        if (this.selected.items[i].uniqueid === item) {
                            return this.selected.items[i];
                        }
                    }
                }
            };
            this.joinOperations = {

                none: {
                    label: 'Nein',
                    operation: null
                },
                union: {
                    label: 'per UNION',
                    operation: 'union'
                },
                join: {
                    label: 'per JOIN',
                    operation: 'join'
                }
            };

        }

        public getFileGroup(document) {
            this.FileGroupService.getAll(document.id, true).then(filegroups => {

                document.$showRows = !document.$showRows;
                if (document.$showRows) {
                    angular.forEach(filegroups, (fg) => {
                        fg.cols = [];
                        console.log('fg', fg);
                        angular.forEach(fg.preview[0].columns, (col) => {
                            fg.cols.push({name: col, alias: col});
                        });
                    });
                    document.fileGroup = filegroups;

                } else {
                    document.fileGroup = [];
                }
            });
        }


        public odhqlInput(newInput:string = '') {
            if (newInput) {
                this.manualEdit = true;
                this.odhqlInputString = newInput;
                return newInput;
            }
            if (!this.manualEdit) {


                var fields:string[] = [];
                var master:string = '';
                var joinStatements:string[];
                var unionStatements:string[];
                unionStatements = [];
                joinStatements = [];
                this.selected.joinTargets = [];
                angular.forEach(this.selected.expression, (value:IExpression, key) => {
                    if (!value.operation.operation) {
                        if (!master) {
                            fields = this.createFieldNames(this.selected.fields[key], key).concat(fields);
                            master = key;
                            this.selected.joinTargets.push(this.selected.getItem(key));

                        }

                    }<commit_msg>DAT-104 #time 1h error handling if filegroup failes.  celanup logs<commit_after>/// <reference path='../../all.d.ts' />


module odh {
    'use strict';
    interface IField {
        name: string;
        alias: string;
    }

    interface IExpression {
        foreignKey: IField;
        joinField: IField;
        joinTable: any;
        operation: any;
    }
    export class OdhQLController {

        public query:string;
        public columns:string[];
        public rows:{};
        public submitted:boolean = false;
        public documents:Object[];
        public odhqlInputString = '';
        public selected;
        public manualEdit:boolean = false;
        public joinOperations:{
            none: {}
            union: {}
            join: {}
        };
        public tableParams:any;
        public alerts:Object[] = [];

        constructor(private $http:ng.IHttpService, private $state:ng.ui.IStateService, private $scope:any,
                    private ToastService:odh.utils.ToastService, private $window:ng.IWindowService, private $upload,
                    private UrlService:odh.utils.UrlService, private FileGroupService:main.FileGroupService,
                    private DocumentService:main.DocumentService,
                    private $log:ng.ILogService, private ngTableParams, public $filter:ng.IFilterService,
                    private $auth:any) {

            this.tableParams = new ngTableParams({
                page: 1,            // show first page
                count: 10,           // count per page
                limit: 10
            }, {
                counts: [10, 25, 50, 100],
                total: 0, // length of data
                getData: ($defer, params) => {
                    DocumentService.getList(params.url()).then(result => {
                        params.total(result.count);
                        $defer.resolve(result.results);
                    });
                }
            });

            this.selected = {
                items: [],
                fields: {},
                expression: {},
                unionTargets: [],
                joinTargets: [],
                remove: (item) => {
                    var index = this.selected.items.indexOf(item);
                    if (index > -1) {
                        this.selected.items.splice(index, 1);
                    }
                    this.selected.fields[item.uniqueid] = [];
                }

                ,
                add: (item) => {
                    if (this.selected.items.indexOf(item) === -1) {
                        item.uniqueid = 'ODH' + item.id;
                        this.selected.expression[item.uniqueid] = {};
                        this.selected.items.push(item);
                        this.selected.expression[item.uniqueid].operation = this.joinOperations.none;
                    }
                }
                ,
                getItem: (item) => {
                    for (var i = 0; i < this.selected.items.length; i++) {
                        if (this.selected.items[i].uniqueid === item) {
                            return this.selected.items[i];
                        }
                    }
                }
            };
            this.joinOperations = {

                none: {
                    label: 'Nein',
                    operation: null
                },
                union: {
                    label: 'per UNION',
                    operation: 'union'
                },
                join: {
                    label: 'per JOIN',
                    operation: 'join'
                }
            };

        }

        public getFileGroup(document) {
            this.FileGroupService.getAll(document.id, true).then(filegroups => {
                if (!document.$showRows) {
                    angular.forEach(filegroups, (fg) => {
                        fg.cols = [];
                        angular.forEach(fg.preview[0].columns, (col) => {
                            fg.cols.push({name: col, alias: col});
                        });
                    });
                    document.fileGroup = filegroups;
                } else {
                    document.fileGroup = [];
                }
                document.$showRows = !document.$showRows;
            }).catch(error => this.ToastService.failure('Es ist ein Fehler aufgetreten.'));
        }


        public odhqlInput(newInput:string = '') {
            if (newInput) {
                this.manualEdit = true;
                this.odhqlInputString = newInput;
                return newInput;
            }
            if (!this.manualEdit) {


                var fields:string[] = [];
                var master:string = '';
                var joinStatements:string[];
                var unionStatements:string[];
                unionStatements = [];
                joinStatements = [];
                this.selected.joinTargets = [];
                angular.forEach(this.selected.expression, (value:IExpression, key) => {
                    if (!value.operation.operation) {
                        if (!master) {
                            fields = this.createFieldNames(this.selected.fields[key], key).concat(fields);
                            master = key;
                            this.selected.joinTargets.push(this.selected.getItem(key));

                        }

                    }
{'fraction_non_alphanumeric': 0.10831489675516225, 'fraction_numerical': 0.004056047197640118, 'mean_word_length': 1.083941605839416, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 26, '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': '3315327', 'n_tokens_mistral': 2720, 'n_tokens_neox': 2486, 'n_words': 474}