<commit_before>/* eslint-disable @typescript-eslint/naming-convention */

import { CdkDragDrop } from '@angular/cdk/drag-drop';
import { ChangeDetectorRef, Component, EventEmitter, Input, OnDestroy, OnInit,
  Output,
} from '@angular/core';
import { Subscription } from 'rxjs';
import * as APITypes from 'src/api-types';
import { CAST_COUNT } from 'src/constants';

import { Cast, CastApi, CastGroup } from '../api/cast-api.service';
import { SegmentApi, Segment, Position } from '../api/segment-api.service';
import { User, UserApi } from '../api/user-api.service';
import { ContextService } from '../services/context.service';
import { CsvGenerator } from '../services/csv-generator.service';


type UICastDancer = {
  uuid: string;
  user: User;
  hasAbsence?: boolean;
};

type UICastRow = {
  subCastDancers: UICastDancer[];
};

type UICastPosition = {
  pos: Position;
  dancerCount: number;
  castRows: UICastRow[];
};

@Component({
  selector: 'app-cast-drag-and-drop',
  templateUrl: './cast-drag-and-drop.component.html',
  styleUrls: ['./cast-drag-and-drop.component.scss']
})
// eslint-disable-next-line @angular-eslint/component-class-suffix
export class CastDragAndDrop implements OnInit, OnDestroy {

  /** Input that idenfies available unavailability information */
  @Input() users: User[];

  /** Input that specifies the currently selected segment */
  @Input() selectedSegment: Segment;

  /** Input that specifies if the cast has been saved before */
  @Input() canDelete: boolean;

  /** Input of the performance date, if available */
  @Input() performanceDate: Date;

  /** Output by which parent components can launch add cast. */
  @Output() addCastEmitter: EventEmitter<void> = new EventEmitter();

  /** Output by which other components can listen to cast changes. */
  @Output() castChangeEmitter: EventEmitter<Cast> = new EventEmitter();

  /** The current cast we're editing, as well as the UUID of it. */
  selectedCastUUID: APITypes.CastUUID;
  cast: Cast;


  /** Whether or not the save/delete buttons should be rendered. */
  buttonsEnabled = true;

  /** The cast that should be bolded, or undefined if none should be. */
  boldedCast: number;

  // The display support data structures
  castPositions: UICastPosition[];
  subCastHeaders: string[];

  castCount = CAST_COUNT;

  castSubscription: Subscription;

  castsLoaded = false;
  dataLoaded = false;
  castSelected = false;
  selectCastHasBeenCalled = false;
  perfDate = 0;

  canSave = false;

  // Marks that drop handling is in effect.
  // When db caching was added, the data load was speeded up
  // to the point that the old logic stepped on itself.
  // This variable helps avoid 'deadly embraces'.
  private dropHandling = false;

  constructor(
    private cdRef: ChangeDetectorRef,
    private g: ContextService,
    private csvGenerator: CsvGenerator,
    private userApi: UserApi,
    private segmentApi: SegmentApi,

    public castApi: CastApi,
  ) {
    this.buildSubCastHeader();
  }

  // eslint-disable-next-line prefer-arrow/prefer-arrow-functions
  ngOnInit(): void {
    this.castSubscription = this.castApi.cache.loadedAll.subscribe(() => {
      this.onCastLoad();
    });
    this.perfDate = this.performanceDate.getTime();
    if (this.perfDate) {
      this.castApi.loadAllCasts();<commit_msg>Fix no performance date error (#178)<commit_after>/* eslint-disable @typescript-eslint/naming-convention */

import { CdkDragDrop } from '@angular/cdk/drag-drop';
import { ChangeDetectorRef, Component, EventEmitter, Input, OnDestroy, OnInit,
  Output,
} from '@angular/core';
import { Subscription } from 'rxjs';
import * as APITypes from 'src/api-types';
import { CAST_COUNT } from 'src/constants';

import { Cast, CastApi, CastGroup } from '../api/cast-api.service';
import { SegmentApi, Segment, Position } from '../api/segment-api.service';
import { User, UserApi } from '../api/user-api.service';
import { ContextService } from '../services/context.service';
import { CsvGenerator } from '../services/csv-generator.service';


type UICastDancer = {
  uuid: string;
  user: User;
  hasAbsence?: boolean;
};

type UICastRow = {
  subCastDancers: UICastDancer[];
};

type UICastPosition = {
  pos: Position;
  dancerCount: number;
  castRows: UICastRow[];
};

@Component({
  selector: 'app-cast-drag-and-drop',
  templateUrl: './cast-drag-and-drop.component.html',
  styleUrls: ['./cast-drag-and-drop.component.scss']
})
// eslint-disable-next-line @angular-eslint/component-class-suffix
export class CastDragAndDrop implements OnInit, OnDestroy {

  /** Input that idenfies available unavailability information */
  @Input() users: User[];

  /** Input that specifies the currently selected segment */
  @Input() selectedSegment: Segment;

  /** Input that specifies if the cast has been saved before */
  @Input() canDelete: boolean;

  /** Input of the performance date, if available */
  @Input() performanceDate: Date;

  /** Output by which parent components can launch add cast. */
  @Output() addCastEmitter: EventEmitter<void> = new EventEmitter();

  /** Output by which other components can listen to cast changes. */
  @Output() castChangeEmitter: EventEmitter<Cast> = new EventEmitter();

  /** The current cast we're editing, as well as the UUID of it. */
  selectedCastUUID: APITypes.CastUUID;
  cast: Cast;


  /** Whether or not the save/delete buttons should be rendered. */
  buttonsEnabled = true;

  /** The cast that should be bolded, or undefined if none should be. */
  boldedCast: number;

  // The display support data structures
  castPositions: UICastPosition[];
  subCastHeaders: string[];

  castCount = CAST_COUNT;

  castSubscription: Subscription;

  castsLoaded = false;
  dataLoaded = false;
  castSelected = false;
  selectCastHasBeenCalled = false;
  perfDate = 0;

  canSave = false;

  // Marks that drop handling is in effect.
  // When db caching was added, the data load was speeded up
  // to the point that the old logic stepped on itself.
  // This variable helps avoid 'deadly embraces'.
  private dropHandling = false;

  constructor(
    private cdRef: ChangeDetectorRef,
    private g: ContextService,
    private csvGenerator: CsvGenerator,
    private userApi: UserApi,
    private segmentApi: SegmentApi,

    public castApi: CastApi,
  ) {
    this.buildSubCastHeader();
  }

  // eslint-disable-next-line prefer-arrow/prefer-arrow-functions
  ngOnInit(): void {
    this.castSubscription = this.castApi.cache.loadedAll.subscribe(() => {
      this.onCastLoad();
    });
    this.perfDate = this.performanceDate?.getTime() ?? 0;
    if (this.perfDate) {
      this.castApi.loadAllCasts();
{'fraction_non_alphanumeric': 0.12287817335135948, 'fraction_numerical': 0.0009013068949977468, 'mean_word_length': 3.8316400580551524, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3749314', 'n_tokens_mistral': 2025, 'n_tokens_neox': 1999, 'n_words': 597}