<commit_before>import { Component, OnInit, Input, Output, EventEmitter, ChangeDetectionStrategy } from '@angular/core';
import { FormGroup, FormControl, FormBuilder, FormArray, Validators } from '@angular/forms';
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';
import { RouterExtensions, Config } from '../../modules/core/index';
import * as area from '@mapbox/geojson-area';

import { IAppState } from '../../modules/ngrx/index';
import { NameRefactorService } from '../../modules/core/services/nameRefactor.service';
import { Platform, Zone } from '../../modules/datas/models/index';
import { PlatformAction } from '../../modules/datas/actions/index';

@Component({
    moduleId: module.id,
    changeDetection: ChangeDetectionStrategy.OnPush,
    selector: 'bc-zone-form',
    templateUrl: 'zone-form.component.html',
    styleUrls: [
        'zone-form.component.css',
    ],
})
export class ZoneFormComponent implements OnInit {
    @Input() platform: Platform;
    @Input() zone: Zone | null;
    @Input() errorMessage: boolean;

    @Output() submitted = new EventEmitter<Zone>();

    code: string;

    zoneForm: FormGroup = new FormGroup({
        type: new FormControl("Feature"),
        geometry: new FormGroup({
            type: new FormControl("Polygon"),
            coordinates: new FormControl(),
        }),
        properties: new FormGroup({
            name: new FormControl(""),
            code: new FormControl(""),
            surface: new FormControl(),
        }),
        codePlatform: new FormControl(""),
        transects: new FormArray([]),
        zonePreferences: new FormArray([])
    });

    constructor(private nameRefactorService: NameRefactorService, private store: Store<IAppState>, public routerext: RouterExtensions, private _fb: FormBuilder) { }

    ngOnInit() {
        this.zoneForm.controls.codePlatform.setValue(this.platform ? this.platform.code : null);
        if(this.zone){
            this.zoneForm.controls.properties.get("name").setValue(this.zone.properties.name) 
            let string = '';
            let coordAr = this.zone.geometry["coordinates"]["0"];
            for(let i = 0; i < coordAr.length; i++){
                string += (coordAr[i]["0"].toString() + "," + coordAr[i]["1"].toString() + "," + coordAr[i]["2"].toString() + " ");
            }
            this.zoneForm.controls.geometry.get("coordinates").setValue(string);
            this.zoneForm.controls.properties.get("name").disable();

        }
    }

    submit() {

        this.zoneForm.controls.properties.get("surface").setValue(parseInt(this.zoneForm.controls.properties.get("surface").value));
        this.zoneForm.controls.properties.get("code").setValue(this.platform.code + "_" +this.nameRefactorService.convertAccent(this.zoneForm.controls.properties.get("name").value).split(' ').join('-').replace(/[^a-zA-Z0-9]/g,''));

        this.refactorCoordinates();
        this.setSurface();
                   
        if (this.zoneForm.valid) {
            if(this.zoneForm.controls.properties.get("surface").value === 0){
                this.errorMessage = true;
            }else{
                this.zoneForm.controls.properties.get("name").enable();
                this.submitted.emit(this.zoneForm.value);
            }
        }
    }<commit_msg>refactor<commit_after>import { Component, OnInit, Input, Output, EventEmitter, ChangeDetectionStrategy } from '@angular/core';
import { FormGroup, FormControl, FormBuilder, FormArray, Validators } from '@angular/forms';
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';
import { RouterExtensions, Config } from '../../modules/core/index';
import * as area from '@mapbox/geojson-area';

import { IAppState } from '../../modules/ngrx/index';
import { NameRefactorService } from '../../modules/core/services/nameRefactor.service';
import { Platform, Zone } from '../../modules/datas/models/index';
import { PlatformAction } from '../../modules/datas/actions/index';

@Component({
    moduleId: module.id,
    changeDetection: ChangeDetectionStrategy.OnPush,
    selector: 'bc-zone-form',
    templateUrl: 'zone-form.component.html',
    styleUrls: [
        'zone-form.component.css',
    ],
})
export class ZoneFormComponent implements OnInit {
    @Input() platform: Platform;
    @Input() zone: Zone | null;
    @Input() errorMessage: boolean;

    @Output() submitted = new EventEmitter<Zone>();

    code: string;

    zoneForm: FormGroup = new FormGroup({
        type: new FormControl("Feature"),
        geometry: new FormGroup({
            type: new FormControl("Polygon"),
            coordinates: new FormControl(),
        }),
        properties: new FormGroup({
            name: new FormControl(""),
            code: new FormControl(""),
            surface: new FormControl(),
        }),
        codePlatform: new FormControl(""),
        transects: new FormArray([]),
        zonePreferences: new FormArray([])
    });

    constructor(private nameRefactorService: NameRefactorService, private store: Store<IAppState>, public routerext: RouterExtensions, private _fb: FormBuilder) { }

    ngOnInit() {
        this.zoneForm.controls.codePlatform.setValue(this.platform ? this.platform.code : null);
        if(this.zone){
            this.zoneForm.controls.properties.get("name").setValue(this.zone.properties.name) 
            let string = '';
            let coordAr = this.zone.geometry["coordinates"]["0"];
            for(let i = 0; i < coordAr.length; i++){
                string += (coordAr[i]["0"].toString() + "," + coordAr[i]["1"].toString() + "," + coordAr[i]["2"].toString() + " ");
            }
            this.zoneForm.controls.geometry.get("coordinates").setValue(string);
            this.zoneForm.controls.properties.get("name").disable();

        }
    }

    submit() {
        this.errorMessage = false;

        this.zoneForm.controls.properties.get("surface").setValue(parseInt(this.zoneForm.controls.properties.get("surface").value));
        this.zoneForm.controls.properties.get("code").setValue(this.platform.code + "_" +this.nameRefactorService.convertAccent(this.zoneForm.controls.properties.get("name").value).split(' ').join('-').replace(/[^a-zA-Z0-9]/g,''));

        this.refactorCoordinates();
        this.setSurface();
        if (this.zoneForm.valid) {
            if(this.zoneForm.controls.properties.get("surface").value === 0){
                this.errorMessage = true;
            }else{
                this.zoneForm.controls.properties.get("name").enable();
                this.submitted.emit(this.zoneForm.value);
            }
        }
    }
{'fraction_non_alphanumeric': 0.15867545699730295, 'fraction_numerical': 0.00239736290080911, 'mean_word_length': 2.860613071139387, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '1786522', 'n_tokens_mistral': 1858, 'n_tokens_neox': 1851, 'n_words': 346}