<commit_before>import { AppState } from './../../../../dist-watch/app/states/app.state.d';
import {
  Component,
  ViewChild,
  OnInit,
  Output,
  EventEmitter,
  Input,
  OnChanges,
  OnDestroy
} from '@angular/core';

import { Observable } from 'rxjs/Observable';
import { Subscription } from 'rxjs/Subscription';

import { cloneDeep } from 'lodash';
import * as moment from 'moment';
import { IMyOptions, IMyDateModel } from 'mydatepicker';
import { Broadcaster } from 'ngx-base';

import { IterationUI } from '../../models/iteration.model';

// ngrx stuff
import { Store } from '@ngrx/store';
import * as IterationActions from './../../actions/iteration.actions';

@Component({
  selector: 'fab-planner-iteration-modal',
  templateUrl: './iterations-modal.component.html',
  styleUrls: ['./iterations-modal.component.less']
})
export class FabPlannerIterationModalComponent implements OnInit, OnDestroy, OnChanges {

  private spaceSubscription: Subscription = null;

  @Output()
  public onSubmit = new EventEmitter();

  @ViewChild('createUpdateIterationDialog') createUpdateIterationDialog: any;
  @ViewChild('iterationSearch') iterationSearch: any;
  @ViewChild('iterationList') iterationList: any;

  public iteration: IterationUI;
  private validationError = false;
  private modalType: string = 'create';
  private submitBtnTxt: string = 'Create';
  private modalTitle: string = 'Create Iteration';
  private startDate: any;
  private endDate: any;
  private spaceError: Boolean = false;
  private iterationName: string;
  private submitLoading: boolean = false;
  iterations: IterationUI[] = [];
  iterationsValue: any = [];
  filteredIterations: any = [];
  selectedParentIteration: IterationUI;
  selectedParentIterationName:string = '';
  iterationSearchDisable: Boolean = false;
  showIterationDropdown: Boolean = false;
  validationString: string = 'Something went wrong.';

  private startDatePickerOptions: IMyOptions = {
    dateFormat: 'dd mmm yyyy',
    selectionTxtFontSize: '14px',
    openSelectorOnInputClick: true,
    editableDateField: false,
    showClearDateBtn: false,
    componentDisabled: false
  };

  private endDatePickerOptions: IMyOptions = {
    dateFormat: 'dd mmm yyyy',
    selectionTxtFontSize: '14px',
    openSelectorOnInputClick: true,
    editableDateField: false,
    showClearDateBtn: false,
    componentDisabled: false
  };

  constructor(
    private broadcaster: Broadcaster,
    private store: Store<AppState>) {}


  ngOnInit() {
    this.resetValues();
    this.store
        .select('iterationPanel')
        .select('iterationUI')
        .subscribe((uiState) => {
          if (uiState.error) {
            this.validationError = true;
            this.validationString = uiState.error;
          }
          if (this.submitLoading &&
              !uiState.modalLoading &&
              !this.validationError) {
            this.createUpdateIterationDialog.close();
          }
          this.submitLoading = uiState.modalLoading;

        },
        (e) => {
          console.log('Some error has occured', e);
        });
  }

  resetValues() {

    this.iteration  = {
      id: '',
      name: '',
      userActive: false,
      isActive: false,
      startAt: null,
      endAt: null,
      description: '',
      state: 'new',
      workItemTotalCount: 0,
      workItemClosedCount: 0
    } as IterationUI;

    let endDatePickerComponentCopy = Object.assign({}, this.endDatePickerOptions);
    let startDatePickerComponentCopy = Object.assign({}, this.startDatePickerOptions);
    let aDayBefore = moment().subtract(1, 'days');
    let aDayBeforeDate = { date: { year: aDayBefore.format('YYYY'), month: aDayBefore.format('M'), day: aDayBefore.format('D') }} as any;
    endDatePickerComponentCopy['disableUntil'] = aDayBeforeDate.date;
    startDatePickerComponentCopy['componentDisabled'] = false;
    this.startDatePickerOptions = startDatePickerComponentCopy;
    this.endDatePickerOptions = endDatePickerComponentCopy;
    this.validationError = false;
    this.spaceError = false;
    this.selectedParentIterationName = '';
    this.filteredIterations = [];
    this.selectedParentIteration = null;
    this.iterationSearchDisable = false;
    this.showIterationDropdown = false;
    this.iterations = [];
    this.iterationsValue = [];
    this.startDate = '';
    this.endDate = '';
  }

  ngOnChanges() {
  }

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

