<commit_before>﻿import {Component, ViewChild, AfterViewInit, OnInit, Input, Output, EventEmitter} from '@angular/core';
import {FunctionsService} from '../services/functions.service';
import {BroadcastService} from '../services/broadcast.service';
import {UserService} from '../services/user.service';
import {BroadcastEvent} from '../models/broadcast-event'
import {BindingType} from '../models/binding';
import {FunctionTemplate} from '../models/function-template';
import {FunctionInfo} from '../models/function-info';
import {TutorialEvent, TutorialStep} from '../models/tutorial';
import {BindingManager} from '../models/binding-manager';
import {ErrorEvent} from '../models/error-event';
import {GlobalStateService} from '../services/global-state.service';
import {UIResource} from '../models/ui-resource';
import {FunctionContainer} from '../models/function-container';
import {BusyStateComponent} from './busy-state.component';
import {TranslateService, TranslatePipe} from 'ng2-translate/ng2-translate';
import {PortalResources} from '../models/portal-resources';

@Component({
    selector: 'try-landing',
    templateUrl: 'templates/try-landing.component.html',
    styleUrls: ['styles/try-landing.style.css'],
    directives: [BusyStateComponent],
    pipes: [TranslatePipe]
})

export class TryLandingComponent implements OnInit {
    @ViewChild(BusyStateComponent) busyState: BusyStateComponent;
    @Output() tryFunctionsContainer: EventEmitter<FunctionContainer>;
    public functionsInfo: FunctionInfo[] = new Array();
    bc: BindingManager = new BindingManager();
    loginOptions: boolean = false;
    selectedFunction: string;
    selectedLanguage: string;
    constructor(private _functionsService: FunctionsService,
        private _broadcastService: BroadcastService,
        private _globalStateService: GlobalStateService,
        private _userService: UserService,
        private _translateService: TranslateService

    ) {
        this.tryFunctionsContainer = new EventEmitter<FunctionContainer>();
    }

    ngOnInit() {
        //Disabling this temporarily. Somehow ngOnInit gets called twice on refresh
        //possibly related to https://github.com/angular/angular/issues/6782
        //and strangely the clearbusystate doesnt get called.
        //this.setBusyState();
        this._functionsService.getTemplates().subscribe((templates) => {
            if (this._globalStateService.TryAppServiceToken) {
                this.selectedFunction = this._functionsService.selectedFunction;
                this.selectedLanguage = this._functionsService.selectedLanguage;

                var selectedTemplate: FunctionTemplate = templates.find((t) => {
                    return t.id === this._functionsService.selectedFunction + "-" + this._functionsService.selectedLanguage;
                });

                if (selectedTemplate) {
                    this.setBusyState();
                    this._functionsService.createTrialResource(selectedTemplate,
                            this._functionsService.selectedProvider, this._functionsService.selectedFunctionName)
                        .subscribe((resource) => {
                                this.clearBusyState();
                                this.createFunctioninResource(resource, selectedTemplate, this._functionsService.selectedFunctionName);
                            },
                            error => {
                                if (error.status === 400) {
                                    // If there is already a free resource assigned ,<commit_msg>Don't block the UI waiting for /api/templates<commit_after>﻿import {Component, ViewChild, AfterViewInit, OnInit, Input, Output, EventEmitter} from '@angular/core';
import {FunctionsService} from '../services/functions.service';
import {BroadcastService} from '../services/broadcast.service';
import {UserService} from '../services/user.service';
import {BroadcastEvent} from '../models/broadcast-event'
import {BindingType} from '../models/binding';
import {FunctionTemplate} from '../models/function-template';
import {FunctionInfo} from '../models/function-info';
import {TutorialEvent, TutorialStep} from '../models/tutorial';
import {BindingManager} from '../models/binding-manager';
import {ErrorEvent} from '../models/error-event';
import {GlobalStateService} from '../services/global-state.service';
import {UIResource} from '../models/ui-resource';
import {FunctionContainer} from '../models/function-container';
import {BusyStateComponent} from './busy-state.component';
import {TranslateService, TranslatePipe} from 'ng2-translate/ng2-translate';
import {PortalResources} from '../models/portal-resources';

@Component({
    selector: 'try-landing',
    templateUrl: 'templates/try-landing.component.html',
    styleUrls: ['styles/try-landing.style.css'],
    directives: [BusyStateComponent],
    pipes: [TranslatePipe]
})

export class TryLandingComponent implements OnInit {
    @ViewChild(BusyStateComponent) busyState: BusyStateComponent;
    @Output() tryFunctionsContainer: EventEmitter<FunctionContainer>;
    public functionsInfo: FunctionInfo[] = new Array();
    bc: BindingManager = new BindingManager();
    loginOptions: boolean = false;
    selectedFunction: string;
    selectedLanguage: string;
    constructor(private _functionsService: FunctionsService,
        private _broadcastService: BroadcastService,
        private _globalStateService: GlobalStateService,
        private _userService: UserService,
        private _translateService: TranslateService

    ) {
        this.tryFunctionsContainer = new EventEmitter<FunctionContainer>();
    }

    ngOnInit() {
        //Disabling this temporarily. Somehow ngOnInit gets called twice on refresh
        //possibly related to https://github.com/angular/angular/issues/6782
        //and strangely the clearbusystate doesnt get called.
        //this.setBusyState();
        this.selectedFunction = this._functionsService.selectedFunction;
        this.selectedLanguage = this._functionsService.selectedLanguage;
        this._functionsService.getTemplates().subscribe((templates) => {
            if (this._globalStateService.TryAppServiceToken) {
                var selectedTemplate: FunctionTemplate = templates.find((t) => {
                    return t.id === this._functionsService.selectedFunction + "-" + this._functionsService.selectedLanguage;
                });

                if (selectedTemplate) {
                    this.setBusyState();
                    this._functionsService.createTrialResource(selectedTemplate,
                            this._functionsService.selectedProvider, this._functionsService.selectedFunctionName)
                        .subscribe((resource) => {
                                this.clearBusyState();
                                this.createFunctioninResource(resource, selectedTemplate, this._functionsService.selectedFunctionName);
                            },
                            error => {
                                if (error.status === 400) {
                                    // If there is already a free resource assigned ,
{'fraction_non_alphanumeric': 0.10891089108910891, 'fraction_numerical': 0.002510110165946172, 'mean_word_length': 2.980022197558269, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '826712', 'n_tokens_mistral': 1741, 'n_tokens_neox': 1686, 'n_words': 392}