<commit_before>import { MapListService } from "@geonature_common/map-list/map-list.service";
import {
  Component,
  OnInit,
  Input,
  Output,
  ViewChild,
  HostListener,
  AfterContentChecked,
  OnChanges,
  ChangeDetectorRef,
  EventEmitter
} from "@angular/core";
import { MapService } from "@geonature_common/map/map.service";
import { NgbModal } from "@ng-bootstrap/ng-bootstrap";
import { CommonService } from "@geonature_common/service/common.service";
import { ModuleConfig } from "../../module.config";
import { DomSanitizer } from "@angular/platform-browser";
import { DatatableComponent } from "@swimlane/ngx-datatable";
import { ValidationModalInfoObsComponent } from "../validation-modal-info-obs/validation-modal-info-obs.component";
import { SyntheseFormService } from "@geonature_common/form/synthese-form/synthese-form.service";
import { SyntheseDataService } from "@geonature_common/form/synthese-form/synthese-data.service";

@Component({
  selector: "pnx-validation-synthese-list",
  templateUrl: "validation-synthese-list.component.html",
  styleUrls: ["validation-synthese-list.component.scss"]
})
export class ValidationSyntheseListComponent
  implements OnInit, OnChanges, AfterContentChecked {
  public VALIDATION_CONFIG = ModuleConfig;
  selectedObs: Array<number> = []; // list of id_synthese values for selected rows
  selectedIndex: Array<number> = [];
  selectedPages = [];
  coordinates_list = []; // list of coordinates for selected rows
  marker: MediaTrackSupportedConstraints;
  public rowNumber: number;
  private _latestWidth: number;
  public id_same_coordinates = []; // list of observation ids having same geographic coordinates
  public modif_text =
    "Attention données modifiées depuis la dernière validation";
  public npage;

  @Input() inputSyntheseData: Array<any>;
  @Input() validationStatus: Array<any>;
  @ViewChild("table") table: DatatableComponent;
  @Output() pageChange: EventEmitter<number>;
  public validationStatusAsDict: any;

  constructor(
    public mapListService: MapListService,
    private _ds: SyntheseDataService,
    public ngbModal: NgbModal,
    private _commonService: CommonService,
    public sanitizer: DomSanitizer,
    public ref: ChangeDetectorRef,
    private _ms: MapService,
    public formService: SyntheseFormService,
  ) { }

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

    // this.group = new FeatureGroup();
    this.onMapClick();
    this.onTableClick();
    this.npage = 1;
  }

  onMapClick() {
    this.mapListService.onMapClik$.subscribe(id => {
      // create list of observation ids having coordinates = to id value


      const selected_id_coordinates = this.mapListService.layerDict[id].feature
        .geometry.coordinates;
      this.id_same_coordinates = [];
      console.log(this.mapListService.geojsonData.features);

      // for (let obs in this.mapListService.geojsonData.features) {
      //   console.log(obs);

      //   if (
      //     JSON.stringify(selected_id_coordinates) ==
      //     JSON.stringify(
      //       this.mapListService.geojsonData.features[obs].geometry.coordinates
      //     )
      //   ) {
      //     this.id_same_coordinates.push(
      //       parseInt(this.mapListService.geojsonData.features[obs].id)
      //     );
      //   }
      // }

      // select rows having id_synthese = to one of the id_same_coordinates values
      this.mapListService.selectedRow = [];
      for (let i = 0; i < this.mapListService.tableData.length; i++) {
        if (this.mapListService.tableData[i]["id_synthese"] === id) {
          this.mapListService.selectedRow.push(
            this.mapListService.tableData[i]
          );
          break;
        }
        const page = Math.trunc(i / this.rowNumber);
        console.log(page);

        this.table.offset = page;
      }

      //this.setSelectedObs();
    });
  }

  onTableClick() {
    this.setSelectedObs();
    this.mapListService.onTableClick$.subscribe(id => {
      this.setSelectedObs();
      this.setOriginStyleToAll();
      this.setSelectedSyleToSelectedRows();
    });
  }

  ngAfterContentChecked() {
    if (this.table && this.table.element.clientWidth !== this._latestWidth) {
      this._latestWidth = this.table.element.clientWidth;
    }
  }

  handlePageChange(event): void {
    this.npage = event.page;
  }

  setOriginStyleToAll() {
    for (let obs in this.mapListService.layerDict) {
      this.mapListService.layerDict[obs].setStyle(
        this.VALIDATION_CONFIG.MAP_POINT_STYLE.originStyle
      );
    }
  }

  setSelectedSyleToSelectedRows() {
    for (let obs of this.selectedObs) {
      this.mapListService.layerDict[obs].setStyle(
        this.VALIDATION_CONFIG.MAP_POINT_STYLE.selectedStyle
      );
    }
  }

  selectAll() {
    this.mapListService.selectedRow = [...this.mapListService.tableData];<commit_msg>Redimensionnement du tableau lorsque la taille de la fenetre change<commit_after>import { MapListService } from "@geonature_common/map-list/map-list.service";
import {
  Component,
  OnInit,
  Input,
  Output,
  ViewChild,
  HostListener,
  AfterContentChecked,
  OnChanges,
  ChangeDetectorRef,
  EventEmitter
} from "@angular/core";
import { MapService } from "@geonature_common/map/map.service";
import { NgbModal } from "@ng-bootstrap/ng-bootstrap";
import { CommonService } from "@geonature_common/service/common.service";
import { ModuleConfig } from "../../module.config";
import { DomSanitizer } from "@angular/platform-browser";
import { DatatableComponent } from "@swimlane/ngx-datatable";
import { ValidationModalInfoObsComponent } from "../validation-modal-info-obs/validation-modal-info-obs.component";
import { SyntheseFormService } from "@geonature_common/form/synthese-form/synthese-form.service";
import { SyntheseDataService } from "@geonature_common/form/synthese-form/synthese-data.service";

@Component({
  selector: "pnx-validation-synthese-list",
  templateUrl: "validation-synthese-list.component.html",
  styleUrls: ["validation-synthese-list.component.scss"]
})
export class ValidationSyntheseListComponent
  implements OnInit, OnChanges, AfterContentChecked {
  public VALIDATION_CONFIG = ModuleConfig;
  selectedObs: Array<number> = []; // list of id_synthese values for selected rows
  selectedIndex: Array<number> = [];
  selectedPages = [];
  coordinates_list = []; // list of coordinates for selected rows
  marker: MediaTrackSupportedConstraints;
  public rowNumber: number;
  private _latestWidth: number;
  public id_same_coordinates = []; // list of observation ids having same geographic coordinates
  public modif_text =
    "Attention données modifiées depuis la dernière validation";
  public npage;

  @Input() inputSyntheseData: Array<any>;
  @Input() validationStatus: Array<any>;
  @ViewChild("table") table: DatatableComponent;
  @Output() pageChange: EventEmitter<number>;
  public validationStatusAsDict: any;

  constructor(
    public mapListService: MapListService,
    private _ds: SyntheseDataService,
    public ngbModal: NgbModal,
    private _commonService: CommonService,
    public sanitizer: DomSanitizer,
    public ref: ChangeDetectorRef,
    private _ms: MapService,
    public formService: SyntheseFormService,
  ) { }

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

    // this.group = new FeatureGroup();
    this.onMapClick();
    this.onTableClick();
    this.npage = 1;
  }

  onMapClick() {
    this.mapListService.onMapClik$.subscribe(id => {
      // create list of observation ids having coordinates = to id value


      const selected_id_coordinates = this.mapListService.layerDict[id].feature
        .geometry.coordinates;
      this.id_same_coordinates = [];
      console.log(this.mapListService.geojsonData.features);

      // for (let obs in this.mapListService.geojsonData.features) {
      //   console.log(obs);

      //   if (
      //     JSON.stringify(selected_id_coordinates) ==
      //     JSON.stringify(
      //       this.mapListService.geojsonData.features[obs].geometry.coordinates
      //     )
      //   ) {
      //     this.id_same_coordinates.push(
      //       parseInt(this.mapListService.geojsonData.features[obs].id)
      //     );
      //   }
      // }

      // select rows having id_synthese = to one of the id_same_coordinates values
      this.mapListService.selectedRow = [];
      for (let i = 0; i < this.mapListService.tableData.length; i++) {
        if (this.mapListService.tableData[i]["id_synthese"] === id) {
          this.mapListService.selectedRow.push(
            this.mapListService.tableData[i]
          );
          break;
        }
        const page = Math.trunc(i / this.rowNumber);
        console.log(page);

        this.table.offset = page;
      }

      //this.setSelectedObs();
    });
  }

  onTableClick() {
    this.setSelectedObs();
    this.mapListService.onTableClick$.subscribe(id => {
      this.setSelectedObs();
      this.setOriginStyleToAll();
      this.setSelectedSyleToSelectedRows();
    });
  }

  ngAfterContentChecked() {
    if (this.table && this.table.element.clientWidth !== this._latestWidth) {
      this._latestWidth = this.table.element.clientWidth;
      this.table.recalculate();
    }
  }

  handlePageChange(event): void {
    this.npage = event.page;
  }

  setOriginStyleToAll() {
    for (let obs in this.mapListService.layerDict) {
      this.mapListService.layerDict[obs].setStyle(
        this.VALIDATION_CONFIG.MAP_POINT_STYLE.originStyle
      );
    }
  }

  setSelectedSyleToSelectedRows() {
    for (let obs of this.selectedObs) {
      this.mapListService.layerDict[obs].setStyle(
        this.VALIDATION_CONFIG.MAP_POINT_STYLE.selectedStyle
      );
    }
  }

  selectAll() {
    this.mapListService.selectedRow = [...this.mapListService.tableData];
{'fraction_non_alphanumeric': 0.11651741293532339, 'fraction_numerical': 0.0007960199004975124, 'mean_word_length': 3.2934643314822725, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, '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': '3962909', 'n_tokens_mistral': 3108, 'n_tokens_neox': 3000, 'n_words': 573}