Skip to content

Commit

Permalink
Merge branch 'master' into IBP-2078-PrintLabelsSubObs
Browse files Browse the repository at this point in the history
  • Loading branch information
nahuel-soldevilla committed Jan 16, 2019
2 parents 309522c + 29ad2f8 commit 7e2f1b7
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class ExcelService {
const ws: XLSX.WorkSheet = wb.Sheets[wsname];

/* save data */
const data = <Array<Array<any>>>(XLSX.utils.sheet_to_json(ws, {header: 1}));
const data = <Array<Array<any>>>(XLSX.utils.sheet_to_json(ws, {header: 1, defval: ''}));
observer.next(data);

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,15 @@ export class SampleImportPlateMappingComponent {
const activeListId = this.sampleContext.getActiveList().id;

if (this.validate()) {

this.sampleListService.importPlateInfo({
listId: activeListId,
sampleIdHeader: this.sampleIdMapping,
plateIdHeader: this.plateIdMapping,
wellHeader: this.wellMapping,
importData: this.importData
}).subscribe((observer) => {
const sampleList = this.buildSampleList();
this.sampleListService.importPlateInfo(activeListId, sampleList).subscribe((observer) => {
this.close();
// Refresh the sample list table.
this.eventManager.broadcast({name: 'sampleListModification', content: ''});
this.eventManager.broadcast({ name: 'sampleListModification', content: '' });
this.alertService.success('bmsjHipsterApp.sample.importPlate.success');
}, (response) => {
if (response.error.errors[0].message) {
this.alertService.error('bmsjHipsterApp.sample.error', {param: response.error.errors[0].message});
this.alertService.error('bmsjHipsterApp.sample.error', { param: response.error.errors[0].message });
} else {
this.alertService.error('bmsjHipsterApp.sample.importPlate.error');
}
Expand Down Expand Up @@ -96,4 +90,27 @@ export class SampleImportPlateMappingComponent {
});
}

buildSampleList() {
const headerRow = this.importData[0];
const sampleUidColumnIndex = headerRow.indexOf(this.sampleIdMapping);
const PlateIdColumnIndex = headerRow.indexOf(this.plateIdMapping);
const WellColumnIndex = headerRow.indexOf(this.wellMapping);

const sampleList = [];
for (let i = 1; i < this.importData.length; i++) {
const sampleId = this.importData[i][sampleUidColumnIndex];
const plateInfo = this.importData[i][PlateIdColumnIndex];
const wellInfo = this.importData[i][WellColumnIndex];

const sample = {
sampleBusinessKey: sampleId,
plateId: plateInfo,
well: wellInfo
};

sampleList.push(sample);
}
return sampleList;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export class SampleListService {
});
}

importPlateInfo(importData: any) {
return this.http.post(`${this.resourceUrl}/plate-information/import`, importData);
importPlateInfo(listId: number, sampleList: any) {
return this.http.patch(`${this.resourceUrl}/sampleList/${listId}/samples`, sampleList);
}

private convertArrayResponse(res: HttpResponse<SampleList[]>): HttpResponse<SampleList[]> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<div>
<h2>
<!--<span jhiTranslate="bmsjHipsterApp.sample.home.title">Samples</span>-->
<!-- <h2>
<span jhiTranslate="bmsjHipsterApp.sample.home.title">Samples</span>-->
<!--
<button class="btn btn-primary float-right jh-create-entity create-sample" [routerLink]="['/', { outlets: { popup: ['sample-new'] } }]">
<span class="fa fa-plus"></span>
<span class="hidden-sm-down" jhiTranslate="bmsjHipsterApp.sample.home.createLabel">
Create new Sample
</span>
</button>
-->
</h2>
</h2> -->
<!-- TODO SEARCH -->
<!--
<div class="row">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ describe('Component Tests', () => {
it('should proceed with import', () => {

spyOn(comp, 'validate').and.returnValue(true);
spyOn(comp, 'buildSampleList').and.returnValue([{
sampleBusinessKey: '3Z62SwmGyn3w3',
plateId: '1',
well: '1'
}]);

spyOn(comp, 'close').and.callThrough();
spyOn(eventManager, 'broadcast').and.callThrough();
spyOn(sampleListService, 'importPlateInfo').and.returnValue(Observable.of(''));
Expand Down Expand Up @@ -101,6 +107,12 @@ describe('Component Tests', () => {
});

spyOn(comp, 'validate').and.returnValue(true);
spyOn(comp, 'buildSampleList').and.returnValue([{
sampleBusinessKey: '3Z62SwmGyn3w3',
plateId: '1',
well: '1'
}]);

spyOn(comp, 'close').and.callThrough();
spyOn(eventManager, 'broadcast').and.callThrough();
spyOn(sampleListService, 'importPlateInfo').and.returnValue(Observable.throw(errorResponse));
Expand All @@ -127,6 +139,12 @@ describe('Component Tests', () => {
});

spyOn(comp, 'validate').and.returnValue(true);
spyOn(comp, 'buildSampleList').and.returnValue([{
sampleBusinessKey: '3Z62SwmGyn3w3',
plateId: '1',
well: '1'
}]);

spyOn(comp, 'close').and.callThrough();
spyOn(eventManager, 'broadcast').and.callThrough();
spyOn(sampleListService, 'importPlateInfo').and.returnValue(Observable.throw(errorResponse));
Expand Down

0 comments on commit 7e2f1b7

Please sign in to comment.