Commit 21aff611 authored by Célia Michotey's avatar Célia Michotey Committed by Célia Michotey
Browse files

WIP: deduplicate models, reduce cyclomatic complexity, change display of...

WIP: deduplicate models, reduce cyclomatic complexity, change display of additional info on site card.
parent 09374a1e
import { BrapiService } from './brapi.service'; import { BrapiService } from './brapi.service';
import { import {
BrapiContacts, BrapiContacts, BrapiData, BrapiDonor,
BrapiGermplasm, BrapiGermplasm, BrapiGermplasmAttributes, BrapiGermplasmPedigree, BrapiGermplasmProgeny,
BrapiLocation, BrapiLocation,
BrapiObservationVariable, BrapiObservationVariable,
BrapiResult, BrapiResult, BrapiResults, BrapiSibling,
BrapiResults, BrapiStudy, BrapiTaxonIds,
BrapiStudy,
BrapiTrial BrapiTrial
} from './models/brapi.model'; } from './models/brapi.model';
import { DataDiscoverySource } from './models/data-discovery.model'; import { DataDiscoverySource } from './models/data-discovery.model';
import {
BrapiDescriptor,
BrapiDonor,
BrapiGermplasmAttributes,
BrapiGermplasmPedigree,
BrapiGermplasmProgeny,
BrapiSibling
} from './models/brapi.germplasm.model';
import { Germplasm, GermplasmData, GermplasmResult, GermplasmSet, Institute, Origin, Site } from './models/gnpis.germplasm.model';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import {Germplasm, GermplasmInstitute, GermplasmSet, Institute, Site} from "./models/gnpis.model";
import Result = jasmine.Result;
describe('BrapiService', () => { describe('BrapiService', () => {
...@@ -111,17 +103,49 @@ describe('BrapiService', () => { ...@@ -111,17 +103,49 @@ describe('BrapiService', () => {
data: [{ data: [{
germplasmDbId: 'g1', germplasmDbId: 'g1',
accessionNumber: 'G_10', accessionNumber: 'G_10',
defaultDisplayName: null,
germplasmPUI: null,
pedigree: null,
seedSource: null,
synonyms: null,
commonCropName: null,
instituteCode: null,
instituteName: null,
biologicalStatusOfAccessionCode: null,
countryOfOriginCode: null,
typeOfGermplasmStorageCode: null,
taxonIds: null,
germplasmName: 'germplam1', germplasmName: 'germplam1',
genus: 'Populus', genus: 'Populus',
species: 'x generosa', species: 'x generosa',
subtaxa: '' subtaxa: '',
speciesAuthority: null,
subtaxaAuthority: null,
donors: null,
acquisitionDate: null
}, { }, {
germplasmDbId: 'g2', germplasmDbId: 'g2',
accessionNumber: 'G_20', accessionNumber: 'G_20',
germplasmName: 'germplam2', germplasmName: 'germplam2',
genus: 'Triticum', genus: 'Triticum',
species: 'aestivum', species: 'aestivum',
subtaxa: 'subsp' subtaxa: 'subsp',
defaultDisplayName: null,
germplasmPUI: null,
pedigree: null,
seedSource: null,
synonyms: null,
commonCropName: null,
instituteCode: null,
instituteName: null,
biologicalStatusOfAccessionCode: null,
countryOfOriginCode: null,
typeOfGermplasmStorageCode: null,
taxonIds: null,
speciesAuthority: null,
subtaxaAuthority: null,
donors: null,
acquisitionDate: null
}], }],
} }
}; };
...@@ -148,13 +172,7 @@ describe('BrapiService', () => { ...@@ -148,13 +172,7 @@ describe('BrapiService', () => {
defaultDisplayName: 'frere1' defaultDisplayName: 'frere1'
}; };
const brapiDescriptor: BrapiDescriptor = { const brapiGermplasmPedigree: BrapiResult<BrapiGermplasmPedigree> = {
name: 'caracteristique1',
pui: '12',
value: '32'
};
const brapiGermplasmPedigree: GermplasmResult<BrapiGermplasmPedigree> = {
result: { result: {
germplasmDbId: 'test', germplasmDbId: 'test',
defaultDisplayName: '12', defaultDisplayName: '12',
...@@ -172,7 +190,7 @@ describe('BrapiService', () => { ...@@ -172,7 +190,7 @@ describe('BrapiService', () => {
} }
}; };
const brapiGermplasmProgeny: GermplasmResult<BrapiGermplasmProgeny> = { const brapiGermplasmProgeny: BrapiResult<BrapiGermplasmProgeny> = {
result: { result: {
germplasmDbId: 'test', germplasmDbId: 'test',
defaultDisplayName: '11', defaultDisplayName: '11',
...@@ -191,7 +209,7 @@ describe('BrapiService', () => { ...@@ -191,7 +209,7 @@ describe('BrapiService', () => {
address: '12', address: '12',
logo: null logo: null
}; };
const origin: Origin = { ... institute, const origin: GermplasmInstitute = { ... institute,
institute: institute, institute: institute,
germplasmPUI: '12', germplasmPUI: '12',
accessionNumber: '12', accessionNumber: '12',
...@@ -219,7 +237,7 @@ describe('BrapiService', () => { ...@@ -219,7 +237,7 @@ describe('BrapiService', () => {
type: 'plan' type: 'plan'
}; };
const brapiGermplasmAttributes: GermplasmResult<GermplasmData<BrapiGermplasmAttributes[]>> = { const brapiGermplasmAttributes: BrapiResult<BrapiData<BrapiGermplasmAttributes[]>> = {
result: { result: {
data: [{ data: [{
attributeName: 'longueur', attributeName: 'longueur',
...@@ -229,8 +247,6 @@ describe('BrapiService', () => { ...@@ -229,8 +247,6 @@ describe('BrapiService', () => {
}; };
const germplasmTest: Germplasm = { const germplasmTest: Germplasm = {
url: 'www.cirad.fr',
source: 'cirad',
germplasmDbId: 'test', germplasmDbId: 'test',
defaultDisplayName: 'test', defaultDisplayName: 'test',
accessionNumber: 'test', accessionNumber: 'test',
...@@ -264,7 +280,6 @@ describe('BrapiService', () => { ...@@ -264,7 +280,6 @@ describe('BrapiService', () => {
holdingGenbank: institute, holdingGenbank: institute,
presenceStatus: null, presenceStatus: null,
children: null, children: null,
descriptors: [brapiDescriptor],
originSite: null, originSite: null,
collectingSite: null, collectingSite: null,
evaluationSites: null, evaluationSites: null,
...@@ -365,7 +380,7 @@ describe('BrapiService', () => { ...@@ -365,7 +380,7 @@ describe('BrapiService', () => {
it('should fetch the pedigree', () => { it('should fetch the pedigree', () => {
let fetchedGermplasmPedigree: GermplasmResult<BrapiGermplasmPedigree>; let fetchedGermplasmPedigree: BrapiResult<BrapiGermplasmPedigree>;
const germplasmDbId: string = brapiGermplasmPedigree.result.germplasmDbId; const germplasmDbId: string = brapiGermplasmPedigree.result.germplasmDbId;
brapiService.germplasmPedigree(germplasmDbId).subscribe(response => { brapiService.germplasmPedigree(germplasmDbId).subscribe(response => {
fetchedGermplasmPedigree = response; fetchedGermplasmPedigree = response;
...@@ -393,7 +408,7 @@ describe('BrapiService', () => { ...@@ -393,7 +408,7 @@ describe('BrapiService', () => {
it('should fetch the germplasm attributes', () => { it('should fetch the germplasm attributes', () => {
let fetchedGermplasmAttributes: GermplasmResult<GermplasmData<BrapiGermplasmAttributes[]>>; let fetchedGermplasmAttributes: BrapiResult<BrapiData<BrapiGermplasmAttributes[]>>;
const germplasmDbId: string = germplasmTest.germplasmDbId; const germplasmDbId: string = germplasmTest.germplasmDbId;
brapiService.germplasmAttributes(germplasmDbId).subscribe(response => { brapiService.germplasmAttributes(germplasmDbId).subscribe(response => {
fetchedGermplasmAttributes = response; fetchedGermplasmAttributes = response;
......
...@@ -3,7 +3,7 @@ import { Observable } from 'rxjs'; ...@@ -3,7 +3,7 @@ import { Observable } from 'rxjs';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { Germplasm, GermplasmData, GermplasmResult } from './models/gnpis.germplasm.model'; import { Germplasm, GermplasmData, GermplasmResult } from './models/gnpis.germplasm.model';
import { import {
BrapiGermplasm, BrapiGermplasm, BrapiGermplasmAttributes,
BrapiLocation, BrapiLocation,
BrapiObservationVariable, BrapiObservationVariable,
BrapiResult, BrapiResult,
...@@ -11,7 +11,7 @@ import { ...@@ -11,7 +11,7 @@ import {
BrapiStudy, BrapiStudy,
BrapiTrial BrapiTrial
} from './models/brapi.model'; } from './models/brapi.model';
import { BrapiGermplasmAttributes, BrapiGermplasmPedigree } from './models/brapi.germplasm.model'; import { BrapiGermplasmPedigree } from './models/brapi.germplasm.model';
export const BASE_URL = 'brapi/v1'; export const BASE_URL = 'brapi/v1';
......
...@@ -2,29 +2,28 @@ ...@@ -2,29 +2,28 @@
<ng-container *ngIf="germplasmGnpis"> <ng-container *ngIf="germplasmGnpis">
<h3 class="mb-4"> <h3 class="mb-4">
<figure *ngIf="germplasmGnpis.holdingGenbank && germplasmGnpis.holdingGenbank.instituteName"> <img *ngIf="germplasmGnpis.holdingGenbank && germplasmGnpis.holdingGenbank.instituteName"
<img [src]="IMAGES_BRC_URL"
[src]="IMAGES_BRC_URL" align="right"/>
align="right" />
</figure>
Germplasm: {{ germplasmGnpis.germplasmName }} Germplasm: {{ germplasmGnpis.germplasmName }}
</h3> </h3>
<!-- Display the map --> <!-- Display the map -->
<gpds-map *ngIf="germplasmLocations.length > 0" [locations]="germplasmLocations"></gpds-map> <gpds-map [locations]="germplasmLocations"></gpds-map>
<div class="row align-items-center"> <div class="row align-items-center">
<!--Templates for gerplasm card--> <!--Templates for gerplasm card-->
<ng-template #holdingInstituteTemplate > <ng-template #holdingInstituteTemplate>
<figure *ngIf="germplasmGnpis.holdingInstitute && germplasmGnpis.holdingInstitute.logo"> <gpds-card-row
<img label=""
[src]="IMAGES_INSTITUTION_URL + germplasmGnpis.holdingInstitute.logo" [test]="germplasmGnpis.holdingInstitute && germplasmGnpis.holdingInstitute.logo">
align="middle" /> <ng-template>
</figure> <img
[src]="IMAGES_INSTITUTION_URL + germplasmGnpis.holdingInstitute.logo"/>
</ng-template>
</gpds-card-row>
<gpds-card-row <gpds-card-row
label="Code" label="Code"
...@@ -53,7 +52,12 @@ ...@@ -53,7 +52,12 @@
<gpds-card-row <gpds-card-row
label="Website" label="Website"
[value]="germplasmGnpis.holdingInstitute.webSite"> [test]="germplasmGnpis.holdingInstitute.webSite">
<ng-template>
<a [href]="germplasmGnpis.breeder.institute.webSite">
{{ germplasmGnpis.holdingInstitute.webSite }}
</a>
</ng-template>
</gpds-card-row> </gpds-card-row>
</ng-template> </ng-template>
...@@ -61,11 +65,14 @@ ...@@ -61,11 +65,14 @@
<ng-template #BreederInstituteTemplate> <ng-template #BreederInstituteTemplate>
<figure *ngIf="germplasmGnpis.breeder && germplasmGnpis.breeder.institute && germplasmGnpis.breeder.institute.logo"> <gpds-card-row
<img label=""
[src]="IMAGES_INSTITUTION_URL + germplasmGnpis.breeder.institute.logo" [test]="germplasmGnpis.breeder && germplasmGnpis.breeder.institute && germplasmGnpis.breeder.institute.logo">
align="middle" /> <ng-template>
</figure> <img
[src]="IMAGES_INSTITUTION_URL + germplasmGnpis.breeder.institute.logo"/>
</ng-template>
</gpds-card-row>
<gpds-card-row <gpds-card-row
label="Code" label="Code"
...@@ -106,11 +113,14 @@ ...@@ -106,11 +113,14 @@
<ng-template #CollectorInstituteTemplate> <ng-template #CollectorInstituteTemplate>
<figure *ngIf="germplasmGnpis.collector && germplasmGnpis.collector.institute && germplasmGnpis.collector.institute.logo"> <gpds-card-row
<img label=""
[src]="IMAGES_INSTITUTION_URL + germplasmGnpis.collector.institute.logo" [test]="germplasmGnpis.collector && germplasmGnpis.collector.institute && germplasmGnpis.collector.institute.logo">
align="middle" /> <ng-template>
</figure> <img
[src]="IMAGES_INSTITUTION_URL + germplasmGnpis.collector.institute.logo"/>
</ng-template>
</gpds-card-row>
<gpds-card-row <gpds-card-row
label="Code" label="Code"
...@@ -142,24 +152,20 @@ ...@@ -142,24 +152,20 @@
</ng-template> </ng-template>
</gpds-card-row> </gpds-card-row>
</ng-template> </ng-template>
<!--Section for the image representing the germplasm and the details about this image--> <!--Section for the image representing the germplasm and the details about this image-->
<div class="col-auto field" *ngIf="germplasmGnpis.photo && germplasmGnpis.photo.thumbnailFileName"> <div class="col-auto field" *ngIf="germplasmGnpis.photo && germplasmGnpis.photo.thumbnailFileName">
<figure class="figure"> <a class="btn popovers" data-boundary="window" placement="right" [ngbPopover]="imageTemplate"
[popoverTitle]="germplasmGnpis.photo.photoName" container="body">
<img <img
[src]="IMAGES_ACCESSION_URL + germplasmGnpis.holdingGenbank.instituteCode + '/' + germplasmGnpis.photo.thumbnailFileName" [src]="IMAGES_ACCESSION_URL + germplasmGnpis.holdingGenbank.instituteCode + '/' + germplasmGnpis.photo.thumbnailFileName"
class="img-fluid"> class="img-fluid">
<figcaption class="figure-caption"> <figcaption class="figure-caption">
<a class="btn popovers" data-boundary="window" placement="right" [ngbPopover]="imageTemplate" Click to see more details
[popoverTitle]="germplasmGnpis.photo.photoName" container="body">
Click to see more details.
</a>
</figcaption> </figcaption>
</figure> </a>
<ng-template #imageTemplate> <ng-template #imageTemplate>
<div class="card ngb-popover-window "> <div class="card ngb-popover-window ">
...@@ -287,7 +293,7 @@ ...@@ -287,7 +293,7 @@
<gpds-card-row <gpds-card-row
label="Institution"> label="Institution">
<ng-template> <ng-template>
<a class="popovers" data-boundary="window" placement="top" <a class="popover-underline" data-boundary="window" placement="top"
[ngbPopover]="holdingInstituteTemplate" [ngbPopover]="holdingInstituteTemplate"
[popoverTitle]="germplasmGnpis.holdingInstitute.instituteName" [popoverTitle]="germplasmGnpis.holdingInstitute.instituteName"
container="body"> container="body">
...@@ -297,16 +303,19 @@ ...@@ -297,16 +303,19 @@
<gpds-card-row <gpds-card-row
label="Stock center name" label="Stock center name"
[test]="germplasmGnpis.holdingGenbank.instituteName"> [test]="germplasmGnpis.holdingGenbank.instituteName && germplasmGnpis.holdingGenbank.webSite">
<ng-template> <ng-template>
<ng-container *ngIf="germplasmGnpis.holdingGenbank.webSite"> <a [href]="germplasmGnpis.holdingGenbank.webSite">
<a [href]="germplasmGnpis.holdingGenbank.webSite">
{{ germplasmGnpis.holdingGenbank.instituteName }}
</a>
</ng-container>
<ng-container *ngIf="!germplasmGnpis.holdingGenbank.webSite">
{{ germplasmGnpis.holdingGenbank.instituteName }} {{ germplasmGnpis.holdingGenbank.instituteName }}
</ng-container> </a>
</ng-template>
</gpds-card-row>
<gpds-card-row
label="Stock center name"
[test]="germplasmGnpis.holdingGenbank.instituteName && !germplasmGnpis.holdingGenbank.webSite">
<ng-template>
{{ germplasmGnpis.holdingGenbank.instituteName }}
</ng-template> </ng-template>
</gpds-card-row> </gpds-card-row>
...@@ -462,11 +471,14 @@ ...@@ -462,11 +471,14 @@
<tr> <tr>
<ng-template #InstituteTemplate> <ng-template #InstituteTemplate>
<figure *ngIf="row.donorInstitute && row.donorInstitute.logo"> <gpds-card-row
<img label=""
[src]="IMAGES_INSTITUTION_URL + row.donorInstitute.logo" [test]="row.donorInstitute && row.donorInstitute.logo">
align="middle" /> <ng-template>
</figure> <img
[src]="IMAGES_INSTITUTION_URL + row.donorInstitute.logo"/>
</ng-template>
</gpds-card-row>
<gpds-card-row <gpds-card-row
label="Code" label="Code"
...@@ -540,11 +552,14 @@ ...@@ -540,11 +552,14 @@
<tr> <tr>
<ng-template #InstituteTemplate> <ng-template #InstituteTemplate>
<figure *ngIf="row.institute && row.institute.logo"> <gpds-card-row
<img label=""
[src]="IMAGES_INSTITUTION_URL + row.institute.logo" [test]="row.institute && row.institute.logo">
align="middle" /> <ng-template>
</figure> <img
[src]="IMAGES_INSTITUTION_URL + row.institute.logo"/>
</ng-template>
</gpds-card-row>
<gpds-card-row <gpds-card-row
label="Code" label="Code"
......
@import "theme"; @import "theme";
@import '../../styles.scss'; @import '../../styles.scss';
...@@ -6,14 +6,7 @@ import { BrapiService } from '../brapi.service'; ...@@ -6,14 +6,7 @@ import { BrapiService } from '../brapi.service';
import { ActivatedRoute, convertToParamMap } from '@angular/router'; import { ActivatedRoute, convertToParamMap } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing'; import { RouterTestingModule } from '@angular/router/testing';
import { of } from 'rxjs'; import { of } from 'rxjs';
import {
BrapiDescriptor,
BrapiDonor,
BrapiGermplasmAttributes,
BrapiGermplasmPedigree,
BrapiSibling
} from '../models/brapi.germplasm.model';
import { Germplasm, GermplasmData, GermplasmResult, GermplasmSet, Institute, Origin, Site } from '../models/gnpis.germplasm.model';
import { NgbPopoverModule } from '@ng-bootstrap/ng-bootstrap'; import { NgbPopoverModule } from '@ng-bootstrap/ng-bootstrap';
import { MomentModule } from 'ngx-moment'; import { MomentModule } from 'ngx-moment';
import { LoadingSpinnerComponent } from '../loading-spinner/loading-spinner.component'; import { LoadingSpinnerComponent } from '../loading-spinner/loading-spinner.component';
...@@ -21,6 +14,13 @@ import { CardSectionComponent } from '../card-section/card-section.component'; ...@@ -21,6 +14,13 @@ import { CardSectionComponent } from '../card-section/card-section.component';
import { CardRowComponent } from '../card-row/card-row.component'; import { CardRowComponent } from '../card-row/card-row.component';
import { CardTableComponent } from '../card-table/card-table.component'; import { CardTableComponent } from '../card-table/card-table.component';
import { MapComponent } from '../map/map.component'; import { MapComponent } from '../map/map.component';
import {
BrapiGermplasmAttributes,
BrapiGermplasmPedigree,
BrapiResult,
BrapiSibling
} from "../models/brapi.model";
import {Donor, Germplasm, GermplasmInstitute, GermplasmSet, Institute, Site} from "../models/gnpis.model";
import { MockComponent } from 'ng-mocks'; import { MockComponent } from 'ng-mocks';
import { XrefsComponent } from '../xrefs/xrefs.component'; import { XrefsComponent } from '../xrefs/xrefs.component';
...@@ -59,7 +59,7 @@ describe('GermplasmCardComponent', () => { ...@@ -59,7 +59,7 @@ describe('GermplasmCardComponent', () => {
] ]
); );
const brapiSite: Site = { const gnpisSite: Site = {
latitude: null, latitude: null,
longitude: null, longitude: null,
siteId: null, siteId: null,
...@@ -72,13 +72,9 @@ describe('GermplasmCardComponent', () => { ...@@ -72,13 +72,9 @@ describe('GermplasmCardComponent', () => {
defaultDisplayName: 'frere1' defaultDisplayName: 'frere1'
}; };
const brapiDescriptor: BrapiDescriptor = {
name: 'caracteristique1',
pui: '12',
value: '32'
};
const brapiGermplasmPedigree: GermplasmResult<BrapiGermplasmPedigree> = { const brapiGermplasmPedigree: BrapiResult<BrapiGermplasmPedigree> = {
metadata: null,
result: { result: {
germplasmDbId: '12', germplasmDbId: '12',
defaultDisplayName: '12', defaultDisplayName: '12',
...@@ -104,7 +100,7 @@ describe('GermplasmCardComponent', () => { ...@@ -104,7 +100,7 @@ describe('GermplasmCardComponent', () => {
} }
};*/ };*/
const brapiInstitute: Institute = { const gnpisInstitute: Institute = {
instituteName: 'urgi', instituteName: 'urgi',
instituteCode: 'inra', instituteCode: 'inra',
acronym: 'urgi', acronym: 'urgi',
...@@ -115,9 +111,8 @@ describe('GermplasmCardComponent', () => { ...@@ -115,9 +111,8 @@ describe('GermplasmCardComponent', () => {
logo: null logo: null
}; };
const brapiOrigin: Origin = { ... brapiInstitute, const gnpisGermplasmInstitute: GermplasmInstitute = { ... gnpisInstitute,
institute: brapiInstitute, institute: gnpisInstitute,
germplasmPUI: '12',