<commit_before>import { Component, OnInit, AfterViewChecked, EventEmitter } from '@angular/core';
import { FormGroup, Validators, FormBuilder } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { ProjectService } from '../common/project.service';
import { Project } from '../common/project';
import { JobTitle } from '../../job-title';
import { Organization } from '../../organization/common/organization';
import { UserService } from '../../user/common/user.service';
import { OrganizationService } from '../../organization/common/organization.service';
import { FormConstantsService } from '../../_services/form-constants.service';
import { SkillService } from '../../skill/common/skill.service';
import { MaterializeAction } from 'angular2-materialize';
import { AuthService} from '../../auth.service';
import { ExtFileHandlerService } from '../../_services/extfilehandler.service';
import { ValidationService } from '../../_services/validation.service';

declare const Materialize: any;

@Component({
  selector: 'my-edit-project',
  templateUrl: 'project-edit.component.html',
  styleUrls: ['project-edit.component.scss']
})

export class ProjectEditComponent implements OnInit, AfterViewChecked {

  public currentUserId;
  public countries: any[];

  public projectId;
  public organizationId;
  public project: Project;
  public organization: Organization;
  public organizations: Organization[];

  public inputValue = '';
  public imageUrl: any = '';
  public jobTitlesArray: JobTitle[] = [];
  public projectSkillsArray: string[] = [];
  public skillsArray: string[] = [];
  public skill = '';
  public skillCounter = 0;

  public isCreate = false; // Create Project or Edit Project
  public isSkillExists = false;
  public isSkillLimit = false;

  public descMaxLength: number = this.validationService.descMaxLength;
  public descMaxLengthEntered = false;
  public descValueLength: number;
  public descFieldFocused = false;

  public projectForm: FormGroup;
  public globalActions = new EventEmitter<string|MaterializeAction>();

  constructor(public fb: FormBuilder,
              private projectService: ProjectService,
              private organizationService: OrganizationService,
              public constantsService: FormConstantsService,
              private route: ActivatedRoute,
              private auth: AuthService,
              private router: Router,
              private skillService: SkillService,
              private extfilehandler: ExtFileHandlerService,
              private validationService: ValidationService,
               private userService: UserService,
              ) {
  }

  ngOnInit(): void {

    this.currentUserId = this.auth.getCurrentUserId();
    this.getFormConstants();
    this.initForm();

    // Populates skills list
    this.skillService.getSkills()
      .subscribe(
        resSkills => {
          resSkills.map((obj) => {
            this.skillsArray.push(obj.skillName);
          });
        }, error => console.log(error)
      );

      

    this.route.params.subscribe(params => {
      this.projectId = +params['projectId'];

      if (this.projectId === 0) { // Create Project
        this.isCreate = true;

        // Gets organization ID for this new project
        this.organizationId = localStorage.getItem('userOrganizationId');

        // Gets project ID for this new project, backend will create a new empty project with project status 'N'.
        this.projectService.getProjectByOrg(Number(this.organizationId), 'N')
          .subscribe(
            res => {
              let projects: Project[];
              projects = res.json();
              projects.forEach((e: Project) => {
                this.projectId = e.id.toString();
                this.project = e;
                this.imageUrl = this.project.imageUrl;
                this.fillForm();
              });
            },
            error => console.log(error)
          );

        // Skills are empty for this new project
        this.projectSkillsArray = [];
      } else { // Edit Project
        // Populates the project
        this.projectService.getProject(this.projectId)
          .subscribe(
            resProject => {
              this.project = resProject;
              this.imageUrl = this.project.imageUrl;
              this.fillForm();
            }, error => console.log(error)
          );

        // Populates skills for the project
        this.skillService.getSkillsByProject(this.projectId)
          .subscribe(
            resSkillsProjects => {
              this.projectSkillsArray = resSkillsProjects;
            }, error => console.log(error)
          );
      }

     
      this.userService.getAllJobTitles()
        .subscribe(
        res => {
          this.jobTitlesArray = res;
        }, error => console.log(error)
        );
    });
  }

