-
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: add status-badges component in GN2CommonModule
- Loading branch information
Showing
9 changed files
with
108 additions
and
98 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
4 changes: 1 addition & 3 deletions
4
frontend/src/app/GN2CommonModule/others/badge/badge.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
8 changes: 8 additions & 0 deletions
8
frontend/src/app/GN2CommonModule/others/status-badges/status-badges.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,8 @@ | ||
<div class="StatusBadges"> | ||
<gn-badge | ||
*ngFor="let status of status" | ||
[tooltip]="status.tooltip" | ||
[text]="status.badge" | ||
[symbology]="status.symbology" | ||
/> | ||
</div> |
7 changes: 7 additions & 0 deletions
7
frontend/src/app/GN2CommonModule/others/status-badges/status-badges.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,7 @@ | ||
.StatusBadges { | ||
display: flex; | ||
flex-flow: row wrap; | ||
width: 100%; | ||
gap: 0.5rem; | ||
line-height: inherit; | ||
} |
83 changes: 83 additions & 0 deletions
83
frontend/src/app/GN2CommonModule/others/status-badges/status-badges.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,83 @@ | ||
import { Component, Input, OnInit } from '@angular/core'; | ||
import { TaxonSheetService } from '@geonature/syntheseModule/taxon-sheet/taxon-sheet.service'; | ||
import { DataFormService } from '@geonature_common/form/data-form.service'; | ||
import { Taxon } from '@geonature_common/form/taxonomy/taxonomy.component'; | ||
import { BadgeSymbology } from '@geonature_common/others/badge/badge.component'; | ||
|
||
interface Status { | ||
badge: string; | ||
tooltip: string; | ||
symbology: BadgeSymbology | null; | ||
} | ||
@Component({ | ||
selector: 'gn-status-badges', | ||
templateUrl: 'status-badges.component.html', | ||
styleUrls: ['status-badges.component.scss'], | ||
}) | ||
export class StatusBadgesComponent implements OnInit { | ||
_taxon: Taxon | null; | ||
_symbology: Array<{ | ||
types: Array<string>; | ||
values: Record<string, BadgeSymbology>; | ||
}>; | ||
status: Array<Status> = []; | ||
|
||
constructor(private _ds: DataFormService) {} | ||
|
||
ngOnInit() { | ||
this._ds.fetchStatusSymbology().subscribe((symbology) => { | ||
this._symbology = []; | ||
if (!symbology || !symbology.symbologies) { | ||
return; | ||
} | ||
this._symbology = symbology.symbologies; | ||
|
||
this.computeStatus(); | ||
}); | ||
} | ||
|
||
_getSymbologyAsBadgeSymbology(type: string, value: string): BadgeSymbology | null { | ||
if (!this._symbology) { | ||
return null; | ||
} | ||
const symbologieItem = this._symbology.find((item) => item.types.includes(type)); | ||
if (!symbologieItem) { | ||
return null; | ||
} | ||
if (!('color' in symbologieItem.values[value])) { | ||
return null; | ||
} | ||
return { | ||
color: symbologieItem.values[value].color, | ||
}; | ||
} | ||
|
||
@Input() | ||
set taxon(taxon: Taxon | null) { | ||
this._taxon = taxon; | ||
this.computeStatus(); | ||
} | ||
|
||
computeStatus() { | ||
this.status = []; | ||
if (!this._taxon) { | ||
return; | ||
} | ||
|
||
for (const status of Object.values(this._taxon.status)) { | ||
for (const text of Object.values<any>(status.text)) { | ||
for (const value of Object.values<any>(text.values)) { | ||
const badgeValue = ['true', 'false'].includes(value.code_statut) | ||
? `${status.cd_type_statut}` | ||
: `${status.cd_type_statut}: ${value.code_statut}`; | ||
|
||
this.status.push({ | ||
badge: badgeValue, | ||
tooltip: `${status.cd_type_statut} : ${value.display} - ${text.full_citation}`, | ||
symbology: this._getSymbologyAsBadgeSymbology(status.cd_type_statut, value.code_statut), | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
} |
7 changes: 1 addition & 6 deletions
7
frontend/src/app/syntheseModule/taxon-sheet/infos/status/status.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 |
---|---|---|
@@ -1,11 +1,6 @@ | ||
<div class="Status"> | ||
<div class="Status__header">Statuts</div> | ||
<div class="Status__badges"> | ||
<gn-badge | ||
*ngFor="let status of status" | ||
[tooltip]="status.tooltip" | ||
[text]="status.badge" | ||
[symbology]="status.symbology" | ||
/> | ||
<gn-status-badges [taxon]="taxon" /> | ||
</div> | ||
</div> |
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
77 changes: 4 additions & 73 deletions
77
frontend/src/app/syntheseModule/taxon-sheet/infos/status/status.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 |
---|---|---|
@@ -1,87 +1,18 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { Component, Input, OnInit } from '@angular/core'; | ||
import { Component, Input } from '@angular/core'; | ||
import { Taxon } from '@geonature_common/form/taxonomy/taxonomy.component'; | ||
import { GN2CommonModule } from '@geonature_common/GN2Common.module'; | ||
import { TaxonSheetService } from '../../taxon-sheet.service'; | ||
import { BadgeSymbology } from '@geonature_common/others/badge/badge.component'; | ||
|
||
interface Status { | ||
badge: string; | ||
tooltip: string; | ||
symbology: BadgeSymbology | null; | ||
} | ||
@Component({ | ||
standalone: true, | ||
selector: 'status', | ||
templateUrl: 'status.component.html', | ||
styleUrls: ['status.component.scss'], | ||
imports: [CommonModule, GN2CommonModule], | ||
}) | ||
export class StatusComponent implements OnInit { | ||
_taxon: Taxon | null; | ||
_symbology: Array<{ | ||
types: Array<string>; | ||
values: Record<string, BadgeSymbology>; | ||
}>; | ||
status: Array<Status> = []; | ||
|
||
constructor(private _tss: TaxonSheetService) {} | ||
|
||
ngOnInit() { | ||
this._tss.symbology.subscribe((symbology) => { | ||
this._symbology = []; | ||
if (!symbology || !symbology.symbologies) { | ||
return; | ||
} | ||
this._symbology = symbology.symbologies; | ||
|
||
this.computeStatus(); | ||
}); | ||
this._tss.fetchStatusSymbology(); | ||
} | ||
|
||
_getSymbologyAsBadgeSymbology(type: string, value: string): BadgeSymbology | null { | ||
if (!this._symbology) { | ||
return null; | ||
} | ||
const symbologieItem = this._symbology.find((item) => item.types.includes(type)); | ||
if (!symbologieItem) { | ||
return null; | ||
} | ||
if (!('color' in symbologieItem.values[value])) { | ||
return null; | ||
} | ||
return { | ||
color: symbologieItem.values[value].color, | ||
}; | ||
} | ||
export class StatusComponent { | ||
constructor() {} | ||
|
||
@Input() | ||
set taxon(taxon: Taxon | null) { | ||
this._taxon = taxon; | ||
this.computeStatus(); | ||
} | ||
|
||
computeStatus() { | ||
this.status = []; | ||
if (!this._taxon) { | ||
return; | ||
} | ||
|
||
for (const status of Object.values(this._taxon.status)) { | ||
for (const text of Object.values<any>(status.text)) { | ||
for (const value of Object.values<any>(text.values)) { | ||
const badgeValue = ['true', 'false'].includes(value.code_statut) | ||
? `${status.cd_type_statut}` | ||
: `${status.cd_type_statut}: ${value.code_statut}`; | ||
|
||
this.status.push({ | ||
badge: badgeValue, | ||
tooltip: `${status.cd_type_statut} : ${value.display} - ${text.full_citation}`, | ||
symbology: this._getSymbologyAsBadgeSymbology(status.cd_type_statut, value.code_statut), | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
taxon: Taxon | null; | ||
} |
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