  openCreateUpdateModal(
    type: string = 'create',
    iteration: IterationUI | null = null,
    e?: any
  ) {
    if(e) {
      e.stopPropagation();
    }

    this.modalType = type;
    if (iteration) {
      this.iteration = cloneDeep(iteration);
      if (this.iteration.startAt) {
        let startDate = moment(this.iteration.startAt);
        this.startDate = { date: { year: startDate.format('YYYY'), month: startDate.format('M'), day: startDate.format('D') } };
      }
      if (this.iteration.endAt) {
        let endDate = moment(this.iteration.endAt);
        this.endDate = { date: { year: endDate.format('YYYY'), month: endDate.format('M'), day: endDate.format('D') } };
      }
    }
    if (this.modalType == 'create') {
      this.getIterations();<commit_msg>fix(iteration): unneccessary space subscription removed<commit_after>import { AppState } from './../../../../dist-watch/app/states/app.state.d';
import {
  Component,
  ViewChild,
  OnInit,
  Output,
  EventEmitter,
  Input,
  OnChanges,
  OnDestroy
} from '@angular/core';

import { Observable } from 'rxjs/Observable';
import { Subscription } from 'rxjs/Subscription';

import { cloneDeep } from 'lodash';
import * as moment from 'moment';
import { IMyOptions, IMyDateModel } from 'mydatepicker';
import { Broadcaster } from 'ngx-base';

import { IterationUI } from '../../models/iteration.model';

// ngrx stuff
import { Store } from '@ngrx/store';
import * as IterationActions from './../../actions/iteration.actions';

@Component({
  selector: 'fab-planner-iteration-modal',
  templateUrl: './iterations-modal.component.html',
  styleUrls: ['./iterations-modal.component.less']
})
export class FabPlannerIterationModalComponent implements OnInit, OnDestroy, OnChanges {

  @Output()
  public onSubmit = new EventEmitter();

  @ViewChild('createUpdateIterationDialog') createUpdateIterationDialog: any;
  @ViewChild('iterationSearch') iterationSearch: any;
  @ViewChild('iterationList') iterationList: any;

  public iteration: IterationUI;
  private validationError = false;
  private modalType: string = 'create';
  private submitBtnTxt: string = 'Create';
  private modalTitle: string = 'Create Iteration';
  private startDate: any;
  private endDate: any;
  private spaceError: Boolean = false;
  private iterationName: string;
  private submitLoading: boolean = false;
  iterations: IterationUI[] = [];
  iterationsValue: any = [];
  filteredIterations: any = [];
  selectedParentIteration: IterationUI;
  selectedParentIterationName:string = '';
  iterationSearchDisable: Boolean = false;
  showIterationDropdown: Boolean = false;
  validationString: string = 'Something went wrong.';

  private startDatePickerOptions: IMyOptions = {
    dateFormat: 'dd mmm yyyy',
    selectionTxtFontSize: '14px',
    openSelectorOnInputClick: true,
    editableDateField: false,
    showClearDateBtn: false,
    componentDisabled: false
  };

  private endDatePickerOptions: IMyOptions = {
    dateFormat: 'dd mmm yyyy',
    selectionTxtFontSize: '14px',
    openSelectorOnInputClick: true,
    editableDateField: false,
    showClearDateBtn: false,
    componentDisabled: false
  };

  constructor(
    private broadcaster: Broadcaster,
    private store: Store<AppState>) {}


  ngOnInit() {
    this.resetValues();
    this.store
        .select('iterationPanel')
        .select('iterationUI')
        .subscribe((uiState) => {
          if (uiState.error) {
            this.validationError = true;
            this.validationString = uiState.error;
          }
          if (this.submitLoading &&
              !uiState.modalLoading &&
              !this.validationError) {
            this.createUpdateIterationDialog.close();
          }
          this.submitLoading = uiState.modalLoading;

        },
        (e) => {
          console.log('Some error has occured', e);
        });
  }

  resetValues() {

    this.iteration  = {
      id: '',
      name: '',
      userActive: false,
      isActive: false,
      startAt: null,
      endAt: null,
      description: '',
      state: 'new',
      workItemTotalCount: 0,
      workItemClosedCount: 0
    } as IterationUI;

    let endDatePickerComponentCopy = Object.assign({}, this.endDatePickerOptions);
    let startDatePickerComponentCopy = Object.assign({}, this.startDatePickerOptions);
    let aDayBefore = moment().subtract(1, 'days');
    let aDayBeforeDate = { date: { year: aDayBefore.format('YYYY'), month: aDayBefore.format('M'), day: aDayBefore.format('D') }} as any;
    endDatePickerComponentCopy['disableUntil'] = aDayBeforeDate.date;
    startDatePickerComponentCopy['componentDisabled'] = false;
    this.startDatePickerOptions = startDatePickerComponentCopy;
    this.endDatePickerOptions = endDatePickerComponentCopy;
    this.validationError = false;
    this.spaceError = false;
    this.selectedParentIterationName = '';
    this.filteredIterations = [];
    this.selectedParentIteration = null;
    this.iterationSearchDisable = false;
    this.showIterationDropdown = false;
    this.iterations = [];
    this.iterationsValue = [];
    this.startDate = '';
    this.endDate = '';
  }

  ngOnChanges() {
  }

  ngOnDestroy() {
    // prevent memory leak when component is destroyed
  }

  openCreateUpdateModal(
    type: string = 'create',
    iteration: IterationUI | null = null,
    e?: any
  ) {
    if(e) {
      e.stopPropagation();
    }

    this.modalType = type;
    if (iteration) {
      this.iteration = cloneDeep(iteration);
      if (this.iteration.startAt) {
        let startDate = moment(this.iteration.startAt);
        this.startDate = { date: { year: startDate.format('YYYY'), month: startDate.format('M'), day: startDate.format('D') } };
      }
      if (this.iteration.endAt) {
        let endDate = moment(this.iteration.endAt);
        this.endDate = { date: { year: endDate.format('YYYY'), month: endDate.format('M'), day: endDate.format('D') } };
      }
    }
    if (this.modalType == 'create') {
      this.getIterations();
{'fraction_non_alphanumeric': 0.12589073634204276, 'fraction_numerical': 0.001330166270783848, 'mean_word_length': 3.345995045417011, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '983251', 'n_tokens_mistral': 3136, 'n_tokens_neox': 3100, 'n_words': 670}