<commit_before>
import {
  Component,
  ViewChild,
  ElementRef,
  ChangeDetectionStrategy,
  AfterViewInit,
  Output,
  EventEmitter,
  Input,
  OnInit,
} from '@angular/core';
import { ResourceResolver } from './ResourceResolver';
import { Layout, LayoutStateListener, LayoutListener } from './Layout';
import { LayoutState } from './LayoutState';
import { YamcsService } from '../../core/services/YamcsService';
import { take } from 'rxjs/operators';
import { DisplayFrame, Coordinates } from './DisplayFrame';
import { DisplayFolder } from '../../../yamcs-client';
import { Observable } from 'rxjs/Observable';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';

@Component({
  selector: 'app-layout-component',
  templateUrl: './LayoutComponent.html',
  styleUrls: ['./LayoutComponent.css'],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class LayoutComponent implements OnInit, AfterViewInit, LayoutListener, LayoutStateListener {

  @Input()
  startWithOpenedNavigator = true;

  @Input()
  layoutState: LayoutState = { frames: [] };

  @Output()
  stateChange = new EventEmitter<LayoutState>();

  @ViewChild('displayContainer')
  private displayContainerRef: ElementRef;

  displayInfo$: Observable<DisplayFolder>;
  showNavigator$: BehaviorSubject<boolean>;

  private resourceResolver: ResourceResolver;
  private layout: Layout;

  constructor(private yamcs: YamcsService) {
    this.displayInfo$ = yamcs.getSelectedInstance().getDisplayInfo();
    this.resourceResolver = new RemoteResourceResolver(yamcs);
  }

  ngOnInit() {
    this.showNavigator$ = new BehaviorSubject<boolean>(this.startWithOpenedNavigator);
  }

  ngAfterViewInit() {
    const targetEl = this.displayContainerRef.nativeElement;
    this.layout = new Layout(targetEl, this.resourceResolver);
    this.layout.layoutListeners.add(this);
    this.restoreState(this.layoutState).then(() => {
      this.layout.layoutStateListeners.add(this);
    });
  }

  openDisplay(id: string, coordinates?: Coordinates): Promise<void> {
    if (this.layout) {
      const existingFrame = this.layout.getDisplayFrame(id);
      if (existingFrame) {
        this.layout.bringToFront(existingFrame);
      } else {
        return this.layout.createDisplayFrame(id, coordinates);
      }
    }
    return Promise.resolve();
  }

  tileFrames() {
    this.layout.tileFrames();
  }

  cascadeFrames() {
    this.layout.cascadeFrames();
  }

  clear() {
    this.layout.clear();
  }<commit_msg>Fix glitch when starting with empty session storage<commit_after>
import {
  Component,
  ViewChild,
  ElementRef,
  ChangeDetectionStrategy,
  AfterViewInit,
  Output,
  EventEmitter,
  Input,
  OnInit,
} from '@angular/core';
import { ResourceResolver } from './ResourceResolver';
import { Layout, LayoutStateListener, LayoutListener } from './Layout';
import { LayoutState } from './LayoutState';
import { YamcsService } from '../../core/services/YamcsService';
import { take } from 'rxjs/operators';
import { DisplayFrame, Coordinates } from './DisplayFrame';
import { DisplayFolder } from '../../../yamcs-client';
import { Observable } from 'rxjs/Observable';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';

@Component({
  selector: 'app-layout-component',
  templateUrl: './LayoutComponent.html',
  styleUrls: ['./LayoutComponent.css'],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class LayoutComponent implements OnInit, AfterViewInit, LayoutListener, LayoutStateListener {

  @Input()
  startWithOpenedNavigator = true;

  @Input()
  layoutState: LayoutState = { frames: [] };

  @Output()
  stateChange = new EventEmitter<LayoutState>();

  @ViewChild('displayContainer')
  private displayContainerRef: ElementRef;

  displayInfo$: Observable<DisplayFolder>;
  showNavigator$: BehaviorSubject<boolean>;

  private resourceResolver: ResourceResolver;
  private layout: Layout;

  constructor(private yamcs: YamcsService) {
    this.displayInfo$ = yamcs.getSelectedInstance().getDisplayInfo();
    this.resourceResolver = new RemoteResourceResolver(yamcs);
  }

  ngOnInit() {
    this.showNavigator$ = new BehaviorSubject<boolean>(this.startWithOpenedNavigator);
  }

  ngAfterViewInit() {
    const targetEl = this.displayContainerRef.nativeElement;
    this.layout = new Layout(targetEl, this.resourceResolver);
    this.layout.layoutListeners.add(this);
    if (this.layoutState) {
      this.restoreState(this.layoutState).then(() => {
        this.layout.layoutStateListeners.add(this);
      });
    } else {
      this.layout.layoutStateListeners.add(this);
    }
  }

  openDisplay(id: string, coordinates?: Coordinates): Promise<void> {
    if (this.layout) {
      const existingFrame = this.layout.getDisplayFrame(id);
      if (existingFrame) {
        this.layout.bringToFront(existingFrame);
      } else {
        return this.layout.createDisplayFrame(id, coordinates);
      }
    }
    return Promise.resolve();
  }

  tileFrames() {
    this.layout.tileFrames();
  }

  cascadeFrames() {
    this.layout.cascadeFrames();
  }

  clear() {
    this.layout.clear();
  }
{'fraction_non_alphanumeric': 0.1281648675171737, 'fraction_numerical': 0.0, 'mean_word_length': 4.242798353909465, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, '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': '3134767', 'n_tokens_mistral': 1491, 'n_tokens_neox': 1460, 'n_words': 295}