<commit_before>import { Component, OnInit, Input, ViewChild, HostListener, OnChanges } from '@angular/core';
import { GeoJSON } from 'leaflet';
import { MapListService } from '@geonature_common/map-list/map-list.service';
import { SYNTHESE_CONFIG } from '../../synthese.config';
import { DataService } from '../../services/data.service';
import { SyntheseFormService } from '../../services/form.service';
import { window } from 'rxjs/operator/window';
import { NgbModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap';
import { CommonService } from '@geonature_common/service/common.service';
import { AppConfig } from '@geonature_config/app.config';

@Component({
  selector: 'pnx-synthese-list',
  templateUrl: 'synthese-list.component.html',
  styleUrls: ['synthese-list.component.scss']
})
export class SyntheseListComponent implements OnInit, OnChanges {
  public SYNTHESE_CONFIG = SYNTHESE_CONFIG;
  public selectedObs: any;
  public previousRow: any;
  public rowNumber: number;
  @Input() inputSyntheseData: GeoJSON;
  @ViewChild('table') table: any;
  constructor(
    public mapListService: MapListService,
    private _ds: DataService,
    public ngbModal: NgbModal,
    private _commonService: CommonService,
    private _fs: SyntheseFormService
  ) {}

  ngOnInit() {
    // Au clique sur la carte, selection dans la liste
    this.mapListService.onMapClik$.subscribe(id => {
      this.mapListService.selectedRow = []; // clear selected list

      const integerId = parseInt(id);
      // const integerId = parseInt(id);
      let i;
      for (i = 0; i < this.mapListService.tableData.length; i++) {
        if (this.mapListService.tableData[i]['id_synthese'] === integerId) {
          this.mapListService.selectedRow.push(this.mapListService.tableData[i]);
          break;
        }
      }
      const page = Math.trunc(i / 10);
      this.table.offset = page;
    });

    // get wiewport height to set the number of rows in the table
    const h = document.documentElement.clientHeight;
    this.rowNumber = Math.trunc(h / 62);
  }

  // update the number of row per page when resize the window
  @HostListener('window:resize', ['$event'])
  onResize(event) {
    this.rowNumber = Math.trunc(event.target.innerHeight / 62);
  }

  loadOneSyntheseReleve(event) {
    this._ds.getOneSyntheseObservation(event.value.id_synthese).subscribe(data => {
      this.selectedObs = data;
    });
  }

  toggleExpandRow(row) {
    // if click twice on same row
    if (this.previousRow && this.previousRow === row) {
      console.log('twice');
      this.table.rowDetail.toggleExpandRow(this.previousRow);
      this.previousRow = null;
      // if click on new row when expanded already activated
    } else if (this.previousRow) {
      console.log('new');
      this.table.rowDetail.toggleExpandRow(this.previousRow);<commit_msg>Synthese: correction changement de page interaction carte/liste<commit_after>import { Component, OnInit, Input, ViewChild, HostListener, OnChanges } from '@angular/core';
import { GeoJSON } from 'leaflet';
import { MapListService } from '@geonature_common/map-list/map-list.service';
import { SYNTHESE_CONFIG } from '../../synthese.config';
import { DataService } from '../../services/data.service';
import { SyntheseFormService } from '../../services/form.service';
import { window } from 'rxjs/operator/window';
import { NgbModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap';
import { CommonService } from '@geonature_common/service/common.service';
import { AppConfig } from '@geonature_config/app.config';

@Component({
  selector: 'pnx-synthese-list',
  templateUrl: 'synthese-list.component.html',
  styleUrls: ['synthese-list.component.scss']
})
export class SyntheseListComponent implements OnInit, OnChanges {
  public SYNTHESE_CONFIG = SYNTHESE_CONFIG;
  public selectedObs: any;
  public previousRow: any;
  public rowNumber: number;
  @Input() inputSyntheseData: GeoJSON;
  @ViewChild('table') table: any;
  constructor(
    public mapListService: MapListService,
    private _ds: DataService,
    public ngbModal: NgbModal,
    private _commonService: CommonService,
    private _fs: SyntheseFormService
  ) {}

  ngOnInit() {
    // get wiewport height to set the number of rows in the table
    const h = document.documentElement.clientHeight;
    this.rowNumber = Math.trunc(h / 62);

    // On map click, select on the list a change the page
    this.mapListService.onMapClik$.subscribe(id => {
      this.mapListService.selectedRow = []; // clear selected list

      const integerId = parseInt(id);
      let i;
      for (i = 0; i < this.mapListService.tableData.length; i++) {
        if (this.mapListService.tableData[i]['id_synthese'] === integerId) {
          this.mapListService.selectedRow.push(this.mapListService.tableData[i]);
          break;
        }
      }
      const page = Math.trunc(i / this.rowNumber);
      this.table.offset = page;
    });
  }

  // update the number of row per page when resize the window
  @HostListener('window:resize', ['$event'])
  onResize(event) {
    this.rowNumber = Math.trunc(event.target.innerHeight / 62);
  }

  loadOneSyntheseReleve(event) {
    this._ds.getOneSyntheseObservation(event.value.id_synthese).subscribe(data => {
      this.selectedObs = data;
    });
  }

  toggleExpandRow(row) {
    // if click twice on same row
    if (this.previousRow && this.previousRow === row) {
      console.log('twice');
      this.table.rowDetail.toggleExpandRow(this.previousRow);
      this.previousRow = null;
      // if click on new row when expanded already activated
    } else if (this.previousRow) {
      console.log('new');
      this.table.rowDetail.toggleExpandRow(this.previousRow);
{'fraction_non_alphanumeric': 0.12587290502793297, 'fraction_numerical': 0.002094972067039106, 'mean_word_length': 3.612721417069243, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '6350544', 'n_tokens_mistral': 1807, 'n_tokens_neox': 1734, 'n_words': 406}