diff --git a/src/app/sample/sample.component.html b/src/app/sample/sample.component.html index 17c94f6..3448b5b 100644 --- a/src/app/sample/sample.component.html +++ b/src/app/sample/sample.component.html @@ -197,7 +197,8 @@
+ [(ngModel)]="sample.condition.condition_template" + (ngModelChange)="reValidate()"> @@ -213,7 +214,7 @@ Cannot be empty - @@ -332,3 +333,4 @@ Do you really want to delete {{samples.length > 1 ? 'these samples' : 'this sample'}}? + diff --git a/src/app/sample/sample.component.ts b/src/app/sample/sample.component.ts index 18046cf..9fa4ba0 100644 --- a/src/app/sample/sample.component.ts +++ b/src/app/sample/sample.component.ts @@ -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('/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('') !== '') {