<commit_before>import { WorkItemType } from './../../models/work-item-type';
import { Space, Spaces } from 'ngx-fabric8-wit';
import {
  AfterViewInit,
  Component,
  EventEmitter,
  ElementRef,
  Input,
  OnInit,
  OnDestroy,
  Output,
  ViewChild,
  ViewChildren,
  Renderer,
  QueryList
} from '@angular/core';
import { Subscription } from 'rxjs/Subscription';
import { cloneDeep } from 'lodash';
import { Broadcaster, Logger } from 'ngx-base';
import { AuthenticationService } from 'ngx-login-client';

import { WorkItem, WorkItemRelations } from '../../models/work-item';
import { WorkItemService } from '../work-item.service';

@Component({
  selector: 'alm-work-item-quick-add',
  templateUrl: './work-item-quick-add.component.html',
  styleUrls: ['./work-item-quick-add.component.scss']
})
export class WorkItemQuickAddComponent implements OnInit, OnDestroy, AfterViewInit {
  @ViewChild('quickAddTitle') qaTitle: any;
  @ViewChild('quickAddDesc') qaDesc: any;
  @ViewChildren('quickAddTitle', {read: ElementRef}) qaTitleRef: QueryList<ElementRef>;

  @Input() wilistview: string = 'wi-list-view';
  @Output('workItemCreate') workItemCreate = new EventEmitter();

  error: any = false;
  workItem: WorkItem;
  validTitle: Boolean;
  showQuickAdd: Boolean;
  showQuickAddBtn: Boolean;
  initialDescHeight: number = 0;
  initialDescHeightDiff: number = 0;
  descHeight: any = '26px';
  descResize: any = 'none';
  spaceSubscription: Subscription = null;

  constructor(
    private workItemService: WorkItemService,
    private broadcaster: Broadcaster,
    private logger: Logger,
    private renderer: Renderer,
    private auth: AuthenticationService,
    private spaces: Spaces) {}

  ngOnInit(): void {
    this.createWorkItemObj();
    this.showQuickAdd = false;
    this.showQuickAddBtn = this.auth.isLoggedIn();
    this.spaceSubscription = this.spaces.current.subscribe(space => {
      if (space) {
        console.log('[WorkItemQuickAddComponent] New Space selected: ' + space.attributes.name);
        this.showQuickAddBtn = true;
      } else {
        console.log('[WorkItemQuickAddComponent] Space deselected.');
        this.showQuickAddBtn = false;
      }
    });
  }

  ngOnDestroy() {
    // prevent memory leak when component is destroyed
    this.spaceSubscription.unsubscribe();
  }

  createWorkItemObj() {
    this.workItem = new WorkItem();
    this.workItem.attributes = new Map<string, string | number>();
    this.workItem.relationships = new WorkItemRelations();
    this.workItem.type = 'workitems';
    this.workItem.id = '42';
    this.workItem.attributes['system.state'] = 'new';
  }

  ngAfterViewInit() {
    this.qaTitleRef.changes.subscribe(item => {
      if (item.length) {
        this.renderer.invokeElementMethod(this.qaTitle.nativeElement, 'focus');
      }
    });
  }

  save(event: any = null): void {
    if (event) event.preventDefault();


    // Set the default type
    // FIXME: Not the proper way to get default wi type
    // FIXME: Need to make a default workitem type subscriber
    // when template is introduced
    let defWit: WorkItemType = this.workItemService.workItemTypes.find((type: WorkItemType) => {
      return type.attributes.name === 'userstory';
    });
    if (!defWit) {
      defWit = this.workItemService.workItemTypes[0];
    }
    // Setting default type in relationship
    this.workItem.relationships = {<commit_msg>fix(quickAddComponent): remove renderer.invokeElementMethod (fix #1418) (#1545)<commit_after>import { WorkItemType } from './../../models/work-item-type';
import { Space, Spaces } from 'ngx-fabric8-wit';
import {
  AfterViewInit,
  Component,
  EventEmitter,
  ElementRef,
  Input,
  OnInit,
  OnDestroy,
  Output,
  ViewChild,
  ViewChildren,
  QueryList
} from '@angular/core';
import { Subscription } from 'rxjs/Subscription';
import { cloneDeep } from 'lodash';
import { Broadcaster, Logger } from 'ngx-base';
import { AuthenticationService } from 'ngx-login-client';

import { WorkItem, WorkItemRelations } from '../../models/work-item';
import { WorkItemService } from '../work-item.service';

@Component({
  selector: 'alm-work-item-quick-add',
  templateUrl: './work-item-quick-add.component.html',
  styleUrls: ['./work-item-quick-add.component.scss']
})
export class WorkItemQuickAddComponent implements OnInit, OnDestroy, AfterViewInit {
  @ViewChild('quickAddTitle') qaTitle: any;
  @ViewChild('quickAddDesc') qaDesc: any;
  @ViewChildren('quickAddTitle', {read: ElementRef}) qaTitleRef: QueryList<ElementRef>;

  @Input() wilistview: string = 'wi-list-view';
  @Output('workItemCreate') workItemCreate = new EventEmitter();

  error: any = false;
  workItem: WorkItem;
  validTitle: Boolean;
  showQuickAdd: Boolean;
  showQuickAddBtn: Boolean;
  initialDescHeight: number = 0;
  initialDescHeightDiff: number = 0;
  descHeight: any = '26px';
  descResize: any = 'none';
  spaceSubscription: Subscription = null;

  constructor(
    private workItemService: WorkItemService,
    private broadcaster: Broadcaster,
    private logger: Logger,
    private auth: AuthenticationService,
    private spaces: Spaces) {}

  ngOnInit(): void {
    this.createWorkItemObj();
    this.showQuickAdd = false;
    this.showQuickAddBtn = this.auth.isLoggedIn();
    this.spaceSubscription = this.spaces.current.subscribe(space => {
      if (space) {
        console.log('[WorkItemQuickAddComponent] New Space selected: ' + space.attributes.name);
        this.showQuickAddBtn = true;
      } else {
        console.log('[WorkItemQuickAddComponent] Space deselected.');
        this.showQuickAddBtn = false;
      }
    });
  }

  ngOnDestroy() {
    // prevent memory leak when component is destroyed
    this.spaceSubscription.unsubscribe();
  }

  createWorkItemObj() {
    this.workItem = new WorkItem();
    this.workItem.attributes = new Map<string, string | number>();
    this.workItem.relationships = new WorkItemRelations();
    this.workItem.type = 'workitems';
    this.workItem.id = '42';
    this.workItem.attributes['system.state'] = 'new';
  }

  ngAfterViewInit() {
    this.qaTitleRef.changes.subscribe(item => {
      if (item.length) {
        this.qaTitle.nativeElement.focus();
      }
    });
  }

  save(event: any = null): void {
    if (event) event.preventDefault();


    // Set the default type
    // FIXME: Not the proper way to get default wi type
    // FIXME: Need to make a default workitem type subscriber
    // when template is introduced
    let defWit: WorkItemType = this.workItemService.workItemTypes.find((type: WorkItemType) => {
      return type.attributes.name === 'userstory';
    });
    if (!defWit) {
      defWit = this.workItemService.workItemTypes[0];
    }
    // Setting default type in relationship
    this.workItem.relationships = {
{'fraction_non_alphanumeric': 0.12941696113074205, 'fraction_numerical': 0.0035335689045936395, 'mean_word_length': 3.6687285223367696, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '3524132', 'n_tokens_mistral': 2107, 'n_tokens_neox': 2068, 'n_words': 474}