Skip to content

Commit

Permalink
feat: add cb percent recov in tab 3
Browse files Browse the repository at this point in the history
  • Loading branch information
edelclaux committed Aug 22, 2024
1 parent 0bc9052 commit 7595c9a
Show file tree
Hide file tree
Showing 9 changed files with 220 additions and 41 deletions.
8 changes: 7 additions & 1 deletion backend/gn_module_zh/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,13 @@ def update_corine_biotopes(id_zh, corine_biotopes):

def post_corine_biotopes(id_zh, corine_biotopes):
for corine_biotope in corine_biotopes:
DB.session.add(CorZhCb(id_zh=id_zh, lb_code=corine_biotope["CB_code"]))
DB.session.add(
CorZhCb(
id_zh=id_zh,
lb_code=corine_biotope["corinBio"]["CB_code"],
cb_cover=corine_biotope["cbCover"],
)
)
DB.session.flush()


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""add_cb_cover_percentage
Revision ID: 9ff769188d93
Revises: 76e89c793961
Create Date: 2024-07-04 15:42:25.691119
"""

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "9ff769188d93"
down_revision = "76e89c793961"
branch_labels = None
depends_on = None


def upgrade():
op.add_column(
table_name="cor_zh_cb",
column=sa.Column("cb_cover", sa.Integer, nullable=True),
schema="pr_zh",
)


def downgrade():
op.drop_column(table_name="cor_zh_cb", column_name="cb_cover", schema="pr_zh")
12 changes: 10 additions & 2 deletions backend/gn_module_zh/model/cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,15 @@ def __str__(self):
"area": self.area,
"sdage": Utils.get_mnemo(self.id_sdage),
"typologie_locale": Utils.get_mnemo(self.id_sage),
"corine_biotope": [cb.__str__() for cb in self.cb_codes_corine_biotope],
"corine_biotope": [
{
"code": cb["lb_code"],
"label": CorineBiotope(cb["lb_code"]).__str__()["label"],
"Humidité": CorineBiotope(cb["lb_code"]).__str__()["Humidité"],
"recouvrement": cb["cb_cover"],
}
for cb in self.cb_codes_corine_biotope
],
"remarques": Utils.get_string(self.remark_pres),
"ef_area": self.ef_area,
}
Expand Down Expand Up @@ -1154,7 +1162,7 @@ def __set_description(self):
return self.description.__str__()

def __get_cb(self):
return [CorineBiotope(cb) for cb in sorted(self.properties["cb_codes_corine_biotope"])]
return [cb for cb in self.properties["cb_codes_corine_biotope"]]

def __set_use(self):
self.description.use = Use()
Expand Down
6 changes: 5 additions & 1 deletion backend/gn_module_zh/model/zh.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ def get_id_references(self):

def get_cb_codes(self):
corine_biotopes = ZH.get_data_by_id(CorZhCb, self.zh.id_zh)
return {"cb_codes_corine_biotope": [cb_code.lb_code for cb_code in corine_biotopes]}
return {
"cb_codes_corine_biotope": [
{"lb_code": cb.lb_code, "cb_cover": cb.cb_cover} for cb in corine_biotopes
]
}

def get_corine_landcovers(self):
landcovers = ZH.get_data_by_id(CorZhCorineCover, self.zh.id_zh)
Expand Down
2 changes: 2 additions & 0 deletions backend/gn_module_zh/model/zh_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,11 +634,13 @@ def get_mnemo_type(id_type):
return ""


# TODO: not really a CorXXX. More a TXXX.
class CorZhCb(DB.Model):
__tablename__ = "cor_zh_cb"
__table_args__ = {"schema": "pr_zh"}
id_zh = DB.Column(DB.Integer, ForeignKey(TZH.id_zh), primary_key=True)
lb_code = DB.Column(DB.Integer, ForeignKey(BibCb.lb_code), primary_key=True)
cb_cover = DB.Column(DB.Integer, nullable=True)


class CorZhCorineCover(DB.Model):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class DescriptionComponent {
{ name: 'code', label: 'Code Corine biotopes' },
{ name: 'label', label: 'Libellé Corine biotopes' },
{ name: 'Humidité', label: 'Humidité', size: '5%' },
{ name: 'recouvrement', label: 'Recouvrement sur la ZH (%)', size: '5%' },
];
activitiesTableCols: TableColumn[] = [
{
Expand Down
1 change: 1 addition & 0 deletions frontend/app/zh-details/models/description.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface Corine {
code: string;
label: string;
Humidité: string;
recouvrement: string;
}

interface Activities {
Expand Down
90 changes: 75 additions & 15 deletions frontend/app/zh-forms/tabs/tab3/zh-form-tab3.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,23 @@ <h5 class="section-title">Présentation de la zone humide et de ses milieux</h5>
<div class="form-row">
<div class="form-group col-md-6">
<small>Types d’habitats Corine biotopes humides (H) ou potentiellement humides (P)</small>
<input
id="typeahead-basic"
type="text"
class="form-control"
placeholder="Tapez les premières lettres..."
[formControl]="form.controls.corinBio"
[resultFormatter]="formatter"
[inputFormatter]="formatter"
[ngbTypeahead]="search"
/>

</div>
<div class="form-group d-flex align-items-end col-md-6">
<button mat-raised-button color="primary" (click)="onAddCorinBio()">
<button mat-raised-button color="primary" (click)="onAddCorinBio($event, corinBioModal)">
<mat-icon>add_box</mat-icon>
Ajouter
Habitat
</button>
</div>
</div>
<div *ngIf="listCorinBio && listCorinBio.length > 0" class="table-responsive">
<zh-table
[tableCols]="corinTableCol"
[data]="listCorinBio"
[editable]="true"
[deletable]="true"
(onDelete)="onDeleteCorin($event?.CB_code)"
(onDelete)="onDeleteCorin($event?.corinBio.CB_code)"
(onEdit)="onEditCorinBio(corinBioModal, $event)"
></zh-table>
</div>
<div class="form-row">
Expand Down Expand Up @@ -239,5 +232,72 @@ <h6>{{ modalTitle }}</h6>
>
{{ modalButtonLabel }}
</button>
</div></ng-template
>
</div>
</ng-template>

<!-- Modal corine biotope-->
<ng-template #corinBioModal let-c="close" let-d="dismiss">
<div class="modal-header">
<h6>{{ modalTitle }}</h6>
<button mat-icon-button class="closeModalBtn" (click)="c()">
<mat-icon class="cancel-icon">cancel</mat-icon>
</button>
</div>
<div class="modal-body">
<form [formGroup]="corinBioForm">
<div class="form-row">
<div class="form-group col-md-6">
<small>Corine biotopes</small>
<input
id="typeahead-basic"
type="text"
class="form-control"
[formControl]="corinBioForm.controls.corinBio"
placeholder="Tapez les premières lettres..."
[resultFormatter]="formatter"
[inputFormatter]="formatter"
[ngbTypeahead]="search"
/>
<small
*ngIf="
(corinBioForm.controls.corinBio.touched || modalFormSubmitted) &&
corinBioForm.controls.corinBio.errors?.required
"
class="error-msg"
>Champ requis</small
>
</div>
<div class="form-group col-md-12">
<small>Recouvrement sur la ZH (%)</small>
<input
class="form-control"
[formControl]="corinBioForm.controls.cbCover"
type="number"
min="0"
max="100"
/>
<small
*ngIf="
corinBioForm.controls.cbCover.value &&
(corinBioForm.controls.cbCover.errors?.min ||
corinBioForm.controls.cbCover.errors?.max)
"
class="error-msg"
>La valeur doit être comprise entre 0 et 100
</small>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button
type="button"
mat-raised-button
color="primary"
class="uppercase"
(click)="patchCorinBio ? onPatchCorinBio() : onPostCorinBio()"
>
{{ addModalBtnLabel }}
</button>
</div>
</ng-template>
Loading

0 comments on commit 7595c9a

Please sign in to comment.