Added value converter to correctly display values
This commit is contained in:
		@@ -76,7 +76,7 @@ export class SamplesComponent implements OnInit {
 | 
			
		||||
    { id: 'number', label: 'Number', active: true, sortable: true },
 | 
			
		||||
    { id: 'material.numbers', label: 'Material numbers', active: false, sortable: false },
 | 
			
		||||
    { 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: 'color', label: 'Color', active: false, 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
 | 
			
		||||
  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(
 | 
			
		||||
    private api: ApiService,
 | 
			
		||||
@@ -114,6 +119,7 @@ export class SamplesComponent implements OnInit {
 | 
			
		||||
    private window: Window,
 | 
			
		||||
    private router: Router
 | 
			
		||||
  ) {
 | 
			
		||||
    //this.valueConverters['notes.comment'] = v => console.log(v['comment']);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  ngOnInit(): void {
 | 
			
		||||
@@ -142,7 +148,7 @@ export class SamplesComponent implements OnInit {
 | 
			
		||||
    this.loadTemplateKeys('material', 'type', onLoad);
 | 
			
		||||
    this.loadTemplateKeys('condition', 'notes', onLoad);
 | 
			
		||||
    this.loadTemplateKeys('measurement', 'status', onLoad);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  loadTemplateKeys(collection, insertBefore, f) {
 | 
			
		||||
    this.d.load(collection + 'Templates', () => {
 | 
			
		||||
@@ -440,7 +446,7 @@ export class SamplesComponent implements OnInit {
 | 
			
		||||
          .push(...Object.entries(measurement.values).filter(e => e[0] !== 'dpt')
 | 
			
		||||
            .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
 | 
			
		||||
          let loadingCounter = data.notes.sample_references.length;
 | 
			
		||||
          this.sampleDetailsSample.notes.sample_references.forEach(reference => {
 | 
			
		||||
@@ -529,27 +535,23 @@ export class SamplesComponent implements OnInit {
 | 
			
		||||
    return string[0].toUpperCase() + string.slice(1);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  refreshMultiSelect(){
 | 
			
		||||
    for(let collection in this.categories){
 | 
			
		||||
     this.categories[collection] = [...this.categories[collection]];
 | 
			
		||||
     console.log(this.categories[collection]);
 | 
			
		||||
  refreshMultiSelect() {
 | 
			
		||||
    for (let collection in this.categories) {
 | 
			
		||||
      this.categories[collection] = [...this.categories[collection]];
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // stores data in a unified way
 | 
			
		||||
  storeData() {    
 | 
			
		||||
  storeData() {
 | 
			
		||||
    this.data = [];
 | 
			
		||||
    this.samples.forEach( sample =>{
 | 
			
		||||
      let value = [];   
 | 
			
		||||
      this.activeKeys.forEach( key =>{     
 | 
			
		||||
    this.samples.forEach(sample => {
 | 
			
		||||
      let value = [];
 | 
			
		||||
      this.activeKeys.forEach(key => {
 | 
			
		||||
        let id = key.id.split('material.')[1];
 | 
			
		||||
        if(id){
 | 
			
		||||
          value.push(this.d.id.materials[sample.material_id][id]);
 | 
			
		||||
        }else{
 | 
			
		||||
          value.push(sample[key.id]);
 | 
			
		||||
        }
 | 
			
		||||
        let tmpValue = id ? this.d.id.materials[sample.material_id][id] : sample[key.id];
 | 
			
		||||
        value.push(this.valueConverters[key.id] ? this.valueConverters[key.id](tmpValue, sample) : tmpValue);
 | 
			
		||||
      });
 | 
			
		||||
      this.data.push({id: sample._id, data: value});
 | 
			
		||||
      this.data.push({ id: sample._id, data: value });
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user