condition fix
This commit is contained in:
		@@ -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>
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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('') !== '') {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user