<commit_before>import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { FormGroup, FormControl, FormBuilder, Validators } from '@angular/forms';
import { MdInput } from '@angular/material';

import '../../../rxjs_operators';

import { UsergroupJson } from '../../../db-models/json';
import { UsergroupsService } from '../usergroups.service';
import { CanComponentDeactivate } from '../../../guards/can-deactivate.guard';

@Component({
  selector: 'app-usergroup',
  templateUrl: './usergroup.component.html',
  styleUrls: ['./usergroup.component.css']
})
export class UsergroupComponent implements OnInit, CanComponentDeactivate {

  @ViewChild('getfocus') getfocus: MdInput;

  groupsData: any[] = [];
  portalsData: any[] = [];

  id: number;

  form: FormGroup;
  nameCtrl: FormControl;
  groupsCtrl: FormControl;
  portalsCtrl: FormControl;

  originalData: any = null;
  pleaseSave: boolean = false;

  errorMsg: string = '';
  errorDetails: string = '';

  static elementsNotEmpty(control: FormControl) {
    return control.value && control.value.length !== 0 ? null : { mustContainValues: true };
  }

  constructor(private route: ActivatedRoute, public router: Router,
    private fb: FormBuilder, public ugs: UsergroupsService) { }

  ngOnInit() {

    this.ugs.loadGroups().subscribe(groups => {
      this.groupsData = groups.map(g => ({ id: g.grp_id, name: g.org_name + ' - ' + g.grp_name }));
    });

    this.ugs.loadPortals().subscribe(portals => {
      this.portalsData = portals.map(p => ({ id: p.por_id, name: p.por_name }));
    });

    this.route.data.pluck<UsergroupJson[]>('usergroup')
      .subscribe(usergroups => {
        let usergroup = usergroups ? usergroups[0] : null;
        this.originalData = usergroup;
        this.id = usergroup ? usergroup.ugr_id : null;
        this.errorDetails = '';
        this.errorMsg = '';
        this.pleaseSave = false;
        if (this.form) {
          this.updateForm(usergroup);
        } else {
          this.createForm(usergroup);
        }
        this.getfocus.focus();
      });

  }

  private createForm(data: UsergroupJson) {
    this.nameCtrl = new FormControl(data ? data.ugr_name : '', Validators.required);
    this.groupsCtrl = new FormControl(data ? data.groups.map(g => g.grp_id) : [], UsergroupComponent.elementsNotEmpty);<commit_msg>debug usergroup json<commit_after>import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { FormGroup, FormControl, FormBuilder, Validators } from '@angular/forms';
import { MdInput } from '@angular/material';

import '../../../rxjs_operators';

import { UsergroupJson } from '../../../db-models/json';
import { UsergroupsService } from '../usergroups.service';
import { CanComponentDeactivate } from '../../../guards/can-deactivate.guard';

@Component({
  selector: 'app-usergroup',
  templateUrl: './usergroup.component.html',
  styleUrls: ['./usergroup.component.css']
})
export class UsergroupComponent implements OnInit, CanComponentDeactivate {

  @ViewChild('getfocus') getfocus: MdInput;

  groupsData: any[] = [];
  portalsData: any[] = [];

  id: number;

  form: FormGroup;
  nameCtrl: FormControl;
  groupsCtrl: FormControl;
  portalsCtrl: FormControl;

  originalData: any = null;
  pleaseSave: boolean = false;

  errorMsg: string = '';
  errorDetails: string = '';

  static elementsNotEmpty(control: FormControl) {
    return control.value && control.value.length !== 0 ? null : { mustContainValues: true };
  }

  constructor(private route: ActivatedRoute, public router: Router,
    private fb: FormBuilder, public ugs: UsergroupsService) { }

  ngOnInit() {

    this.ugs.loadGroups().subscribe(groups => {
      this.groupsData = groups.map(g => ({ id: g.grp_id, name: g.org_name + ' - ' + g.grp_name }));
    });

    this.ugs.loadPortals().subscribe(portals => {
      this.portalsData = portals.map(p => ({ id: p.por_id, name: p.por_name }));
    });

    this.route.data.pluck<UsergroupJson>('usergroup')
      .subscribe(usergroup => {
        this.originalData = usergroup;
        this.id = usergroup ? usergroup.ugr_id : null;
        this.errorDetails = '';
        this.errorMsg = '';
        this.pleaseSave = false;
        if (this.form) {
          this.updateForm(usergroup);
        } else {
          this.createForm(usergroup);
        }
        this.getfocus.focus();
      });

  }

  private createForm(data: UsergroupJson) {
    this.nameCtrl = new FormControl(data ? data.ugr_name : '', Validators.required);
    this.groupsCtrl = new FormControl(data ? data.groups.map(g => g.grp_id) : [], UsergroupComponent.elementsNotEmpty);
{'fraction_non_alphanumeric': 0.15277484701413802, 'fraction_numerical': 0.0006330449461911796, 'mean_word_length': 3.392956441149212, 'pattern_counts': {'":': 0, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1561110', 'n_tokens_mistral': 1468, 'n_tokens_neox': 1445, 'n_words': 298}