<commit_before>import { Component, OnInit, ViewChild, HostListener } from "@angular/core";
import { OcchabStoreService } from "../../services/store.service";
import { MapListService } from "@geonature_common/map-list/map-list.service";
import { OccHabDataService } from "../../services/data.service";
import { DatatableComponent } from "@swimlane/ngx-datatable/release";
import { OccHabModalDownloadComponent } from "./modal-download.component";
import { NgbModal, NgbActiveModal } from "@ng-bootstrap/ng-bootstrap";
import { CommonService } from "@geonature_common/service/common.service";
import * as moment from "moment";
import { ModuleConfig } from "../../../../../../external_modules/occhab/frontend/app/module.config";

@Component({
  selector: "pnx-occhab-map-list",
  templateUrl: "occhab-map-list.component.html",
  styleUrls: ["./occhab-map-list.component.scss", "../responsive-map.scss"],
  providers: [NgbActiveModal]
})
export class OccHabMapListComponent implements OnInit {
  public displayedColumns = [
    { name: "Date", prop: "date_min", width: "100" },
    { name: "Habitats", prop: "habitats", width: "300" },
    { name: "Jeu de données", prop: "dataset_name", width: "200" }
  ];
  @ViewChild("dataTable") dataTable: DatatableComponent;
  public rowNumber: number;
  public dataLoading = true;
  public deleteOne: any;
  constructor(
    public storeService: OcchabStoreService,
    private _occHabDataService: OccHabDataService,
    public mapListService: MapListService,
    private _ngbModal: NgbModal,
    private _commonService: CommonService
  ) {}
  ngOnInit() {
    if (this.storeService.firstMessageMapList) {
      this._commonService.regularToaster(
        "info",
        "Les 50 dernières stations saisies"
      );
      this.storeService.firstMessageMapList = false;
    }

    this.getStations({ limit: 50 });
    // get wiewport height to set the number of rows in the tabl
    const h = document.documentElement.clientHeight;
    this.rowNumber = Math.trunc(h / 55);
    // observable on mapListService.currentIndexRow to find the current page
    this.mapListService.currentIndexRow$.subscribe(indexRow => {
      const currentPage = Math.trunc(indexRow / this.rowNumber);
      this.dataTable.offset = currentPage;
    });
  }

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

  getStations(params?) {
    this.dataLoading = true;
    this._occHabDataService
      .getStations(params)
      .subscribe(featuresCollection => {<commit_msg>Maplist: correction superposition boutton et pagination<commit_after>import { Component, OnInit, ViewChild, HostListener } from "@angular/core";
import { OcchabStoreService } from "../../services/store.service";
import { MapListService } from "@geonature_common/map-list/map-list.service";
import { OccHabDataService } from "../../services/data.service";
import { DatatableComponent } from "@swimlane/ngx-datatable/release";
import { OccHabModalDownloadComponent } from "./modal-download.component";
import { NgbModal, NgbActiveModal } from "@ng-bootstrap/ng-bootstrap";
import { CommonService } from "@geonature_common/service/common.service";
import * as moment from "moment";
import { ModuleConfig } from "../../../../../../external_modules/occhab/frontend/app/module.config";

@Component({
  selector: "pnx-occhab-map-list",
  templateUrl: "occhab-map-list.component.html",
  styleUrls: ["./occhab-map-list.component.scss", "../responsive-map.scss"],
  providers: [NgbActiveModal]
})
export class OccHabMapListComponent implements OnInit {
  public displayedColumns = [
    { name: "Date", prop: "date_min", width: "100" },
    { name: "Habitats", prop: "habitats", width: "300" },
    { name: "Jeu de données", prop: "dataset_name", width: "200" }
  ];
  @ViewChild("dataTable") dataTable: DatatableComponent;
  public rowNumber: number;
  public dataLoading = true;
  public deleteOne: any;
  constructor(
    public storeService: OcchabStoreService,
    private _occHabDataService: OccHabDataService,
    public mapListService: MapListService,
    private _ngbModal: NgbModal,
    private _commonService: CommonService
  ) {}
  ngOnInit() {
    if (this.storeService.firstMessageMapList) {
      this._commonService.regularToaster(
        "info",
        "Les 50 dernières stations saisies"
      );
      this.storeService.firstMessageMapList = false;
    }

    this.getStations({ limit: 50 });
    // get wiewport height to set the number of rows in the tabl
    const h = document.documentElement.clientHeight;
    console.log(h);

    this.rowNumber = this.calculeteRowNumber(h);
    // observable on mapListService.currentIndexRow to find the current page
    this.mapListService.currentIndexRow$.subscribe(indexRow => {
      const currentPage = Math.trunc(indexRow / this.rowNumber);
      this.dataTable.offset = currentPage;
    });
  }

  /** Calculate the number of row with the client screen height */
  calculeteRowNumber(screenHeight: number): number {
    //if(scr)
    if (screenHeight > 1000) {
      return Math.trunc(screenHeight / 52);
    } else if (screenHeight > 800) {
      return Math.trunc(screenHeight / 55);
    } else if (screenHeight <= 800) {
      return Math.trunc(screenHeight / 62);
    }
  }

  // update the number of row per page when resize the window
  @HostListener("window:resize", ["$event"])
  onResize(event) {
    console.log(event.target.innerHeight);

    this.rowNumber = this.calculeteRowNumber(event.target.innerHeight);
  }

  getStations(params?) {
    this.dataLoading = true;
    this._occHabDataService
      .getStations(params)
      .subscribe(featuresCollection => {
{'fraction_non_alphanumeric': 0.1295525494276795, 'fraction_numerical': 0.007977800901838363, 'mean_word_length': 3.8666666666666667, 'pattern_counts': {'":': 0, '<': 4, '<?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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4945184', 'n_tokens_mistral': 1787, 'n_tokens_neox': 1734, 'n_words': 401}