Skip to content
Snippets Groups Projects
Commit 84273ba1 authored by Tifenn Guillas's avatar Tifenn Guillas
Browse files

Export CSV + ASCII => DONE, Tests => DONE

parent e737f5e1
No related branches found
No related tags found
2 merge requests!100Develop,!88Resolve "Export des résultats"
.dl-btn {
height: 60px;
}
.title, .badge {
font-size: 1.5rem;
}
.btn {
width: fit-content;
}
.bold {
font-weight: 900;
}
.dl-btn {
height: 60px;
}
......@@ -10,44 +10,30 @@
<div class="col">
<div class="row justify-content-around">
<div class="col-auto mb-2">
<button class="btn btn-lg btn-block btn-success">
<img src="assets/logo_csv.png" class="dl-btn" alt="">
</button>
<!-- BADGE -->
<!-- <button class="btn badge badge-pill badge-success">CSV</button> -->
<a [href]="getUrl('csv')" class="btn btn-lg btn-block btn-success">
<img src="assets/logo_csv.png" class="dl-btn" alt="Download results in CSV fornt">
</a>
</div>
<div class="col-auto mb-2">
<button class="btn btn-lg btn-block btn-success">
<img src="assets/logo_ascii.png" class="dl-btn" alt="">
</button>
<!-- BADGE -->
<!-- <button class="btn badge badge-pill badge-success">ASCII</button> -->
<a [href]="getUrl('ascii')" target="_blank" class="btn btn-lg btn-block btn-success">
<img src="assets/logo_ascii.png" class="dl-btn" alt="Download results in ASCII formt">
</a>
</div>
<div class="col-auto mb-2">
<button class="btn btn-lg btn-success btn-block">
<img src="assets/logo_vo.png" class="dl-btn" alt="">
<div *ngIf="getDataset().vo" class="col-auto mb-2">
<button class="btn btn-lg btn-block btn-success">
<img src="assets/logo_vo.png" class="dl-btn" alt="Download results in VO format">
</button>
<!-- BADGE -->
<!-- <button class="btn badge badge-pill badge-success">VO</button> -->
</div>
<div class="w-100 d-block d-lg-none"></div>
<div class="col-auto mb-2">
<button class="btn btn-lg btn-block btn-success">
<img src="assets/logo_spectra.png" class="dl-btn" alt="">
<!-- SVG -->
<!-- <object data="assets/logo_spectra.svg" type="image/svg+xml" class="dl-btn svg">
<img src="ssets/logo_spectra.png" />
</object> -->
<img src="assets/logo_spectra.png" class="dl-btn" alt="Download SPECTRA archive">
</button>
<!-- BADGE -->
<!-- <button class="btn badge badge-pill badge-success">SPECTRA</button> -->
</div>
<div class="col-auto mb-2">
<button class="btn btn-lg btn-block btn-success">
<img src="assets/logo_stamp.png" class="dl-btn" alt="">
<img src="assets/logo_stamp.png" class="dl-btn" alt=" Download STAMP archive">
</button>
<!-- BADGE -->
<!-- <button class="btn badge badge-pill badge-success">STAMP</button> -->
</div>
</div>
</div>
......
// import { ComponentFixture, TestBed } from '@angular/core/testing';
// import { Component, Input, Attribute } from '@angular/core';
// import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
// import { AccordionModule } from 'ngx-bootstrap';
// import { DatatableComponent } from './datatable.component';
// import { Dataset } from '../../../metamodel/model';
// import { ATTRIBUTE_LIST, DATASET_LIST } from '../../../../settings/test-data';
// describe('[Search][Result] Component: DatatableComponent', () => {
// @Component({ selector: 'app-img', template: '' })
// class ImgStubComponent {
// @Input() src: string;
// }
// @Component({ selector: 'app-thumbnail', template: '' })
// class ThumbnailStubComponent {
// @Input() src: string;
// @Input() attributeName: string;
// }
// @Component({ selector: 'app-link', template: '' })
// class LinkStubComponent {
// @Input() href: string;
// }
// @Component({ selector: 'app-btn', template: '' })
// class BtnStubComponent {
// @Input() href: string;
// }
// @Component({ selector: 'app-detail', template: '' })
// class DetailStubComponent {
// @Input() style: string;
// @Input() datasetName: string;
// @Input() data: string | number;
// }
// @Component({ selector: 'app-download', template: '' })
// class DownloadStubComponent {
// @Input() href: string;
// }
// @Component({ selector: 'app-json-renderer', template: '' })
// class JsonStubComponent {
// @Input() attributeName: string;
// @Input() json: string;
// }
// @Component({ selector: 'pagination', template: '' })
// class PaginationStubComponent {
// @Input() totalItems: number;
// @Input() boundaryLinks: boolean;
// @Input() rotate: boolean;
// @Input() maxSize: number;
// }
// let component: DatatableComponent;
// let fixture: ComponentFixture<DatatableComponent>;
// beforeEach(() => {
// TestBed.configureTestingModule({
// declarations: [
// DatatableComponent,
// ImgStubComponent,
// ThumbnailStubComponent,
// LinkStubComponent,
// BtnStubComponent,
// DetailStubComponent,
// DownloadStubComponent,
// JsonStubComponent,
// PaginationStubComponent
// ],
// imports: [AccordionModule.forRoot(), BrowserAnimationsModule]
// });
// fixture = TestBed.createComponent(DatatableComponent);
// component = fixture.componentInstance;
// });
// it('should create the component', () => {
// expect(component).toBeTruthy();
// });
// it('#getOutputList() should return filtered output list', () => {
// component.outputList = [2]
// component.datasetAttributeList = ATTRIBUTE_LIST;
// const outputList = component.getOutputList();
// expect(outputList.length).toBe(1);
// });
// it('#getDataset() should return dataset object', () => {
// 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');
// });
// it('#getAttributeId(attributeName) should return id of attributeName', () => {
// component.datasetAttributeList = ATTRIBUTE_LIST;
// expect(component.getAttributeId('name_one')).toBe(1);
// });
// it('#getAttributeRenderer(attributeName) should return renderer type of attributeName', () => {
// component.datasetAttributeList = ATTRIBUTE_LIST;
// expect(component.getAttributeRenderer('name_one')).toBe('btn');
// });
// it('#getAttributeUriAction(attributeName, datum) should return uri action of attributeName', () => {
// component.datasetAttributeList = ATTRIBUTE_LIST;
// expect(component.getAttributeUriAction('name_one', 'test')).toBe('test');
// expect(component.getAttributeUriAction('name_two', 'test')).toBe('http://test.com/test');
// });
// it('#toggleSelection(datum) should return add datum to selectedData', () => {
// const datum = { label_one: 123456 };
// component.datasetAttributeList = ATTRIBUTE_LIST;
// component.selectedData = [];
// component.addSelectedData.subscribe((event: any) => expect(event).toBe(123456));
// component.toggleSelection(datum);
// });
// it('#toggleSelection(datum) should return remove datum to selectedData', () => {
// const datum = { label_one: 123456 };
// component.selectedData = [123456];
// component.datasetAttributeList = ATTRIBUTE_LIST;
// component.deleteSelectedData.subscribe((event: any) => expect(event).toBe(123456));
// component.toggleSelection(datum);
// });
// it('#isSelected(datum) should return true datum is selected', () => {
// const datum = { label_one: 123456 };
// component.datasetAttributeList = ATTRIBUTE_LIST;
// component.selectedData = [123456];
// expect(component.isSelected(datum)).toBeTruthy();
// });
// it('#isSelected(datum) should return false datum is not selected', () => {
// const datum = { label_one: 123456 };
// component.datasetAttributeList = ATTRIBUTE_LIST;
// component.selectedData = [];
// expect(component.isSelected(datum)).toBeFalsy();
// });
// it('#noSelectedData() should return true if no selectedData', () => {
// component.selectedData = [];
// expect(component.noSelectedData()).toBeTruthy();
// });
// it('#noSelectedData() should return false if there are selectedData', () => {
// component.selectedData = [123456];
// expect(component.noSelectedData()).toBeFalsy();
// });
// it('#emitProcess() should raise executeProcess event and transmit process type', () => {
// component.executeProcess.subscribe((event: string) => expect(event).toBe('test'));
// component.emitProcess('test');
// });
// it('#changePage() should change page value and raise getSearchData event', () => {
// component.sortedCol = 1;
// component.sortedOrder = 'a';
// component.getSearchData.subscribe((event: [number, number, number, string]) => expect(event).toEqual([2, 10, 1, 'a']));
// component.changePage(2);
// });
// it('#changeNbItems() should change nbItems value and raise getSearchData event', () => {
// component.sortedCol = 1;
// component.sortedOrder = 'a';
// component.getSearchData.subscribe((event: [number, number, number, string]) => expect(event).toEqual([1, 20, 1, 'a']));
// component.changeNbItems(20);
// });
// it('#ngOnInit() should init sortedCol and sortedOrder values', () => {
// component.datasetAttributeList = ATTRIBUTE_LIST;
// component.ngOnInit();
// expect(component.sortedCol).toEqual(1);
// expect(component.sortedOrder).toBe('a');
// });
// it('#sort() should raise getSearchData event with correct parameters', () => {
// component.sortedOrder = 'a';
// let subscribtion = component.getSearchData.subscribe((event: [number, number, number, string]) => expect(event).toEqual([1, 10, 1, 'a']));
// component.sort(1);
// subscribtion.unsubscribe();
// component.sortedCol = 1;
// component.sortedOrder = 'a';
// subscribtion = component.getSearchData.subscribe((event: [number, number, number, string]) => expect(event).toEqual([1, 10, 1, 'd']));
// component.sort(1);
// subscribtion.unsubscribe();
// component.sortedCol = 1;
// component.sortedOrder = 'd';
// subscribtion = component.getSearchData.subscribe((event: [number, number, number, string]) => expect(event).toEqual([1, 10, 1, 'a']));
// component.sort(1);
// });
// });
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { DownloadSectionComponent } from './download.component';
import { DATASET_LIST, CRITERIA_LIST } from '../../../../settings/test-data';
import { Dataset } from 'src/app/metamodel/model';
describe('[Search][Result] Component: DownloadSectionComponent', () => {
let component: DownloadSectionComponent;
let fixture: ComponentFixture<DownloadSectionComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [DownloadSectionComponent]
});
fixture = TestBed.createComponent(DownloadSectionComponent);
component = fixture.componentInstance;
});
it('should create the component', () => {
expect(component).toBeTruthy();
});
it('#getDataset() should return dataset object', () => {
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');
});
it('#getUrl(format) should construct url with format parameter', () => {
component.apiPath = 'http://test.com';
component.datasetName = 'dataset';
component.outputList = [1, 2, 3];
component.criteriaList = [];
component.criteriaList = CRITERIA_LIST;
const url = component.getUrl('csv');
expect(url).toBe('http://test.com/search/dataset?a=1;2;3&c=1::eq::fd_crit_1;2::eq::fd_crit_2&f=csv');
});
});
import { Component, Input, Output, EventEmitter, ViewEncapsulation } from '@angular/core';
import { Component, Input } from '@angular/core';
import { Criterion } from '../../store/model';
import { getCriterionStr } from '../../../shared/utils';
import { Dataset } from 'src/app/metamodel/model';
@Component({
selector: 'app-result-download',
templateUrl: 'download.component.html',
styleUrls: ['download.component.css'],
// encapsulation: ViewEncapsulation.None
styleUrls: ['download.component.css']
})
export class DownloadSectionComponent {
@Input() datasetName: string;
@Input() datasetList: Dataset[];
@Input() dataLength: number;
// @Output() addSelectedData: EventEmitter<any> = new EventEmitter();
@Input() apiPath: string;
@Input() criteriaList: Criterion[];
@Input() outputList: number[];
getDataset(): Dataset {
return this.datasetList.find(dataset => dataset.name === this.datasetName);
}
getUrl(format: string): string {
let query: string;
if (!this.apiPath.startsWith('http')) {
const url = window.location;
query = url.protocol + '//' + url.host + '/server';
} else {
query = this.apiPath;
}
query += '/search/' + this.datasetName + '?a=' + this.outputList.join(';');
if (this.criteriaList.length > 0) {
query += '&c=' + this.criteriaList.map(criterion => getCriterionStr(criterion)).join(';');
}
query += '&f=' + format
return query;
}
}
......@@ -27,7 +27,6 @@ describe('[Search][Result] Component: UrlDisplayComponent', () => {
it('#getUrl() should construct url', () => {
component.apiPath = 'http://test.com';
component.instanceName = 'instance';
component.datasetName = 'dataset';
component.outputList = [1, 2, 3];
component.criteriaList = [];
......
......@@ -11,14 +11,13 @@ import { getCriterionStr } from '../../../shared/utils';
})
export class UrlDisplaySectionComponent {
@Input() apiPath: string;
@Input() instanceName: string;
@Input() datasetName: string;
@Input() criteriaList: Criterion[];
@Input() outputList: number[];
constructor(private toastr: ToastrService) { }
getUrl() {
getUrl(): string {
let query: string;
if (!this.apiPath.startsWith('http')) {
const url = window.location;
......
......@@ -7,7 +7,11 @@
<div class="col-12">
<app-result-download
[datasetName]="datasetName | async"
[dataLength]="dataLength | async">
[datasetList]="datasetList | async"
[dataLength]="dataLength | async"
[apiPath]="apiPath"
[criteriaList]="criteriaList | async"
[outputList]="outputList | async">
</app-result-download>
<app-result-summary
[datasetAttributeList]="datasetAttributeList | async"
......@@ -16,7 +20,6 @@
</app-result-summary>
<app-result-url-display
[apiPath]="apiPath"
[instanceName]="instanceName"
[datasetName]="datasetName | async"
[criteriaList]="criteriaList | async"
[outputList]="outputList | async">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment