<commit_before>﻿import {Component, OnInit, ViewChild} from 'angular2/core';
import {SideBarComponent} from './sidebar.component';
import {TopBarComponent} from './top-bar.component';
import {FunctionNewV2Component} from './function-new-v2.component';
import {FunctionEditComponent} from './function-edit.component';
import {DropDownComponent} from './drop-down.component';
import {AppSettingsComponent} from './app-settings.component';
import {FunctionsService} from '../services/functions.service';
import {UserService} from '../services/user.service';
import {PortalService} from '../services/portal.service';
import {FunctionInfo} from '../models/function-info';
import {VfsObject} from '../models/vfs-object';
import {FunctionTemplate} from '../models/function-template';
import {ScmInfo} from '../models/scm-info';
import {Subscription} from '../models/subscription';
import {DropDownElement} from '../models/drop-down-element';
import {ServerFarm} from '../models/server-farm';
import {BroadcastEvent, IBroadcastService} from '../services/ibroadcast.service';
import {FunctionNewComponent} from './function-new.component';

@Component({
    selector: 'functions-dashboard',
    templateUrl: 'templates/dashboard.component.html',
    styleUrls: ['styles/dashboard.style.css'],
    directives: [
        SideBarComponent,
        TopBarComponent,
        FunctionNewV2Component,
        FunctionEditComponent,
        DropDownComponent,
        AppSettingsComponent,
        FunctionNewComponent
    ]
})
export class DashboardComponent implements OnInit {
    @ViewChild(SideBarComponent) sideBar: SideBarComponent;

    public functionsInfo: FunctionInfo[];
    public functionTemplates: FunctionTemplate[];
    public selectedFunction: FunctionInfo;
    public openAppSettings: boolean;


    constructor(private _functionsService: FunctionsService,
        private _userService: UserService,
        private _portalService: PortalService,
        private _broadcastService: IBroadcastService) {



        this._broadcastService.subscribe<FunctionInfo>(BroadcastEvent.FunctionDeleted, fi => {
            if (this.selectedFunction === fi) {
                delete this.selectedFunction;
            }
        });

        this._broadcastService.subscribe<FunctionInfo>(BroadcastEvent.FunctionSelected, fi => {
            this.resetView();
            this.selectedFunction = fi;
            this.sideBar.selectedFunction = fi;
        });
    }

    ngOnInit() {
        this._broadcastService.setBusyState();

        if (this._portalService.inIFrame) {
            this._portalService.initializeIframe((token: string) => {
                this._functionsService.setToken(token);
                this._functionsService.getTemplates()
                    .subscribe(res => this.functionTemplates = res);
                this.initFunctions();
            });
        }
        else {
            this._functionsService.getTemplates()
                .subscribe(res => this.functionTemplates = res);
            this.initFunctions();
        }
    }

    initFunctions() {
        this._functionsService.redirectToIbizaIfNeeded();
        this._functionsService.getFunctions()<commit_msg>Call InitializaUser wen in iframe<commit_after>﻿import {Component, OnInit, ViewChild} from 'angular2/core';
import {SideBarComponent} from './sidebar.component';
import {TopBarComponent} from './top-bar.component';
import {FunctionNewV2Component} from './function-new-v2.component';
import {FunctionEditComponent} from './function-edit.component';
import {DropDownComponent} from './drop-down.component';
import {AppSettingsComponent} from './app-settings.component';
import {FunctionsService} from '../services/functions.service';
import {UserService} from '../services/user.service';
import {PortalService} from '../services/portal.service';
import {FunctionInfo} from '../models/function-info';
import {VfsObject} from '../models/vfs-object';
import {FunctionTemplate} from '../models/function-template';
import {ScmInfo} from '../models/scm-info';
import {Subscription} from '../models/subscription';
import {DropDownElement} from '../models/drop-down-element';
import {ServerFarm} from '../models/server-farm';
import {BroadcastEvent, IBroadcastService} from '../services/ibroadcast.service';
import {FunctionNewComponent} from './function-new.component';

@Component({
    selector: 'functions-dashboard',
    templateUrl: 'templates/dashboard.component.html',
    styleUrls: ['styles/dashboard.style.css'],
    directives: [
        SideBarComponent,
        TopBarComponent,
        FunctionNewV2Component,
        FunctionEditComponent,
        DropDownComponent,
        AppSettingsComponent,
        FunctionNewComponent
    ]
})
export class DashboardComponent implements OnInit {
    @ViewChild(SideBarComponent) sideBar: SideBarComponent;

    public functionsInfo: FunctionInfo[];
    public functionTemplates: FunctionTemplate[];
    public selectedFunction: FunctionInfo;
    public openAppSettings: boolean;


    constructor(private _functionsService: FunctionsService,
        private _userService: UserService,
        private _portalService: PortalService,
        private _broadcastService: IBroadcastService) {

        this._broadcastService.subscribe<FunctionInfo>(BroadcastEvent.FunctionDeleted, fi => {
            if (this.selectedFunction === fi) {
                delete this.selectedFunction;
            }
        });

        this._broadcastService.subscribe<FunctionInfo>(BroadcastEvent.FunctionSelected, fi => {
            this.resetView();
            this.selectedFunction = fi;
            this.sideBar.selectedFunction = fi;
        });
    }

    ngOnInit() {
        this._broadcastService.setBusyState();

        if (this._portalService.inIFrame) {
            this._portalService.initializeIframe((token: string) => {
                this._functionsService.setToken(token);
                this._functionsService.getTemplates()
                    .subscribe(res => this.functionTemplates = res);
                this._functionsService.initializeUser()
                    .subscribe(r => this.initFunctions());
            });
        }
        else {
            this._functionsService.getTemplates()
                .subscribe(res => this.functionTemplates = res);
            this.initFunctions();
        }
    }

    initFunctions() {
        this._functionsService.redirectToIbizaIfNeeded();
        this._functionsService.getFunctions()
{'fraction_non_alphanumeric': 0.11703932151117964, 'fraction_numerical': 0.001233616037008481, 'mean_word_length': 3.1710610932475882, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 18, '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': '6538708', 'n_tokens_mistral': 1643, 'n_tokens_neox': 1633, 'n_words': 327}