condition fix

This commit is contained in:
VLE2FE 2020-08-27 15:45:52 +02:00
parent 04c2ff2678
commit 819666c344
2 changed files with 18 additions and 3 deletions

View File

@ -197,7 +197,8 @@
</h5>
<div *ngIf="sample.condition.condition_template" [@inOut]>
<rb-form-select [name]="'conditionSelect-' + gIndex" label="Condition"
[(ngModel)]="sample.condition.condition_template">
[(ngModel)]="sample.condition.condition_template"
(ngModelChange)="reValidate()">
<option [value]="sample.condition.condition_template">
{{d.id.conditionTemplates[sample.condition.condition_template].name}} - current
</option>
@ -213,7 +214,7 @@
<option *ngFor="let value of parameter.range.values" [value]="value">{{value}}</option>
<ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
</rb-form-select>
<rb-form-input *ngSwitchDefault
<rb-form-input *ngSwitchDefault (focus)="checkFormAfterInit = true"
[name]="'conditionParameter-' + gIndex + '-' + i"
[label]="parameter.name" appValidate="string" required
[(ngModel)]="sample.condition[parameter.name]" #parameterInput="ngModel">
@ -332,3 +333,4 @@
Do you really want to delete {{samples.length > 1 ? 'these samples' : 'this sample'}}?
</rb-alert>
</ng-template>

View File

@ -1,6 +1,7 @@
import cloneDeep from 'lodash/cloneDeep';
import merge from 'lodash/merge';
import omit from 'lodash/omit';
import pick from 'lodash/pick';
import isEqual from 'lodash/isEqual';
import strCompare from 'str-compare';
import {
@ -210,6 +211,7 @@ export class SampleComponent implements OnInit, AfterContentChecked {
}
});
}
this.checkFormAfterInit = true;
this.loading--;
sampleIds.slice(1).forEach(sampleId => {
this.api.get<SampleModel>('/sample/' + sampleId, data => {
@ -280,6 +282,7 @@ export class SampleComponent implements OnInit, AfterContentChecked {
}
if (formReady) { // fields are ready, do validation
this.checkFormAfterInit = false;
console.log('init');
Object.keys(this.cmForm.form.controls).forEach(field => {
this.cmForm.form.get(field).updateValueAndValidity();
});
@ -311,6 +314,10 @@ export class SampleComponent implements OnInit, AfterContentChecked {
}
}
reValidate() {
setTimeout(() => this.checkFormAfterInit = true, 0);
}
// save base sample
saveSample() {
if (this.samples.length === 0) {
@ -371,7 +378,13 @@ export class SampleComponent implements OnInit, AfterContentChecked {
cmSave() { // save measurements and conditions
this.samples.forEach(sample => {
if (sample.condition.condition_template) { // condition was set
this.api.put('/sample/' + sample._id, {condition: sample.condition});
console.log(sample.condition);
console.log(this.d.id.conditionTemplates[sample.condition.condition_template]);
this.api.put('/sample/' + sample._id,
{condition: pick(sample.condition,
['condition_template', ...this.d.id.conditionTemplates[sample.condition.condition_template].parameters.map(e => e.name)]
)}
);
}
sample.measurements.forEach(measurement => { // save measurements
if (Object.keys(measurement.values).map(e => measurement.values[e]).join('') !== '') {