first version of sample.component finished

This commit is contained in:
VLE2FE
2020-06-19 08:43:22 +02:00
parent 60298e53a5
commit 0d77113704
53 changed files with 1336 additions and 275 deletions

View File

@ -0,0 +1,7 @@
import { CustomFieldsModel } from './custom-fields.model';
describe('CustomFieldsModel', () => {
it('should create an instance', () => {
expect(new CustomFieldsModel()).toBeTruthy();
});
});

View File

@ -0,0 +1,13 @@
import {Deserializable} from './deserializable.model';
// TODO: put all deserialize methods in one place
export class CustomFieldsModel implements Deserializable{
name = '';
qty = 0;
deserialize(input: any): this {
Object.assign(this, input);
return this;
}
}

View File

@ -0,0 +1,5 @@
// import { DeserializableModel } from './deserializable.model';
//
// describe('DeserializableModel', () => {
//
// });

View File

@ -0,0 +1,3 @@
export interface Deserializable {
deserialize(input: any): this;
}

View File

@ -0,0 +1,5 @@
import { IdModel } from './id.model';
describe('IdModel', () => {
});

View File

@ -0,0 +1 @@
export type IdModel = string | null;

View File

@ -0,0 +1,7 @@
import { MaterialModel } from './material.model';
describe('MaterialModel', () => {
it('should create an instance', () => {
expect(new MaterialModel()).toBeTruthy();
});
});

View File

@ -0,0 +1,33 @@
import _ from 'lodash';
import {Deserializable} from './deserializable.model';
import {IdModel} from './id.model';
import {SendFormat} from './sendformat.model';
export class MaterialModel implements Deserializable, SendFormat {
_id: IdModel = null;
name = '';
supplier = '';
group = '';
mineral = 0;
glass_fiber = 0;
carbon_fiber = 0;
private numberTemplate = {color: '', number: ''};
numbers: {color: string, number: string}[] = [_.cloneDeep(this.numberTemplate)];
deserialize(input: any): this {
Object.assign(this, input);
return this;
}
sendFormat() {
return _.pick(this, ['name', 'supplier', 'group', 'mineral', 'glass_fiber', 'carbon_fiber', 'numbers']);
}
addNumber() {
this.numbers.push(_.cloneDeep(this.numberTemplate));
}
popNumber() {
this.numbers.pop();
}
}

View File

@ -0,0 +1,7 @@
import { MeasurementModel } from './measurement.model';
describe('MeasurementModel', () => {
it('should create an instance', () => {
expect(new MeasurementModel()).toBeTruthy();
});
});

View File

@ -0,0 +1,29 @@
import _ from 'lodash';
import {IdModel} from './id.model';
import {SendFormat} from './sendformat.model';
import {Deserializable} from './deserializable.model';
export class MeasurementModel implements Deserializable, SendFormat{
_id: IdModel = null;
sample_id: IdModel = null;
measurement_template: IdModel;
values: {[prop: string]: any} = {};
constructor(measurementTemplate: IdModel = null) {
this.measurement_template = measurementTemplate;
}
deserialize(input: any): this {
Object.assign(this, input);
Object.keys(this.values).forEach(key => {
if (this.values[key] === null) {
this.values[key] = '';
}
});
return this;
}
sendFormat(omit = []) {
return _.omit(_.pick(this, ['sample_id', 'measurement_template', 'values']), omit);
}
}

View File

@ -0,0 +1,7 @@
import { SampleModel } from './sample.model';
describe('SampleModel', () => {
it('should create an instance', () => {
expect(new SampleModel()).toBeTruthy();
});
});

View File

@ -0,0 +1,37 @@
import _ from 'lodash';
import {Deserializable} from './deserializable.model';
import {IdModel} from './id.model';
import {SendFormat} from './sendformat.model';
import {MaterialModel} from './material.model';
import {MeasurementModel} from './measurement.model';
export class SampleModel implements Deserializable, SendFormat {
_id: IdModel = null;
color = '';
number = '';
type = '';
batch = '';
condition: {condition_template: string, [prop: string]: string} | {} = {};
material_id: IdModel = null;
material: MaterialModel;
measurements: MeasurementModel[];
note_id: IdModel = null;
user_id: IdModel = null;
notes: {comment: string, sample_references: {sample_id: IdModel, relation: string}[], custom_fields: {[prop: string]: string}} = {comment: '', sample_references: [], custom_fields: {}};
deserialize(input: any): this {
Object.assign(this, input);
if (input.hasOwnProperty('material')) {
this.material = new MaterialModel().deserialize(input.material);
this.material_id = input.material._id;
}
if (input.hasOwnProperty('measurements')) {
this.measurements = input.measurements.map(e => new MeasurementModel().deserialize(e));
}
return this;
}
sendFormat() {
return _.pick(this, ['color', 'type', 'batch', 'condition', 'material_id', 'notes']);
}
}

View File

@ -0,0 +1,5 @@
// import { SendformatModel } from './sendformat.model';
//
// describe('SendformatModel', () => {
//
// });

View File

@ -0,0 +1,3 @@
export interface SendFormat {
sendFormat(omit?: string[]): {[prop: string]: any};
}

View File

@ -0,0 +1,7 @@
import { TemplateModel } from './template.model';
describe('TemplateModel', () => {
it('should create an instance', () => {
expect(new TemplateModel()).toBeTruthy();
});
});

View File

@ -0,0 +1,14 @@
import {Deserializable} from './deserializable.model';
import {IdModel} from './id.model';
export class TemplateModel implements Deserializable{
_id: IdModel = null;
name = '';
version = 1;
parameters: {name: string, range: {[prop: string]: any}}[] = [];
deserialize(input: any): this {
Object.assign(this, input);
return this;
}
}