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

View File

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