2020-05-22 09:36:50 +02:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
2020-06-19 08:43:22 +02:00
|
|
|
import {ApiService} from '../services/api.service';
|
2020-05-22 09:36:50 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-samples',
|
|
|
|
templateUrl: './samples.component.html',
|
|
|
|
styleUrls: ['./samples.component.scss']
|
|
|
|
})
|
2020-05-22 12:52:17 +02:00
|
|
|
export class SamplesComponent implements OnInit { // TODO: implement paging
|
2020-05-22 09:36:50 +02:00
|
|
|
|
2020-05-22 12:52:17 +02:00
|
|
|
materials = {};
|
|
|
|
samples = [];
|
2020-06-19 08:43:22 +02:00
|
|
|
filters = {status: 'validated'};
|
2020-05-22 12:52:17 +02:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
private api: ApiService
|
|
|
|
) { }
|
2020-05-22 09:36:50 +02:00
|
|
|
|
|
|
|
ngOnInit(): void {
|
2020-06-19 08:43:22 +02:00
|
|
|
this.api.get('/materials?status=all', (mData: any) => {
|
2020-05-22 12:52:17 +02:00
|
|
|
this.materials = {};
|
|
|
|
mData.forEach(material => {
|
|
|
|
this.materials[material._id] = material;
|
|
|
|
});
|
2020-06-19 08:43:22 +02:00
|
|
|
this.loadSamples();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
loadSamples() {
|
|
|
|
this.api.get(`/samples?status=${this.filters.status}`, sData => {
|
|
|
|
this.samples = sData as any;
|
|
|
|
this.samples.forEach(sample => {
|
|
|
|
sample.material_number = this.materials[sample.material_id].numbers.find(e => sample.color === e.color).number;
|
2020-05-22 12:52:17 +02:00
|
|
|
});
|
|
|
|
});
|
2020-05-22 09:36:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|