Added value converter to correctly display values
This commit is contained in:
parent
fa164b424c
commit
84ccb4df91
@ -76,7 +76,7 @@ export class SamplesComponent implements OnInit {
|
|||||||
{ id: 'number', label: 'Number', active: true, sortable: true },
|
{ id: 'number', label: 'Number', active: true, sortable: true },
|
||||||
{ id: 'material.numbers', label: 'Material numbers', active: false, sortable: false },
|
{ id: 'material.numbers', label: 'Material numbers', active: false, sortable: false },
|
||||||
{ id: 'material.supplier', label: 'Supplier', active: false, sortable: true },
|
{ id: 'material.supplier', label: 'Supplier', active: false, sortable: true },
|
||||||
{ id: 'material.group', label: 'Material', active: true, sortable: true},
|
{ id: 'material.group', label: 'Material', active: true, sortable: true },
|
||||||
{ id: 'type', label: 'Type', active: true, sortable: true },
|
{ id: 'type', label: 'Type', active: true, sortable: true },
|
||||||
{ id: 'color', label: 'Color', active: false, sortable: true },
|
{ id: 'color', label: 'Color', active: false, sortable: true },
|
||||||
{ id: 'batch', label: 'Batch', active: true, sortable: true },
|
{ id: 'batch', label: 'Batch', active: true, sortable: true },
|
||||||
@ -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 => {
|
||||||
@ -529,27 +535,23 @@ export class SamplesComponent implements OnInit {
|
|||||||
return string[0].toUpperCase() + string.slice(1);
|
return string[0].toUpperCase() + string.slice(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
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]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// stores data in a unified way
|
// stores data in a unified way
|
||||||
storeData() {
|
storeData() {
|
||||||
this.data = [];
|
this.data = [];
|
||||||
this.samples.forEach( sample =>{
|
this.samples.forEach(sample => {
|
||||||
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