added batch edit
This commit is contained in:
		@@ -36,7 +36,6 @@ export class AppComponent implements OnInit{
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  ngOnInit() {
 | 
					  ngOnInit() {
 | 
				
			||||||
    this.login.login().then(res => {
 | 
					    this.login.login().then(res => {
 | 
				
			||||||
      console.log(res);
 | 
					 | 
				
			||||||
      if (!res) {
 | 
					      if (!res) {
 | 
				
			||||||
        this.router.navigate(['/']);
 | 
					        this.router.navigate(['/']);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,6 +8,7 @@ export class MeasurementModel extends BaseModel {
 | 
				
			|||||||
  sample_id: IdModel = null;
 | 
					  sample_id: IdModel = null;
 | 
				
			||||||
  measurement_template: IdModel;
 | 
					  measurement_template: IdModel;
 | 
				
			||||||
  values: {[prop: string]: any} = {};
 | 
					  values: {[prop: string]: any} = {};
 | 
				
			||||||
 | 
					  status = '';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  constructor(measurementTemplate: IdModel = null) {
 | 
					  constructor(measurementTemplate: IdModel = null) {
 | 
				
			||||||
    super();
 | 
					    super();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,7 +17,7 @@ export class SampleModel extends BaseModel {
 | 
				
			|||||||
  measurements: MeasurementModel[] = [];
 | 
					  measurements: MeasurementModel[] = [];
 | 
				
			||||||
  note_id: IdModel = null;
 | 
					  note_id: IdModel = null;
 | 
				
			||||||
  user_id: IdModel = null;
 | 
					  user_id: IdModel = null;
 | 
				
			||||||
  validate = false;
 | 
					  selected = false;
 | 
				
			||||||
  notes: {
 | 
					  notes: {
 | 
				
			||||||
    comment: string,
 | 
					    comment: string,
 | 
				
			||||||
    sample_references: {sample_id: IdModel, relation: string}[],
 | 
					    sample_references: {sample_id: IdModel, relation: string}[],
 | 
				
			||||||
@@ -42,7 +42,16 @@ export class SampleModel extends BaseModel {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  sendFormat() {
 | 
					  sendFormat() {
 | 
				
			||||||
    return pick(this.conditionTemplateCheck(), ['color', 'type', 'batch', 'condition', 'material_id', 'notes']);
 | 
					    const tmp = pick(this.conditionTemplateCheck(), ['color', 'type', 'batch', 'condition', 'material_id', 'notes']);
 | 
				
			||||||
 | 
					    Object.keys(tmp).forEach(key => {
 | 
				
			||||||
 | 
					      if (tmp[key] === undefined) {
 | 
				
			||||||
 | 
					        delete tmp[key];
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    if (this.material && this.material.name === undefined) {
 | 
				
			||||||
 | 
					      delete tmp.material_id;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return tmp;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private conditionTemplateCheck() {
 | 
					  private conditionTemplateCheck() {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -44,9 +44,13 @@
 | 
				
			|||||||
    <ng-template #placeholder><div></div></ng-template>
 | 
					    <ng-template #placeholder><div></div></ng-template>
 | 
				
			||||||
  </ng-template>
 | 
					  </ng-template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <rb-form-checkbox name="multiple-samples" [(ngModel)]="multipleSamples">
 | 
					  <div>
 | 
				
			||||||
    multiple samples
 | 
					    Prediction of:
 | 
				
			||||||
  </rb-form-checkbox>
 | 
					    <rb-form-radio name="multiple-samples" label="Single sample" [(ngModel)]="multipleSamples" [value]="false">
 | 
				
			||||||
 | 
					    </rb-form-radio>
 | 
				
			||||||
 | 
					    <rb-form-radio name="multiple-samples" label="Multiple samples" [(ngModel)]="multipleSamples" [value]="true">
 | 
				
			||||||
 | 
					    </rb-form-radio>
 | 
				
			||||||
 | 
					  </div>
 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<div class="dpt-chart">
 | 
					<div class="dpt-chart">
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -129,13 +129,38 @@ export class RbArrayInputComponent implements ControlValueAccessor, OnInit, Afte
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  writeValue(obj: any) {  // add empty value on init
 | 
					  writeValue(obj: any) {  // add empty value on init
 | 
				
			||||||
    this.values = obj ? obj : [];
 | 
					    if (obj) {
 | 
				
			||||||
    if (this.values.length === 0 || this.values[0] !== '') {
 | 
					 | 
				
			||||||
      // add empty last field if pushTemplate is specified
 | 
					 | 
				
			||||||
      if (this.pushTemplate !== null) {
 | 
					      if (this.pushTemplate !== null) {
 | 
				
			||||||
        this.values.push(cloneDeep(this.pushTemplate));
 | 
					        this.values = [...obj.filter(e => e[this.pushPath] !== ''), cloneDeep(this.pushTemplate)];
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      else {
 | 
				
			||||||
 | 
					        this.values = obj;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    else {
 | 
				
			||||||
 | 
					      if (this.pushTemplate !== null) {
 | 
				
			||||||
 | 
					        this.values = [cloneDeep(this.pushTemplate)];
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      else {
 | 
				
			||||||
 | 
					        this.values = [''];
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    // this.values = obj ? obj : [];
 | 
				
			||||||
 | 
					    // console.log('-----');
 | 
				
			||||||
 | 
					    // console.log(obj);
 | 
				
			||||||
 | 
					    // console.log(this.pushPath);
 | 
				
			||||||
 | 
					    // if (this.values && this.values.length) {
 | 
				
			||||||
 | 
					    //   this.values = obj.filter(e => this.pushPath ? e[this.pushPath] !== '' : e !== '');
 | 
				
			||||||
 | 
					    // }
 | 
				
			||||||
 | 
					    // console.log(this.values);
 | 
				
			||||||
 | 
					    // // console.log(obj.filter(e => this.pushPath ? e[this.pushPath] !== '' : e !== ''));
 | 
				
			||||||
 | 
					    // // this.values = obj ? obj.filter(e => this.pushPath ? e[this.pushPath] !== '' : e !== '') : [];
 | 
				
			||||||
 | 
					    // if (this.values.length === 0 || this.values[0] !== '') {
 | 
				
			||||||
 | 
					    //   // add empty last field if pushTemplate is specified
 | 
				
			||||||
 | 
					    //   if (this.pushTemplate !== null) {
 | 
				
			||||||
 | 
					    //     this.values.push(cloneDeep(this.pushTemplate));
 | 
				
			||||||
 | 
					    //   }
 | 
				
			||||||
 | 
					    // }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  registerOnChange(fn: any) {
 | 
					  registerOnChange(fn: any) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,263 +1,324 @@
 | 
				
			|||||||
<h2>{{new ? 'Add new sample' : 'Edit sample ' + sample.number}}</h2>
 | 
					<h2>{{mode === 'new' ? 'Add new sample' : 'Edit sample '}}</h2>
 | 
				
			||||||
 | 
					<!--TODO: title-->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<rb-loading-spinner *ngIf="loading"></rb-loading-spinner>
 | 
					<rb-loading-spinner *ngIf="loading; else content"></rb-loading-spinner>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<form #sampleForm="ngForm" *ngIf="(!generatedSamples.length || editSampleBase) && !loading">
 | 
					<ng-template #content>
 | 
				
			||||||
  <div class="sample">
 | 
					 | 
				
			||||||
    <div>
 | 
					 | 
				
			||||||
      <rb-form-input name="materialname" label="material name" [rbDebounceTime]="0" [rbInitialOpen]="true"
 | 
					 | 
				
			||||||
                     [rbFormInputAutocomplete]="autocomplete.bind(this, materialNames)" appValidate="stringOf"
 | 
					 | 
				
			||||||
                     (keydown)="preventDefault($event)" (ngModelChange)="findMaterial($event)" ngModel
 | 
					 | 
				
			||||||
                     [appValidateArgs]="[materialNames]" required [(ngModel)]="material.name" [autofocus]="true"
 | 
					 | 
				
			||||||
                     title="trade name of the material, eg. Ultradur B4300 G6">
 | 
					 | 
				
			||||||
        <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>
 | 
					 | 
				
			||||||
      <rb-icon-button class="set-new-material space-below" icon="add" mode="secondary"
 | 
					 | 
				
			||||||
                      (click)="setNewMaterial(!newMaterial)">New material</rb-icon-button>
 | 
					 | 
				
			||||||
    </div>
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <div class="material shaded-container" *ngIf="newMaterial" [@inOut]>
 | 
					<!--BASE-->
 | 
				
			||||||
      <h4>Material properties</h4>
 | 
					 | 
				
			||||||
      <rb-form-input name="supplier" label="supplier"
 | 
					 | 
				
			||||||
                     [rbFormInputAutocomplete]="autocomplete.bind(this, d.arr.materialSuppliers)"
 | 
					 | 
				
			||||||
                     [rbDebounceTime]="0" [rbInitialOpen]="true" appValidate="string" required
 | 
					 | 
				
			||||||
                     [(ngModel)]="material.supplier" #supplierInput="ngModel"
 | 
					 | 
				
			||||||
                     (focusout)="checkTypo($event, 'materialSuppliers', 'supplier', modalWarning)"
 | 
					 | 
				
			||||||
                     title="material supplier, eg. BASF">
 | 
					 | 
				
			||||||
        <ng-template rbFormValidationMessage="failure">{{supplierInput.errors.failure}}</ng-template>
 | 
					 | 
				
			||||||
      </rb-form-input>
 | 
					 | 
				
			||||||
      <rb-form-input name="group" label="group"
 | 
					 | 
				
			||||||
                     [rbFormInputAutocomplete]="autocomplete.bind(this, d.arr.materialGroups)"
 | 
					 | 
				
			||||||
                     [rbDebounceTime]="0" [rbInitialOpen]="true" appValidate="string" required
 | 
					 | 
				
			||||||
                     [(ngModel)]="material.group" #groupInput="ngModel"
 | 
					 | 
				
			||||||
                     (focusout)="checkTypo($event, 'materialGroups', 'group', modalWarning)"
 | 
					 | 
				
			||||||
                     title="chemical material type, eg. PA66">
 | 
					 | 
				
			||||||
        <ng-template rbFormValidationMessage="failure">{{groupInput.errors.failure}}</ng-template>
 | 
					 | 
				
			||||||
      </rb-form-input>
 | 
					 | 
				
			||||||
      <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" title="Bosch material part number, eg. 5515753021"></rb-form-input>
 | 
					 | 
				
			||||||
      </rb-array-input>
 | 
					 | 
				
			||||||
      <rb-form-select name="propertiesSelect" label="Type" title="=overall material group specific properties"
 | 
					 | 
				
			||||||
                      [(ngModel)]="material.properties.material_template">
 | 
					 | 
				
			||||||
        <option *ngFor="let m of d.latest.materialTemplates" [value]="m._id">{{m.name}}</option>
 | 
					 | 
				
			||||||
      </rb-form-select>
 | 
					 | 
				
			||||||
      <rb-form-input *ngFor="let parameter of d.id.materialTemplates[material.properties.material_template].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>
 | 
					 | 
				
			||||||
    </div>
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <div>
 | 
					  <form #sampleForm="ngForm" *ngIf="view.base">
 | 
				
			||||||
      <rb-form-select name="type" label="type" required [(ngModel)]="sample.type" ngModel
 | 
					    <div class="sample">
 | 
				
			||||||
                      title="material status of the sample">
 | 
					 | 
				
			||||||
        <option value="as-delivered/raw">as-delivered/raw</option>
 | 
					 | 
				
			||||||
        <option value="processed">processed</option>
 | 
					 | 
				
			||||||
        <ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
 | 
					 | 
				
			||||||
      </rb-form-select>
 | 
					 | 
				
			||||||
      <rb-form-input name="color" label="color" appValidate="string" [(ngModel)]="sample.color"
 | 
					 | 
				
			||||||
                     #colorInput="ngModel" title="sample color, eg. black">
 | 
					 | 
				
			||||||
        <ng-template rbFormValidationMessage="failure">{{colorInput.errors.failure}}</ng-template>
 | 
					 | 
				
			||||||
        <ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
 | 
					 | 
				
			||||||
      </rb-form-input>
 | 
					 | 
				
			||||||
      <rb-form-input name="batch" label="batch" appValidate="string" [(ngModel)]="sample.batch" #batchInput="ngModel"
 | 
					 | 
				
			||||||
                     title="batch number the sample was from, eg. 2264486614">
 | 
					 | 
				
			||||||
        <ng-template rbFormValidationMessage="failure">{{batchInput.errors.failure}}</ng-template>
 | 
					 | 
				
			||||||
      </rb-form-input>
 | 
					 | 
				
			||||||
    </div>
 | 
					 | 
				
			||||||
  </div>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  <div class="notes">
 | 
					 | 
				
			||||||
    <rb-form-input name="comment" label="comment" appValidate="stringLength" [appValidateArgs]="[512]"
 | 
					 | 
				
			||||||
                   [(ngModel)]="sample.notes.comment" #commentInput="ngModel"
 | 
					 | 
				
			||||||
                   title="general remarks that cannot be expressed in additional properties, eg. stabilized">
 | 
					 | 
				
			||||||
      <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>
 | 
					      <div>
 | 
				
			||||||
        <rb-form-input [name]="'sr-id' + i" label="sample number" [rbFormInputAutocomplete]="sampleReferenceListBind()"
 | 
					        <rb-form-input name="materialname" label="material name" [rbDebounceTime]="0" [rbInitialOpen]="true"
 | 
				
			||||||
                       [rbDebounceTime]="300" appValidate="stringOf"
 | 
					                       [rbFormInputAutocomplete]="autocomplete.bind(this, materialNames)" appValidate="stringOf"
 | 
				
			||||||
                       [appValidateArgs]="[sampleReferenceAutocomplete[i]]"
 | 
					                       (keydown)="preventDefault($event)" (ngModelChange)="findMaterial($event)" ngModel
 | 
				
			||||||
                       (ngModelChange)="checkSampleReference($event, i)" [ngModel]="reference[0]" ngModel
 | 
					                       [appValidateArgs]="[materialNames]" required [(ngModel)]="material.name" [autofocus]="true"
 | 
				
			||||||
                       title="sample number of the referenced sample, eg. An31">
 | 
					                       *ngIf="baseSample.material !== undefined || mode === 'new'"
 | 
				
			||||||
          <ng-template rbFormValidationMessage="failure">Unknown sample number</ng-template>
 | 
					                       title="trade name of the material, eg. Ultradur B4300 G6">
 | 
				
			||||||
 | 
					          <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>
 | 
					        </rb-form-input>
 | 
				
			||||||
 | 
					        <rb-icon-button class="set-new-material space-below" icon="add" mode="secondary"
 | 
				
			||||||
 | 
					                        (click)="setNewMaterial(!newMaterial)" *ngIf="baseSample.material !== undefined">
 | 
				
			||||||
 | 
					          New material
 | 
				
			||||||
 | 
					        </rb-icon-button>
 | 
				
			||||||
      </div>
 | 
					      </div>
 | 
				
			||||||
      <rb-form-input [name]="'sr-relation' + i" label="relation" appValidate="string" [required]="reference[0] !== ''"
 | 
					
 | 
				
			||||||
                     [(ngModel)]="reference[1]" title="description how the samples are connected, eg. belongs to">
 | 
					      <div class="material shaded-container" *ngIf="newMaterial" [@inOut]>
 | 
				
			||||||
        <ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
 | 
					        <h4>Material properties</h4>
 | 
				
			||||||
      </rb-form-input>
 | 
					        <rb-form-input name="supplier" label="supplier"
 | 
				
			||||||
    </div>
 | 
					                       [rbFormInputAutocomplete]="autocomplete.bind(this, d.arr.materialSuppliers)"
 | 
				
			||||||
    <h5>Additional properties</h5>
 | 
					                       [rbDebounceTime]="0" [rbInitialOpen]="true" appValidate="string" required
 | 
				
			||||||
    <rb-array-input [(ngModel)]="customFields" name="customFields" [pushTemplate]="['', '']" pushPath="0"
 | 
					                       [(ngModel)]="material.supplier" #supplierInput="ngModel"
 | 
				
			||||||
                    class="two-col" [@inOut]>
 | 
					                       (focusout)="checkTypo($event, 'materialSuppliers', 'supplier', modalWarning)"
 | 
				
			||||||
      <ng-container *rbArrayInputItem="let item">
 | 
					                       title="material supplier, eg. BASF">
 | 
				
			||||||
        <div>
 | 
					          <ng-template rbFormValidationMessage="failure">{{supplierInput.errors.failure}}</ng-template>
 | 
				
			||||||
          <rb-form-input [name]="'cf-key' + item.i" label="key" [rbArrayInputListener]="'cf-key'" [index]="item.i"
 | 
					        </rb-form-input>
 | 
				
			||||||
                         [rbFormInputAutocomplete]="autocomplete.bind(this, availableCustomFields)" [rbDebounceTime]="0"
 | 
					        <rb-form-input name="group" label="group"
 | 
				
			||||||
                         [rbInitialOpen]="true" appValidate="unique" [appValidateArgs]="[uniqueCfValues(item.i)]"
 | 
					                       [rbFormInputAutocomplete]="autocomplete.bind(this, d.arr.materialGroups)"
 | 
				
			||||||
                         [ngModel]="item.value[0]" #keyInput="ngModel" title="name of additional property, eg. vwz">
 | 
					                       [rbDebounceTime]="0" [rbInitialOpen]="true" appValidate="string" required
 | 
				
			||||||
            <ng-template rbFormValidationMessage="failure">{{keyInput.errors.failure}}</ng-template>
 | 
					                       [(ngModel)]="material.group" #groupInput="ngModel"
 | 
				
			||||||
          </rb-form-input>
 | 
					                       (focusout)="checkTypo($event, 'materialGroups', 'group', modalWarning)"
 | 
				
			||||||
        </div>
 | 
					                       title="chemical material type, eg. PA66">
 | 
				
			||||||
        <rb-form-input [name]="'cf-value' + item.i" label="value" appValidate="string" [required]="item.value[0] !== ''"
 | 
					          <ng-template rbFormValidationMessage="failure">{{groupInput.errors.failure}}</ng-template>
 | 
				
			||||||
                       [ngModel]="item.value[1]" title="value of additional property, eg. 0 min">
 | 
					        </rb-form-input>
 | 
				
			||||||
 | 
					        <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" title="Bosch material part number, eg. 5515753021"></rb-form-input>
 | 
				
			||||||
 | 
					        </rb-array-input>
 | 
				
			||||||
 | 
					        <rb-form-select name="propertiesSelect" label="Type" title="=overall material group specific properties"
 | 
				
			||||||
 | 
					                        [(ngModel)]="material.properties.material_template">
 | 
				
			||||||
 | 
					          <option *ngFor="let m of d.latest.materialTemplates" [value]="m._id">{{m.name}}</option>
 | 
				
			||||||
 | 
					        </rb-form-select>
 | 
				
			||||||
 | 
					        <rb-form-input *ngFor="let parameter of
 | 
				
			||||||
 | 
					                         d.id.materialTemplates[material.properties.material_template].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>
 | 
					          <ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
 | 
				
			||||||
        </rb-form-input>
 | 
					        </rb-form-input>
 | 
				
			||||||
      </ng-container>
 | 
					      </div>
 | 
				
			||||||
    </rb-array-input>
 | 
					 | 
				
			||||||
  </div>
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <div *ngIf="editSampleBase; else generateSamples" class="space-below">
 | 
					      <div>
 | 
				
			||||||
    <button class="rb-btn rb-primary" type="submit" (click)="saveSample()" [disabled]="!sampleForm.form.valid">
 | 
					        <rb-form-select name="type" label="type" required [(ngModel)]="baseSample.type" ngModel
 | 
				
			||||||
      Save sample
 | 
					                        *ngIf="baseSample.type !== undefined"
 | 
				
			||||||
    </button>
 | 
					                        title="material status of the sample">
 | 
				
			||||||
  </div>
 | 
					          <option value="as-delivered/raw">as-delivered/raw</option>
 | 
				
			||||||
  <ng-template #generateSamples>
 | 
					          <option value="processed">processed</option>
 | 
				
			||||||
    <rb-form-input type="number" name="sample-count" label="number of samples" pattern="^\d+?$" required
 | 
					          <ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
 | 
				
			||||||
                   rbNumberConverter rbMin="1" [(ngModel)]="sampleCount" class="sample-count"
 | 
					        </rb-form-select>
 | 
				
			||||||
                   title="number of samples to create with this base information">
 | 
					        <rb-form-input name="color" label="color" appValidate="string" [(ngModel)]="baseSample.color"
 | 
				
			||||||
      <ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
 | 
					                       *ngIf="baseSample.color !== undefined" #colorInput="ngModel" title="sample color, eg. black">
 | 
				
			||||||
      <ng-template rbFormValidationMessage="rbMin">Must be at least 1</ng-template>
 | 
					          <ng-template rbFormValidationMessage="failure">{{colorInput.errors.failure}}</ng-template>
 | 
				
			||||||
    </rb-form-input>
 | 
					          <ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
 | 
				
			||||||
    <button class="rb-btn rb-primary space-below" type="submit" (click)="saveSample()"
 | 
					        </rb-form-input>
 | 
				
			||||||
            [disabled]="!sampleForm.form.valid">
 | 
					        <rb-form-input name="batch" label="batch" appValidate="string" [(ngModel)]="baseSample.batch"
 | 
				
			||||||
      Generate sample{{sampleCount > 1 ? 's' : ''}}
 | 
					                       #batchInput="ngModel" *ngIf="baseSample.batch !== undefined"
 | 
				
			||||||
    </button>
 | 
					                       title="batch number the sample was from, eg. 2264486614">
 | 
				
			||||||
  </ng-template>
 | 
					          <ng-template rbFormValidationMessage="failure">{{batchInput.errors.failure}}</ng-template>
 | 
				
			||||||
</form>
 | 
					        </rb-form-input>
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <div class="notes" *ngIf="baseSample.notes !== undefined">
 | 
				
			||||||
 | 
					      <rb-form-input name="comment" label="comment" appValidate="stringLength" [appValidateArgs]="[512]"
 | 
				
			||||||
 | 
					                     [(ngModel)]="baseSample.notes.comment" #commentInput="ngModel"
 | 
				
			||||||
 | 
					                     title="general remarks that cannot be expressed in additional properties, eg. stabilized">
 | 
				
			||||||
 | 
					        <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
 | 
				
			||||||
 | 
					                         title="sample number of the referenced sample, eg. An31">
 | 
				
			||||||
 | 
					            <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]" title="description how the samples are connected, eg. belongs to">
 | 
				
			||||||
 | 
					          <ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
 | 
				
			||||||
 | 
					        </rb-form-input>
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
 | 
					      <h5>Additional properties</h5>
 | 
				
			||||||
 | 
					      <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" title="name of additional property, eg. vwz">
 | 
				
			||||||
 | 
					              <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]" title="value of additional property, eg. 0 min">
 | 
				
			||||||
 | 
					            <ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
 | 
				
			||||||
 | 
					          </rb-form-input>
 | 
				
			||||||
 | 
					        </ng-container>
 | 
				
			||||||
 | 
					      </rb-array-input>
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<div *ngIf="generatedSamples.length && !loading">
 | 
					    <div *ngIf="samples.length; else generateSamples" class="space-below">
 | 
				
			||||||
  <div *ngIf="!editSampleBase">
 | 
					      <rb-icon-button icon="save" mode="primary" type="submit" (click)="saveSample()"
 | 
				
			||||||
    <h3 *ngIf="new">Successfully added samples:</h3>
 | 
					                      [disabled]="!sampleForm.form.valid">
 | 
				
			||||||
    <span *ngIf="!new" class="rb-ic rb-ic-edit clickable" (click)="checkFormAfterInit = editSampleBase = true"></span>
 | 
					        Save sample
 | 
				
			||||||
 | 
					      </rb-icon-button>
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
 | 
					    <ng-template #generateSamples>
 | 
				
			||||||
 | 
					      <rb-form-input type="number" name="sample-count" label="number of samples" pattern="^\d+?$" required
 | 
				
			||||||
 | 
					                     rbNumberConverter rbMin="1" [(ngModel)]="sampleCount" class="sample-count"
 | 
				
			||||||
 | 
					                     title="number of samples to create with this base information">
 | 
				
			||||||
 | 
					        <ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
 | 
				
			||||||
 | 
					        <ng-template rbFormValidationMessage="rbMin">Must be at least 1</ng-template>
 | 
				
			||||||
 | 
					      </rb-form-input>
 | 
				
			||||||
 | 
					      <button class="rb-btn rb-primary space-below" type="submit" (click)="saveSample()"
 | 
				
			||||||
 | 
					              [disabled]="!sampleForm.form.valid">
 | 
				
			||||||
 | 
					        Generate sample{{sampleCount > 1 ? 's' : ''}}
 | 
				
			||||||
 | 
					      </button>
 | 
				
			||||||
 | 
					    </ng-template>
 | 
				
			||||||
 | 
					  </form>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<!--BASE SUMMARY-->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  <div *ngIf="view.baseSum">
 | 
				
			||||||
 | 
					    <h3 *ngIf="mode === 'new'">Successfully added samples:</h3>
 | 
				
			||||||
 | 
					    <span class="rb-ic rb-ic-edit clickable" (click)="checkFormAfterInit = view.base = true; view.baseSum = false">
 | 
				
			||||||
 | 
					    </span>
 | 
				
			||||||
    <rb-table id="response-data">
 | 
					    <rb-table id="response-data">
 | 
				
			||||||
      <tr><td>Material</td><td>{{generatedSamples[0].material.name}}</td></tr>
 | 
					      <tr><td>Material</td><td>{{material.name}}</td></tr>
 | 
				
			||||||
      <tr><td>Type</td><td>{{generatedSamples[0].type}}</td></tr>
 | 
					      <tr><td>Type</td><td>{{baseSample.type}}</td></tr>
 | 
				
			||||||
      <tr><td>color</td><td>{{generatedSamples[0].color}}</td></tr>
 | 
					      <tr><td>color</td><td>{{baseSample.color}}</td></tr>
 | 
				
			||||||
      <tr><td>Batch</td><td>{{generatedSamples[0].batch}}</td></tr>
 | 
					      <tr><td>Batch</td><td>{{baseSample.batch}}</td></tr>
 | 
				
			||||||
 | 
					      <tr><td>Comment</td><td>{{baseSample.notes.comment}}</td></tr>
 | 
				
			||||||
 | 
					      <tr *ngFor="let reference of sampleReferences.slice(0, -1)">
 | 
				
			||||||
 | 
					        <td>Sample reference</td><td>{{reference[0]}} - {{reference[1]}}</td>
 | 
				
			||||||
 | 
					      </tr>
 | 
				
			||||||
 | 
					      <tr *ngFor="let field of customFields"><td>{{field[0]}}</td><td>{{field[1]}}</td></tr>
 | 
				
			||||||
    </rb-table>
 | 
					    </rb-table>
 | 
				
			||||||
  </div>
 | 
					  </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <form #cmForm="ngForm">
 | 
					<!--CM-->
 | 
				
			||||||
    <div *ngFor="let gSample of generatedSamples; index as gIndex">
 | 
					 | 
				
			||||||
      <h4 *ngIf="new">{{gSample.number}}</h4>
 | 
					 | 
				
			||||||
      <div class="conditions shaded-container space-below">
 | 
					 | 
				
			||||||
        <h5>
 | 
					 | 
				
			||||||
          Condition
 | 
					 | 
				
			||||||
          <button class="rb-btn rb-secondary condition-set" type="button" (click)="toggleCondition(gSample)">
 | 
					 | 
				
			||||||
            {{gSample.condition.condition_template ? 'Do not set condition' : 'Set condition'}}
 | 
					 | 
				
			||||||
          </button>
 | 
					 | 
				
			||||||
        </h5>
 | 
					 | 
				
			||||||
        <div *ngIf="gSample.condition.condition_template" [@inOut]>
 | 
					 | 
				
			||||||
          <rb-form-select name="conditionSelect" label="Condition"
 | 
					 | 
				
			||||||
                          [(ngModel)]="gSample.condition.condition_template">
 | 
					 | 
				
			||||||
            <option *ngFor="let c of d.latest.conditionTemplates" [value]="c._id">{{c.name}}</option>
 | 
					 | 
				
			||||||
          </rb-form-select>
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
          <ng-container *ngFor="let parameter of
 | 
					  <div *ngIf="view.cm">
 | 
				
			||||||
                        d.id.conditionTemplates[gSample.condition.condition_template].parameters; index as i"
 | 
					    <form #cmForm="ngForm" [ngClass]="{'cm-form': samples.length > 1}">
 | 
				
			||||||
                        [ngSwitch]="(parameter.range.values ? 1 : 0)">
 | 
					      <rb-tab-panel (tabChanged)="cmSampleIndex = $event" class="space-below" *ngIf="samples.length > 1">
 | 
				
			||||||
            <rb-form-select *ngSwitchCase="1"
 | 
					        <ng-container *ngFor="let sample of samples; index as i">
 | 
				
			||||||
                            [name]="'conditionParameter-' + gIndex + '-' + i"
 | 
					          <div *rbTabPanelItem="sample.number; id: i"></div>
 | 
				
			||||||
                            [label]="parameter.name" [(ngModel)]="gSample.condition[parameter.name]" ngModel>
 | 
					        </ng-container>
 | 
				
			||||||
              <option *ngFor="let value of parameter.range.values" [value]="value">{{value}}</option>
 | 
					      </rb-tab-panel>
 | 
				
			||||||
              <ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
 | 
					      <div *ngFor="let sample of samples; index as gIndex"
 | 
				
			||||||
 | 
					           [ngStyle]="{display: gIndex == cmSampleIndex || gIndex == cmSampleIndex  + 1 ? 'initial' : 'none'}">
 | 
				
			||||||
 | 
					        <h4 *ngIf="samples.length > 1">{{sample.number}}</h4>
 | 
				
			||||||
 | 
					        <div class="conditions shaded-container space-below">
 | 
				
			||||||
 | 
					          <h5>
 | 
				
			||||||
 | 
					            Condition
 | 
				
			||||||
 | 
					            <button class="rb-btn rb-secondary condition-set" type="button" (click)="toggleCondition(sample)">
 | 
				
			||||||
 | 
					              {{sample.condition.condition_template ? 'Do not set condition' : 'Set condition'}}
 | 
				
			||||||
 | 
					            </button>
 | 
				
			||||||
 | 
					          </h5>
 | 
				
			||||||
 | 
					          <div *ngIf="sample.condition.condition_template" [@inOut]>
 | 
				
			||||||
 | 
					            <rb-form-select name="conditionSelect" label="Condition"
 | 
				
			||||||
 | 
					                            [(ngModel)]="sample.condition.condition_template">
 | 
				
			||||||
 | 
					              <option *ngFor="let c of d.latest.conditionTemplates" [value]="c._id">{{c.name}}</option>
 | 
				
			||||||
            </rb-form-select>
 | 
					            </rb-form-select>
 | 
				
			||||||
            <rb-form-input *ngSwitchDefault
 | 
					 | 
				
			||||||
                           [name]="'conditionParameter-' + gIndex + '-' + i"
 | 
					 | 
				
			||||||
                           [label]="parameter.name" appValidate="string" required
 | 
					 | 
				
			||||||
                           [(ngModel)]="gSample.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>
 | 
					 | 
				
			||||||
          </ng-container>
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
      </div>
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
      <div class="measurements shaded-container space-below">
 | 
					            <ng-container *ngFor="let parameter of
 | 
				
			||||||
        <h5>Measurements</h5>
 | 
					                          d.id.conditionTemplates[sample.condition.condition_template].parameters; index as i"
 | 
				
			||||||
        <div *ngFor="let measurement of gSample.measurements; index as mIndex" [@inOut]>
 | 
					                          [ngSwitch]="(parameter.range.values ? 1 : 0)">
 | 
				
			||||||
          <rb-form-select [name]="'measurementTemplateSelect-' + gIndex + '-' + mIndex" label="Template"
 | 
					              <rb-form-select *ngSwitchCase="1"
 | 
				
			||||||
                          [(ngModel)]="measurement.measurement_template"
 | 
					                              [name]="'conditionParameter-' + gIndex + '-' + i"
 | 
				
			||||||
                          (ngModelChange)="clearMeasurement(gIndex, mIndex)">
 | 
					                              [label]="parameter.name" [(ngModel)]="sample.condition[parameter.name]" ngModel>
 | 
				
			||||||
            <option *ngFor="let m of d.latest.measurementTemplates" [value]="m._id">{{m.name}}</option>
 | 
					                <option *ngFor="let value of parameter.range.values" [value]="value">{{value}}</option>
 | 
				
			||||||
          </rb-form-select>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
          <div *ngFor="let parameter of d.id.measurementTemplates[measurement.measurement_template].parameters;
 | 
					 | 
				
			||||||
               index as pIndex">
 | 
					 | 
				
			||||||
            <ng-container [ngSwitch]="(parameter.range.type ? 1 : 0) + (parameter.range.values ? 2 : 0)">
 | 
					 | 
				
			||||||
              <rb-form-file *ngSwitchCase="1"
 | 
					 | 
				
			||||||
                            [name]="'measurementParameter-' + gIndex + '-' + mIndex + '-' + pIndex"
 | 
					 | 
				
			||||||
                            [label]="parameter.name" maxSize="10000000" multiple
 | 
					 | 
				
			||||||
                            [required]="measurement.values[parameter.name] &&
 | 
					 | 
				
			||||||
                            !measurement.values[parameter.name].length"
 | 
					 | 
				
			||||||
                            (ngModelChange)="fileToArray($event, gIndex, mIndex, parameter.name)"
 | 
					 | 
				
			||||||
                            placeholder="Select file or drag and drop" dragDrop ngModel>
 | 
					 | 
				
			||||||
                <ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
 | 
					 | 
				
			||||||
              </rb-form-file>
 | 
					 | 
				
			||||||
              <rb-form-select *ngSwitchCase="2"
 | 
					 | 
				
			||||||
                              [name]="'measurementParameter-' + gIndex + '-' + mIndex + '-' + pIndex"
 | 
					 | 
				
			||||||
                              [label]="parameter.name" [(ngModel)]="measurement.values[parameter.name]" ngModel>
 | 
					 | 
				
			||||||
                <option *ngFor="let device of d.d.user.devices" [value]="device">{{device}}</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
 | 
				
			||||||
                             [name]="'measurementParameter-' + gIndex + '-' + mIndex + '-' + pIndex"
 | 
					                             [name]="'conditionParameter-' + gIndex + '-' + i"
 | 
				
			||||||
                             [label]="parameter.name" appValidate="string"
 | 
					                             [label]="parameter.name" appValidate="string" required
 | 
				
			||||||
                             [(ngModel)]="measurement.values[parameter.name]" #parameterInput="ngModel">
 | 
					                             [(ngModel)]="sample.condition[parameter.name]" #parameterInput="ngModel">
 | 
				
			||||||
                <ng-template rbFormValidationMessage="failure">{{parameterInput.errors.failure}}</ng-template>
 | 
					                <ng-template rbFormValidationMessage="failure">{{parameterInput.errors.failure}}</ng-template>
 | 
				
			||||||
                <ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
 | 
					                <ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
 | 
				
			||||||
              </rb-form-input>
 | 
					              </rb-form-input>
 | 
				
			||||||
            </ng-container>
 | 
					            </ng-container>
 | 
				
			||||||
            <canvas baseChart *ngIf="parameter.range.type && charts[gIndex][mIndex][0].data.length > 0"
 | 
					 | 
				
			||||||
                    class="dpt-chart"
 | 
					 | 
				
			||||||
                    [@inOut]
 | 
					 | 
				
			||||||
                    [datasets]="charts[gIndex][mIndex]"
 | 
					 | 
				
			||||||
                    [labels]="[]"
 | 
					 | 
				
			||||||
                    [options]="chartOptions"
 | 
					 | 
				
			||||||
                    [legend]="false"
 | 
					 | 
				
			||||||
                    chartType="scatter">
 | 
					 | 
				
			||||||
            </canvas>
 | 
					 | 
				
			||||||
          </div>
 | 
					          </div>
 | 
				
			||||||
          <rb-icon-button icon="delete" mode="danger" (click)="removeMeasurement(gIndex, mIndex)">
 | 
					 | 
				
			||||||
            Delete measurement
 | 
					 | 
				
			||||||
          </rb-icon-button>
 | 
					 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
         
 | 
					        <div class="measurements shaded-container space-below">
 | 
				
			||||||
 | 
					          <h5>
 | 
				
			||||||
 | 
					            Measurements
 | 
				
			||||||
 | 
					            <rb-icon-button icon="undo" mode="secondary" *ngIf="measurementRestoreData.length"
 | 
				
			||||||
 | 
					                            class="restore-measurements" (click)="restoreMeasurements()">
 | 
				
			||||||
 | 
					              Restore measurements
 | 
				
			||||||
 | 
					            </rb-icon-button>
 | 
				
			||||||
 | 
					          </h5>
 | 
				
			||||||
 | 
					          <div *ngFor="let measurement of sample.measurements; index as mIndex" [@inOut]  class="space-below">
 | 
				
			||||||
 | 
					            <rb-form-select [name]="'measurementTemplateSelect-' + gIndex + '-' + mIndex" label="Template"
 | 
				
			||||||
 | 
					                            [(ngModel)]="measurement.measurement_template"
 | 
				
			||||||
 | 
					                            (ngModelChange)="clearMeasurement(gIndex, mIndex)">
 | 
				
			||||||
 | 
					              <option *ngFor="let m of d.latest.measurementTemplates" [value]="m._id">{{m.name}}</option>
 | 
				
			||||||
 | 
					            </rb-form-select>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        <div>
 | 
					            <div *ngFor="let parameter of d.id.measurementTemplates[measurement.measurement_template].parameters;
 | 
				
			||||||
          <rb-icon-button icon="add" mode="secondary" (click)="addMeasurement(gIndex)">
 | 
					                 index as pIndex">
 | 
				
			||||||
            New measurement
 | 
					              <ng-container [ngSwitch]="(parameter.range.type ? 1 : 0) + (parameter.range.values ? 2 : 0)">
 | 
				
			||||||
          </rb-icon-button>
 | 
					                <rb-form-file *ngSwitchCase="1"
 | 
				
			||||||
 | 
					                              [name]="'measurementParameter-' + gIndex + '-' + mIndex + '-' + pIndex"
 | 
				
			||||||
 | 
					                              [label]="parameter.name" maxSize="10000000" multiple
 | 
				
			||||||
 | 
					                              [required]="measurement.values[parameter.name] &&
 | 
				
			||||||
 | 
					                              !measurement.values[parameter.name].length"
 | 
				
			||||||
 | 
					                              (ngModelChange)="fileToArray($event, gIndex, mIndex, parameter.name)"
 | 
				
			||||||
 | 
					                              placeholder="Select file or drag and drop" dragDrop ngModel>
 | 
				
			||||||
 | 
					                  <ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
 | 
				
			||||||
 | 
					                </rb-form-file>
 | 
				
			||||||
 | 
					                <rb-form-select *ngSwitchCase="2"
 | 
				
			||||||
 | 
					                                [name]="'measurementParameter-' + gIndex + '-' + mIndex + '-' + pIndex"
 | 
				
			||||||
 | 
					                                [label]="parameter.name" [(ngModel)]="measurement.values[parameter.name]" ngModel>
 | 
				
			||||||
 | 
					                  <option *ngFor="let device of d.d.user.devices" [value]="device">{{device}}</option>
 | 
				
			||||||
 | 
					                  <ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
 | 
				
			||||||
 | 
					                </rb-form-select>
 | 
				
			||||||
 | 
					                <rb-form-input *ngSwitchDefault
 | 
				
			||||||
 | 
					                               [name]="'measurementParameter-' + gIndex + '-' + 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>
 | 
				
			||||||
 | 
					              </ng-container>
 | 
				
			||||||
 | 
					              <canvas baseChart *ngIf="parameter.range.type && charts[gIndex][mIndex][0].data.length > 0"
 | 
				
			||||||
 | 
					                      class="dpt-chart"
 | 
				
			||||||
 | 
					                      [@inOut]
 | 
				
			||||||
 | 
					                      [datasets]="charts[gIndex][mIndex]"
 | 
				
			||||||
 | 
					                      [labels]="[]"
 | 
				
			||||||
 | 
					                      [options]="chartOptions"
 | 
				
			||||||
 | 
					                      [legend]="false"
 | 
				
			||||||
 | 
					                      chartType="scatter">
 | 
				
			||||||
 | 
					              </canvas>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					            <rb-icon-button icon="delete" mode="danger" (click)="removeMeasurement(gIndex, mIndex)">
 | 
				
			||||||
 | 
					              Delete measurement
 | 
				
			||||||
 | 
					            </rb-icon-button>
 | 
				
			||||||
 | 
					          </div>
 | 
				
			||||||
 | 
					          <div>
 | 
				
			||||||
 | 
					            <rb-icon-button icon="add" mode="secondary" (click)="addMeasurement(gIndex)">
 | 
				
			||||||
 | 
					              New measurement
 | 
				
			||||||
 | 
					            </rb-icon-button>
 | 
				
			||||||
 | 
					          </div>
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
      </div>
 | 
					      </div>
 | 
				
			||||||
    </div>
 | 
					      <div class="buttons">
 | 
				
			||||||
    <rb-icon-button icon="save" mode="primary" type="submit" (click)="cmSave()" [disabled]="!cmForm.form.valid">
 | 
					        <rb-icon-button icon="summary" mode="primary" type="submit" (click)="view.cm = false; view.cmSum = true"
 | 
				
			||||||
      Save sample{{generatedSamples.length > 1 ? 's' : ''}}
 | 
					                        [disabled]="!cmForm.form.valid">
 | 
				
			||||||
 | 
					          Summary
 | 
				
			||||||
 | 
					        </rb-icon-button>
 | 
				
			||||||
 | 
					        <rb-icon-button class="delete-sample" icon="delete" mode="danger" *ngIf="mode !== 'new'"
 | 
				
			||||||
 | 
					                        (click)="deleteConfirm(modalDeleteConfirm)">
 | 
				
			||||||
 | 
					          Delete sample
 | 
				
			||||||
 | 
					        </rb-icon-button>
 | 
				
			||||||
 | 
					        <ng-template #modalDeleteConfirm>
 | 
				
			||||||
 | 
					          <rb-alert alertTitle="Are you sure?" type="danger" okBtnLabel="Delete sample" cancelBtnLabel="Cancel">
 | 
				
			||||||
 | 
					            Do you really want to delete this sample?
 | 
				
			||||||
 | 
					          </rb-alert>
 | 
				
			||||||
 | 
					        </ng-template>
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
 | 
					    </form>
 | 
				
			||||||
 | 
					  </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<!--CM SUMMARY-->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  <div *ngIf="view.cmSum">
 | 
				
			||||||
 | 
					    <span class="rb-ic rb-ic-edit clickable" (click)="checkFormAfterInit = view.cm = true; view.cmSum = false">
 | 
				
			||||||
 | 
					    </span>
 | 
				
			||||||
 | 
					    <rb-table>
 | 
				
			||||||
 | 
					      <ng-container *ngFor="let sample of samples; index as gIndex">
 | 
				
			||||||
 | 
					        <tr><th>{{sample.number}}</th><th></th></tr>
 | 
				
			||||||
 | 
					        <tr *ngFor="let parameter of (d.id.conditionTemplates[sample.condition.condition_template] || {parameters: []})
 | 
				
			||||||
 | 
					            .parameters">
 | 
				
			||||||
 | 
					          <td>{{parameter.name}}</td><td>{{sample.condition[parameter.name]}}</td>
 | 
				
			||||||
 | 
					        </tr>
 | 
				
			||||||
 | 
					        <ng-container *ngFor="let measurement of sample.measurements">
 | 
				
			||||||
 | 
					          <tr *ngFor="let parameter of d.id.measurementTemplates[measurement.measurement_template].parameters">
 | 
				
			||||||
 | 
					            <td>{{parameter.name}}</td><td>{{measurement.values[parameter.name]}}</td>
 | 
				
			||||||
 | 
					          </tr>
 | 
				
			||||||
 | 
					        </ng-container>
 | 
				
			||||||
 | 
					      </ng-container>
 | 
				
			||||||
 | 
					    </rb-table>
 | 
				
			||||||
 | 
					    <rb-icon-button icon="save" mode="primary" type="submit" (click)="cmSave()">
 | 
				
			||||||
 | 
					      Save sample{{samples.length > 1 ? 's' : ''}}
 | 
				
			||||||
    </rb-icon-button>
 | 
					    </rb-icon-button>
 | 
				
			||||||
    <rb-icon-button class="delete-sample" icon="delete" mode="danger" *ngIf="!new"
 | 
					  </div>
 | 
				
			||||||
                    (click)="deleteConfirm(modalDeleteConfirm)">
 | 
					</ng-template>
 | 
				
			||||||
      Delete sample
 | 
					 | 
				
			||||||
    </rb-icon-button>
 | 
					 | 
				
			||||||
    <ng-template #modalDeleteConfirm>
 | 
					 | 
				
			||||||
      <rb-alert alertTitle="Are you sure?" type="danger" okBtnLabel="Delete sample" cancelBtnLabel="Cancel">
 | 
					 | 
				
			||||||
        Do you really want to delete {{sample.number}}?
 | 
					 | 
				
			||||||
      </rb-alert>
 | 
					 | 
				
			||||||
    </ng-template>
 | 
					 | 
				
			||||||
  </form>
 | 
					 | 
				
			||||||
</div>
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -33,3 +33,17 @@ td:first-child {
 | 
				
			|||||||
.delete-sample {
 | 
					.delete-sample {
 | 
				
			||||||
  float: right;
 | 
					  float: right;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.cm-form {
 | 
				
			||||||
 | 
					  display: grid;
 | 
				
			||||||
 | 
					  grid-template-columns: 1fr 1fr;
 | 
				
			||||||
 | 
					  grid-column-gap: 1rem;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  rb-tab-panel, div.buttons {
 | 
				
			||||||
 | 
					    grid-column: span 2;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.restore-measurements {
 | 
				
			||||||
 | 
					  float: right;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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 isEqual from 'lodash/isEqual';
 | 
				
			||||||
import strCompare from 'str-compare';
 | 
					import strCompare from 'str-compare';
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
  AfterContentChecked,
 | 
					  AfterContentChecked,
 | 
				
			||||||
@@ -21,6 +22,7 @@ import {animate, style, transition, trigger} from '@angular/animations';
 | 
				
			|||||||
import {Observable} from 'rxjs';
 | 
					import {Observable} from 'rxjs';
 | 
				
			||||||
import {ModalService} from '@inst-iot/bosch-angular-ui-components';
 | 
					import {ModalService} from '@inst-iot/bosch-angular-ui-components';
 | 
				
			||||||
import {DataService} from '../services/data.service';
 | 
					import {DataService} from '../services/data.service';
 | 
				
			||||||
 | 
					import {LoginService} from '../services/login.service';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// TODO: additional property value not validated on edit
 | 
					// TODO: additional property value not validated on edit
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -48,9 +50,9 @@ export class SampleComponent implements OnInit, AfterContentChecked {
 | 
				
			|||||||
  @ViewChild('sampleForm') sampleForm: NgForm;
 | 
					  @ViewChild('sampleForm') sampleForm: NgForm;
 | 
				
			||||||
  @ViewChild('cmForm') cmForm: NgForm;
 | 
					  @ViewChild('cmForm') cmForm: NgForm;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  sample = new SampleModel();            // base sample which is saved
 | 
					  baseSample = new SampleModel();            // base sample which is saved
 | 
				
			||||||
  sampleCount = 1;                       // number of samples to be generated
 | 
					  sampleCount = 1;                       // number of samples to be generated
 | 
				
			||||||
  generatedSamples: SampleModel[] = [];  // gets filled with response data after saving the sample
 | 
					  samples: SampleModel[] = [];  // gets filled with response data after saving the sample
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  sampleReferences: [string, string, string][] = [['', '', '']];
 | 
					  sampleReferences: [string, string, string][] = [['', '', '']];
 | 
				
			||||||
  sampleReferenceFinds: {_id: string, number: string}[] = [];    // raw sample reference data from db
 | 
					  sampleReferenceFinds: {_id: string, number: string}[] = [];    // raw sample reference data from db
 | 
				
			||||||
@@ -66,11 +68,20 @@ export class SampleComponent implements OnInit, AfterContentChecked {
 | 
				
			|||||||
  material = new MaterialModel();        // object of current selected material
 | 
					  material = new MaterialModel();        // object of current selected material
 | 
				
			||||||
  defaultDevice = '';                    // default device for spectra
 | 
					  defaultDevice = '';                    // default device for spectra
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  new;                                   // true if new sample should be created
 | 
					  // component mode, either new for generating new samples, editOne or editMulti, editing one or multiple samples
 | 
				
			||||||
  editSampleBase = false;                // set true to edit sample base values even when generatedSamples .length > 0
 | 
					  mode = 'new';
 | 
				
			||||||
 | 
					  view = {                               // active views
 | 
				
			||||||
 | 
					    base: false,                         // base sample
 | 
				
			||||||
 | 
					    baseSum: false,                      // base sample summary
 | 
				
			||||||
 | 
					    cm: false,                           // conditions and measurements
 | 
				
			||||||
 | 
					    cmSum: false                         // conditions and measurements summary
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
  loading = 0;                           // number of currently loading instances
 | 
					  loading = 0;                           // number of currently loading instances
 | 
				
			||||||
  checkFormAfterInit = false;
 | 
					  checkFormAfterInit = false;
 | 
				
			||||||
  modalText = {list: '', suggestion: ''};
 | 
					  modalText = {list: '', suggestion: ''};
 | 
				
			||||||
 | 
					  cmSampleIndex = '0';
 | 
				
			||||||
 | 
					  measurementDeleteList = [];            // buffer with measurements to delete, if the user confirms and saves the cm changes
 | 
				
			||||||
 | 
					  measurementRestoreData: MeasurementModel[] = [];  // deleted measurements if user is allowed and measurements are available
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  charts = [[]];                         // chart data for spectra
 | 
					  charts = [[]];                         // chart data for spectra
 | 
				
			||||||
  readonly chartInit = [{
 | 
					  readonly chartInit = [{
 | 
				
			||||||
@@ -101,11 +112,12 @@ export class SampleComponent implements OnInit, AfterContentChecked {
 | 
				
			|||||||
    private validation: ValidationService,
 | 
					    private validation: ValidationService,
 | 
				
			||||||
    public autocomplete: AutocompleteService,
 | 
					    public autocomplete: AutocompleteService,
 | 
				
			||||||
    private modal: ModalService,
 | 
					    private modal: ModalService,
 | 
				
			||||||
    public d: DataService
 | 
					    public d: DataService,
 | 
				
			||||||
 | 
					    private login: LoginService
 | 
				
			||||||
  ) { }
 | 
					  ) { }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ngOnInit(): void {
 | 
					  ngOnInit(): void {
 | 
				
			||||||
    this.new = this.router.url === '/samples/new';
 | 
					    this.mode = this.router.url === '/samples/new' ? 'new' : '';
 | 
				
			||||||
    this.loading = 7;
 | 
					    this.loading = 7;
 | 
				
			||||||
    this.d.load('materials', () => {
 | 
					    this.d.load('materials', () => {
 | 
				
			||||||
      this.materialNames = this.d.arr.materials.map(e => e.name);
 | 
					      this.materialNames = this.d.arr.materials.map(e => e.name);
 | 
				
			||||||
@@ -144,49 +156,88 @@ export class SampleComponent implements OnInit, AfterContentChecked {
 | 
				
			|||||||
      this.availableCustomFields = this.d.arr.sampleNotesFields.map(e => e.name);
 | 
					      this.availableCustomFields = this.d.arr.sampleNotesFields.map(e => e.name);
 | 
				
			||||||
      this.loading--;
 | 
					      this.loading--;
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    if (!this.new) {
 | 
					    if (this.mode !== 'new') {
 | 
				
			||||||
      this.loading++;
 | 
					      const sampleIds = this.route.snapshot.paramMap.get('id').split(',');
 | 
				
			||||||
      this.api.get<SampleModel>('/sample/' + this.route.snapshot.paramMap.get('id'), sData => {
 | 
					      if (sampleIds.length === 1) {
 | 
				
			||||||
        this.sample.deserialize(sData);
 | 
					        this.mode = 'editOne';
 | 
				
			||||||
        this.generatedSamples[0] = this.sample;
 | 
					        this.view.baseSum = true;
 | 
				
			||||||
        this.charts = [[]];
 | 
					        this.view.cm = true;
 | 
				
			||||||
        let spectrumCounter = 0;  // generate charts for spectrum measurements
 | 
					        if (this.login.isLevel.dev) {  // load measurement restore data
 | 
				
			||||||
        this.generatedSamples[0].measurements.forEach((measurement, i) => {
 | 
					          this.api.get<MeasurementModel[]>('/measurement/sample/' + sampleIds[0], (data, ignore) => {
 | 
				
			||||||
          this.charts[0].push(cloneDeep(this.chartInit));
 | 
					            if (data) {
 | 
				
			||||||
          if (measurement.values.dpt) {
 | 
					              this.measurementRestoreData = data.filter(e => e.status === 'deleted').map(e => new MeasurementModel().deserialize(e));
 | 
				
			||||||
            setTimeout(() => {
 | 
					            }
 | 
				
			||||||
              this.generateChart(measurement.values.dpt, 0, i);
 | 
					            console.log(this.measurementRestoreData);
 | 
				
			||||||
            }, spectrumCounter * 20);  // generate charts one after another to avoid freezing the UI
 | 
					 | 
				
			||||||
            spectrumCounter ++;
 | 
					 | 
				
			||||||
          }
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
        this.material = new MaterialModel().deserialize(sData.material);  // read material
 | 
					 | 
				
			||||||
        this.customFields = this.sample.notes.custom_fields && this.sample.notes.custom_fields !== {} ?  // read 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) {  // read sample references
 | 
					 | 
				
			||||||
          this.sampleReferences = [];
 | 
					 | 
				
			||||||
          this.sampleReferenceAutocomplete = [];
 | 
					 | 
				
			||||||
          let loadCounter = this.sample.notes.sample_references.length;  // count down instances still loading
 | 
					 | 
				
			||||||
          this.sample.notes.sample_references.forEach(reference => {
 | 
					 | 
				
			||||||
            this.api.get<SampleModel>('/sample/' + reference.sample_id, srData => {  // get sample numbers for ids
 | 
					 | 
				
			||||||
              this.sampleReferences.push([srData.number, reference.relation, reference.sample_id]);
 | 
					 | 
				
			||||||
              this.sampleReferenceAutocomplete.push([srData.number]);
 | 
					 | 
				
			||||||
              if (!--loadCounter) {  // insert empty template when all instances were loaded
 | 
					 | 
				
			||||||
                this.sampleReferences.push(['', '', '']);
 | 
					 | 
				
			||||||
                this.sampleReferenceAutocomplete.push([]);
 | 
					 | 
				
			||||||
              }
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
          });
 | 
					          });
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        this.loading--;
 | 
					      }
 | 
				
			||||||
        this.checkFormAfterInit = true;
 | 
					      else {
 | 
				
			||||||
 | 
					        this.mode = 'editMulti';
 | 
				
			||||||
 | 
					        this.view.base = true;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      this.loading += sampleIds.length;
 | 
				
			||||||
 | 
					      this.samples = [];
 | 
				
			||||||
 | 
					      sampleIds.forEach((sampleId, i) => {
 | 
				
			||||||
 | 
					        this.api.get<SampleModel>('/sample/' + sampleId, sData => {
 | 
				
			||||||
 | 
					          this.samples.push(new SampleModel().deserialize(sData));
 | 
				
			||||||
 | 
					          if (i === 0) {
 | 
				
			||||||
 | 
					            this.baseSample.deserialize(sData);
 | 
				
			||||||
 | 
					            this.material = new MaterialModel().deserialize(sData.material);  // read material
 | 
				
			||||||
 | 
					            this.customFields = this.baseSample.notes.custom_fields && this.baseSample.notes.custom_fields !== {} ?  // read custom fields
 | 
				
			||||||
 | 
					              Object.keys(this.baseSample.notes.custom_fields).map(e => [e, this.baseSample.notes.custom_fields[e]]) : [];
 | 
				
			||||||
 | 
					            if (this.baseSample.notes.sample_references.length) {  // read sample references
 | 
				
			||||||
 | 
					              this.sampleReferences = [];
 | 
				
			||||||
 | 
					              this.sampleReferenceAutocomplete = [];
 | 
				
			||||||
 | 
					              let loadCounter = this.baseSample.notes.sample_references.length;  // count down instances still loading
 | 
				
			||||||
 | 
					              this.baseSample.notes.sample_references.forEach(reference => {
 | 
				
			||||||
 | 
					                this.api.get<SampleModel>('/sample/' + reference.sample_id, srData => {  // get sample numbers for ids
 | 
				
			||||||
 | 
					                  this.sampleReferences.push([srData.number, reference.relation, reference.sample_id]);
 | 
				
			||||||
 | 
					                  this.sampleReferenceAutocomplete.push([srData.number]);
 | 
				
			||||||
 | 
					                  if (!--loadCounter) {  // insert empty template when all instances were loaded
 | 
				
			||||||
 | 
					                    this.sampleReferences.push(['', '', '']);
 | 
				
			||||||
 | 
					                    this.sampleReferenceAutocomplete.push([]);
 | 
				
			||||||
 | 
					                  }
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					              });
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            if (this.mode === 'editOne') {
 | 
				
			||||||
 | 
					              this.charts = [[]];
 | 
				
			||||||
 | 
					              let spectrumCounter = 0;  // generate charts for spectrum measurements
 | 
				
			||||||
 | 
					              this.samples[i].measurements.forEach((measurement, j) => {
 | 
				
			||||||
 | 
					                this.charts[i].push(cloneDeep(this.chartInit));
 | 
				
			||||||
 | 
					                if (measurement.values.dpt) {
 | 
				
			||||||
 | 
					                  setTimeout(() => {
 | 
				
			||||||
 | 
					                    this.generateChart(measurement.values.dpt, 0, j);
 | 
				
			||||||
 | 
					                  }, spectrumCounter * 20);  // generate charts one after another to avoid freezing the UI
 | 
				
			||||||
 | 
					                  spectrumCounter ++;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					              });
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            this.checkFormAfterInit = true;
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					          else {
 | 
				
			||||||
 | 
					            ['type', 'color', 'batch', 'notes'].forEach((key) => {
 | 
				
			||||||
 | 
					              console.log(isEqual(sData[key], this.baseSample[key]));
 | 
				
			||||||
 | 
					              if (!isEqual(sData[key], this.baseSample[key])) {
 | 
				
			||||||
 | 
					                this.baseSample[key] = undefined;
 | 
				
			||||||
 | 
					              }
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					            if (!isEqual(sData.material.name, this.baseSample.material.name)) {
 | 
				
			||||||
 | 
					              this.baseSample.material.name = undefined;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					          this.loading--;
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    else {
 | 
				
			||||||
 | 
					      this.view.base = true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ngAfterContentChecked() {
 | 
					  ngAfterContentChecked() {
 | 
				
			||||||
    if (this.generatedSamples.length) {  // conditions are displayed
 | 
					    if (this.samples.length) {  // conditions are displayed
 | 
				
			||||||
      this.generatedSamples.forEach((gSample, gIndex) => {
 | 
					      this.samples.forEach((gSample, gIndex) => {
 | 
				
			||||||
        if (this.d.id.conditionTemplates[gSample.condition.condition_template]) {
 | 
					        if (this.d.id.conditionTemplates[gSample.condition.condition_template]) {
 | 
				
			||||||
          this.d.id.conditionTemplates[gSample.condition.condition_template].parameters.forEach((parameter, pIndex) => {
 | 
					          this.d.id.conditionTemplates[gSample.condition.condition_template].parameters.forEach((parameter, pIndex) => {
 | 
				
			||||||
            this.attachValidator(this.cmForm, `conditionParameter-${gIndex}-${pIndex}`, parameter.range, true);
 | 
					            this.attachValidator(this.cmForm, `conditionParameter-${gIndex}-${pIndex}`, parameter.range, true);
 | 
				
			||||||
@@ -207,7 +258,7 @@ export class SampleComponent implements OnInit, AfterContentChecked {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (this.checkFormAfterInit) {
 | 
					    if (this.checkFormAfterInit) {
 | 
				
			||||||
      if (this.editSampleBase) {  // validate sampleForm
 | 
					      if (this.view.base) {  // validate sampleForm
 | 
				
			||||||
        if (this.sampleForm !== undefined && this.sampleForm.form.get('cf-key0')) {
 | 
					        if (this.sampleForm !== undefined && this.sampleForm.form.get('cf-key0')) {
 | 
				
			||||||
          this.checkFormAfterInit = false;
 | 
					          this.checkFormAfterInit = false;
 | 
				
			||||||
          Object.keys(this.sampleForm.form.controls).forEach(field => {
 | 
					          Object.keys(this.sampleForm.form.controls).forEach(field => {
 | 
				
			||||||
@@ -218,13 +269,13 @@ export class SampleComponent implements OnInit, AfterContentChecked {
 | 
				
			|||||||
      else {  // validate cmForm
 | 
					      else {  // validate cmForm
 | 
				
			||||||
        // check that all fields are ready for validation
 | 
					        // check that all fields are ready for validation
 | 
				
			||||||
        let formReady: boolean = this.cmForm !== undefined;  // forms exist
 | 
					        let formReady: boolean = this.cmForm !== undefined;  // forms exist
 | 
				
			||||||
        if (this.generatedSamples[0].condition.condition_template) {  // if condition is set, last condition field exists
 | 
					        if (this.samples[0].condition.condition_template) {  // if condition is set, last condition field exists
 | 
				
			||||||
          formReady = formReady && this.cmForm.form.get('conditionParameter-0-' +
 | 
					          formReady = formReady && this.cmForm.form.get('conditionParameter-0-' +
 | 
				
			||||||
            (this.d.id.conditionTemplates[this.generatedSamples[0].condition.condition_template].parameters.length - 1)) as any;
 | 
					            (this.d.id.conditionTemplates[this.samples[0].condition.condition_template].parameters.length - 1)) as any;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if (this.generatedSamples[0].measurements.length) {  // if there are measurements, last measurement field exists
 | 
					        if (this.samples[0].measurements.length) {  // if there are measurements, last measurement field exists
 | 
				
			||||||
          formReady = formReady && this.cmForm.form.get('measurementParameter-0-' + (this.generatedSamples[0].measurements.length - 1) +
 | 
					          formReady = formReady && this.cmForm.form.get('measurementParameter-0-' + (this.samples[0].measurements.length - 1) +
 | 
				
			||||||
            '-' + (this.d.id.measurementTemplates[this.generatedSamples[0].measurements[this.generatedSamples[0].measurements.length - 1]
 | 
					            '-' + (this.d.id.measurementTemplates[this.samples[0].measurements[this.samples[0].measurements.length - 1]
 | 
				
			||||||
              .measurement_template].parameters.length - 1)) as any;
 | 
					              .measurement_template].parameters.length - 1)) as any;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if (formReady) {  // fields are ready, do validation
 | 
					        if (formReady) {  // fields are ready, do validation
 | 
				
			||||||
@@ -262,7 +313,7 @@ export class SampleComponent implements OnInit, AfterContentChecked {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  // save base sample
 | 
					  // save base sample
 | 
				
			||||||
  saveSample() {
 | 
					  saveSample() {
 | 
				
			||||||
    if (this.new) {
 | 
					    if (this.samples.length === 0) {
 | 
				
			||||||
      this.loading = this.sampleCount;  // set up loading spinner
 | 
					      this.loading = this.sampleCount;  // set up loading spinner
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    new Promise<void>(resolve => {
 | 
					    new Promise<void>(resolve => {
 | 
				
			||||||
@@ -271,7 +322,7 @@ export class SampleComponent implements OnInit, AfterContentChecked {
 | 
				
			|||||||
        this.api.post<MaterialModel>('/material/new', this.material.sendFormat(), data => {
 | 
					        this.api.post<MaterialModel>('/material/new', this.material.sendFormat(), data => {
 | 
				
			||||||
          this.d.arr.materials.push(data);  // add material to data
 | 
					          this.d.arr.materials.push(data);  // add material to data
 | 
				
			||||||
          this.material = data;
 | 
					          this.material = data;
 | 
				
			||||||
          this.sample.material_id = data._id;  // add new material id to sample data
 | 
					          this.baseSample.material_id = data._id;  // add new material id to sample data
 | 
				
			||||||
          resolve();
 | 
					          resolve();
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
@@ -279,29 +330,36 @@ export class SampleComponent implements OnInit, AfterContentChecked {
 | 
				
			|||||||
        resolve();
 | 
					        resolve();
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }).then(() => {  // save sample
 | 
					    }).then(() => {  // save sample
 | 
				
			||||||
      this.sample.notes.custom_fields = {};
 | 
					      this.baseSample.notes.custom_fields = {};
 | 
				
			||||||
      this.customFields.forEach(element => {
 | 
					      this.customFields.forEach(element => {
 | 
				
			||||||
        if (element[0] !== '') {
 | 
					        if (element[0] !== '') {
 | 
				
			||||||
          this.sample.notes.custom_fields[element[0]] = element[1];
 | 
					          this.baseSample.notes.custom_fields[element[0]] = element[1];
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
      this.sample.notes.sample_references = this.sampleReferences
 | 
					      this.baseSample.notes.sample_references = this.sampleReferences
 | 
				
			||||||
        .filter(e => e[0] && e[1] && e[2])
 | 
					        .filter(e => e[0] && e[1] && e[2])
 | 
				
			||||||
        .map(e => ({sample_id: e[2], relation: e[1]}));
 | 
					        .map(e => ({sample_id: e[2], relation: e[1]}));
 | 
				
			||||||
      if (this.new) {
 | 
					      if (this.samples.length === 0) {  // only save new sample for the first time in mode new, otherwise save changes
 | 
				
			||||||
        for (let i = 0; i < this.sampleCount; i ++) {
 | 
					        for (let i = 0; i < this.sampleCount; i ++) {
 | 
				
			||||||
          this.api.post<SampleModel>('/sample/new', this.sample.sendFormat(), data => {
 | 
					          this.api.post<SampleModel>('/sample/new', this.baseSample.sendFormat(), data => {
 | 
				
			||||||
            this.generatedSamples[i] = new SampleModel().deserialize(data);
 | 
					            this.samples[i] = new SampleModel().deserialize(data);
 | 
				
			||||||
            this.generatedSamples[i].material = this.d.arr.materials.find(e => e._id === this.generatedSamples[i].material_id);
 | 
					            this.samples[i].material = this.d.arr.materials.find(e => e._id === this.samples[i].material_id);
 | 
				
			||||||
            this.loading --;
 | 
					            this.loading --;
 | 
				
			||||||
          });
 | 
					          });
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        this.view.base = false;
 | 
				
			||||||
 | 
					        this.view.baseSum = true;
 | 
				
			||||||
 | 
					        this.view.cm = true;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      else {
 | 
					      else {
 | 
				
			||||||
        this.api.put<SampleModel>('/sample/' + this.sample._id, this.sample.sendFormat(), data => {
 | 
					        this.samples.forEach((sample, i) => {
 | 
				
			||||||
          merge(this.generatedSamples[0], omit(data, ['condition']));
 | 
					          console.log(sample._id);
 | 
				
			||||||
          this.generatedSamples[0].material = this.d.arr.materials.find(e => e._id === this.generatedSamples[0].material_id);
 | 
					          this.api.put<SampleModel>('/sample/' + sample._id, this.baseSample.sendFormat(), data => {
 | 
				
			||||||
          this.editSampleBase = false;
 | 
					            merge(this.samples[i], omit(data, ['condition']));
 | 
				
			||||||
 | 
					            this.samples[i].material = this.d.arr.materials.find(e => e._id === this.samples[0].material_id);
 | 
				
			||||||
 | 
					            this.view.base = false;
 | 
				
			||||||
 | 
					            this.view.baseSum = true;
 | 
				
			||||||
 | 
					          });
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
@@ -309,7 +367,7 @@ export class SampleComponent implements OnInit, AfterContentChecked {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  // save conditions and measurements
 | 
					  // save conditions and measurements
 | 
				
			||||||
  cmSave() {  // save measurements and conditions
 | 
					  cmSave() {  // save measurements and conditions
 | 
				
			||||||
    this.generatedSamples.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});
 | 
					        this.api.put('/sample/' + sample._id, {condition: sample.condition});
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
@@ -331,24 +389,45 @@ export class SampleComponent implements OnInit, AfterContentChecked {
 | 
				
			|||||||
          this.api.delete('/measurement/' + measurement._id);
 | 
					          this.api.delete('/measurement/' + measurement._id);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
 | 
					      this.measurementDeleteList.forEach(measurement => {
 | 
				
			||||||
 | 
					        this.api.delete('/measurement/' + measurement);
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.router.navigate(['/samples']);
 | 
					    this.router.navigate(['/samples']);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  restoreMeasurements() {
 | 
				
			||||||
 | 
					    let spectrumCounter = 0;  // generate charts for spectrum measurements
 | 
				
			||||||
 | 
					    const measurementCount = this.samples[0].measurements.length;
 | 
				
			||||||
 | 
					    this.measurementRestoreData.forEach((measurement, i) => {
 | 
				
			||||||
 | 
					      this.api.put('/measurement/restore/' + measurement._id, {}, () => {
 | 
				
			||||||
 | 
					        this.samples[0].measurements.push(measurement);
 | 
				
			||||||
 | 
					        this.charts[0].push(cloneDeep(this.chartInit));
 | 
				
			||||||
 | 
					        if (measurement.values.dpt) {
 | 
				
			||||||
 | 
					          setTimeout(() => {
 | 
				
			||||||
 | 
					            this.generateChart(measurement.values.dpt, 0, measurementCount + i);
 | 
				
			||||||
 | 
					          }, spectrumCounter * 20);  // generate charts one after another to avoid freezing the UI
 | 
				
			||||||
 | 
					          spectrumCounter ++;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        this.checkFormAfterInit = true;
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // set material based on found material name
 | 
					  // set material based on found material name
 | 
				
			||||||
  findMaterial(name) {
 | 
					  findMaterial(name) {
 | 
				
			||||||
    const res = this.d.arr.materials.find(e => e.name === name);  // search for match
 | 
					    const res = this.d.arr.materials.find(e => e.name === name);  // search for match
 | 
				
			||||||
    if (res) {  // material found
 | 
					    if (res) {  // material found
 | 
				
			||||||
      this.material = cloneDeep(res);
 | 
					      this.material = cloneDeep(res);
 | 
				
			||||||
      this.sample.material_id = this.material._id;
 | 
					      this.baseSample.material_id = this.material._id;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else {  // no matching material found
 | 
					    else {  // no matching material found
 | 
				
			||||||
      if (this.sample.material_id !== null) {  // reset previous match
 | 
					      if (this.baseSample.material_id !== null) {  // reset previous match
 | 
				
			||||||
        this.material = new MaterialModel();
 | 
					        this.material = new MaterialModel();
 | 
				
			||||||
        this.material.properties.material_template = this.d.latest.materialTemplates.find(e => e.name === 'plastic')._id;
 | 
					        this.material.properties.material_template = this.d.latest.materialTemplates.find(e => e.name === 'plastic')._id;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      this.sample.material_id = null;
 | 
					      this.baseSample.material_id = null;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    this.setNewMaterial();
 | 
					    this.setNewMaterial();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -356,9 +435,9 @@ export class SampleComponent implements OnInit, AfterContentChecked {
 | 
				
			|||||||
  // set newMaterial, if value === null -> toggle
 | 
					  // set newMaterial, if value === null -> toggle
 | 
				
			||||||
  setNewMaterial(value = null) {
 | 
					  setNewMaterial(value = null) {
 | 
				
			||||||
    if (value === null) {  // toggle dialog
 | 
					    if (value === null) {  // toggle dialog
 | 
				
			||||||
      this.newMaterial = !this.sample.material_id;
 | 
					      this.newMaterial = !this.baseSample.material_id;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else if (value || (!value && this.sample.material_id !== null )) {  // set to false only if material already exists
 | 
					    else if (value || (!value && this.baseSample.material_id !== null )) {  // set to false only if material already exists
 | 
				
			||||||
      this.newMaterial = value;
 | 
					      this.newMaterial = value;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (this.newMaterial) {  // set validators if dialog is open
 | 
					    if (this.newMaterial) {  // set validators if dialog is open
 | 
				
			||||||
@@ -373,7 +452,7 @@ export class SampleComponent implements OnInit, AfterContentChecked {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  // add a new measurement for generated sample at index
 | 
					  // add a new measurement for generated sample at index
 | 
				
			||||||
  addMeasurement(gIndex) {
 | 
					  addMeasurement(gIndex) {
 | 
				
			||||||
    this.generatedSamples[gIndex].measurements.push(
 | 
					    this.samples[gIndex].measurements.push(
 | 
				
			||||||
      new MeasurementModel(this.d.latest.measurementTemplates.find(e => e.name === 'spectrum')._id)
 | 
					      new MeasurementModel(this.d.latest.measurementTemplates.find(e => e.name === 'spectrum')._id)
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
    if (!this.charts[gIndex]) {  // add array if there are no charts yet
 | 
					    if (!this.charts[gIndex]) {  // add array if there are no charts yet
 | 
				
			||||||
@@ -383,18 +462,18 @@ export class SampleComponent implements OnInit, AfterContentChecked {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // remove the measurement at the specified index
 | 
					  // remove the measurement at the specified index
 | 
				
			||||||
  removeMeasurement(gIndex, mIndex) {
 | 
					  removeMeasurement(gIndex, mIndex) {  // TODO: do not delete directly but only after confirmation
 | 
				
			||||||
    if (this.generatedSamples[gIndex].measurements[mIndex]._id !== null) {
 | 
					    if (this.samples[gIndex].measurements[mIndex]._id !== null) {
 | 
				
			||||||
      this.api.delete('/measurement/' + this.generatedSamples[gIndex].measurements[mIndex]._id);
 | 
					      this.measurementDeleteList.push(this.samples[gIndex].measurements[mIndex]._id);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    this.generatedSamples[gIndex].measurements.splice(mIndex, 1);
 | 
					    this.samples[gIndex].measurements.splice(mIndex, 1);
 | 
				
			||||||
    this.charts[gIndex].splice(mIndex, 1);
 | 
					    this.charts[gIndex].splice(mIndex, 1);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // remove measurement data at the specified index
 | 
					  // clear entered measurement data at the specified index due to template change
 | 
				
			||||||
  clearMeasurement(gIndex, mIndex) {
 | 
					  clearMeasurement(gIndex, mIndex) {
 | 
				
			||||||
    this.charts[gIndex][mIndex][0].data = [];
 | 
					    this.charts[gIndex][mIndex][0].data = [];
 | 
				
			||||||
    this.generatedSamples[gIndex].measurements[mIndex].values = {};
 | 
					    this.samples[gIndex].measurements[mIndex].values = {};
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  fileToArray(files, gIndex, mIndex, parameter) {
 | 
					  fileToArray(files, gIndex, mIndex, parameter) {
 | 
				
			||||||
@@ -405,14 +484,14 @@ export class SampleComponent implements OnInit, AfterContentChecked {
 | 
				
			|||||||
          let index: number = mIndex;
 | 
					          let index: number = mIndex;
 | 
				
			||||||
          if (Number(i) > 0) {  // append further spectra
 | 
					          if (Number(i) > 0) {  // append further spectra
 | 
				
			||||||
            this.addMeasurement(gIndex);
 | 
					            this.addMeasurement(gIndex);
 | 
				
			||||||
            index = this.generatedSamples[gIndex].measurements.length - 1;
 | 
					            index = this.samples[gIndex].measurements.length - 1;
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
          this.generatedSamples[gIndex].measurements[index].values.device =
 | 
					          this.samples[gIndex].measurements[index].values.device =
 | 
				
			||||||
            this.generatedSamples[gIndex].measurements[mIndex].values.device;
 | 
					            this.samples[gIndex].measurements[mIndex].values.device;
 | 
				
			||||||
          this.generatedSamples[gIndex].measurements[index].values.filename = files[i].name;
 | 
					          this.samples[gIndex].measurements[index].values.filename = files[i].name;
 | 
				
			||||||
          this.generatedSamples[gIndex].measurements[index].values[parameter] =
 | 
					          this.samples[gIndex].measurements[index].values[parameter] =
 | 
				
			||||||
            fileReader.result.toString().split('\r\n').map(e => e.split(','));
 | 
					            fileReader.result.toString().split('\r\n').map(e => e.split(',')).filter(el => el.length === 2);
 | 
				
			||||||
          this.generateChart(this.generatedSamples[gIndex].measurements[index].values[parameter], gIndex, index);
 | 
					          this.generateChart(this.samples[gIndex].measurements[index].values[parameter], gIndex, index);
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
        fileReader.readAsText(files[i]);
 | 
					        fileReader.readAsText(files[i]);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
@@ -452,7 +531,7 @@ export class SampleComponent implements OnInit, AfterContentChecked {
 | 
				
			|||||||
  deleteConfirm(modal) {
 | 
					  deleteConfirm(modal) {
 | 
				
			||||||
    this.modal.open(modal).then(result => {
 | 
					    this.modal.open(modal).then(result => {
 | 
				
			||||||
      if (result) {
 | 
					      if (result) {
 | 
				
			||||||
        this.api.delete('/sample/' + this.sample._id);
 | 
					        this.api.delete('/sample/' + this.baseSample._id);
 | 
				
			||||||
        this.router.navigate(['/samples']);
 | 
					        this.router.navigate(['/samples']);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,14 +4,16 @@
 | 
				
			|||||||
  <a routerLink="/samples/new" *ngIf="login.isLevel.write">
 | 
					  <a routerLink="/samples/new" *ngIf="login.isLevel.write">
 | 
				
			||||||
    <rb-icon-button icon="add" mode="primary" class="space-left">New sample</rb-icon-button>
 | 
					    <rb-icon-button icon="add" mode="primary" class="space-left">New sample</rb-icon-button>
 | 
				
			||||||
  </a>
 | 
					  </a>
 | 
				
			||||||
  <rb-icon-button *ngIf="validation" mode="secondary" icon="close" (click)="validation = false" class="validation-close"
 | 
					  <rb-icon-button *ngIf="sampleSelect === 2" mode="secondary" icon="close" (click)="sampleSelect = 0"
 | 
				
			||||||
                  iconOnly></rb-icon-button>
 | 
					                  class="validation-close" iconOnly></rb-icon-button>
 | 
				
			||||||
  <rb-icon-button *ngIf="login.isLevel.dev" [icon]="validation ? 'checkmark' : 'clear-all'"
 | 
					  <rb-icon-button *ngIf="login.isLevel.dev" [icon]="sampleSelect === 2 ? 'checkmark' : 'clear-all'"
 | 
				
			||||||
                  mode="secondary" (click)="validate()">
 | 
					                  mode="secondary" (click)="validate()">
 | 
				
			||||||
    {{validation ? 'Validate' : 'Validation'}}
 | 
					    {{sampleSelect === 2 ? 'Validate' : 'Validation'}}
 | 
				
			||||||
  </rb-icon-button>
 | 
					  </rb-icon-button>
 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<!--FILTERS-->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<rb-accordion>
 | 
					<rb-accordion>
 | 
				
			||||||
  <rb-accordion-title [open]="false"><span class="rb-ic rb-ic-filter"></span>  Filter</rb-accordion-title>
 | 
					  <rb-accordion-title [open]="false"><span class="rb-ic rb-ic-filter"></span>  Filter</rb-accordion-title>
 | 
				
			||||||
  <rb-accordion-body>
 | 
					  <rb-accordion-body>
 | 
				
			||||||
@@ -121,6 +123,8 @@
 | 
				
			|||||||
  <div>Loading...</div>
 | 
					  <div>Loading...</div>
 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<!--DOWNLOAD BUTTONS-->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<div class="download space-below" *ngIf="login.isLevel.dev">
 | 
					<div class="download space-below" *ngIf="login.isLevel.dev">
 | 
				
			||||||
  <rb-icon-button class="space-right" icon="download" mode="secondary" [rbModal]="linkModal">
 | 
					  <rb-icon-button class="space-right" icon="download" mode="secondary" [rbModal]="linkModal">
 | 
				
			||||||
    JSON download link
 | 
					    JSON download link
 | 
				
			||||||
@@ -149,10 +153,12 @@
 | 
				
			|||||||
  </a>
 | 
					  </a>
 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<!--TABLE-->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<rb-table class="samples-table" scrollTop ellipsis>
 | 
					<rb-table class="samples-table" scrollTop ellipsis>
 | 
				
			||||||
  <tr>
 | 
					  <tr>
 | 
				
			||||||
    <th *ngIf="validation">
 | 
					    <th *ngIf="sampleSelect">
 | 
				
			||||||
      <rb-form-checkbox name="validate-all" (change)="selectAll($event)">all</rb-form-checkbox>
 | 
					      <rb-form-checkbox name="select-all" (change)="selectAll($event)">all</rb-form-checkbox>
 | 
				
			||||||
    </th>
 | 
					    </th>
 | 
				
			||||||
    <th *ngFor="let key of activeKeys" [title]="key.label">
 | 
					    <th *ngFor="let key of activeKeys" [title]="key.label">
 | 
				
			||||||
      <div class="sort-header">
 | 
					      <div class="sort-header">
 | 
				
			||||||
@@ -167,13 +173,16 @@
 | 
				
			|||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
      </div>
 | 
					      </div>
 | 
				
			||||||
    </th>
 | 
					    </th>
 | 
				
			||||||
    <th *ngIf="login.isLevel.write"></th>
 | 
					    <th *ngIf="login.isLevel.write">
 | 
				
			||||||
 | 
					      <span class="rb-ic rb-ic-edit clickable" *ngIf="login.isLevel.dev" (click)="batchEdit()"></span>
 | 
				
			||||||
 | 
					      <span class="rb-ic rb-ic-close clickable" *ngIf="sampleSelect === 1" (click)="sampleSelect = 0"></span>
 | 
				
			||||||
 | 
					    </th>
 | 
				
			||||||
  </tr>
 | 
					  </tr>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <tr *ngFor="let sample of samples; index as i" class="clickable" (click)="sampleDetails(sample._id, sampleModal)">
 | 
					  <tr *ngFor="let sample of samples; index as i" class="clickable" (click)="sampleDetails(sample._id, sampleModal)">
 | 
				
			||||||
    <td *ngIf="validation">
 | 
					    <td *ngIf="sampleSelect">
 | 
				
			||||||
      <rb-form-checkbox *ngIf="sample.status !== 'deleted'" [name]="'validate-' + i" (click)="stopPropagation($event)"
 | 
					      <rb-form-checkbox *ngIf="sample.status !== 'deleted'" [name]="'validate-' + i" (click)="stopPropagation($event)"
 | 
				
			||||||
                        [(ngModel)]="sample.validate">
 | 
					                        [(ngModel)]="sample.selected">
 | 
				
			||||||
      </rb-form-checkbox>
 | 
					      </rb-form-checkbox>
 | 
				
			||||||
    </td>
 | 
					    </td>
 | 
				
			||||||
    <td *ngIf="isActiveKey['number']">{{sample.number}}</td>
 | 
					    <td *ngIf="isActiveKey['number']">{{sample.number}}</td>
 | 
				
			||||||
@@ -224,6 +233,8 @@
 | 
				
			|||||||
  </div>
 | 
					  </div>
 | 
				
			||||||
</ng-template>
 | 
					</ng-template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<!--SAMPLE DETAILS-->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<ng-template #sampleModal>
 | 
					<ng-template #sampleModal>
 | 
				
			||||||
  <rb-loading-spinner *ngIf="sampleDetailsSample === null; else sampleDetailsTemplate"></rb-loading-spinner>
 | 
					  <rb-loading-spinner *ngIf="sampleDetailsSample === null; else sampleDetailsTemplate"></rb-loading-spinner>
 | 
				
			||||||
  <ng-template #sampleDetailsTemplate>
 | 
					  <ng-template #sampleDetailsTemplate>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,6 +9,7 @@ import {LoginService} from '../services/login.service';
 | 
				
			|||||||
import {ModalService} from '@inst-iot/bosch-angular-ui-components';
 | 
					import {ModalService} from '@inst-iot/bosch-angular-ui-components';
 | 
				
			||||||
import {DataService} from '../services/data.service';
 | 
					import {DataService} from '../services/data.service';
 | 
				
			||||||
import {LocalStorageService} from 'angular-2-local-storage';
 | 
					import {LocalStorageService} from 'angular-2-local-storage';
 | 
				
			||||||
 | 
					import {Router} from '@angular/router';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// TODO: turn off sort field
 | 
					// TODO: turn off sort field
 | 
				
			||||||
// TODO reset sort when field is excluded
 | 
					// TODO reset sort when field is excluded
 | 
				
			||||||
@@ -63,6 +64,7 @@ export class SamplesComponent implements OnInit {
 | 
				
			|||||||
      {field: 'type', label: 'Type', active: false, autocomplete: [], mode: 'eq', values: ['']},
 | 
					      {field: 'type', label: 'Type', active: false, autocomplete: [], mode: 'eq', values: ['']},
 | 
				
			||||||
      {field: 'color', label: 'Color', active: false, autocomplete: [], mode: 'eq', values: ['']},
 | 
					      {field: 'color', label: 'Color', active: false, autocomplete: [], mode: 'eq', values: ['']},
 | 
				
			||||||
      {field: 'batch', label: 'Batch', active: false, autocomplete: [], mode: 'eq', values: ['']},
 | 
					      {field: 'batch', label: 'Batch', active: false, autocomplete: [], mode: 'eq', values: ['']},
 | 
				
			||||||
 | 
					      // {field: 'notes.comment', label: 'Comment', active: false, autocomplete: [], mode: 'eq', values: ['']},
 | 
				
			||||||
      {field: 'added', label: 'Added', active: false, autocomplete: [], mode: 'eq', values: ['']}
 | 
					      {field: 'added', label: 'Added', active: false, autocomplete: [], mode: 'eq', values: ['']}
 | 
				
			||||||
    ]
 | 
					    ]
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
@@ -78,6 +80,7 @@ export class SamplesComponent implements OnInit {
 | 
				
			|||||||
    {id: 'type', label: 'Type', active: true, sortable: true},
 | 
					    {id: 'type', label: 'Type', active: true, sortable: true},
 | 
				
			||||||
    {id: 'color', label: 'Color', active: false, sortable: true},
 | 
					    {id: 'color', label: 'Color', active: false, sortable: true},
 | 
				
			||||||
    {id: 'batch', label: 'Batch', active: true, sortable: true},
 | 
					    {id: 'batch', label: 'Batch', active: true, sortable: true},
 | 
				
			||||||
 | 
					    // {id: 'notes.comment', label: 'Comment', active: false, sortable: false},
 | 
				
			||||||
    {id: 'notes', label: 'Notes', active: false, sortable: false},
 | 
					    {id: 'notes', label: 'Notes', active: false, sortable: false},
 | 
				
			||||||
    {id: 'status', label: 'Status', active: false, sortable: true},
 | 
					    {id: 'status', label: 'Status', active: false, sortable: true},
 | 
				
			||||||
    {id: 'added', label: 'Added', active: true, sortable: true}
 | 
					    {id: 'added', label: 'Added', active: true, sortable: true}
 | 
				
			||||||
@@ -86,7 +89,7 @@ export class SamplesComponent implements OnInit {
 | 
				
			|||||||
  activeKeys: KeyInterface[] = [];
 | 
					  activeKeys: KeyInterface[] = [];
 | 
				
			||||||
  activeTemplateKeys = {material: [], condition: [], measurements: []};
 | 
					  activeTemplateKeys = {material: [], condition: [], measurements: []};
 | 
				
			||||||
  sampleDetailsSample: any = null;
 | 
					  sampleDetailsSample: any = null;
 | 
				
			||||||
  validation = false;  // true to activate validation mode
 | 
					  sampleSelect = 0;  // modes: 0 - no selection, 1 - sample edit selection, 2 - validation selection
 | 
				
			||||||
  loading = 0;
 | 
					  loading = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -97,7 +100,8 @@ export class SamplesComponent implements OnInit {
 | 
				
			|||||||
    private modalService: ModalService,
 | 
					    private modalService: ModalService,
 | 
				
			||||||
    public d: DataService,
 | 
					    public d: DataService,
 | 
				
			||||||
    private storage: LocalStorageService,
 | 
					    private storage: LocalStorageService,
 | 
				
			||||||
    private window: Window
 | 
					    private window: Window,
 | 
				
			||||||
 | 
					    private router: Router
 | 
				
			||||||
  ) {
 | 
					  ) {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -285,7 +289,7 @@ export class SamplesComponent implements OnInit {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  loadPage(delta) {
 | 
					  loadPage(delta) {
 | 
				
			||||||
    if (!/[0-9]+/.test(delta) || (this.page <= 1 && delta < 0)) {  // invalid delta
 | 
					    if (!/[0-9]+/.test(delta) || this.page + delta < 1 || this.page + delta > this.pages) {  // invalid delta
 | 
				
			||||||
      return;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    this.page += delta;
 | 
					    this.page += delta;
 | 
				
			||||||
@@ -414,17 +418,27 @@ export class SamplesComponent implements OnInit {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  validate() {
 | 
					  validate() {
 | 
				
			||||||
    if (this.validation) {
 | 
					    if (this.sampleSelect) {
 | 
				
			||||||
      this.samples.forEach(sample => {
 | 
					      this.samples.forEach(sample => {
 | 
				
			||||||
        if (sample.validate) {
 | 
					        if (sample.selected) {
 | 
				
			||||||
          this.api.put('/sample/validate/' + sample._id);
 | 
					          this.api.put('/sample/validate/' + sample._id);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
      this.loadSamples();
 | 
					      this.loadSamples();
 | 
				
			||||||
      this.validation = false;
 | 
					      this.sampleSelect = 0;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else {
 | 
					    else {
 | 
				
			||||||
      this.validation = true;
 | 
					      this.sampleSelect = 2;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  batchEdit() {
 | 
				
			||||||
 | 
					    if (this.sampleSelect) {
 | 
				
			||||||
 | 
					      this.router.navigate(['/samples/edit/' + this.samples.filter(e => e.selected).map(e => e._id).join(',')]);
 | 
				
			||||||
 | 
					      this.sampleSelect = 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    else {
 | 
				
			||||||
 | 
					      this.sampleSelect = 1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -442,10 +456,10 @@ export class SamplesComponent implements OnInit {
 | 
				
			|||||||
  selectAll(event) {
 | 
					  selectAll(event) {
 | 
				
			||||||
    this.samples.forEach(sample => {
 | 
					    this.samples.forEach(sample => {
 | 
				
			||||||
      if (sample.status !== 'deleted') {
 | 
					      if (sample.status !== 'deleted') {
 | 
				
			||||||
        sample.validate = event.target.checked;
 | 
					        sample.selected = event.target.checked;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      else {
 | 
					      else {
 | 
				
			||||||
        sample.validate = false;
 | 
					        sample.selected = false;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,9 +7,7 @@ $rb-extended-breakpoints: false;  // whether to use extended breakpoints xxl and
 | 
				
			|||||||
  src: url(/assets/fonts/BoschMono.ttf);
 | 
					  src: url(/assets/fonts/BoschMono.ttf);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* {
 | 
					*, ::after, ::before {
 | 
				
			||||||
  margin: 0;
 | 
					 | 
				
			||||||
  padding: 0;
 | 
					 | 
				
			||||||
  box-sizing: border-box;
 | 
					  box-sizing: border-box;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user