<commit_before>//TODO: Check if this import is still needed. Breaks production though
//import 'ol-popup/src/ol-popup.css';
import {Component, OnDestroy} from '@angular/core';

import Popup from 'ol-popup';
import {Subject} from 'rxjs';
import {takeUntil} from 'rxjs/operators';

import {HsConfig} from '../../config.service';
import {HsDrawService} from '../draw/draw.service';
import {HsEventBusService} from '../core/event-bus.service';
import {HsLayoutService} from '../layout/layout.service';
import {HsMapService} from '../map/map.service';
import {HsQueryBaseService} from './query-base.service';
import {HsQueryVectorService} from './query-vector.service';
import {HsQueryWmsService} from './query-wms.service';

@Component({
  selector: 'hs-query',
  templateUrl: './partials/infopanel.html',
})
export class HsQueryComponent implements OnDestroy {
  popup = new Popup();
  popupOpens: Subject<any> = new Subject();
  private ngUnsubscribe = new Subject();
  constructor(
    public HsConfig: HsConfig,
    public HsQueryBaseService: HsQueryBaseService,
    public HsLayoutService: HsLayoutService,
    public HsMapService: HsMapService,
    public HsEventBusService: HsEventBusService,
    public HsQueryVectorService: HsQueryVectorService,
    public HsQueryWmsService: HsQueryWmsService,
    public HsDrawService: HsDrawService
  ) {
    this.HsMapService.loaded().then((map) => {
      map.addOverlay(this.popup);
    });

    //add current panel queriable - activate/deactivate
    this.HsEventBusService.mainPanelChanges
      .pipe(takeUntil(this.ngUnsubscribe))
      .subscribe((closed) => {
        if (this.HsQueryBaseService.currentPanelQueryable()) {
          if (
            !this.HsQueryBaseService.queryActive &&
            !this.HsDrawService.drawActive
          ) {
            this.HsQueryBaseService.activateQueries();
          }
        } else {
          if (this.HsQueryBaseService.queryActive) {
            this.HsQueryBaseService.deactivateQueries();
          }
        }
      });

    this.HsQueryBaseService.queryStatusChanges
      .pipe(takeUntil(this.ngUnsubscribe))
      .subscribe(() => {
        this.HsQueryBaseService.getFeatureInfoStarted
          .pipe(takeUntil(this.ngUnsubscribe))
          .subscribe((e) => {
            this.popup.hide();
            if (
              this.HsQueryBaseService.currentPanelQueryable() &&
              this.HsLayoutService.mainpanel != 'draw'
            ) {
              this.HsLayoutService.setMainPanel('info');
            }
          });

        this.HsQueryBaseService.getFeatureInfoCollected
          .pipe(takeUntil(this.ngUnsubscribe))
          .subscribe((coordinate) => {
            const invisiblePopup: any =
              this.HsQueryBaseService.getInvisiblePopup();
            const bodyElementsFound = this.checkForBodyElements(
              invisiblePopup.contentDocument.body.children
            );
            if (bodyElementsFound) {
              //TODO: dont count style, title, meta towards length
              if (this.HsQueryBaseService.popupClassname.length > 0) {
                this.popup.getElement().className =
                  this.HsQueryBaseService.popupClassname;
              } else {
                this.popup.getElement().className = 'ol-popup';
              }
              this.popup.show(
                coordinate,
                invisiblePopup.contentDocument.body.innerHTML
              );
              this.popupOpens.next('hs.query');
            }
          });
      });

    this.popupOpens.pipe(takeUntil(this.ngUnsubscribe)).subscribe((source) => {
      if (source && source != 'hs.query' && this.popup !== undefined) {
        this.popup.hide();
      }
    });

    this.HsQueryVectorService.featureRemovals
      .pipe(takeUntil(this.ngUnsubscribe))
      .subscribe((feature) => {<commit_msg>fix: Fix invisiblePopup undefined error (#1855)<commit_after>//TODO: Check if this import is still needed. Breaks production though
//import 'ol-popup/src/ol-popup.css';
import {Component, OnDestroy} from '@angular/core';

import Popup from 'ol-popup';
import {Subject} from 'rxjs';
import {takeUntil} from 'rxjs/operators';

import {HsConfig} from '../../config.service';
import {HsDrawService} from '../draw/draw.service';
import {HsEventBusService} from '../core/event-bus.service';
import {HsLayoutService} from '../layout/layout.service';
import {HsMapService} from '../map/map.service';
import {HsQueryBaseService} from './query-base.service';
import {HsQueryVectorService} from './query-vector.service';
import {HsQueryWmsService} from './query-wms.service';

@Component({
  selector: 'hs-query',
  templateUrl: './partials/infopanel.html',
})
export class HsQueryComponent implements OnDestroy {
  popup = new Popup();
  popupOpens: Subject<any> = new Subject();
  private ngUnsubscribe = new Subject();
  constructor(
    public HsConfig: HsConfig,
    public HsQueryBaseService: HsQueryBaseService,
    public HsLayoutService: HsLayoutService,
    public HsMapService: HsMapService,
    public HsEventBusService: HsEventBusService,
    public HsQueryVectorService: HsQueryVectorService,
    public HsQueryWmsService: HsQueryWmsService,
    public HsDrawService: HsDrawService
  ) {
    this.HsMapService.loaded().then((map) => {
      map.addOverlay(this.popup);
    });

    //add current panel queriable - activate/deactivate
    this.HsEventBusService.mainPanelChanges
      .pipe(takeUntil(this.ngUnsubscribe))
      .subscribe((closed) => {
        if (this.HsQueryBaseService.currentPanelQueryable()) {
          if (
            !this.HsQueryBaseService.queryActive &&
            !this.HsDrawService.drawActive
          ) {
            this.HsQueryBaseService.activateQueries();
          }
        } else {
          if (this.HsQueryBaseService.queryActive) {
            this.HsQueryBaseService.deactivateQueries();
          }
        }
      });

    this.HsQueryBaseService.queryStatusChanges
      .pipe(takeUntil(this.ngUnsubscribe))
      .subscribe(() => {
        this.HsQueryBaseService.getFeatureInfoStarted
          .pipe(takeUntil(this.ngUnsubscribe))
          .subscribe((e) => {
            this.popup.hide();
            if (
              this.HsQueryBaseService.currentPanelQueryable() &&
              this.HsLayoutService.mainpanel != 'draw'
            ) {
              this.HsLayoutService.setMainPanel('info');
            }
          });

        this.HsQueryBaseService.getFeatureInfoCollected
          .pipe(takeUntil(this.ngUnsubscribe))
          .subscribe((coordinate) => {
            const invisiblePopup: any =
              this.HsQueryBaseService.getInvisiblePopup();
            if (!invisiblePopup) {
              return;
            }
            const bodyElementsFound = this.checkForBodyElements(
              invisiblePopup.contentDocument.body.children
            );
            if (bodyElementsFound) {
              //TODO: dont count style, title, meta towards length
              if (this.HsQueryBaseService.popupClassname.length > 0) {
                this.popup.getElement().className =
                  this.HsQueryBaseService.popupClassname;
              } else {
                this.popup.getElement().className = 'ol-popup';
              }
              this.popup.show(
                coordinate,
                invisiblePopup.contentDocument.body.innerHTML
              );
              this.popupOpens.next('hs.query');
            }
          });
      });

    this.popupOpens.pipe(takeUntil(this.ngUnsubscribe)).subscribe((source) => {
      if (source && source != 'hs.query' && this.popup !== undefined) {
        this.popup.hide();
      }
    });

    this.HsQueryVectorService.featureRemovals
      .pipe(takeUntil(this.ngUnsubscribe))
      .subscribe((feature) => {
{'fraction_non_alphanumeric': 0.11805289382905328, 'fraction_numerical': 0.0007665772326561902, 'mean_word_length': 2.4469396741523557, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '4227160', 'n_tokens_mistral': 2212, 'n_tokens_neox': 2159, 'n_words': 376}