Commit e37b3d7e authored by Guillaume Cornut's avatar Guillaume Cornut
Browse files

Merge branch 'feat/xrefs' into 'master'

Xref part, Fix GNP-5842.

Closes GNP-5842 and GNP-5482

See merge request urgi-is/gpds!15
parents 60e11820 47fe20d1
...@@ -6577,6 +6577,11 @@ ...@@ -6577,6 +6577,11 @@
"integrity": "sha512-MFh0d/Wa7vkKO3Y3LlacqAEeHK0mckVqzDieUKTT+KGxi+zIpeVsFxymkIiRpbpDziHc290Xr9A1O4Om7otoRA==", "integrity": "sha512-MFh0d/Wa7vkKO3Y3LlacqAEeHK0mckVqzDieUKTT+KGxi+zIpeVsFxymkIiRpbpDziHc290Xr9A1O4Om7otoRA==",
"dev": true "dev": true
}, },
"ng-mocks": {
"version": "7.6.0",
"resolved": "https://registry.npmjs.org/ng-mocks/-/ng-mocks-7.6.0.tgz",
"integrity": "sha512-Zorpd5I6KmvTtiYwcjymzCaortznMZr5CRB737XaNheITTUb2rVLUoEBk1dwQE3b/Cp5sByuS85fzwJRvjEXKQ=="
},
"ngx-moment": { "ngx-moment": {
"version": "3.3.0", "version": "3.3.0",
"resolved": "https://registry.npmjs.org/ngx-moment/-/ngx-moment-3.3.0.tgz", "resolved": "https://registry.npmjs.org/ngx-moment/-/ngx-moment-3.3.0.tgz",
......
...@@ -21,15 +21,16 @@ ...@@ -21,15 +21,16 @@
"@angular/platform-browser": "7.2.7", "@angular/platform-browser": "7.2.7",
"@angular/platform-browser-dynamic": "7.2.7", "@angular/platform-browser-dynamic": "7.2.7",
"@angular/router": "7.2.7", "@angular/router": "7.2.7",
"@ng-bootstrap/ng-bootstrap": "4.0.0",
"@types/leaflet": "1.2.14", "@types/leaflet": "1.2.14",
"@types/leaflet.markercluster": "1.0.3", "@types/leaflet.markercluster": "1.0.3",
"@ng-bootstrap/ng-bootstrap": "4.0.0",
"bootstrap": "4.1.3", "bootstrap": "4.1.3",
"core-js": "2.5.7", "core-js": "2.5.7",
"font-awesome": "4.7.0", "font-awesome": "4.7.0",
"moment": "2.24.0",
"leaflet": "1.3.4", "leaflet": "1.3.4",
"leaflet.markercluster": "1.4.1", "leaflet.markercluster": "1.4.1",
"moment": "2.24.0",
"ng-mocks": "^7.6.0",
"ngx-moment": "3.3.0", "ngx-moment": "3.3.0",
"popper.js": "1.14.6", "popper.js": "1.14.6",
"rxjs": "6.4.0", "rxjs": "6.4.0",
......
...@@ -23,6 +23,8 @@ import { CardSectionComponent } from './card-section/card-section.component'; ...@@ -23,6 +23,8 @@ import { CardSectionComponent } from './card-section/card-section.component';
import { LoadingSpinnerComponent } from './loading-spinner/loading-spinner.component'; import { LoadingSpinnerComponent } from './loading-spinner/loading-spinner.component';
import { CardTableComponent } from './card-table/card-table.component'; import { CardTableComponent } from './card-table/card-table.component';
import { MomentModule } from 'ngx-moment'; import { MomentModule } from 'ngx-moment';
import { XrefsComponent } from './xrefs/xrefs.component';
@NgModule({ @NgModule({
declarations: [ declarations: [
...@@ -43,6 +45,7 @@ import { MomentModule } from 'ngx-moment'; ...@@ -43,6 +45,7 @@ import { MomentModule } from 'ngx-moment';
CardSectionComponent, CardSectionComponent,
LoadingSpinnerComponent, LoadingSpinnerComponent,
CardTableComponent, CardTableComponent,
XrefsComponent
], ],
imports: [ imports: [
BrowserModule, BrowserModule,
......
...@@ -660,4 +660,9 @@ ...@@ -660,4 +660,9 @@
</ng-container> </ng-container>
</div> </div>
</div> </div>
<!--XRefs part -->
<gpds-xrefs [xrefId]="germplasmGnpis.germplasmPUI"></gpds-xrefs>
</ng-container> </ng-container>
...@@ -19,6 +19,9 @@ import { Germplasm, GermplasmData, GermplasmResult, Institute, Origin, Site } fr ...@@ -19,6 +19,9 @@ import { Germplasm, GermplasmData, GermplasmResult, Institute, Origin, Site } fr
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';
import { MockComponent } from 'ng-mocks';
import { XrefsComponent } from '../xrefs/xrefs.component';
describe('GermplasmCardComponent', () => { describe('GermplasmCardComponent', () => {
...@@ -74,7 +77,7 @@ describe('GermplasmCardComponent', () => { ...@@ -74,7 +77,7 @@ describe('GermplasmCardComponent', () => {
}; };
const brapiGermplasmPedigree: GermplasmResult<BrapiGermplasmPedigree> = { const brapiGermplasmPedigree: GermplasmResult<BrapiGermplasmPedigree> = {
result : { result: {
germplasmDbId: '12', germplasmDbId: '12',
defaultDisplayName: '12', defaultDisplayName: '12',
pedigree: null, pedigree: null,
...@@ -139,7 +142,7 @@ describe('GermplasmCardComponent', () => { ...@@ -139,7 +142,7 @@ describe('GermplasmCardComponent', () => {
const brapiGermplasmAttributes: GermplasmResult<GermplasmData<BrapiGermplasmAttributes[]>> = { const brapiGermplasmAttributes: GermplasmResult<GermplasmData<BrapiGermplasmAttributes[]>> = {
result: { result: {
data: [ { data: [{
attributeName: 'longueur', attributeName: 'longueur',
value: '30' value: '30'
}] }]
...@@ -202,13 +205,14 @@ describe('GermplasmCardComponent', () => { ...@@ -202,13 +205,14 @@ describe('GermplasmCardComponent', () => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [RouterTestingModule, NgbPopoverModule, MomentModule], imports: [RouterTestingModule, NgbPopoverModule, MomentModule],
declarations: [ declarations: [
GermplasmCardComponent, LoadingSpinnerComponent GermplasmCardComponent, LoadingSpinnerComponent, MockComponent(XrefsComponent)
], ],
providers: [ providers: [
// { provide: ActivatedRoute, useValue: activatedRoute }, // { provide: ActivatedRoute, useValue: activatedRoute },
{ provide: BrapiService, useValue: brapiService }, { provide: BrapiService, useValue: brapiService },
{ provide: GnpisService, useValue: gnpisService }, { provide: GnpisService, useValue: gnpisService },
{ provide: ActivatedRoute, {
provide: ActivatedRoute,
useValue: { useValue: {
snapshot: { snapshot: {
queryParams: convertToParamMap({ queryParams: convertToParamMap({
......
...@@ -5,6 +5,7 @@ import { Germplasm } from './models/gnpis.germplasm.model'; ...@@ -5,6 +5,7 @@ import { Germplasm } from './models/gnpis.germplasm.model';
import { DataDiscoveryCriteria, DataDiscoveryFacet, DataDiscoveryResults, DataDiscoverySource } from './models/data-discovery.model'; import { DataDiscoveryCriteria, DataDiscoveryFacet, DataDiscoveryResults, DataDiscoverySource } from './models/data-discovery.model';
import { BrapiResults } from './models/brapi.model'; import { BrapiResults } from './models/brapi.model';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { XrefResponse } from './models/xref.model';
export const BASE_URL = 'gnpis/v1/datadiscovery'; export const BASE_URL = 'gnpis/v1/datadiscovery';
...@@ -106,4 +107,9 @@ export class GnpisService { ...@@ -106,4 +107,9 @@ export class GnpisService {
getSource(sourceURI: string): Observable<DataDiscoverySource> { getSource(sourceURI: string): Observable<DataDiscoverySource> {
return this.sourceByURI$.pipe(map(sourceByURI => sourceByURI[sourceURI])); return this.sourceByURI$.pipe(map(sourceByURI => sourceByURI[sourceURI]));
} }
xref(xrefId: string): Observable<XrefResponse> {
return this.http.get<XrefResponse>(`gnpis/v1/xref/documentbyfulltextid?linkedRessourcesID=${xrefId}`);
}
} }
export interface XrefModel {
url: string;
description: string;
database_name: string;
entry_type: string;
db_version: string;
}
export type XrefResponse = XrefModel[];
...@@ -3,10 +3,14 @@ ...@@ -3,10 +3,14 @@
<ng-container *ngIf="location"> <ng-container *ngIf="location">
<h3> <h3>
Site: {{ location.locationName }} Site: {{ location.locationName }}
</h3> </h3>
<gpds-map [locations]="[location]" *ngIf="location && location.latitude && location.longitude"></gpds-map> <gpds-map [locations]="[location]" *ngIf="location && location.latitude && location.longitude"></gpds-map>
<gpds-card-section <gpds-card-section
header="Details"> header="Details">
<ng-template> <ng-template>
...@@ -75,4 +79,8 @@ ...@@ -75,4 +79,8 @@
</gpds-card-table> </gpds-card-table>
</ng-template> </ng-template>
</gpds-card-section> </gpds-card-section>
<!--XRefs part -->
<gpds-xrefs [xrefId]="location.locationDbId"></gpds-xrefs>
</ng-container> </ng-container>
...@@ -10,6 +10,9 @@ import { CardRowComponent } from '../card-row/card-row.component'; ...@@ -10,6 +10,9 @@ import { CardRowComponent } from '../card-row/card-row.component';
import { LoadingSpinnerComponent } from '../loading-spinner/loading-spinner.component'; import { LoadingSpinnerComponent } from '../loading-spinner/loading-spinner.component';
import { CardTableComponent } from '../card-table/card-table.component'; import { CardTableComponent } from '../card-table/card-table.component';
import { CardSectionComponent } from '../card-section/card-section.component'; import { CardSectionComponent } from '../card-section/card-section.component';
import { MockComponent } from 'ng-mocks';
import { XrefsComponent } from '../xrefs/xrefs.component';
describe('SiteCardComponent', () => { describe('SiteCardComponent', () => {
const brapiService = jasmine.createSpyObj( const brapiService = jasmine.createSpyObj(
...@@ -48,7 +51,8 @@ describe('SiteCardComponent', () => { ...@@ -48,7 +51,8 @@ describe('SiteCardComponent', () => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [ declarations: [
SiteCardComponent, MapComponent, LoadingSpinnerComponent, SiteCardComponent, MapComponent, LoadingSpinnerComponent,
CardRowComponent, CardSectionComponent, CardTableComponent CardRowComponent, CardSectionComponent, CardTableComponent,
MockComponent(XrefsComponent)
], ],
providers: [ providers: [
{ provide: BrapiService, useValue: brapiService }, { provide: BrapiService, useValue: brapiService },
......
...@@ -15,6 +15,7 @@ export class SiteCardComponent implements OnInit { ...@@ -15,6 +15,7 @@ export class SiteCardComponent implements OnInit {
additionalInfos: KeyValueObject[]; additionalInfos: KeyValueObject[];
loading = true; loading = true;
constructor(private brapiService: BrapiService, private route: ActivatedRoute) { constructor(private brapiService: BrapiService, private route: ActivatedRoute) {
} }
...@@ -22,11 +23,9 @@ export class SiteCardComponent implements OnInit { ...@@ -22,11 +23,9 @@ export class SiteCardComponent implements OnInit {
this.route.paramMap.subscribe(paramMap => { this.route.paramMap.subscribe(paramMap => {
// initialize site from location ID // initialize site from location ID
const locationId = paramMap.get('id'); const locationId = paramMap.get('id');
this.brapiService.location(locationId).subscribe( this.brapiService.location(locationId).subscribe(
response => { response => {
this.location = response.result; this.location = response.result;
this.additionalInfos = []; this.additionalInfos = [];
if (this.location.additionalInfo) { if (this.location.additionalInfo) {
this.additionalInfos = KeyValueObject.fromObject(this.location.additionalInfo); this.additionalInfos = KeyValueObject.fromObject(this.location.additionalInfo);
......
...@@ -254,5 +254,7 @@ ...@@ -254,5 +254,7 @@
</ng-template> </ng-template>
</gpds-card-section> </gpds-card-section>
</ng-container>
<!--XRefs part -->
<gpds-xrefs [xrefId]="study.studyDbId"></gpds-xrefs>
</ng-container>
...@@ -23,6 +23,9 @@ import { CardSectionComponent } from '../card-section/card-section.component'; ...@@ -23,6 +23,9 @@ 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 { LoadingSpinnerComponent } from '../loading-spinner/loading-spinner.component'; import { LoadingSpinnerComponent } from '../loading-spinner/loading-spinner.component';
import { CardTableComponent } from '../card-table/card-table.component'; import { CardTableComponent } from '../card-table/card-table.component';
import { MockComponent } from 'ng-mocks';
import { XrefsComponent } from '../xrefs/xrefs.component';
describe('StudyCardComponent', () => { describe('StudyCardComponent', () => {
beforeEach(() => jasmine.addMatchers(speculoosMatchers)); beforeEach(() => jasmine.addMatchers(speculoosMatchers));
...@@ -204,7 +207,7 @@ describe('StudyCardComponent', () => { ...@@ -204,7 +207,7 @@ describe('StudyCardComponent', () => {
imports: [RouterTestingModule], imports: [RouterTestingModule],
declarations: [ declarations: [
StudyCardComponent, MapComponent, CardSectionComponent, StudyCardComponent, MapComponent, CardSectionComponent,
CardRowComponent, LoadingSpinnerComponent, CardTableComponent CardRowComponent, LoadingSpinnerComponent, CardTableComponent, MockComponent(XrefsComponent)
], ],
providers: [ providers: [
{ provide: ActivatedRoute, useValue: activatedRoute }, { provide: ActivatedRoute, useValue: activatedRoute },
......
<gpds-card-section *ngIf="xrefs.length > 0"
header="Cross References">
<ng-template>
<gpds-card-table
[headers]="[
'Name',
'Source',
'Type',
'Description'
]"
[rows]=xrefs>
<ng-template let-crossRef>
<tr>
<td><a [href]="crossRef.url">{{ crossRef.db_version }}</a></td>
<td>{{ crossRef.database_name }}</td>
<td>{{ crossRef.entry_type }}</td>
<td>{{ crossRef.description | slice:0:120 }}...</td>
</tr>
</ng-template>
</gpds-card-table>
</ng-template>
</gpds-card-section>
import { async, TestBed } from '@angular/core/testing';
import { XrefsComponent } from './xrefs.component';
import { ComponentTester, speculoosMatchers } from 'ngx-speculoos';
import { XrefModel } from '../models/xref.model';
import { of } from 'rxjs';
import { GnpisService } from '../gnpis.service';
import { CardSectionComponent } from '../card-section/card-section.component';
import { CardTableComponent } from '../card-table/card-table.component';
describe('XrefsComponent', () => {
beforeEach(() => jasmine.addMatchers(speculoosMatchers));
class XrefsComponentTester extends ComponentTester<XrefsComponent> {
constructor() {
super(XrefsComponent);
}
get cardHeader() {
return this.element('div.card-header');
}
get columns() {
return this.elements('td');
}
}
const gnpisService = jasmine.createSpyObj(
'GnpisService', [
'xref'
]
);
const xref: XrefModel[] = [{
url: 'https://urgi.versailles.inra.fr/association/association/viewer.do#results/analysisIds=1808038',
description: 'Col-Fa-b*_MLM+Q+K is a GWASd anté paneCol-Fa-b*_MLM+Q+K is aGAS anlysis involving CC_Qualité' +
'djs dsqdsq djsqpodsjqodsqdsqkpdqpdWOLOLOLOOOOOOOsqpkdsqkdsqkdsqdsdsqdsqdsqddsqffjùsodfusjùfsfsd',
database_name: 'GnpIS',
entry_type: 'GWAS analysis',
db_version: 'GWAS_ANALYSIS_1808038_1'
}];
const xrefBlank: XrefModel[] = [];
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
XrefsComponent, CardSectionComponent, CardTableComponent
],
providers: [
{ provide: GnpisService, useValue: gnpisService },
]
});
}));
it('should fetch the xref information', async(() => {
gnpisService.xref.and.returnValue(of(xref));
const tester = new XrefsComponentTester();
tester.detectChanges();
expect(tester.cardHeader).toContainText('Cross References');
expect(tester.columns[0]).toContainText(xref[0].db_version);
expect(tester.columns[1]).toContainText(xref[0].database_name);
expect(tester.columns[2]).toContainText(xref[0].entry_type);
expect(tester.columns[3].textContent.length).toBeLessThanOrEqual(124);
}));
it('should not display cross references', async(() => {
gnpisService.xref.and.returnValue(of(xrefBlank));
const tester = new XrefsComponentTester();
tester.detectChanges();
expect(tester.cardHeader).toBeFalsy();
}));
});
import { Component, Input, OnInit } from '@angular/core';
import { GnpisService } from '../gnpis.service';
import { XrefModel } from '../models/xref.model';
@Component({
selector: 'gpds-xrefs',
templateUrl: './xrefs.component.html',
styleUrls: ['./xrefs.component.scss']
})
export class XrefsComponent implements OnInit {
xrefs: Array<XrefModel> = new Array<XrefModel>();
@Input() xrefId: string;
constructor(private gnpisService: GnpisService) {
}
ngOnInit() {
this.gnpisService.xref(this.xrefId).subscribe(
xrefs => {
this.xrefs = xrefs;
}
);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment