implemented icon buttons, array input, reformatting, minor sample component improvements
This commit is contained in:
@ -6,28 +6,48 @@
|
||||
<!--<form #sampleForm="ngForm">-->
|
||||
<div class="sample">
|
||||
<div>
|
||||
<rb-form-input name="materialname" label="material name" [rbFormInputAutocomplete]="autocomplete.bind(this, materialNames)" [rbDebounceTime]="0" [rbInitialOpen]="true" (keydown)="preventDefault($event)" (ngModelChange)="findMaterial($event)" appValidate="stringOf" [appValidateArgs]="[materialNames]" required [(ngModel)]="material.name" [autofocus]="true" ngModel>
|
||||
<rb-form-input name="materialname" label="material name" [rbDebounceTime]="0" [rbInitialOpen]="true"
|
||||
[rbFormInputAutocomplete]="autocomplete.bind(this, ac.materialNames)" appValidate="stringOf"
|
||||
(keydown)="preventDefault($event)" (ngModelChange)="findMaterial($event)" ngModel
|
||||
[appValidateArgs]="[ac.materialName]" required [(ngModel)]="material.name" [autofocus]="true">
|
||||
<ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
|
||||
<ng-template rbFormValidationMessage="failure">Unknown material, add properties for new material</ng-template>
|
||||
</rb-form-input>
|
||||
<button class="rb-btn rb-secondary" type="button" (click)="setNewMaterial(!newMaterial)"><span class="rb-ic rb-ic-add"></span> New material</button>
|
||||
<rb-icon-button icon="add" mode="secondary" (click)="setNewMaterial(!newMaterial)">New material</rb-icon-button>
|
||||
</div>
|
||||
|
||||
<div class="material shaded-container" *ngIf="newMaterial" [@inOut]>
|
||||
<h4>Material properties</h4>
|
||||
<rb-form-input name="supplier" label="supplier" [rbFormInputAutocomplete]="autocomplete.bind(this, suppliers)" [rbDebounceTime]="0" [rbInitialOpen]="true" appValidate="string" required [(ngModel)]="material.supplier" #supplierInput="ngModel">
|
||||
<rb-form-input name="supplier" label="supplier" [rbFormInputAutocomplete]="autocomplete.bind(this, ac.supplier)"
|
||||
[rbDebounceTime]="0" [rbInitialOpen]="true" appValidate="string" required
|
||||
[(ngModel)]="material.supplier" #supplierInput="ngModel"
|
||||
(focusout)="checkTypo('supplier', modalWarning)">
|
||||
<ng-template rbFormValidationMessage="failure">{{supplierInput.errors.failure}}</ng-template>
|
||||
</rb-form-input>
|
||||
<rb-form-input name="group" label="group" [rbFormInputAutocomplete]="autocomplete.bind(this, groups)" [rbDebounceTime]="0" [rbInitialOpen]="true" appValidate="string" required [(ngModel)]="material.group" #groupInput="ngModel">
|
||||
<rb-form-input name="group" label="group" [rbFormInputAutocomplete]="autocomplete.bind(this, ac.mgroup)"
|
||||
[rbDebounceTime]="0" [rbInitialOpen]="true" appValidate="string" required
|
||||
[(ngModel)]="material.group" #groupInput="ngModel"
|
||||
(focusout)="checkTypo('mgroup', modalWarning)">
|
||||
<ng-template rbFormValidationMessage="failure">{{groupInput.errors.failure}}</ng-template>
|
||||
</rb-form-input>
|
||||
<div class="material-numbers">
|
||||
<rb-form-input *ngFor="let ignore of [].constructor(material.numbers.length); index as i" label="material number" appValidate="string" [name]="'material.number-' + i" (keyup)="handleMaterialNumbers()" [(ngModel)]="material.numbers[i]" ngModel></rb-form-input>
|
||||
</div>
|
||||
<rb-form-select name="conditionSelect" label="Condition" (ngModelChange)="selectMaterialTemplate($event)" [ngModel]="material.properties.material_template">
|
||||
<ng-template #modalWarning>
|
||||
<rb-alert alertTitle="Warning" type="warning" okBtnLabel="Use suggestion" cancelBtnLabel="Keep value">
|
||||
The specified {{modalText.list}} could not be found in the list. <br>
|
||||
Did you mean {{modalText.suggestion}}?
|
||||
</rb-alert>
|
||||
</ng-template>
|
||||
<rb-array-input [(ngModel)]="material.numbers" name="materialNumbers" [pushTemplate]="''">
|
||||
<rb-form-input *rbArrayInputItem="let item" [rbArrayInputListener]="'materialNumber'" [index]="item.i"
|
||||
label="material number" appValidate="string" [name]="'materialNumber-' + item.i"
|
||||
[ngModel]="item.value"></rb-form-input>
|
||||
</rb-array-input>
|
||||
<rb-form-select name="conditionSelect" label="Condition" (ngModelChange)="selectMaterialTemplate($event)"
|
||||
[ngModel]="material.properties.material_template">
|
||||
<option *ngFor="let m of materialTemplates" [value]="m._id">{{m.name}}</option>
|
||||
</rb-form-select>
|
||||
<rb-form-input *ngFor="let parameter of materialTemplate.parameters; index as i" [name]="'materialParameter' + i" [label]="parameter.name" appValidate="string" required [(ngModel)]="material.properties[parameter.name]" #parameterInput="ngModel">
|
||||
<rb-form-input *ngFor="let parameter of materialTemplate.parameters; index as i" [name]="'materialParameter' + i"
|
||||
[label]="parameter.name" appValidate="string" required
|
||||
[(ngModel)]="material.properties[parameter.name]" #parameterInput="ngModel">
|
||||
<ng-template rbFormValidationMessage="failure">{{parameterInput.errors.failure}}</ng-template>
|
||||
<ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
|
||||
</rb-form-input>
|
||||
@ -36,11 +56,13 @@
|
||||
|
||||
|
||||
<div>
|
||||
<rb-form-input name="type" label="type" appValidate="string" required [(ngModel)]="sample.type" #typeInput="ngModel">
|
||||
<rb-form-input name="type" label="type" appValidate="string" required [(ngModel)]="sample.type"
|
||||
#typeInput="ngModel">
|
||||
<ng-template rbFormValidationMessage="failure">{{typeInput.errors.failure}}</ng-template>
|
||||
<ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
|
||||
</rb-form-input>
|
||||
<rb-form-input name="color" label="color" appValidate="string" required [(ngModel)]="sample.color" #colorInput="ngModel">
|
||||
<rb-form-input name="color" label="color" appValidate="string" required [(ngModel)]="sample.color"
|
||||
#colorInput="ngModel">
|
||||
<ng-template rbFormValidationMessage="failure">{{colorInput.errors.failure}}</ng-template>
|
||||
<ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
|
||||
</rb-form-input>
|
||||
@ -51,31 +73,43 @@
|
||||
</div>
|
||||
|
||||
<div class="notes">
|
||||
<rb-form-input name="comment" label="comment" appValidate="stringLength" [appValidateArgs]="[512]" [(ngModel)]="sample.notes.comment" #commentInput="ngModel">
|
||||
<rb-form-input name="comment" label="comment" appValidate="stringLength" [appValidateArgs]="[512]"
|
||||
[(ngModel)]="sample.notes.comment" #commentInput="ngModel">
|
||||
<ng-template rbFormValidationMessage="failure">{{commentInput.errors.failure}}</ng-template>
|
||||
</rb-form-input>
|
||||
<h5>Sample references</h5>
|
||||
<div *ngFor="let reference of sampleReferences; index as i" class="two-col" [@inOut]>
|
||||
<div>
|
||||
<rb-form-input [name]="'sr-id' + i" label="sample number" [rbFormInputAutocomplete]="sampleReferenceListBind()" [rbDebounceTime]="300" appValidate="stringOf" [appValidateArgs]="[sampleReferenceAutocomplete[i]]" (ngModelChange)="checkSampleReference($event, i)" [ngModel]="reference[0]" ngModel>
|
||||
<rb-form-input [name]="'sr-id' + i" label="sample number" [rbFormInputAutocomplete]="sampleReferenceListBind()"
|
||||
[rbDebounceTime]="300" appValidate="stringOf"
|
||||
[appValidateArgs]="[sampleReferenceAutocomplete[i]]"
|
||||
(ngModelChange)="checkSampleReference($event, i)" [ngModel]="reference[0]" ngModel>
|
||||
<ng-template rbFormValidationMessage="failure">Unknown sample number</ng-template>
|
||||
</rb-form-input>
|
||||
</div>
|
||||
<rb-form-input [name]="'sr-relation' + i" label="relation" appValidate="string" [required]="reference[0] !== ''" [(ngModel)]="reference[1]">
|
||||
<rb-form-input [name]="'sr-relation' + i" label="relation" appValidate="string" [required]="reference[0] !== ''"
|
||||
[(ngModel)]="reference[1]">
|
||||
<ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
|
||||
</rb-form-input>
|
||||
</div>
|
||||
<h5>Additional properties</h5>
|
||||
<div *ngFor="let field of customFields; index as i" class="two-col" [@inOut]>
|
||||
<div>
|
||||
<rb-form-input [name]="'cf-key' + i" label="key" [rbFormInputAutocomplete]="autocomplete.bind(this, availableCustomFields)" [rbDebounceTime]="0" [rbInitialOpen]="true" appValidate="unique" [appValidateArgs]="[uniqueCfValues(i)]" (ngModelChange)="adjustCustomFields($event, i)" [ngModel]="field[0]" #keyInput="ngModel">
|
||||
<ng-template rbFormValidationMessage="failure">{{keyInput.errors.failure}}</ng-template>
|
||||
<rb-array-input [(ngModel)]="customFields" name="customFields" [pushTemplate]="['', '']" pushPath="0"
|
||||
class="two-col" [@inOut]>
|
||||
<ng-container *rbArrayInputItem="let item">
|
||||
<div>
|
||||
<rb-form-input [name]="'cf-key' + item.i" label="key" [rbArrayInputListener]="'cf-key'" [index]="item.i"
|
||||
[rbFormInputAutocomplete]="autocomplete.bind(this, availableCustomFields)" [rbDebounceTime]="0"
|
||||
[rbInitialOpen]="true" appValidate="unique" [appValidateArgs]="[uniqueCfValues(item.i)]"
|
||||
[ngModel]="item.value[0]" #keyInput="ngModel">
|
||||
<ng-template rbFormValidationMessage="failure">{{keyInput.errors.failure}}</ng-template>
|
||||
</rb-form-input>
|
||||
</div>
|
||||
<rb-form-input [name]="'cf-value' + item.i" label="value" appValidate="string" [required]="item.value[0] !== ''"
|
||||
[ngModel]="item.value[1]">
|
||||
<ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
|
||||
</rb-form-input>
|
||||
</div>
|
||||
<rb-form-input [name]="'cf-value' + i" label="value" appValidate="string" [required]="field[0] !== ''" [(ngModel)]="field[1]">
|
||||
<ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
|
||||
</rb-form-input>
|
||||
</div>
|
||||
</ng-container>
|
||||
</rb-array-input>
|
||||
</div>
|
||||
|
||||
|
||||
@ -83,14 +117,18 @@
|
||||
<div class="conditions shaded-container">
|
||||
<h4>
|
||||
Condition
|
||||
<button class="rb-btn rb-secondary condition-set" type="button" (click)="toggleCondition()" [disabled]="!conditionTemplates">{{condition ? 'Do not set condition' : 'Set condition'}}</button>
|
||||
<button class="rb-btn rb-secondary condition-set" type="button" (click)="toggleCondition()"
|
||||
[disabled]="!conditionTemplates">{{condition ? 'Do not set condition' : 'Set condition'}}</button>
|
||||
</h4>
|
||||
<div *ngIf="condition" [@inOut]>
|
||||
<rb-form-select name="conditionSelect" label="Condition" (ngModelChange)="selectCondition($event)" [ngModel]="condition._id">
|
||||
<rb-form-select name="conditionSelect" label="Condition" (ngModelChange)="selectCondition($event)"
|
||||
[ngModel]="condition._id">
|
||||
<option *ngFor="let c of conditionTemplates" [value]="c._id">{{c.name}}</option>
|
||||
</rb-form-select>
|
||||
|
||||
<rb-form-input *ngFor="let parameter of condition.parameters; index as i" [name]="'conditionParameter' + i" [label]="parameter.name" appValidate="string" required [(ngModel)]="sample.condition[parameter.name]" #parameterInput="ngModel">
|
||||
<rb-form-input *ngFor="let parameter of condition.parameters; index as i" [name]="'conditionParameter' + i"
|
||||
[label]="parameter.name" appValidate="string" required
|
||||
[(ngModel)]="sample.condition[parameter.name]" #parameterInput="ngModel">
|
||||
<ng-template rbFormValidationMessage="failure">{{parameterInput.errors.failure}}</ng-template>
|
||||
<ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
|
||||
</rb-form-input>
|
||||
@ -102,16 +140,23 @@
|
||||
<div class="measurements shaded-container">
|
||||
<h4>Measurements</h4>
|
||||
<div *ngFor="let measurement of sample.measurements; index as mIndex" [@inOut]>
|
||||
<rb-form-select name="measurementTemplateSelect" label="Template" [(ngModel)]="measurement.measurement_template" (ngModelChange)="clearChart(mIndex)">
|
||||
<rb-form-select name="measurementTemplateSelect" label="Template" [(ngModel)]="measurement.measurement_template"
|
||||
(ngModelChange)="clearChart(mIndex)">
|
||||
<option *ngFor="let m of measurementTemplates" [value]="m._id">{{m.name}}</option>
|
||||
</rb-form-select>
|
||||
|
||||
<div *ngFor="let parameter of getMeasurementTemplate(measurement.measurement_template).parameters; index as pIndex">
|
||||
<rb-form-input *ngIf="!parameter.range.type" [name]="'measurementParameter' + mIndex + '-' + pIndex" [label]="parameter.name" appValidate="string" [(ngModel)]="measurement.values[parameter.name]" #parameterInput="ngModel">
|
||||
<div *ngFor="let parameter of getMeasurementTemplate(measurement.measurement_template).parameters;
|
||||
index as pIndex">
|
||||
<rb-form-input *ngIf="!parameter.range.type" [name]="'measurementParameter' + mIndex + '-' + pIndex"
|
||||
[label]="parameter.name" appValidate="string" [(ngModel)]="measurement.values[parameter.name]"
|
||||
#parameterInput="ngModel">
|
||||
<ng-template rbFormValidationMessage="failure">{{parameterInput.errors.failure}}</ng-template>
|
||||
<ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
|
||||
</rb-form-input>
|
||||
<rb-form-file *ngIf="parameter.range.type" [name]="'measurementParameter' + mIndex + '-' + pIndex" [label]="parameter.name" maxSize="10000000" (ngModelChange)="fileToArray($event, mIndex, parameter.name)" placeholder="Select file or drag and drop" dragDrop required ngModel>
|
||||
<rb-form-file *ngIf="parameter.range.type" [name]="'measurementParameter' + mIndex + '-' + pIndex"
|
||||
[label]="parameter.name" maxSize="10000000" multiple
|
||||
(ngModelChange)="fileToArray($event, mIndex, parameter.name)"
|
||||
placeholder="Select file or drag and drop" dragDrop required ngModel>
|
||||
<ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
|
||||
</rb-form-file>
|
||||
<canvas baseChart *ngIf="parameter.range.type && charts[mIndex][0].data.length > 0" class="dpt-chart" [@inOut]
|
||||
@ -122,20 +167,26 @@
|
||||
chartType="scatter">
|
||||
</canvas>
|
||||
</div>
|
||||
|
||||
<button class="rb-btn rb-danger" type="button" (click)="removeMeasurement(mIndex)"><span class="rb-ic rb-ic-delete"></span> Delete measurement</button>
|
||||
<rb-icon-button icon="delete" mode="danger" (click)="removeMeasurement(mIndex)"
|
||||
[disabled]="!measurementTemplates">
|
||||
Delete measurement
|
||||
</rb-icon-button>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div>
|
||||
<button class="rb-btn rb-secondary" type="button" (click)="addMeasurement()" [disabled]="!measurementTemplates"><span class="rb-ic rb-ic-add"></span> New measurement</button>
|
||||
<rb-icon-button icon="add" mode="secondary" (click)="addMeasurement()" [disabled]="!measurementTemplates">
|
||||
New measurement
|
||||
</rb-icon-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div>
|
||||
<button class="rb-btn rb-primary" type="submit" (click)="saveSample()" [disabled]="!sampleForm.form.valid">Save sample</button>
|
||||
<button class="rb-btn rb-primary" type="submit" (click)="saveSample()" [disabled]="!sampleForm.form.valid">
|
||||
Save sample
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// import { SampleComponent } from './sample.component';
|
||||
//
|
||||
// // TODO
|
||||
// // TODO: tests
|
||||
//
|
||||
// describe('SampleComponent', () => {
|
||||
// let component: SampleComponent;
|
||||
|
@ -1,8 +1,9 @@
|
||||
import _ from 'lodash';
|
||||
import strCompare from 'str-compare';
|
||||
import {
|
||||
AfterContentChecked,
|
||||
Component,
|
||||
OnInit,
|
||||
OnInit, TemplateRef,
|
||||
ViewChild
|
||||
} from '@angular/core';
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
@ -17,18 +18,14 @@ import {MeasurementModel} from '../models/measurement.model';
|
||||
import { ChartOptions } from 'chart.js';
|
||||
import {animate, style, transition, trigger} from '@angular/animations';
|
||||
import {Observable} from 'rxjs';
|
||||
import {ModalService} from '@inst-iot/bosch-angular-ui-components';
|
||||
import {UserModel} from '../models/user.model';
|
||||
|
||||
|
||||
// TODO: tests
|
||||
// TODO: confirmation for new group/supplier
|
||||
// TODO: work on better recognition for file input
|
||||
// TODO: only show condition (if not set) and measurements in edit sample dialog at first
|
||||
// TODO: multiple spectra
|
||||
// TODO: multiple samples for base data, extend multiple measurements, conditions
|
||||
|
||||
// TODO: material properties, color (in material and sample (not required))
|
||||
|
||||
// TODO: device autocomplete
|
||||
|
||||
@Component({
|
||||
selector: 'app-sample',
|
||||
templateUrl: './sample.component.html',
|
||||
@ -55,16 +52,18 @@ export class SampleComponent implements OnInit, AfterContentChecked {
|
||||
new; // true if new sample should be created
|
||||
newMaterial = false; // true if new material should be created
|
||||
materials: MaterialModel[] = []; // all materials
|
||||
suppliers: string[] = []; // all suppliers
|
||||
groups: string[] = []; // all groups
|
||||
ac: {[group: string]: string[]} = { // autocomplete data
|
||||
supplier: [],
|
||||
group: [],
|
||||
materialName: []
|
||||
};
|
||||
conditionTemplates: TemplateModel[]; // all conditions
|
||||
condition: TemplateModel | null = null; // selected condition
|
||||
materialTemplates: TemplateModel[]; // all material templates
|
||||
materialTemplate: TemplateModel | null = null; // selected material template
|
||||
materialNames = []; // names of all materials
|
||||
material = new MaterialModel(); // object of current selected material
|
||||
sample = new SampleModel();
|
||||
customFields: [string, string][] = [['', '']];
|
||||
customFields: [string, string][];
|
||||
sampleReferences: [string, string, string][] = [['', '', '']];
|
||||
sampleReferenceFinds: {_id: string, number: string}[] = []; // raw sample reference data from db
|
||||
currentSRIndex = 0; // index of last entered sample reference
|
||||
@ -74,7 +73,9 @@ export class SampleComponent implements OnInit, AfterContentChecked {
|
||||
measurementTemplates: TemplateModel[];
|
||||
loading = 0; // number of currently loading instances
|
||||
checkFormAfterInit = false;
|
||||
charts = []; // chart data for spectrums
|
||||
modalText = {list: '', suggestion: ''};
|
||||
charts = []; // chart data for spectra
|
||||
defaultDevice = '';
|
||||
readonly chartInit = [{
|
||||
data: [],
|
||||
label: 'Spectrum',
|
||||
@ -101,7 +102,8 @@ export class SampleComponent implements OnInit, AfterContentChecked {
|
||||
private route: ActivatedRoute,
|
||||
private api: ApiService,
|
||||
private validation: ValidationService,
|
||||
public autocomplete: AutocompleteService
|
||||
public autocomplete: AutocompleteService,
|
||||
private modal: ModalService
|
||||
) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
@ -109,15 +111,15 @@ export class SampleComponent implements OnInit, AfterContentChecked {
|
||||
this.loading = 7;
|
||||
this.api.get<MaterialModel[]>('/materials?status=all', (data: any) => {
|
||||
this.materials = data.map(e => new MaterialModel().deserialize(e));
|
||||
this.materialNames = data.map(e => e.name);
|
||||
this.ac.materialName = data.map(e => e.name);
|
||||
this.loading--;
|
||||
});
|
||||
this.api.get<string[]>('/material/suppliers', (data: any) => {
|
||||
this.suppliers = data;
|
||||
this.ac.supplier = data;
|
||||
this.loading--;
|
||||
});
|
||||
this.api.get<string[]>('/material/groups', (data: any) => {
|
||||
this.groups = data;
|
||||
this.ac.mgroup = data;
|
||||
this.loading--;
|
||||
});
|
||||
this.api.get<TemplateModel[]>('/template/conditions', data => {
|
||||
@ -129,6 +131,9 @@ export class SampleComponent implements OnInit, AfterContentChecked {
|
||||
this.selectMaterialTemplate(this.materialTemplates[0]._id);
|
||||
this.loading--;
|
||||
});
|
||||
this.api.get<UserModel>('/user', data => {
|
||||
this.defaultDevice = data.device_name;
|
||||
});
|
||||
this.api.get<TemplateModel[]>('/template/measurements', data => {
|
||||
this.measurementTemplates = data.map(e => new TemplateModel().deserialize(e));
|
||||
if (!this.new) {
|
||||
@ -149,7 +154,8 @@ export class SampleComponent implements OnInit, AfterContentChecked {
|
||||
}
|
||||
});
|
||||
this.material = sData.material;
|
||||
this.customFields = this.sample.notes.custom_fields && this.sample.notes.custom_fields !== {} ? Object.keys(this.sample.notes.custom_fields).map(e => [e, this.sample.notes.custom_fields[e]]) : [['', '']];
|
||||
this.customFields = this.sample.notes.custom_fields && this.sample.notes.custom_fields !== {} ?
|
||||
Object.keys(this.sample.notes.custom_fields).map(e => [e, this.sample.notes.custom_fields[e]]) : [['', '']];
|
||||
if (this.sample.notes.sample_references.length) {
|
||||
this.sampleReferences = [];
|
||||
this.sampleReferenceAutocomplete = [];
|
||||
@ -185,7 +191,8 @@ export class SampleComponent implements OnInit, AfterContentChecked {
|
||||
|
||||
ngAfterContentChecked() {
|
||||
// attach validators to dynamic condition fields when all values are available and template was fully created
|
||||
if (this.condition && this.condition.hasOwnProperty('parameters') && this.condition.parameters.length > 0 && this.condition.parameters[0].hasOwnProperty('range') && this.sampleForm && this.sampleForm.form.get('conditionParameter0')) {
|
||||
if (this.condition && this.condition.hasOwnProperty('parameters') && this.condition.parameters.length > 0 &&
|
||||
this.condition.parameters[0].hasOwnProperty('range') && this.sampleForm && this.sampleForm.form.get('conditionParameter0')) {
|
||||
for (const i in this.condition.parameters) {
|
||||
if (this.condition.parameters[i]) {
|
||||
this.attachValidator('conditionParameter' + i, this.condition.parameters[i].range, true);
|
||||
@ -194,7 +201,8 @@ export class SampleComponent implements OnInit, AfterContentChecked {
|
||||
}
|
||||
|
||||
// attach validators to dynamic material fields when all values are available and template was fully created
|
||||
if (this.materialTemplate && this.materialTemplate.hasOwnProperty('parameters') && this.materialTemplate.parameters.length > 0 && this.materialTemplate.parameters[0].hasOwnProperty('range') && this.sampleForm && this.sampleForm.form.get('materialParameter0')) {
|
||||
if (this.materialTemplate && this.materialTemplate.hasOwnProperty('parameters') && this.materialTemplate.parameters.length > 0 &&
|
||||
this.materialTemplate.parameters[0].hasOwnProperty('range') && this.sampleForm && this.sampleForm.form.get('materialParameter0')) {
|
||||
for (const i in this.materialTemplate.parameters) {
|
||||
if (this.materialTemplate.parameters[i]) {
|
||||
this.attachValidator('materialParameter' + i, this.materialTemplate.parameters[i].range, true);
|
||||
@ -250,7 +258,6 @@ export class SampleComponent implements OnInit, AfterContentChecked {
|
||||
saveSample() {
|
||||
new Promise<void>(resolve => {
|
||||
if (this.newMaterial) { // save material first if new one exists
|
||||
this.material.numbers = this.material.numbers.filter(e => e !== '');
|
||||
this.api.post<MaterialModel>('/material/new', this.material.sendFormat(), data => {
|
||||
this.materials.push(data); // add material to data
|
||||
this.material = data;
|
||||
@ -268,7 +275,9 @@ export class SampleComponent implements OnInit, AfterContentChecked {
|
||||
this.sample.notes.custom_fields[element[0]] = element[1];
|
||||
}
|
||||
});
|
||||
this.sample.notes.sample_references = this.sampleReferences.filter(e => e[0] && e[1] && e[2]).map(e => ({sample_id: e[2], relation: e[1]}));
|
||||
this.sample.notes.sample_references = this.sampleReferences
|
||||
.filter(e => e[0] && e[1] && e[2])
|
||||
.map(e => ({sample_id: e[2], relation: e[1]}));
|
||||
new Promise<SampleModel>(resolve => {
|
||||
if (this.new) {
|
||||
this.api.post<SampleModel>('/sample/new', this.sample.sendFormat(), resolve);
|
||||
@ -289,7 +298,8 @@ export class SampleComponent implements OnInit, AfterContentChecked {
|
||||
this.api.post<MeasurementModel>('/measurement/new', measurement.sendFormat());
|
||||
}
|
||||
else { // update measurement
|
||||
this.api.put<MeasurementModel>('/measurement/' + measurement._id, measurement.sendFormat(['sample_id', 'measurement_template']));
|
||||
this.api.put<MeasurementModel>('/measurement/' + measurement._id,
|
||||
measurement.sendFormat(['sample_id', 'measurement_template']));
|
||||
}
|
||||
}
|
||||
else if (measurement._id !== null) { // existing measurement was left empty to delete
|
||||
@ -321,7 +331,6 @@ export class SampleComponent implements OnInit, AfterContentChecked {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: rework later
|
||||
setNewMaterial(value = null) {
|
||||
if (value === null) {
|
||||
this.newMaterial = !this.sample.material_id;
|
||||
@ -333,24 +342,12 @@ export class SampleComponent implements OnInit, AfterContentChecked {
|
||||
this.sampleForm.form.get('materialname').setValidators([Validators.required]);
|
||||
}
|
||||
else {
|
||||
this.sampleForm.form.get('materialname').setValidators([Validators.required, this.validation.generate('stringOf', [this.materialNames])]);
|
||||
this.sampleForm.form.get('materialname')
|
||||
.setValidators([Validators.required, this.validation.generate('stringOf', [this.ac.materialName])]);
|
||||
}
|
||||
this.sampleForm.form.get('materialname').updateValueAndValidity();
|
||||
}
|
||||
|
||||
handleMaterialNumbers() {
|
||||
const fieldNo = this.material.numbers.length;
|
||||
const filledFields = this.material.numbers.filter(e => e !== '').length;
|
||||
// append new field
|
||||
if (filledFields === fieldNo) {
|
||||
this.material.numbers.push('');
|
||||
}
|
||||
// remove if two end fields are empty
|
||||
if (fieldNo > 1 && this.material.numbers[fieldNo - 1] === '' && this.material.numbers[fieldNo - 2] === '') {
|
||||
this.material.numbers.pop();
|
||||
}
|
||||
}
|
||||
|
||||
selectCondition(id) {
|
||||
this.condition = this.conditionTemplates.find(e => e._id === id);
|
||||
console.log(this.condition);
|
||||
@ -372,7 +369,8 @@ export class SampleComponent implements OnInit, AfterContentChecked {
|
||||
}
|
||||
|
||||
addMeasurement() {
|
||||
this.sample.measurements.push(new MeasurementModel(this.measurementTemplates[0]._id));
|
||||
this.sample.measurements.push(new MeasurementModel(this.measurementTemplates.filter(e => e.name === 'spectrum').reverse()[0]._id));
|
||||
this.sample.measurements[this.sample.measurements.length - 1].values.device = this.defaultDevice;
|
||||
this.charts.push(_.cloneDeep(this.chartInit));
|
||||
}
|
||||
|
||||
@ -389,12 +387,22 @@ export class SampleComponent implements OnInit, AfterContentChecked {
|
||||
}
|
||||
|
||||
fileToArray(files, mIndex, parameter) {
|
||||
const fileReader = new FileReader();
|
||||
fileReader.onload = () => {
|
||||
this.sample.measurements[mIndex].values[parameter] = fileReader.result.toString().split('\r\n').map(e => e.split(','));
|
||||
this.generateChart(this.sample.measurements[mIndex].values[parameter], mIndex);
|
||||
};
|
||||
fileReader.readAsText(files[0]);
|
||||
for (const i in files) {
|
||||
if (files.hasOwnProperty(i)) {
|
||||
const fileReader = new FileReader();
|
||||
fileReader.onload = () => {
|
||||
let index: number = mIndex;
|
||||
if (Number(i) > 0) { // append further spectra
|
||||
this.addMeasurement();
|
||||
index = this.sample.measurements.length - 1;
|
||||
}
|
||||
this.sample.measurements[index].values[parameter] =
|
||||
fileReader.result.toString().split('\r\n').map(e => e.split(','));
|
||||
this.generateChart(this.sample.measurements[index].values[parameter], index);
|
||||
};
|
||||
fileReader.readAsText(files[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
generateChart(spectrum, index) {
|
||||
@ -411,22 +419,17 @@ export class SampleComponent implements OnInit, AfterContentChecked {
|
||||
}
|
||||
}
|
||||
|
||||
adjustCustomFields(value, index) {
|
||||
this.customFields[index][0] = value;
|
||||
const fieldNo = this.customFields.length;
|
||||
let filledFields = 0;
|
||||
this.customFields.forEach(field => {
|
||||
if (field[0] !== '') {
|
||||
filledFields ++;
|
||||
}
|
||||
});
|
||||
// append new field
|
||||
if (filledFields === fieldNo) {
|
||||
this.customFields.push(['', '']);
|
||||
}
|
||||
// remove if two end fields are empty
|
||||
if (fieldNo > 1 && this.customFields[fieldNo - 1][0] === '' && this.customFields[fieldNo - 2][0] === '') {
|
||||
this.customFields.pop();
|
||||
checkTypo(list, modal: TemplateRef<any>) {
|
||||
if (this.ac[list].indexOf(this.material[list]) < 0) { // entry is not in lise
|
||||
this.modalText.list = list;
|
||||
this.modalText.suggestion = this.ac[list] // find possible entry from list
|
||||
.map(e => ({v: e, s: strCompare.sorensenDice(e, this.material[list])}))
|
||||
.sort((a, b) => b.s - a.s)[0].v;
|
||||
this.modal.open(modal).then(result => {
|
||||
if (result) { // use suggestion
|
||||
this.material[list] = this.modalText.suggestion;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -457,7 +460,9 @@ export class SampleComponent implements OnInit, AfterContentChecked {
|
||||
|
||||
sampleReferenceList(value) {
|
||||
return new Observable(observer => {
|
||||
this.api.get<{_id: string, number: string}[]>('/samples?status=all&page-size=25&sort=number-asc&fields[]=number&fields[]=_id&filters[]=%7B%22mode%22%3A%22stringin%22%2C%22field%22%3A%22number%22%2C%22values%22%3A%5B%22' + value + '%22%5D%7D', data => {
|
||||
this.api.get<{_id: string, number: string}[]>(
|
||||
'/samples?status=all&page-size=25&sort=number-asc&fields[]=number&fields[]=_id&' +
|
||||
'filters[]=%7B%22mode%22%3A%22stringin%22%2C%22field%22%3A%22number%22%2C%22values%22%3A%5B%22' + value + '%22%5D%7D', data => {
|
||||
console.log(data);
|
||||
this.sampleReferenceAutocomplete[this.currentSRIndex] = data.map(e => e.number);
|
||||
this.sampleReferenceFinds = data;
|
||||
@ -483,12 +488,14 @@ export class SampleComponent implements OnInit, AfterContentChecked {
|
||||
}
|
||||
|
||||
uniqueCfValues(index) { // returns all names until index for unique check
|
||||
return this.customFields.slice(0, index).map(e => e[0]);
|
||||
return this.customFields ? this.customFields.slice(0, index).map(e => e[0]) : [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 1. ngAfterViewInit wird ja jedes mal nach einem ngOnChanges aufgerufen, also zB wenn sich dein ngFor aufbaut. Du könntest also in der Methode prüfen, ob die Daten schon da sind und dann dementsprechend handeln. Das wäre die Eleganteste Variante
|
||||
// 1. ngAfterViewInit wird ja jedes mal nach einem ngOnChanges aufgerufen, also zB wenn sich dein ngFor aufbaut. Du könntest also in der
|
||||
// Methode prüfen, ob die Daten schon da sind und dann dementsprechend handeln. Das wäre die Eleganteste Variante
|
||||
// 2. Der state "dirty" soll eigentlich anzeigen, wenn ein Form-Field vom User geändert wurde; damit missbrauchst du es hier etwas
|
||||
// 3. Die Dirty-Variante: Pack in deine ngFor ein {{ onFirstLoad(data) }} rein, das einfach ausgeführt wird. müsstest dann natürlich abfangen, dass das nicht nach jedem view-cycle neu getriggert wird. Schön ist das nicht, aber besser als mit Timeouts^^
|
||||
// 3. Die Dirty-Variante: Pack in deine ngFor ein {{ onFirstLoad(data) }} rein, das einfach ausgeführt wird. müsstest dann natürlich
|
||||
// abfangen, dass das nicht nach jedem view-cycle neu getriggert wird. Schön ist das nicht, aber besser als mit Timeouts^^
|
||||
|
Reference in New Issue
Block a user