-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: setup tab-observers with paginated content
- Loading branch information
Showing
10 changed files
with
219 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import typing | ||
from geonature.utils.env import db | ||
from ref_geo.models import LAreas, BibAreasTypes | ||
|
||
from geonature.core.gn_synthese.models import Synthese | ||
from sqlalchemy import select | ||
from apptax.taxonomie.models import Taxref | ||
from geonature.core.gn_synthese.utils.query_select_sqla import SyntheseQuery | ||
|
||
|
||
class SpeciesSheetUtils: | ||
|
||
@staticmethod | ||
def get_cd_nom_list_from_cd_ref(cd_ref: int) -> typing.List[int]: | ||
return db.session.scalars(select(Taxref.cd_nom).where(Taxref.cd_ref == cd_ref)) | ||
|
||
@staticmethod | ||
def get_synthese_query_with_scope(current_user, scope: int, query) -> any: | ||
synthese_query_obj = SyntheseQuery(Synthese, query, {}) | ||
synthese_query_obj.filter_query_with_cruved(current_user, scope) | ||
return synthese_query_obj.query | ||
|
||
@staticmethod | ||
def is_valid_area_type(area_type: str) -> bool: | ||
# Ensure area_type is valid | ||
valid_area_types = ( | ||
db.session.query(BibAreasTypes.type_code) | ||
.distinct() | ||
.filter(BibAreasTypes.type_code == area_type) | ||
.scalar() | ||
) | ||
|
||
return valid_area_types | ||
|
||
@staticmethod | ||
def get_area_subquery(area_type: str) -> any: | ||
|
||
# Subquery to fetch areas based on area_type | ||
return ( | ||
select([LAreas.id_area]) | ||
.where(LAreas.id_type == BibAreasTypes.id_type) | ||
.where(BibAreasTypes.type_code == area_type) | ||
.alias("areas") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
frontend/src/app/GN2CommonModule/form/synthese-form/synthese-data-pagination-item.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export interface SyntheseDataPaginationItem { | ||
totalItems: number; | ||
currentPage: number; | ||
perPage: number; | ||
} | ||
|
||
export const DEFAULT_PAGINATION: SyntheseDataPaginationItem = { | ||
totalItems: 0, | ||
currentPage: 1, | ||
perPage: 10, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
frontend/src/app/syntheseModule/taxon-sheet/tab-observers/tab-observers.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<div class="Observers"> | ||
<ngx-datatable | ||
class="Observers__table material striped" | ||
[rows]="items" | ||
[columns]="columns" | ||
columnMode="force" | ||
[draggable]="false" | ||
[externalPaging]="true" | ||
[count]="pagination.totalItems" | ||
(page)="onChangePage($event)" | ||
footerHeight="auto" | ||
headerHeight="auto" | ||
rowHeight="auto" | ||
></ngx-datatable> | ||
</div> |
5 changes: 5 additions & 0 deletions
5
frontend/src/app/syntheseModule/taxon-sheet/tab-observers/tab-observers.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.Observers { | ||
&__table { | ||
box-shadow: none; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
frontend/src/app/syntheseModule/taxon-sheet/tab-observers/tab-observers.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { GN2CommonModule } from '@geonature_common/GN2Common.module'; | ||
import { CommonModule } from '@angular/common'; | ||
import { ConfigService } from '@geonature/services/config.service'; | ||
import { Taxon } from '@geonature_common/form/taxonomy/taxonomy.component'; | ||
import { TaxonSheetService } from '../taxon-sheet.service'; | ||
import { SyntheseDataService } from '@geonature_common/form/synthese-form/synthese-data.service'; | ||
import { | ||
DEFAULT_PAGINATION, | ||
SyntheseDataPaginationItem, | ||
} from '@geonature_common/form/synthese-form/synthese-data-pagination-item'; | ||
@Component({ | ||
standalone: true, | ||
selector: 'tab-observers', | ||
templateUrl: 'tab-observers.component.html', | ||
styleUrls: ['tab-observers.component.scss'], | ||
imports: [GN2CommonModule, CommonModule], | ||
}) | ||
export class TabObserversComponent implements OnInit { | ||
items: any[] = []; | ||
pagination: SyntheseDataPaginationItem = DEFAULT_PAGINATION; | ||
|
||
readonly columns = [ | ||
{ prop: 'observer', name: 'Observateur' }, | ||
{ prop: 'date_min', name: 'Plus ancienne' }, | ||
{ prop: 'date_max', name: 'Plus récente' }, | ||
{ prop: 'count', name: "Nombre d'observations" }, | ||
]; | ||
|
||
constructor( | ||
private _syntheseDataService: SyntheseDataService, | ||
private _config: ConfigService, | ||
private _tss: TaxonSheetService | ||
) {} | ||
|
||
ngOnInit() { | ||
this._tss.taxon.subscribe((taxon: Taxon | null) => { | ||
this.fetchObservers(); | ||
}); | ||
} | ||
|
||
onChangePage(event) { | ||
this.pagination.currentPage = event.offset + 1; | ||
this.fetchObservers(); | ||
} | ||
|
||
fetchObservers() { | ||
const taxon = this._tss.taxon.getValue(); | ||
if (!taxon) { | ||
console.log('taxon is undefined'); | ||
return; | ||
} | ||
this._syntheseDataService | ||
.getSyntheseSpeciesSheetObservers(taxon.cd_ref, this.pagination) | ||
.subscribe((data) => { | ||
// Store result | ||
this.items = data.items; | ||
this.pagination = { | ||
totalItems: data.total, | ||
currentPage: data.page, | ||
perPage: data.per_page, | ||
}; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters