Added value converter to correctly display values
This commit is contained in:
parent
fa164b424c
commit
84ccb4df91
@ -103,6 +103,11 @@ export class SamplesComponent implements OnInit {
|
|||||||
sampleSelect = 0; // modes: 0 - no selection, 1 - sample edit selection, 2 - validation selection
|
sampleSelect = 0; // modes: 0 - no selection, 1 - sample edit selection, 2 - validation selection
|
||||||
loading = 0; // number of loading instances
|
loading = 0; // number of loading instances
|
||||||
|
|
||||||
|
valueConverters = {
|
||||||
|
added: (v: string, _sample) => new Date(v).toLocaleDateString(),
|
||||||
|
notes: v => v.sample_references.length > 0 ? Object.keys(v.sample_references).map(r => v.sample_references[r].relation).join(", ") : "",
|
||||||
|
'notes.comment': (v: any, sample: any) => sample['notes']['comment']
|
||||||
|
}
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private api: ApiService,
|
private api: ApiService,
|
||||||
@ -114,6 +119,7 @@ export class SamplesComponent implements OnInit {
|
|||||||
private window: Window,
|
private window: Window,
|
||||||
private router: Router
|
private router: Router
|
||||||
) {
|
) {
|
||||||
|
//this.valueConverters['notes.comment'] = v => console.log(v['comment']);
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
@ -440,7 +446,7 @@ export class SamplesComponent implements OnInit {
|
|||||||
.push(...Object.entries(measurement.values).filter(e => e[0] !== 'dpt')
|
.push(...Object.entries(measurement.values).filter(e => e[0] !== 'dpt')
|
||||||
.map(e => ({ name: this.ucFirst(name) + ' ' + e[0], value: e[1] })));
|
.map(e => ({ name: this.ucFirst(name) + ' ' + e[0], value: e[1] })));
|
||||||
});
|
});
|
||||||
new Promise(resolve => {
|
new Promise<void>(resolve => {
|
||||||
if (data.notes.sample_references.length) { // load referenced samples if available
|
if (data.notes.sample_references.length) { // load referenced samples if available
|
||||||
let loadingCounter = data.notes.sample_references.length;
|
let loadingCounter = data.notes.sample_references.length;
|
||||||
this.sampleDetailsSample.notes.sample_references.forEach(reference => {
|
this.sampleDetailsSample.notes.sample_references.forEach(reference => {
|
||||||
@ -532,7 +538,6 @@ export class SamplesComponent implements OnInit {
|
|||||||
refreshMultiSelect() {
|
refreshMultiSelect() {
|
||||||
for (let collection in this.categories) {
|
for (let collection in this.categories) {
|
||||||
this.categories[collection] = [...this.categories[collection]];
|
this.categories[collection] = [...this.categories[collection]];
|
||||||
console.log(this.categories[collection]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -543,11 +548,8 @@ export class SamplesComponent implements OnInit {
|
|||||||
let value = [];
|
let value = [];
|
||||||
this.activeKeys.forEach(key => {
|
this.activeKeys.forEach(key => {
|
||||||
let id = key.id.split('material.')[1];
|
let id = key.id.split('material.')[1];
|
||||||
if(id){
|
let tmpValue = id ? this.d.id.materials[sample.material_id][id] : sample[key.id];
|
||||||
value.push(this.d.id.materials[sample.material_id][id]);
|
value.push(this.valueConverters[key.id] ? this.valueConverters[key.id](tmpValue, sample) : tmpValue);
|
||||||
}else{
|
|
||||||
value.push(sample[key.id]);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
this.data.push({ id: sample._id, data: value });
|
this.data.push({ id: sample._id, data: value });
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user