Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/taxon media display adjustement #3287

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
<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 [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>
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@
justify-content: center;
row-gap: 0rem;
padding: 1rem;
height: 9rem;
height: 100%;
width: auto;
min-width: 12rem;
&__media {
height: 100%;
width: 100%;
}
&__icon {
$icon-size: 2rem;
font-size: $icon-size;
Expand All @@ -34,7 +30,6 @@

.Indicator--small {
border: none;
height: auto;
.Indicator__icon {
$icon-size: 1.5rem;
font-size: $icon-size;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
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, CommonModule],
imports: [MatIconModule],
})
export class IndicatorComponent {
@Input()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ export interface Indicator {
name: string;
matIcon: string;
value: string | null;
type: IndicatorRawType;
}

type IndicatorRawType = 'number' | 'string' | 'date' | 'image';
type IndicatorRawType = 'number' | 'string' | 'date';
export interface IndicatorDescription {
name: string;
matIcon: string;
Expand Down Expand Up @@ -58,6 +57,5 @@ 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 @@ -16,14 +16,9 @@ import { TaxonomyComponent } from './taxonomy/taxonomy.component';
imports: [CommonModule, StatusComponent, TaxonomyComponent],
})
export class InfosComponent implements OnInit {
mediaUrl: string;
taxon: Taxon | null = null;

constructor(
private _config: ConfigService,
private _ds: DataFormService,
private _tss: TaxonSheetService
) {}
constructor(private _tss: TaxonSheetService) {}

ngOnInit() {
this._tss.taxon.subscribe((taxon: Taxon | null) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<img
*ngIf="mediaUrl"
class="TaxonImage"
[src]="mediaUrl"
/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.TaxonImage {
height: 100%;
width: auto;
border-radius: 0.25rem;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { CommonModule } from '@angular/common';
import { Component, Input } from '@angular/core';
import { ConfigService } from '@geonature/services/config.service';
import { DataFormService } from '@geonature_common/form/data-form.service';
import { Taxon } from '@geonature_common/form/taxonomy/taxonomy.component';
import { TaxonSheetService } from '../../taxon-sheet.service';

@Component({
standalone: true,
selector: 'taxon-image',
templateUrl: 'taxon-image.component.html',
styleUrls: ['taxon-image.component.scss'],
imports: [CommonModule],
})
export class TaxonImageComponent {
mediaUrl: string = '';

constructor(
private _ds: DataFormService,
private _tss: TaxonSheetService,
private _config: ConfigService
) {}

ngOnInit() {
this._tss.taxon.subscribe((taxon: Taxon | null) => {
this.mediaUrl = '';
if (!taxon) {
return;
}
this._ds.getTaxonInfo(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,12 +2,11 @@
<div class="TaxonSheet">
<infos class="TaxonSheet__infos" />
<div class="TaxonSheet__indicators">
<ng-container *ngFor="let indicator of indicators">
<indicator
*ngIf="indicator.type != 'image' || indicator.value != '-'"
[indicator]="indicator"
/>
</ng-container>
<taxon-image />
<indicator
*ngFor="let indicator of indicators"
[indicator]="indicator"
/>
</div>
<div class="card AvancedInfos">
<nav
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
flex-flow: row wrap;
justify-content: space-evenly;
gap: 1rem;

indicator,
taxon-image {
height: 9rem;
}
}
.AvancedInfos {
&__navBar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,14 @@ import {
Indicator,
IndicatorDescription,
} from './indicator/indicator';
import { TaxonImageComponent } from './infos/taxon-image/taxon-image.component';
import { IndicatorComponent } from './indicator/indicator.component';
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 @@ -78,12 +70,12 @@ const INDICATORS: Array<IndicatorDescription> = [
RouterOutlet,
RouterLink,
RouterLinkActive,
TaxonImageComponent,
],
providers: [TaxonSheetService],
})
export class TaxonSheetComponent implements OnInit {
readonly TAB_LINKS = [];
mediaUrl: string = null;

indicators: Array<Indicator>;

Expand All @@ -92,29 +84,17 @@ export class TaxonSheetComponent implements OnInit {
private _route: ActivatedRoute,
private _tss: TaxonSheetService,
private _syntheseDataService: SyntheseDataService,
private _routes: RouteService,
private _ds: DataFormService,
private _config: ConfigService
private _routes: RouteService
) {
this.TAB_LINKS = this._routes.TAB_LINKS;
}
ngOnInit() {
this._route.params.subscribe((params) => {
const cd_ref = params['cd_ref'];
if (cd_ref) {
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);
});
this._tss.updateTaxonByCdRef(cd_ref);
this._syntheseDataService.getSyntheseTaxonSheetStat(cd_ref).subscribe((stats) => {
this.setIndicators(stats);
});
}
});
Expand Down
Loading