  private getFormConstants(): void {<commit_msg>Update project-edit.component.ts<commit_after>import { Component, OnInit, AfterViewChecked, EventEmitter } from '@angular/core';
import { FormGroup, Validators, FormBuilder } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { ProjectService } from '../common/project.service';
import { Project } from '../common/project';
import { JobTitle } from '../../job-title';
import { Organization } from '../../organization/common/organization';
import { UserService } from '../../user/common/user.service';
import { OrganizationService } from '../../organization/common/organization.service';
import { FormConstantsService } from '../../_services/form-constants.service';
import { SkillService } from '../../skill/common/skill.service';
import { MaterializeAction } from 'angular2-materialize';
import { AuthService} from '../../auth.service';
import { ExtFileHandlerService } from '../../_services/extfilehandler.service';
import { ValidationService } from '../../_services/validation.service';

declare const Materialize: any;

@Component({
  selector: 'my-edit-project',
  templateUrl: 'project-edit.component.html',
  styleUrls: ['project-edit.component.scss']
})

export class ProjectEditComponent implements OnInit, AfterViewChecked {

  public currentUserId;
  public countries: any[];

  public projectId;
  public organizationId;
  public project: Project;
  public organization: Organization;
  public organizations: Organization[];

  public inputValue = '';
  public imageUrl: any = '';
  public jobTitlesArray: JobTitle[] = [];
  public projectSkillsArray: string[] = [];
  public skillsArray: string[] = [];
  public skill = '';
  public skillCounter = 0;

  public isCreate = false; // Create Project or Edit Project
  public isSkillExists = false;
  public isSkillLimit = false;

  public descMaxLength: number = this.validationService.descMaxLength;
  public descMaxLengthEntered = false;
  public descValueLength: number;
  public descFieldFocused = false;

  public projectForm: FormGroup;
  public globalActions = new EventEmitter<string|MaterializeAction>();

  constructor(public fb: FormBuilder,
              private projectService: ProjectService,
              private organizationService: OrganizationService,
              public constantsService: FormConstantsService,
              private route: ActivatedRoute,
              private auth: AuthService,
              private router: Router,
              private skillService: SkillService,
              private extfilehandler: ExtFileHandlerService,
              private validationService: ValidationService,
               private userService: UserService,
              ) {
  }

  ngOnInit(): void {

    this.currentUserId = this.auth.getCurrentUserId();
    this.getFormConstants();
    this.initForm();

    // Populates skills list
    this.skillService.getSkills()
      .subscribe(
        resSkills => {
          resSkills.map((obj) => {
            this.skillsArray.push(obj.skillName);
          });
        }, error => console.log(error)
      );

    this.route.params.subscribe(params => {
      this.projectId = +params['projectId'];

      if (this.projectId === 0) { // Create Project
        this.isCreate = true;

        // Gets organization ID for this new project
        this.organizationId = localStorage.getItem('userOrganizationId');

        // Gets project ID for this new project, backend will create a new empty project with project status 'N'.
        this.projectService.getProjectByOrg(Number(this.organizationId), 'N')
          .subscribe(
            res => {
              let projects: Project[];
              projects = res.json();
              projects.forEach((e: Project) => {
                this.projectId = e.id.toString();
                this.project = e;
                this.imageUrl = this.project.imageUrl;
                this.fillForm();
              });
            },
            error => console.log(error)
          );

        // Skills are empty for this new project
        this.projectSkillsArray = [];
      } else { // Edit Project
        // Populates the project
        this.projectService.getProject(this.projectId)
          .subscribe(
            resProject => {
              this.project = resProject;
              this.imageUrl = this.project.imageUrl;
              this.fillForm();
            }, error => console.log(error)
          );

        // Populates skills for the project
        this.skillService.getSkillsByProject(this.projectId)
          .subscribe(
            resSkillsProjects => {
              this.projectSkillsArray = resSkillsProjects;
            }, error => console.log(error)
          );
      }

      this.userService.getAllJobTitles()
        .subscribe(
        res => {
          this.jobTitlesArray = res;
        }, error => console.log(error)
        );
    });
  }

  private getFormConstants(): void {
{'fraction_non_alphanumeric': 0.11548210483625672, 'fraction_numerical': 0.0006083341782419143, 'mean_word_length': 2.4892111779271313, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, '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': '6952123', 'n_tokens_mistral': 2517, 'n_tokens_neox': 2493, 'n_words': 613}