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 {
BrapiContacts,
BrapiGermplasm,
BrapiContacts, BrapiData, BrapiDonor,
BrapiGermplasm, BrapiGermplasmAttributes, BrapiGermplasmPedigree, BrapiGermplasmProgeny,
BrapiLocation,
BrapiObservationVariable,
BrapiResult,
BrapiResults,
BrapiStudy,
BrapiResult, BrapiResults, BrapiSibling,
BrapiStudy, BrapiTaxonIds,
BrapiTrial
} from './models/brapi.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 { TestBed } from '@angular/core/testing';
import {Germplasm, GermplasmInstitute, GermplasmSet, Institute, Site} from "./models/gnpis.model";
import Result = jasmine.Result;
describe('BrapiService', () => {
......@@ -111,17 +103,49 @@ describe('BrapiService', () => {
data: [{
germplasmDbId: 'g1',
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',
genus: 'Populus',
species: 'x generosa',
subtaxa: ''
subtaxa: '',
speciesAuthority: null,
subtaxaAuthority: null,
donors: null,
acquisitionDate: null
}, {
germplasmDbId: 'g2',
accessionNumber: 'G_20',
germplasmName: 'germplam2',
genus: 'Triticum',
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', () => {
defaultDisplayName: 'frere1'
};
const brapiDescriptor: BrapiDescriptor = {
name: 'caracteristique1',
pui: '12',
value: '32'
};
const brapiGermplasmPedigree: GermplasmResult<BrapiGermplasmPedigree> = {
const brapiGermplasmPedigree: BrapiResult<BrapiGermplasmPedigree> = {
result: {
germplasmDbId: 'test',
defaultDisplayName: '12',
......@@ -172,7 +190,7 @@ describe('BrapiService', () => {
}
};
const brapiGermplasmProgeny: GermplasmResult<BrapiGermplasmProgeny> = {
const brapiGermplasmProgeny: BrapiResult<BrapiGermplasmProgeny> = {
result: {
germplasmDbId: 'test',
defaultDisplayName: '11',
......@@ -191,7 +209,7 @@ describe('BrapiService', () => {
address: '12',
logo: null
};
const origin: Origin = { ... institute,
const origin: GermplasmInstitute = { ... institute,
institute: institute,
germplasmPUI: '12',
accessionNumber: '12',
......@@ -219,7 +237,7 @@ describe('BrapiService', () => {
type: 'plan'
};
const brapiGermplasmAttributes: GermplasmResult<GermplasmData<BrapiGermplasmAttributes[]>> = {
const brapiGermplasmAttributes: BrapiResult<BrapiData<BrapiGermplasmAttributes[]>> = {
result: {
data: [{
attributeName: 'longueur',
......@@ -229,8 +247,6 @@ describe('BrapiService', () => {
};
const germplasmTest: Germplasm = {
url: 'www.cirad.fr',
source: 'cirad',
germplasmDbId: 'test',
defaultDisplayName: 'test',
accessionNumber: 'test',
......@@ -264,7 +280,6 @@ describe('BrapiService', () => {
holdingGenbank: institute,
presenceStatus: null,
children: null,
descriptors: [brapiDescriptor],
originSite: null,
collectingSite: null,
evaluationSites: null,
......@@ -365,7 +380,7 @@ describe('BrapiService', () => {
it('should fetch the pedigree', () => {
let fetchedGermplasmPedigree: GermplasmResult<BrapiGermplasmPedigree>;
let fetchedGermplasmPedigree: BrapiResult<BrapiGermplasmPedigree>;
const germplasmDbId: string = brapiGermplasmPedigree.result.germplasmDbId;
brapiService.germplasmPedigree(germplasmDbId).subscribe(response => {
fetchedGermplasmPedigree = response;
......@@ -393,7 +408,7 @@ describe('BrapiService', () => {
it('should fetch the germplasm attributes', () => {
let fetchedGermplasmAttributes: GermplasmResult<GermplasmData<BrapiGermplasmAttributes[]>>;
let fetchedGermplasmAttributes: BrapiResult<BrapiData<BrapiGermplasmAttributes[]>>;
const germplasmDbId: string = germplasmTest.germplasmDbId;
brapiService.germplasmAttributes(germplasmDbId).subscribe(response => {
fetchedGermplasmAttributes = response;
......
......@@ -3,7 +3,7 @@ import { Observable } from 'rxjs';
import { HttpClient } from '@angular/common/http';
import { Germplasm, GermplasmData, GermplasmResult } from './models/gnpis.germplasm.model';
import {
BrapiGermplasm,
BrapiGermplasm, BrapiGermplasmAttributes,
BrapiLocation,
BrapiObservationVariable,
BrapiResult,
......@@ -11,7 +11,7 @@ import {
BrapiStudy,
BrapiTrial
} 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';
......
......@@ -2,29 +2,28 @@
<ng-container *ngIf="germplasmGnpis">
<h3 class="mb-4">
<figure *ngIf="germplasmGnpis.holdingGenbank && germplasmGnpis.holdingGenbank.instituteName">
<img
[src]="IMAGES_BRC_URL"
align="right" />
</figure>
<img *ngIf="germplasmGnpis.holdingGenbank && germplasmGnpis.holdingGenbank.instituteName"
[src]="IMAGES_BRC_URL"
align="right"/>
Germplasm: {{ germplasmGnpis.germplasmName }}
</h3>
<!-- 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">
<!--Templates for gerplasm card-->
<ng-template #holdingInstituteTemplate >
<ng-template #holdingInstituteTemplate>
<figure *ngIf="germplasmGnpis.holdingInstitute && germplasmGnpis.holdingInstitute.logo">
<img
[src]="IMAGES_INSTITUTION_URL + germplasmGnpis.holdingInstitute.logo"
align="middle" />
</figure>
<gpds-card-row
label=""
[test]="germplasmGnpis.holdingInstitute && germplasmGnpis.holdingInstitute.logo">
<ng-template>
<img
[src]="IMAGES_INSTITUTION_URL + germplasmGnpis.holdingInstitute.logo"/>
</ng-template>
</gpds-card-row>
<gpds-card-row
label="Code"
......@@ -53,7 +52,12 @@
<gpds-card-row
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>
</ng-template>
......@@ -61,11 +65,14 @@
<ng-template #BreederInstituteTemplate>
<figure *ngIf="germplasmGnpis.breeder && germplasmGnpis.breeder.institute && germplasmGnpis.breeder.institute.logo">
<img
[src]="IMAGES_INSTITUTION_URL + germplasmGnpis.breeder.institute.logo"
align="middle" />
</figure>
<gpds-card-row
label=""
[test]="germplasmGnpis.breeder && germplasmGnpis.breeder.institute && germplasmGnpis.breeder.institute.logo">
<ng-template>
<img
[src]="IMAGES_INSTITUTION_URL + germplasmGnpis.breeder.institute.logo"/>
</ng-template>
</gpds-card-row>
<gpds-card-row
label="Code"
......@@ -106,11 +113,14 @@
<ng-template #CollectorInstituteTemplate>
<figure *ngIf="germplasmGnpis.collector && germplasmGnpis.collector.institute && germplasmGnpis.collector.institute.logo">
<img
[src]="IMAGES_INSTITUTION_URL + germplasmGnpis.collector.institute.logo"
align="middle" />
</figure>
<gpds-card-row
label=""
[test]="germplasmGnpis.collector && germplasmGnpis.collector.institute && germplasmGnpis.collector.institute.logo">
<ng-template>
<img
[src]="IMAGES_INSTITUTION_URL + germplasmGnpis.collector.institute.logo"/>
</ng-template>
</gpds-card-row>
<gpds-card-row
label="Code"
......@@ -142,24 +152,20 @@
</ng-template>
</gpds-card-row>
</ng-template>
<!--Section for the image representing the germplasm and the details about this image-->
<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
[src]="IMAGES_ACCESSION_URL + germplasmGnpis.holdingGenbank.instituteCode + '/' + germplasmGnpis.photo.thumbnailFileName"
class="img-fluid">
<figcaption class="figure-caption">
<a class="btn popovers" data-boundary="window" placement="right" [ngbPopover]="imageTemplate"
[popoverTitle]="germplasmGnpis.photo.photoName" container="body">
Click to see more details.
</a>
Click to see more details
</figcaption>
</figure>
</a>
<ng-template #imageTemplate>
<div class="card ngb-popover-window ">
......@@ -287,7 +293,7 @@
<gpds-card-row
label="Institution">
<ng-template>
<a class="popovers" data-boundary="window" placement="top"
<a class="popover-underline" data-boundary="window" placement="top"
[ngbPopover]="holdingInstituteTemplate"
[popoverTitle]="germplasmGnpis.holdingInstitute.instituteName"
container="body">
......@@ -297,16 +303,19 @@
<gpds-card-row
label="Stock center name"
[test]="germplasmGnpis.holdingGenbank.instituteName">
[test]="germplasmGnpis.holdingGenbank.instituteName && germplasmGnpis.holdingGenbank.webSite">
<ng-template>
<ng-container *ngIf="germplasmGnpis.holdingGenbank.webSite">
<a [href]="germplasmGnpis.holdingGenbank.webSite">
{{ germplasmGnpis.holdingGenbank.instituteName }}
</a>
</ng-container>
<ng-container *ngIf="!germplasmGnpis.holdingGenbank.webSite">
<a [href]="germplasmGnpis.holdingGenbank.webSite">
{{ 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>
</gpds-card-row>
......@@ -462,11 +471,14 @@
<tr>
<ng-template #InstituteTemplate>
<figure *ngIf="row.donorInstitute && row.donorInstitute.logo">
<img
[src]="IMAGES_INSTITUTION_URL + row.donorInstitute.logo"
align="middle" />
</figure>
<gpds-card-row
label=""
[test]="row.donorInstitute && row.donorInstitute.logo">
<ng-template>
<img
[src]="IMAGES_INSTITUTION_URL + row.donorInstitute.logo"/>
</ng-template>
</gpds-card-row>
<gpds-card-row
label="Code"
......@@ -540,11 +552,14 @@
<tr>
<ng-template #InstituteTemplate>
<figure *ngIf="row.institute && row.institute.logo">
<img
[src]="IMAGES_INSTITUTION_URL + row.institute.logo"
align="middle" />
</figure>
<gpds-card-row
label=""
[test]="row.institute && row.institute.logo">
<ng-template>
<img
[src]="IMAGES_INSTITUTION_URL + row.institute.logo"/>
</ng-template>
</gpds-card-row>
<gpds-card-row
label="Code"
......
......@@ -6,14 +6,7 @@ import { BrapiService } from '../brapi.service';
import { ActivatedRoute, convertToParamMap } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
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 { MomentModule } from 'ngx-moment';
import { LoadingSpinnerComponent } from '../loading-spinner/loading-spinner.component';
......@@ -21,6 +14,13 @@ import { CardSectionComponent } from '../card-section/card-section.component';
import { CardRowComponent } from '../card-row/card-row.component';
import { CardTableComponent } from '../card-table/card-table.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 { XrefsComponent } from '../xrefs/xrefs.component';
......@@ -59,7 +59,7 @@ describe('GermplasmCardComponent', () => {
]
);
const brapiSite: Site = {
const gnpisSite: Site = {
latitude: null,
longitude: null,
siteId: null,
......@@ -72,13 +72,9 @@ describe('GermplasmCardComponent', () => {
defaultDisplayName: 'frere1'
};
const brapiDescriptor: BrapiDescriptor = {
name: 'caracteristique1',
pui: '12',
value: '32'
};
const brapiGermplasmPedigree: GermplasmResult<BrapiGermplasmPedigree> = {
const brapiGermplasmPedigree: BrapiResult<BrapiGermplasmPedigree> = {
metadata: null,
result: {
germplasmDbId: '12',
defaultDisplayName: '12',
......@@ -104,7 +100,7 @@ describe('GermplasmCardComponent', () => {
}
};*/
const brapiInstitute: Institute = {
const gnpisInstitute: Institute = {
instituteName: 'urgi',
instituteCode: 'inra',
acronym: 'urgi',
......@@ -115,9 +111,8 @@ describe('GermplasmCardComponent', () => {
logo: null
};
const brapiOrigin: Origin = { ... brapiInstitute,
institute: brapiInstitute,
germplasmPUI: '12',
const gnpisGermplasmInstitute: GermplasmInstitute = { ... gnpisInstitute,
institute: gnpisInstitute,
accessionNumber: '12',
accessionCreationDate: '1993',
materialType: 'feuille',
......@@ -127,15 +122,15 @@ describe('GermplasmCardComponent', () => {
distributionStatus: null
};
const brapiDonor: BrapiDonor = {
donorInstitute: brapiInstitute,
const gnpisDonor: Donor = {
donorInstitute: gnpisInstitute,
donorGermplasmPUI: '12',
donorAccessionNumber: '12',
donorInstituteCode: 'urgi',
donationDate: null
};
const germplasmSet: GermplasmSet = {
const gnpisGermplasmSet: GermplasmSet = {
germplasmCount: 12,
germplasmRef: null,
id: 12,
......@@ -143,18 +138,21 @@ describe('GermplasmCardComponent', () => {
type: 'plan'
};
const brapiGermplasmAttributes: GermplasmResult<GermplasmData<BrapiGermplasmAttributes[]>> = {
const brapiGermplasmAttributes: BrapiResult<BrapiGermplasmAttributes> = {
metadata: null,
result: {
germplasmDbId: '12',
data: [{
attributeName: 'longueur',
value: '30'
value: '30',
attributeDbId: '1',
attributeCode: 'longeur',
determinedDate: 'today'
}]
}
};
const germplasmTest: Germplasm = {
url: 'www.cirad.fr',
source: 'cirad',
germplasmDbId: 'test',
defaultDisplayName: 'test',
accessionNumber: 'test',
......@@ -175,7 +173,7 @@ describe('GermplasmCardComponent', () => {
speciesAuthority: 'L',
subtaxa: null,
subtaxaAuthority: null,
donors: [brapiDonor],
donors: [gnpisDonor],
acquisitionDate: null,
genusSpecies: null,
genusSpeciesSubtaxa: null,
......@@ -184,20 +182,19 @@ describe('GermplasmCardComponent', () => {
geneticNature: null,
comment: null,
photo: null,
holdingInstitute: brapiInstitute,
holdingGenbank: brapiInstitute,
holdingInstitute: gnpisInstitute,
holdingGenbank: gnpisInstitute,
presenceStatus: null,
children: null,
descriptors: [brapiDescriptor],
originSite: null,
collectingSite: null,
evaluationSites: null,
collector: brapiOrigin,
breeder: brapiOrigin,
distributors: [brapiOrigin],
panel: [germplasmSet],
collection: [germplasmSet],
population: [germplasmSet]
collector: gnpisGermplasmInstitute,
breeder: gnpisGermplasmInstitute,
distributors: [gnpisGermplasmInstitute],
panel: [gnpisGermplasmSet],
collection: [gnpisGermplasmSet],
population: [gnpisGermplasmSet]
};
beforeEach(async(() => {
......
......@@ -2,15 +2,15 @@ import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
import { BrapiService } from '../brapi.service';
import { GnpisService } from '../gnpis.service';
import { Germplasm, GermplasmProgeny, Site } from '../models/gnpis.germplasm.model';
import { BrapiGermplasmAttributes, BrapiGermplasmPedigree } from '../models/brapi.germplasm.model';
import { BrapiLocation } from '../models/brapi.model';
import { Germplasm, Children, Site } from '../models/gnpis.germplasm.model';
import { BrapiGermplasmPedigree } from '../models/brapi.germplasm.model';
import { BrapiGermplasmAttributes, BrapiLocation } from '../models/brapi.model';
@Component({
@Component( {
selector: 'gpds-germplasm-card',
templateUrl: './germplasm-card.component.html',
styleUrls: ['./germplasm-card.component.scss']
})
} )
export class GermplasmCardComponent implements OnInit {
......@@ -31,7 +31,7 @@ export class GermplasmCardComponent implements OnInit {
germplasmGnpis: Germplasm;
germplasmPedigree: BrapiGermplasmPedigree;
germplasmProgeny: GermplasmProgeny[];
germplasmProgeny: Children[];
germplasmAttributes: BrapiGermplasmAttributes[];
germplasmLocations: BrapiLocation[] = [];
germplasmId: string;
......
import { Germplasm, GermplasmSet, Institute, Origin, Site } from './models/gnpis.germplasm.model';
import { Germplasm, GermplasmSet, Institute, GermplasmInstitute, Site } from './models/gnpis.germplasm.model';
import { BASE_URL, BASE_URL_GERMPLASM, GnpisService } from './gnpis.service';
import { BrapiMetaData, BrapiResults } from './models/brapi.model';
import {BrapiDonor, BrapiMetaData, BrapiResults} from './models/brapi.model';
import { DataDiscoveryCriteria, DataDiscoverySource } from './models/data-discovery.model';
import { BrapiDescriptor, BrapiDonor } from './models/brapi.germplasm.model';
import { BrapiDescriptor} from './models/brapi.germplasm.model';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { TestBed } from '@angular/core/testing';
......@@ -51,7 +51,7 @@ describe('GnpisService', () => {
logo: null
};
const brapiOrigin: Origin = { ...brapiInstitute,
const brapiOrigin: GermplasmInstitute = { ...brapiInstitute,
institute: brapiInstitute,
germplasmPUI: '12',
accessionNumber: '12',
......
<div id="map" class="rounded">
</div>
<div id="maplegend">
<div *ngIf="curatedLocationList.length > 0" id="maplegend">
<img src="assets/gpds/images/marker-icon-red.png" id="red"/>
<label for="red">Origin site</label>
<img src="assets/gpds/images/marker-icon-blue.png" id="blue"/>
......
......@@ -11,17 +11,20 @@ import { BrapiLocation } from '../models/brapi.model';
export class MapComponent implements OnInit {