Commit c87cbf5d authored by Tifenn Guillas's avatar Tifenn Guillas
Browse files

Merge branch '136-detail-page-not-displayed-if-spectrum_1d-not-definied-in-admin' into 'develop'

Resolve "[Detail] Page not displayed if  `SPECTRUM_1D` not definied in admin"

Closes #136

See merge request !151
parents 56f034df 6510eeab
Pipeline #3225 passed with stages
in 8 minutes and 39 seconds
<div class="row justify-content-center">
<div class="col col-lg-10 col-xl-8 mt-4">
<app-object-data
[datasetName]="datasetName"
[outputFamilyList]="outputFamilyList"
[categoryList]="categoryList"
[attributeList]="attributeList"
[object]="object">
</app-object-data>
</div>
</div>
\ No newline at end of file
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Component, Input } from '@angular/core';
import { DefaultObjectComponent } from './default-object.component';
import { Attribute, Category, Family } from '../../metamodel/model';
describe('[Detail] Component: DefaultObjectComponent', () => {
@Component({ selector: 'app-object-data', template: '' })
class ObjectDataStubComponent {
@Input() datasetName: string;
@Input() outputFamilyList: Family[];
@Input() categoryList: Category[];
@Input() attributeList: Attribute[];
@Input() object: any;
}
let component: DefaultObjectComponent;
let fixture: ComponentFixture<DefaultObjectComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
DefaultObjectComponent,
ObjectDataStubComponent
]
});
fixture = TestBed.createComponent(DefaultObjectComponent);
component = fixture.componentInstance;
}));
it('should create the component', () => {
expect(component).toBeTruthy();
});
});
import { Component, Input, ChangeDetectionStrategy } from '@angular/core';
import { Attribute, Category, Family } from '../../metamodel/model';
@Component({
selector: 'app-default-object',
templateUrl: 'default-object.component.html',
changeDetection: ChangeDetectionStrategy.OnPush
})
export class DefaultObjectComponent {
@Input() datasetName: string;
@Input() outputFamilyList: Family[];
@Input() categoryList: Category[];
@Input() attributeList: Attribute[];
@Input() object: any;
}
import { ObjectDisplayComponent } from './object-display.component';
import { SpectraGraphComponent } from './spectra-graph/spectra-graph.component';
import { SpectraObjectComponent } from './spectra/spectra-object.component';
import { SpectraGraphComponent } from './spectra/spectra-graph/spectra-graph.component';
import { DefaultObjectComponent } from './default-object.component';
import { ObjectDataComponent } from './object-data.component';
export const dummiesComponents = [
ObjectDisplayComponent,
SpectraGraphComponent
SpectraObjectComponent,
SpectraGraphComponent,
DefaultObjectComponent,
ObjectDataComponent
];
<div *ngIf="getAttributeBySearchFlag('RA') && getAttributeBySearchFlag('DEC')" class="row">
<div class="col-12">
<table class="table mb-1">
<tr>
<th>Alpha</th>
<th>Delta</th>
<th class="text-center" rowspan="2"><img src="assets/cesam_anis80.png" alt="CeSAM logo" /></th>
</tr>
<tr>
<td>{{ object[getAttributeBySearchFlag('RA').label] }}</td>
<td>{{ object[getAttributeBySearchFlag('DEC').label] }}</td>
</tr>
</table>
<hr class="mt-0 mb-4">
</div>
</div>
<!-- Accordion families -->
<accordion [isAnimated]="true">
<accordion-group *ngFor="let family of outputFamilyList" #ag panelClass="abstract-accordion" [isOpen]="true" class="pl-2">
<button class="btn btn-link btn-block clearfix pb-2" accordion-heading>
<span class="pull-left float-left text-primary">
{{ family.label }}
&nbsp;
<span *ngIf="ag.isOpen">
<span class="fas fa-chevron-up"></span>
</span>
<span *ngIf="!ag.isOpen">
<span class="fas fa-chevron-down"></span>
</span>
</span>
</button>
<!-- Accordion categories -->
<accordion [isAnimated]="true">
<accordion-group *ngFor="let category of getCategoryByFamilySortedByDisplay(family.id)" #ag panelClass="abstract-accordion" [isOpen]="true" class="pl-4">
<button class="btn btn-link btn-block clearfix pb-2" accordion-heading>
<span class="pull-left float-left text-primary">
{{ category.label }}
&nbsp;
<span *ngIf="ag.isOpen">
<span class="fas fa-chevron-up"></span>
</span>
<span *ngIf="!ag.isOpen">
<span class="fas fa-chevron-down"></span>
</span>
</span>
</button>
<!-- Output list -->
<div *ngFor="let attribute of getAttributesVisibleByCategory(category.id)" class="row pb-2">
<div class="col-5 font-weight-bold">{{ attribute.form_label }}</div>
<div class="col">{{ object[attribute.label] }}</div>
</div>
</accordion-group>
</accordion>
</accordion-group>
</accordion>
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { AccordionModule } from 'ngx-bootstrap/accordion';
import { ObjectDataComponent } from './object-data.component';
import { ATTRIBUTE_LIST, CATEGORY_LIST } from '../../../settings/test-data';
describe('[Detail] Component: ObjectDataComponent', () => {
let component: ObjectDataComponent;
let fixture: ComponentFixture<ObjectDataComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ObjectDataComponent],
imports: [AccordionModule.forRoot()]
});
fixture = TestBed.createComponent(ObjectDataComponent);
component = fixture.componentInstance;
}));
it('should create the component', () => {
expect(component).toBeTruthy();
});
it('#getCategoryByFamilySortedByDisplay() should return sorted categories for the given family', () => {
component.categoryList = CATEGORY_LIST;
expect(component.getCategoryByFamilySortedByDisplay(1).length).toEqual(2);
});
it('#getAttributesVisibleByCategory() should return visible attributes for the given category', () => {
component.attributeList = ATTRIBUTE_LIST;
expect(component.getAttributesVisibleByCategory(1).length).toEqual(1);
expect(component.getAttributesVisibleByCategory(1)[0].id).toEqual(1);
});
it('#getAttributesVisible() should return visible attributes', () => {
component.attributeList = ATTRIBUTE_LIST;
expect(component.getAttributesVisible().length).toEqual(2);
});
it('#getAttributeBySearchFlag() should return attribute for the given search_flag', () => {
component.attributeList = ATTRIBUTE_LIST;
expect(component.getAttributeBySearchFlag('ID').name).toEqual('name_one');
});
});
import { Component, Input, ChangeDetectionStrategy } from '@angular/core';
import { Attribute, Category, Family } from '../../metamodel/model';
@Component({
selector: 'app-object-data',
templateUrl: 'object-data.component.html',
changeDetection: ChangeDetectionStrategy.OnPush
})
export class ObjectDataComponent {
@Input() datasetName: string;
@Input() outputFamilyList: Family[];
@Input() categoryList: Category[];
@Input() attributeList: Attribute[];
@Input() object: any;
getCategoryByFamilySortedByDisplay(idFamily: number): Category[] {
return this.categoryList
.filter(category => category.id_output_family === idFamily)
.sort((a, b) => a.display - b.display);
}
getAttributesVisibleByCategory(idCategory: number): Attribute[] {
return this.attributeList
.filter(a => a.detail)
.filter(a => a.id_output_category === idCategory)
.sort((a, b) => a.display_detail - b.display_detail);
}
getAttributesVisible(): Attribute[] {
return this.attributeList
.filter(a => a.detail)
.sort((a, b) => a.display_detail - b.display_detail);
}
getAttributeBySearchFlag(searchFlag: string): Attribute {
return this.getAttributesVisible().find(attribute => attribute.search_flag === searchFlag);
}
}
<div class="row">
<div *ngIf="getAttributeSpectraGraph()" class="col col-md-8 col-sm-12">
<div *ngIf="spectraIsLoading" id="div-spinner" class="text-center">
<span class="fas fa-circle-notch fa-spin fa-3x"></span>
<span class="sr-only">Loading...</span>
</div>
<app-spectra-graph *ngIf="spectraIsLoaded" [z]="getZ()" [spectraCSV]="spectraCSV"></app-spectra-graph>
</div>
<div [ngClass]="{'col-md-4 col-sm-12': getAttributeSpectraGraph()}" class="col mt-4">
<div *ngIf="getSpectra()" class="col text-right mb-2 p-0">
<a [href]="getSpectra()" class="btn btn-outline-primary" target="_blank">
Download spectra <span class="fas fa-download"></span>
</a>
</div>
<div *ngIf="getAttributeBySearchFlag('RA') && getAttributeBySearchFlag('DEC')" class="row">
<div class="col-12">
<table class="table mb-1">
<tr>
<th>Alpha</th>
<th>Delta</th>
<th class="text-center" rowspan="2"><img src="assets/cesam_anis80.png" alt="CeSAM logo" /></th>
</tr>
<tr>
<td>{{ object[getAttributeBySearchFlag('RA').label] }}</td>
<td>{{ object[getAttributeBySearchFlag('DEC').label] }}</td>
</tr>
</table>
<hr class="mt-0 mb-4">
</div>
</div>
<!-- Accordion families -->
<accordion [isAnimated]="true">
<accordion-group *ngFor="let family of outputFamilyList" #ag panelClass="abstract-accordion" [isOpen]="true" class="pl-2">
<button class="btn btn-link btn-block clearfix pb-2" accordion-heading>
<span class="pull-left float-left text-primary">
{{ family.label }}
&nbsp;
<span *ngIf="ag.isOpen">
<span class="fas fa-chevron-up"></span>
</span>
<span *ngIf="!ag.isOpen">
<span class="fas fa-chevron-down"></span>
</span>
</span>
</button>
<!-- Accordion categories -->
<accordion [isAnimated]="true">
<accordion-group *ngFor="let category of getCategoryByFamilySortedByDisplay(family.id)" #ag panelClass="abstract-accordion" [isOpen]="true" class="pl-4">
<button class="btn btn-link btn-block clearfix pb-2" accordion-heading>
<span class="pull-left float-left text-primary">
{{ category.label }}
&nbsp;
<span *ngIf="ag.isOpen">
<span class="fas fa-chevron-up"></span>
</span>
<span *ngIf="!ag.isOpen">
<span class="fas fa-chevron-down"></span>
</span>
</span>
</button>
<!-- Output list -->
<div *ngFor="let attribute of getAttributesVisibleByCategory(category.id)" class="row pb-2">
<div class="col-5 font-weight-bold">{{ attribute.form_label }}</div>
<div class="col">{{ object[attribute.label] }}</div>
</div>
</accordion-group>
</accordion>
</accordion-group>
</accordion>
</div>
</div>
\ No newline at end of file
.dl-btn {
height: 80px;
display: inline-block;
}
\ No newline at end of file
<div class="row">
<div *ngIf="getAttributeSpectraGraph()" class="col col-md-8 col-sm-12">
<div *ngIf="spectraIsLoading" id="div-spinner" class="text-center">
<span class="fas fa-circle-notch fa-spin fa-3x"></span>
<span class="sr-only">Loading...</span>
</div>
<app-spectra-graph *ngIf="spectraIsLoaded" [z]="getZ()" [spectraCSV]="spectraCSV"></app-spectra-graph>
</div>
<div [ngClass]="{'col-md-4 col-sm-12': getAttributeSpectraGraph()}" class="col mt-4">
<div *ngIf="getSpectra()" class="jumbotron row mb-3 p-4">
<div class="col-auto align-self-center">
<p>Download:</p>
</div>
<div class="w-100 d-block d-xl-none"></div>
<div class="col">
<div class="row justify-content-center">
<div class="col-auto">
<a [href]="getSpectra()" target="_blank" class="btn btn-lg btn-block dl-btn">
<span [inlineSVG]="'assets/logo_spectra.svg'" title="Download SPECTRA archive"></span>
</a>
</div>
</div>
</div>
</div>
<app-object-data
[datasetName]="datasetName"
[outputFamilyList]="outputFamilyList"
[categoryList]="categoryList"
[attributeList]="attributeList"
[object]="object">
</app-object-data>
</div>
</div>
\ No newline at end of file
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { Component, Input } from '@angular/core';
import { AccordionModule } from 'ngx-bootstrap/accordion';
import { SpectraObjectComponent } from './spectra-object.component';
import { Attribute, Category, Family } from '../../../metamodel/model';
import { ATTRIBUTE_LIST, OBJECT_DETAIL } from '../../../../settings/test-data';
import { ObjectDisplayComponent } from './object-display.component';
import { Attribute } from '../../metamodel/model';
import { ATTRIBUTE_LIST, CATEGORY_LIST, OBJECT_DETAIL } from '../../../settings/test-data';
describe('[Detail][Spectra] Component: SpectraObjectComponent', () => {
@Component({ selector: 'app-object-data', template: '' })
class ObjectDataStubComponent {
@Input() datasetName: string;
@Input() outputFamilyList: Family[];
@Input() categoryList: Category[];
@Input() attributeList: Attribute[];
@Input() object: any;
}
describe('[Detail] Component: ObjectDisplayComponent', () => {
let component: ObjectDisplayComponent;
let fixture: ComponentFixture<ObjectDisplayComponent>;
let component: SpectraObjectComponent;
let fixture: ComponentFixture<SpectraObjectComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [ObjectDisplayComponent],
imports: [AccordionModule.forRoot()]
declarations: [
SpectraObjectComponent,
ObjectDataStubComponent
]
});
fixture = TestBed.createComponent(ObjectDisplayComponent);
fixture = TestBed.createComponent(SpectraObjectComponent);
component = fixture.componentInstance;
});
......@@ -39,27 +49,6 @@ describe('[Detail] Component: ObjectDisplayComponent', () => {
expect(component.getSpectra()).toEqual('http://localhost:8080/download-file/dname/spec1d');
});
it('#getCategoryByFamilySortedByDisplay() should return sorted categories for the given family', () => {
component.categoryList = CATEGORY_LIST;
expect(component.getCategoryByFamilySortedByDisplay(1).length).toEqual(2);
});
it('#getAttributesVisibleByCategory() should return visible attributes for the given category', () => {
component.attributeList = ATTRIBUTE_LIST;
expect(component.getAttributesVisibleByCategory(1).length).toEqual(1);
expect(component.getAttributesVisibleByCategory(1)[0].id).toEqual(1);
});
it('#getAttributesVisible() should return visible attributes', () => {
component.attributeList = ATTRIBUTE_LIST;
expect(component.getAttributesVisible().length).toEqual(2);
});
it('#getAttributeBySearchFlag() should return attribute for the given search_flag', () => {
component.attributeList = ATTRIBUTE_LIST;
expect(component.getAttributeBySearchFlag('ID').name).toEqual('name_one');
});
it('#getAttributeSpectraGraph() should return attribute for the spectra_graph renderer_detail', () => {
component.attributeList = ATTRIBUTE_LIST;
expect(component.getAttributeSpectraGraph().name).toEqual('name_two');
......
import { Component, Input, ChangeDetectionStrategy, Output, EventEmitter, OnInit } from '@angular/core';
import { Attribute, Category, Family } from '../../metamodel/model';
import { getHost } from '../../shared/utils';
import { Attribute, Category, Family } from '../../../metamodel/model';
import { getHost } from '../../../shared/utils';
@Component({
selector: 'app-object-display',
templateUrl: 'object-display.component.html',
selector: 'app-spectra-object',
templateUrl: 'spectra-object.component.html',
styleUrls: ['spectra-object.component.css'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class ObjectDisplayComponent implements OnInit {
export class SpectraObjectComponent implements OnInit {
@Input() datasetName: string;
@Input() outputFamilyList: Family[];
@Input() categoryList: Category[];
......@@ -27,38 +28,22 @@ export class ObjectDisplayComponent implements OnInit {
}
getSpectra(): string {
return getHost() + '/download-file/' + this.datasetName + '/' + this.object[this.getAttributeBySearchFlag('SPECTRUM_1D').label];
}
getCategoryByFamilySortedByDisplay(idFamily: number): Category[] {
return this.categoryList
.filter(category => category.id_output_family === idFamily)
.sort((a, b) => a.display - b.display);
}
getAttributesVisibleByCategory(idCategory: number): Attribute[] {
return this.attributeList
const spectraAttribute: Attribute = this.attributeList
.filter(a => a.detail)
.filter(a => a.id_output_category === idCategory)
.sort((a, b) => a.display_detail - b.display_detail);
.find(attribute => attribute.search_flag === 'SPECTRUM_1D');
return getHost() + '/download-file/' + this.datasetName + '/' + this.object[spectraAttribute.label];
}
getAttributesVisible(): Attribute[] {
getAttributeSpectraGraph(): Attribute {
return this.attributeList
.filter(a => a.detail)
.sort((a, b) => a.display_detail - b.display_detail);
}
getAttributeBySearchFlag(searchFlag: string): Attribute {
return this.getAttributesVisible().find(attribute => attribute.search_flag === searchFlag);
}
getAttributeSpectraGraph(): Attribute {
return this.getAttributesVisible().find(attribute => attribute.renderer_detail === 'spectra_graph');
.find(attribute => attribute.renderer_detail === 'spectra_graph');
}
getZ(): number {
const attributeZ = this.getAttributeBySearchFlag('Z');
const attributeZ = this.attributeList
.filter(a => a.detail)
.find(attribute => attribute.search_flag === 'Z');
if (attributeZ) {
return +this.object[attributeZ.label];
} else {
......
......@@ -10,8 +10,8 @@
<span class="fas fa-circle-notch fa-spin fa-3x"></span>
<span class="sr-only">Loading...</span>
</div>
<div *ngIf="objectIsLoaded | async">
<app-object-display
<div *ngIf="objectIsLoaded | async" [ngSwitch]="getObjectType(attributeList | async)">
<app-spectra-object *ngSwitchCase="'spectra'"
[datasetName]="datasetName | async"
[outputFamilyList]="outputFamilyList | async"
[categoryList]="categoryList | async"
......@@ -21,6 +21,13 @@
[spectraIsLoaded]="spectraIsLoaded | async"
[spectraCSV]="spectraCSV | async"
(getSpectraCSV)="getSpectraCSV($event)">
</app-object-display>
</app-spectra-object>
<app-default-object *ngSwitchDefault
[datasetName]="datasetName | async"
[outputFamilyList]="outputFamilyList | async"
[categoryList]="categoryList | async"
[attributeList]="attributeList | async"
[object]="object | async">
</app-default-object>
</div>
</div>
......@@ -9,6 +9,7 @@ import { DetailComponent } from './detail.component';
import * as fromDetail from '../store/detail.reducer';
import * as detailActions from '../store/detail.action';
import { Attribute, Family, Category } from '../../metamodel/model';
import { ATTRIBUTE_LIST } from '../../../settings/test-data';
describe('[Detail] Container: DetailComponent', () => {
@Component({ selector: 'app-object-display', template: '' })
......@@ -63,6 +64,12 @@ describe('[Detail] Container: DetailComponent', () => {
});
});
it ('#getObjectType() should return object type', () => {
expect(component.getObjectType(ATTRIBUTE_LIST)).toEqual('spectra');
const defaultAttributeList = ATTRIBUTE_LIST.filter(a => a.search_flag !== 'SPECTRUM_1D');
expect(component.getObjectType(defaultAttributeList)).toEqual('default');
});
it ('#goBackToResult() should go to the previous location', inject([LOCATION_TOKEN], (location: Location) => {
spyOn(location, 'back');
component.goBackToResult();
......
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