Commit 59f69c66 authored by Tifenn Guillas's avatar Tifenn Guillas

Merge branch '126-display-export-results-as-configured-in-admin' into 'develop'

Resolve "Display export results as configured in admin"

Closes #126

See merge request !141
parents ed765cb4 d3af45e8
Pipeline #3148 passed with stages
in 8 minutes and 33 seconds
......@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- #111: Fix search lost when back to dataset page
### Changed
- #126 => Download results in different formats are now a configurable option in anis-admin
- #124 => Navigation links are now a configurable option in anis-admin
- #125 => Display datasets with cone search only on search multiple
- #118 => Refactoring metamodel
......
......@@ -6,7 +6,6 @@ export interface Dataset {
display: number;
count: number;
vo: boolean;
selectable_row: boolean;
project_name: string;
id_dataset_family: number;
config: {
......@@ -14,10 +13,17 @@ export interface Dataset {
enabled: boolean;
column_ra: number;
column_dec: number;
},
results_server_link?: {
enabled: boolean;
},
opened_datatable?: boolean
}
};
results_server_link?: boolean;
opened_datatable?: boolean;
selectable_row?: boolean;
download_results_format?: {
csv: boolean;
ascii: boolean;
spectra: boolean;
stamp: boolean;
vo: boolean;
fits: boolean;
};
};
}
......@@ -5,28 +5,28 @@
<div class="w-100 d-block d-xl-none"></div>
<div class="col">
<div class="row justify-content-around">
<div class="col-auto mb-2">
<div *ngIf="getConfigDownloadResultFormat('csv')" class="col-auto mb-2">
<a [href]="getUrl('csv')" class="btn btn-lg btn-block dl-btn">
<span [inlineSVG]="'assets/logo_csv.svg'" title="Download results in CSV format"></span>
</a>
</div>
<div class="col-auto mb-2">
<div *ngIf="getConfigDownloadResultFormat('ascii')" class="col-auto mb-2">
<a [href]="getUrl('ascii')" target="_blank" class="btn btn-lg btn-block dl-btn">
<span [inlineSVG]="'assets/logo_ascii.svg'" title="Download results in ASCII format"></span>
</a>
</div>
<div *ngIf="dataset.vo" class="col-auto mb-2">
<div *ngIf="getConfigDownloadResultFormat('vo')" class="col-auto mb-2">
<button class="btn btn-lg btn-block dl-btn">
<span [inlineSVG]="'assets/logo_vo.svg'" title="Download results in VO format"></span>
</button>
</div>
<div class="w-100 d-block d-lg-none"></div>
<div class="col-auto mb-2">
<div *ngIf="getConfigDownloadResultFormat('spectra')" class="col-auto mb-2">
<button class="btn btn-lg btn-block dl-btn">
<span [inlineSVG]="'assets/logo_spectra.svg'" title="Download SPECTRA archive"></span>
</button>
</div>
<div class="col-auto mb-2">
<div *ngIf="getConfigDownloadResultFormat('stamp')" class="col-auto mb-2">
<button class="btn btn-lg btn-block dl-btn">
<span [inlineSVG]="'assets/logo_stamp.svg'" title="Download STAMP archive"></span>
</button>
......
......@@ -2,7 +2,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
import { DownloadSectionComponent } from './download-section.component';
import { ConeSearch } from '../../../shared/cone-search/store/model';
import { DATASET } from '../../../../settings/test-data';
import { DATASET, DATASET_LIST } from '../../../../settings/test-data';
import { environment } from '../../../../environments/environment';
describe('[SearchMultiple][Result] Component: DownloadSectionComponent', () => {
......@@ -21,6 +21,13 @@ describe('[SearchMultiple][Result] Component: DownloadSectionComponent', () => {
expect(component).toBeTruthy();
});
it('#getConfigDownloadResultFormat() should return if download button has to be displayed for the given format', () => {
component.dataset = DATASET;
expect(component.getConfigDownloadResultFormat('csv')).toBeTruthy();
component.dataset = DATASET_LIST.find(d => d.name === 'cat_2');
expect(component.getConfigDownloadResultFormat('csv')).toBeFalsy();
});
it('#getUrl(format) should construct url with format parameter', () => {
component.dataset = DATASET;
component.outputList = [1, 2, 3];
......
......@@ -15,6 +15,13 @@ export class DownloadSectionComponent {
@Input() coneSearch: ConeSearch;
@Input() outputList: number[];
getConfigDownloadResultFormat(format: string): boolean {
if (this.dataset.config && this.dataset.config.download_results_format && this.dataset.config.download_results_format[format]) {
return this.dataset.config.download_results_format[format];
}
return false;
}
getUrl(format: string): string {
let query: string = host() + '/search/' + this.dataset.name + '?a=' + this.outputList.join(';');
query += '&cs=' + this.coneSearch.ra + ':' + this.coneSearch.dec + ':' + this.coneSearch.radius;
......
......@@ -9,28 +9,28 @@
<div class="w-100 d-block d-xl-none"></div>
<div class="col">
<div class="row justify-content-around">
<div class="col-auto mb-2">
<div *ngIf="getConfigDownloadResultFormat('csv')" class="col-auto mb-2">
<a [href]="getUrl('csv')" class="btn btn-lg btn-block dl-btn">
<span [inlineSVG]="'assets/logo_csv.svg'" title="Download results in CSV format"></span>
</a>
</div>
<div class="col-auto mb-2">
<div *ngIf="getConfigDownloadResultFormat('ascii')" class="col-auto mb-2">
<a [href]="getUrl('ascii')" target="_blank" class="btn btn-lg btn-block dl-btn">
<span [inlineSVG]="'assets/logo_ascii.svg'" title="Download results in ASCII format"></span>
</a>
</div>
<div *ngIf="getDataset().vo" class="col-auto mb-2">
<div *ngIf="getConfigDownloadResultFormat('vo')" class="col-auto mb-2">
<button class="btn btn-lg btn-block dl-btn">
<span [inlineSVG]="'assets/logo_vo.svg'" title="Download results in VO format"></span>
</button>
</div>
<div class="w-100 d-block d-lg-none"></div>
<div class="col-auto mb-2">
<div *ngIf="getConfigDownloadResultFormat('spectra')" class="col-auto mb-2">
<button class="btn btn-lg btn-block dl-btn">
<span [inlineSVG]="'assets/logo_spectra.svg'" title="Download SPECTRA archive"></span>
</button>
</div>
<div class="col-auto mb-2">
<div *ngIf="getConfigDownloadResultFormat('stamp')" class="col-auto mb-2">
<button class="btn btn-lg btn-block dl-btn">
<span [inlineSVG]="'assets/logo_stamp.svg'" title="Download STAMP archive"></span>
</button>
......
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { DownloadComponent } from './download.component';
import { Dataset } from '../../../metamodel/model';
import { ConeSearch } from '../../../shared/cone-search/store/model';
import { DATASET_LIST, CRITERIA_LIST } from '../../../../settings/test-data';
import { environment } from '../../../../environments/environment';
......@@ -27,12 +26,11 @@ describe('[Search][Result] Component: DownloadComponent', () => {
component.ngOnInit();
});
it('#getDataset() should return dataset object', () => {
it('#getConfigDownloadResultFormat() should return if download button for the given format has to be displayed', () => {
component.datasetList = DATASET_LIST;
component.datasetName = 'cat_1';
const dataset: Dataset = component.getDataset();
expect(dataset.name).toBe('cat_1');
expect(dataset.label).toBe('Cat 1');
expect(component.getConfigDownloadResultFormat('csv')).toBeTruthy();
expect(component.getConfigDownloadResultFormat('ascii')).toBeFalsy();
});
it('#getUrl(format) should construct url with format parameter', () => {
......@@ -41,8 +39,10 @@ describe('[Search][Result] Component: DownloadComponent', () => {
component.criteriaList = CRITERIA_LIST;
component.isConeSearchAdded = true;
component.coneSearch = { ra: 4, dec: 5, radius: 6 } as ConeSearch;
const url = component.getUrl('csv');
expect(url).toBe(environment.apiUrl + '/search/dataset?a=1;2;3&c=1::eq::fd_crit_1;2::eq::fd_crit_2&cs=4:5:6&f=csv');
expect(component.getUrl('csv')).toBe(environment.apiUrl + '/search/dataset?a=1;2;3&c=1::eq::fd_crit_1;2::eq::fd_crit_2&cs=4:5:6&f=csv');
component.criteriaList = [];
component.isConeSearchAdded = false;
expect(component.getUrl('csv')).toBe(environment.apiUrl + '/search/dataset?a=1;2;3&f=csv');
});
});
......@@ -25,8 +25,12 @@ export class DownloadComponent implements OnInit {
this.getDataLength.emit();
}
getDataset(): Dataset {
return this.datasetList.find(dataset => dataset.name === this.datasetName);
getConfigDownloadResultFormat(format: string): boolean {
const dataset = this.datasetList.find(dataset => dataset.name === this.datasetName);
if (dataset.config && dataset.config.download_results_format && dataset.config.download_results_format[format]) {
return dataset.config.download_results_format[format];
}
return false;
}
getUrl(format: string): string {
......
......@@ -26,7 +26,7 @@ export class UrlDisplaySectionComponent {
urlDisplayEnabled(): boolean {
const config = this.datasetList.find(d => d.name === this.datasetName).config;
if (config !== null && 'results_server_link' in config) {
return config.results_server_link.enabled;
return config.results_server_link;
}
return false;
}
......
......@@ -3,7 +3,7 @@
<span class="sr-only">Loading...</span>
</div>
<div *ngIf="requiredParams()">
<div *ngIf="dataset.selectable_row" class="mb-2">
<div *ngIf="dataset.config.selectable_row" class="mb-2">
<button [disabled]="noSelectedData() || processWip" (click)="executeProcess.emit('csv')"
class="btn btn-sm btn-outline-primary">
To CSV
......@@ -20,7 +20,7 @@
<table class="table table-bordered table-hover">
<thead>
<tr>
<th *ngIf="dataset.selectable_row"></th>
<th *ngIf="dataset.config.selectable_row"></th>
<th *ngFor="let attribute of getOutputList()" scope="col" class="clickable" (click)="sort(attribute.id)">
{{ attribute.label }}
<span *ngIf="attribute.id === sortedCol" class="pl-2">
......@@ -44,7 +44,7 @@
</thead>
<tbody>
<tr *ngFor="let datum of data">
<td *ngIf="dataset.selectable_row" class="data-selected"
<td *ngIf="dataset.config.selectable_row" class="data-selected"
(click)="toggleSelection(datum)">
<button class="btn btn-block text-left p-0 m-0">
<span *ngIf="!isSelected(datum)">
......
......@@ -9,7 +9,6 @@ export const DATASET_LIST: Dataset[] = [
display: 10,
count: 10000,
vo: false,
selectable_row: false,
project_name: 'project_1',
id_dataset_family: 1,
config: {
......@@ -18,10 +17,17 @@ export const DATASET_LIST: Dataset[] = [
column_ra: 2,
column_dec: 3
},
results_server_link: {
enabled: true
},
opened_datatable: true
results_server_link: true,
opened_datatable: true,
selectable_row: true,
download_results_format: {
csv: true,
ascii: false,
spectra: true,
stamp: true,
vo: true,
fits: true
}
}
},
{
......@@ -32,7 +38,6 @@ export const DATASET_LIST: Dataset[] = [
display: 30,
count: 30000,
vo: false,
selectable_row: false,
project_name: 'project_2',
id_dataset_family: 2,
config: {}
......@@ -45,7 +50,6 @@ export const DATASET_LIST: Dataset[] = [
display: 20,
count: 20000,
vo: false,
selectable_row: false,
project_name: 'project_1',
id_dataset_family: 2,
config: {}
......
......@@ -8,7 +8,6 @@ export const DATASET: Dataset = {
display: 10,
count: 10000,
vo: false,
selectable_row: false,
project_name: 'project_1',
id_dataset_family: 1,
config: {
......@@ -16,6 +15,14 @@ export const DATASET: Dataset = {
enabled: true,
column_ra: 2,
column_dec: 3
},
download_results_format: {
csv: true,
ascii: false,
spectra: false,
stamp: false,
vo: false,
fits: false
}
}
};
Markdown is supported
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