Skip to content

Commit

Permalink
fix(frontend) taxon sheet media
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Narcisi committed Dec 10, 2024
1 parent dd15f73 commit fab84e1
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<div [className]="small ? 'card Indicator Indicator--small' : 'card Indicator'">
<mat-icon class="Indicator__icon">{{ indicator.matIcon }}</mat-icon>
<span class="Indicator__value">{{ indicator.value }}</span>
<span class="Indicator__name text-secondary">{{ indicator.name }}</span>
<div
[className]="small ? 'card Indicator Indicator--small' : 'card Indicator'"
[style]="indicator.type == 'image' ? 'padding: 0' : 'padding: 1rem'"
>
<ng-container *ngIf="indicator.type != 'image'; else media">
<mat-icon class="Indicator__icon">{{ indicator.matIcon }}</mat-icon>
<span class="Indicator__value">{{ indicator.value }}</span>
<span class="Indicator__name text-secondary">{{ indicator.name }}</span>
</ng-container>
<ng-template #media>
<div
class="Indicator__media cover image"
[style.background-image]="'url(' + indicator.value + ')'"
></div>
</ng-template>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
height: 9rem;
width: auto;
min-width: 12rem;
&__media {
height: 100%;
width: 100%;
}
&__icon {
$icon-size: 2rem;
font-size: $icon-size;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Component, Input } from '@angular/core';
import { MatIconModule } from '@angular/material/icon';
import { Indicator } from './indicator';
import { CommonModule } from '@angular/common';

@Component({
standalone: true,
selector: 'indicator',
templateUrl: 'indicator.component.html',
styleUrls: ['indicator.component.scss'],
imports: [MatIconModule],
imports: [MatIconModule, CommonModule],
})
export class IndicatorComponent {
@Input()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ export interface Indicator {
name: string;
matIcon: string;
value: string | null;
type: IndicatorRawType;
}

type IndicatorRawType = 'number' | 'string' | 'date';
type IndicatorRawType = 'number' | 'string' | 'date' | 'image';
export interface IndicatorDescription {
name: string;
matIcon: string;
Expand Down Expand Up @@ -57,5 +58,6 @@ export function computeIndicatorFromDescription(
name: indicatorDescription.name,
matIcon: indicatorDescription.matIcon,
value: value,
type: indicatorDescription.type,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,3 @@
<taxonomy [taxon]="taxon"></taxonomy>
<status [taxon]="taxon"></status>
</div>
<div
class="card"
*ngIf="mediaUrl"
>
<div
class="card-body cover image"
[style.background-image]="'url(' + mediaUrl + ')'"
></div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,6 @@ export class InfosComponent implements OnInit {
ngOnInit() {
this._tss.taxon.subscribe((taxon: Taxon | null) => {
this.taxon = taxon;
if (!this.taxon) {
return;
}
this._ds
.getTaxonInfo(this.taxon.cd_ref, ['medias', 'cd_nom'])
.subscribe((taxonAttrAndMedias) => {
const media = taxonAttrAndMedias['medias'].find(
(m) => m.id_type == this._config.TAXHUB.ID_TYPE_MAIN_PHOTO
);
if (media) {
this.mediaUrl = `${this._ds.getTaxhubAPI()}/tmedias/thumbnail/${
media.id_media
}?h=300&w300`;
}
});
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
<div class="TaxonSheet">
<infos class="TaxonSheet__infos" />
<div class="TaxonSheet__indicators">
<indicator
*ngFor="let indicator of indicators"
[indicator]="indicator"
/>
<ng-container *ngFor="let indicator of indicators">
<indicator
*ngIf="indicator.type != 'image' || indicator.value != '-'"
[indicator]="indicator"
/>
</ng-container>
</div>
<div class="card AvancedInfos">
<nav
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,17 @@ import { CommonModule } from '@angular/common';
import { SyntheseDataService } from '@geonature_common/form/synthese-form/synthese-data.service';
import { TaxonSheetService } from './taxon-sheet.service';
import { RouteService } from './taxon-sheet.route.service';
import { Taxon } from '@geonature_common/form/taxonomy/taxonomy.component';
import { DataFormService } from '@geonature_common/form/data-form.service';
import { ConfigService } from '@geonature/services/config.service';

const INDICATORS: Array<IndicatorDescription> = [
{
name: 'Image',
matIcon: '',
type: 'image',
field: 'media',
},
{
name: 'observation(s)',
matIcon: 'search',
Expand Down Expand Up @@ -74,6 +83,7 @@ const INDICATORS: Array<IndicatorDescription> = [
})
export class TaxonSheetComponent implements OnInit {
readonly TAB_LINKS = [];
mediaUrl: string = null;

indicators: Array<Indicator>;

Expand All @@ -82,17 +92,29 @@ export class TaxonSheetComponent implements OnInit {
private _route: ActivatedRoute,
private _tss: TaxonSheetService,
private _syntheseDataService: SyntheseDataService,
private _routes: RouteService
private _routes: RouteService,
private _ds: DataFormService,
private _config: ConfigService
) {
this.TAB_LINKS = this._routes.TAB_LINKS;
}
ngOnInit() {
this._route.params.subscribe((params) => {
const cd_ref = params['cd_ref'];
if (cd_ref) {
this._tss.updateTaxonByCdRef(cd_ref);
this._syntheseDataService.getSyntheseTaxonSheetStat(cd_ref).subscribe((stats) => {
this.setIndicators(stats);
this._ds.getTaxonInfo(cd_ref, ['medias', 'cd_nom']).subscribe((taxonAttrAndMedias) => {
const media = taxonAttrAndMedias['medias'].find(
(m) => m.id_type == this._config.TAXHUB.ID_TYPE_MAIN_PHOTO
);
let mediaUrl;
if (media) {
mediaUrl = `${this._ds.getTaxhubAPI()}/tmedias/thumbnail/${media.id_media}?h=300&w300`;
}
this._tss.updateTaxonByCdRef(cd_ref);
this._syntheseDataService.getSyntheseTaxonSheetStat(cd_ref).subscribe((stats) => {
stats['media'] = mediaUrl;
this.setIndicators(stats);
});
});
}
});
Expand Down

0 comments on commit fab84e1

Please sign in to comment.