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

WIP: put spetra object in a dedicated component

parent 56f034df
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';
export const dummiesComponents = [
ObjectDisplayComponent,
SpectraObjectComponent,
SpectraGraphComponent
];
<div class="row">
<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
import { Component, Input, ChangeDetectionStrategy } from '@angular/core';
import { Attribute, Category, Family } from '../../metamodel/model';
import { getHost } from '../../shared/utils';
@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;
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
.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);
}
getAttributeSpectraGraph(): Attribute {
return this.getAttributesVisible().find(attribute => attribute.renderer_detail === 'spectra_graph');
}
getZ(): number {
const attributeZ = this.getAttributeBySearchFlag('Z');
if (attributeZ) {
return +this.object[attributeZ.label];
} else {
return 0;
}
}
}
......@@ -20,7 +20,7 @@
<tr>
<th>Alpha</th>
<th>Delta</th>
<th class="text-center" rowspan="2"><img src="assets/cesam_anis80.png" alt="CeSAM logo" /></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>
......
......@@ -2,9 +2,9 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AccordionModule } from 'ngx-bootstrap/accordion';
import { ObjectDisplayComponent } from './object-display.component';
import { Attribute } from '../../metamodel/model';
import { ATTRIBUTE_LIST, CATEGORY_LIST, OBJECT_DETAIL } from '../../../settings/test-data';
import { ObjectDisplayComponent } from './spectra-object.component';
import { Attribute } from '../../../metamodel/model';
import { ATTRIBUTE_LIST, CATEGORY_LIST, OBJECT_DETAIL } from '../../../../settings/test-data';
describe('[Detail] Component: ObjectDisplayComponent', () => {
let component: ObjectDisplayComponent;
......
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',
changeDetection: ChangeDetectionStrategy.OnPush
})
export class ObjectDisplayComponent implements OnInit {
export class SpectraObjectComponent implements OnInit {
@Input() datasetName: string;
@Input() outputFamilyList: Family[];
@Input() categoryList: Category[];
......
......@@ -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]="objectType(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-object-data *ngSwitchDefault-->
<!-- [datasetName]="datasetName | async"-->
<!-- [outputFamilyList]="outputFamilyList | async"-->
<!-- [categoryList]="categoryList | async"-->
<!-- [attributeList]="attributeList | async"-->
<!-- [object]="object | async">-->
<!-- </app-object-data>-->
</div>
</div>
......@@ -55,6 +55,16 @@ export class DetailComponent implements OnInit, OnDestroy {
});
}
objectType(attributeList: Attribute[]): string {
const spectrumAttribute: Attribute = attributeList
.filter(a => a.detail)
.find(attribute => attribute.search_flag === 'SPECTRUM_1D');
if (spectrumAttribute) {
return 'spectra';
}
return 'default';
}
goBackToResult() {
this.location.back();
}
......
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