added batch edit
This commit is contained in:
parent
433572f819
commit
602dfb51da
@ -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,20 +1,28 @@
|
|||||||
<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>
|
||||||
|
|
||||||
|
<!--BASE-->
|
||||||
|
|
||||||
|
<form #sampleForm="ngForm" *ngIf="view.base">
|
||||||
<div class="sample">
|
<div class="sample">
|
||||||
<div>
|
<div>
|
||||||
<rb-form-input name="materialname" label="material name" [rbDebounceTime]="0" [rbInitialOpen]="true"
|
<rb-form-input name="materialname" label="material name" [rbDebounceTime]="0" [rbInitialOpen]="true"
|
||||||
[rbFormInputAutocomplete]="autocomplete.bind(this, materialNames)" appValidate="stringOf"
|
[rbFormInputAutocomplete]="autocomplete.bind(this, materialNames)" appValidate="stringOf"
|
||||||
(keydown)="preventDefault($event)" (ngModelChange)="findMaterial($event)" ngModel
|
(keydown)="preventDefault($event)" (ngModelChange)="findMaterial($event)" ngModel
|
||||||
[appValidateArgs]="[materialNames]" required [(ngModel)]="material.name" [autofocus]="true"
|
[appValidateArgs]="[materialNames]" required [(ngModel)]="material.name" [autofocus]="true"
|
||||||
|
*ngIf="baseSample.material !== undefined || mode === 'new'"
|
||||||
title="trade name of the material, eg. Ultradur B4300 G6">
|
title="trade name of the material, eg. Ultradur B4300 G6">
|
||||||
<ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
|
<ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
|
||||||
<ng-template rbFormValidationMessage="failure">Unknown material, add properties for new material</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"
|
<rb-icon-button class="set-new-material space-below" icon="add" mode="secondary"
|
||||||
(click)="setNewMaterial(!newMaterial)">New material</rb-icon-button>
|
(click)="setNewMaterial(!newMaterial)" *ngIf="baseSample.material !== undefined">
|
||||||
|
New material
|
||||||
|
</rb-icon-button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="material shaded-container" *ngIf="newMaterial" [@inOut]>
|
<div class="material shaded-container" *ngIf="newMaterial" [@inOut]>
|
||||||
@ -50,7 +58,8 @@
|
|||||||
[(ngModel)]="material.properties.material_template">
|
[(ngModel)]="material.properties.material_template">
|
||||||
<option *ngFor="let m of d.latest.materialTemplates" [value]="m._id">{{m.name}}</option>
|
<option *ngFor="let m of d.latest.materialTemplates" [value]="m._id">{{m.name}}</option>
|
||||||
</rb-form-select>
|
</rb-form-select>
|
||||||
<rb-form-input *ngFor="let parameter of d.id.materialTemplates[material.properties.material_template].parameters;
|
<rb-form-input *ngFor="let parameter of
|
||||||
|
d.id.materialTemplates[material.properties.material_template].parameters;
|
||||||
index as i" [name]="'materialParameter' + i"
|
index as i" [name]="'materialParameter' + i"
|
||||||
[label]="parameter.name" appValidate="string" required
|
[label]="parameter.name" appValidate="string" required
|
||||||
[(ngModel)]="material.properties[parameter.name]" #parameterInput="ngModel">
|
[(ngModel)]="material.properties[parameter.name]" #parameterInput="ngModel">
|
||||||
@ -60,34 +69,37 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<rb-form-select name="type" label="type" required [(ngModel)]="sample.type" ngModel
|
<rb-form-select name="type" label="type" required [(ngModel)]="baseSample.type" ngModel
|
||||||
|
*ngIf="baseSample.type !== undefined"
|
||||||
title="material status of the sample">
|
title="material status of the sample">
|
||||||
<option value="as-delivered/raw">as-delivered/raw</option>
|
<option value="as-delivered/raw">as-delivered/raw</option>
|
||||||
<option value="processed">processed</option>
|
<option value="processed">processed</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 name="color" label="color" appValidate="string" [(ngModel)]="sample.color"
|
<rb-form-input name="color" label="color" appValidate="string" [(ngModel)]="baseSample.color"
|
||||||
#colorInput="ngModel" title="sample color, eg. black">
|
*ngIf="baseSample.color !== undefined" #colorInput="ngModel" title="sample color, eg. black">
|
||||||
<ng-template rbFormValidationMessage="failure">{{colorInput.errors.failure}}</ng-template>
|
<ng-template rbFormValidationMessage="failure">{{colorInput.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>
|
||||||
<rb-form-input name="batch" label="batch" appValidate="string" [(ngModel)]="sample.batch" #batchInput="ngModel"
|
<rb-form-input name="batch" label="batch" appValidate="string" [(ngModel)]="baseSample.batch"
|
||||||
|
#batchInput="ngModel" *ngIf="baseSample.batch !== undefined"
|
||||||
title="batch number the sample was from, eg. 2264486614">
|
title="batch number the sample was from, eg. 2264486614">
|
||||||
<ng-template rbFormValidationMessage="failure">{{batchInput.errors.failure}}</ng-template>
|
<ng-template rbFormValidationMessage="failure">{{batchInput.errors.failure}}</ng-template>
|
||||||
</rb-form-input>
|
</rb-form-input>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="notes">
|
<div class="notes" *ngIf="baseSample.notes !== undefined">
|
||||||
<rb-form-input name="comment" label="comment" appValidate="stringLength" [appValidateArgs]="[512]"
|
<rb-form-input name="comment" label="comment" appValidate="stringLength" [appValidateArgs]="[512]"
|
||||||
[(ngModel)]="sample.notes.comment" #commentInput="ngModel"
|
[(ngModel)]="baseSample.notes.comment" #commentInput="ngModel"
|
||||||
title="general remarks that cannot be expressed in additional properties, eg. stabilized">
|
title="general remarks that cannot be expressed in additional properties, eg. stabilized">
|
||||||
<ng-template rbFormValidationMessage="failure">{{commentInput.errors.failure}}</ng-template>
|
<ng-template rbFormValidationMessage="failure">{{commentInput.errors.failure}}</ng-template>
|
||||||
</rb-form-input>
|
</rb-form-input>
|
||||||
<h5>Sample references</h5>
|
<h5>Sample references</h5>
|
||||||
<div *ngFor="let reference of sampleReferences; index as i" class="two-col" [@inOut]>
|
<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]="'sr-id' + i" label="sample number"
|
||||||
|
[rbFormInputAutocomplete]="sampleReferenceListBind()"
|
||||||
[rbDebounceTime]="300" appValidate="stringOf"
|
[rbDebounceTime]="300" appValidate="stringOf"
|
||||||
[appValidateArgs]="[sampleReferenceAutocomplete[i]]"
|
[appValidateArgs]="[sampleReferenceAutocomplete[i]]"
|
||||||
(ngModelChange)="checkSampleReference($event, i)" [ngModel]="reference[0]" ngModel
|
(ngModelChange)="checkSampleReference($event, i)" [ngModel]="reference[0]" ngModel
|
||||||
@ -106,24 +118,27 @@
|
|||||||
<ng-container *rbArrayInputItem="let item">
|
<ng-container *rbArrayInputItem="let item">
|
||||||
<div>
|
<div>
|
||||||
<rb-form-input [name]="'cf-key' + item.i" label="key" [rbArrayInputListener]="'cf-key'" [index]="item.i"
|
<rb-form-input [name]="'cf-key' + item.i" label="key" [rbArrayInputListener]="'cf-key'" [index]="item.i"
|
||||||
[rbFormInputAutocomplete]="autocomplete.bind(this, availableCustomFields)" [rbDebounceTime]="0"
|
[rbFormInputAutocomplete]="autocomplete.bind(this, availableCustomFields)"
|
||||||
|
[rbDebounceTime]="0"
|
||||||
[rbInitialOpen]="true" appValidate="unique" [appValidateArgs]="[uniqueCfValues(item.i)]"
|
[rbInitialOpen]="true" appValidate="unique" [appValidateArgs]="[uniqueCfValues(item.i)]"
|
||||||
[ngModel]="item.value[0]" #keyInput="ngModel" title="name of additional property, eg. vwz">
|
[(ngModel)]="item.value[0]" #keyInput="ngModel" title="name of additional property, eg. vwz">
|
||||||
<ng-template rbFormValidationMessage="failure">{{keyInput.errors.failure}}</ng-template>
|
<ng-template rbFormValidationMessage="failure">{{keyInput.errors.failure}}</ng-template>
|
||||||
</rb-form-input>
|
</rb-form-input>
|
||||||
</div>
|
</div>
|
||||||
<rb-form-input [name]="'cf-value' + item.i" label="value" appValidate="string" [required]="item.value[0] !== ''"
|
<rb-form-input [name]="'cf-value' + item.i" label="value" appValidate="string"
|
||||||
[ngModel]="item.value[1]" title="value of additional property, eg. 0 min">
|
[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>
|
<ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
|
||||||
</rb-form-input>
|
</rb-form-input>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
</rb-array-input>
|
</rb-array-input>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div *ngIf="editSampleBase; else generateSamples" class="space-below">
|
<div *ngIf="samples.length; else generateSamples" class="space-below">
|
||||||
<button class="rb-btn rb-primary" type="submit" (click)="saveSample()" [disabled]="!sampleForm.form.valid">
|
<rb-icon-button icon="save" mode="primary" type="submit" (click)="saveSample()"
|
||||||
|
[disabled]="!sampleForm.form.valid">
|
||||||
Save sample
|
Save sample
|
||||||
</button>
|
</rb-icon-button>
|
||||||
</div>
|
</div>
|
||||||
<ng-template #generateSamples>
|
<ng-template #generateSamples>
|
||||||
<rb-form-input type="number" name="sample-count" label="number of samples" pattern="^\d+?$" required
|
<rb-form-input type="number" name="sample-count" label="number of samples" pattern="^\d+?$" required
|
||||||
@ -137,50 +152,65 @@
|
|||||||
Generate sample{{sampleCount > 1 ? 's' : ''}}
|
Generate sample{{sampleCount > 1 ? 's' : ''}}
|
||||||
</button>
|
</button>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<!--BASE SUMMARY-->
|
||||||
|
|
||||||
<div *ngIf="generatedSamples.length && !loading">
|
<div *ngIf="view.baseSum">
|
||||||
<div *ngIf="!editSampleBase">
|
<h3 *ngIf="mode === 'new'">Successfully added samples:</h3>
|
||||||
<h3 *ngIf="new">Successfully added samples:</h3>
|
<span class="rb-ic rb-ic-edit clickable" (click)="checkFormAfterInit = view.base = true; view.baseSum = false">
|
||||||
<span *ngIf="!new" class="rb-ic rb-ic-edit clickable" (click)="checkFormAfterInit = editSampleBase = true"></span>
|
</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 *ngIf="view.cm">
|
||||||
|
<form #cmForm="ngForm" [ngClass]="{'cm-form': samples.length > 1}">
|
||||||
|
<rb-tab-panel (tabChanged)="cmSampleIndex = $event" class="space-below" *ngIf="samples.length > 1">
|
||||||
|
<ng-container *ngFor="let sample of samples; index as i">
|
||||||
|
<div *rbTabPanelItem="sample.number; id: i"></div>
|
||||||
|
</ng-container>
|
||||||
|
</rb-tab-panel>
|
||||||
|
<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">
|
<div class="conditions shaded-container space-below">
|
||||||
<h5>
|
<h5>
|
||||||
Condition
|
Condition
|
||||||
<button class="rb-btn rb-secondary condition-set" type="button" (click)="toggleCondition(gSample)">
|
<button class="rb-btn rb-secondary condition-set" type="button" (click)="toggleCondition(sample)">
|
||||||
{{gSample.condition.condition_template ? 'Do not set condition' : 'Set condition'}}
|
{{sample.condition.condition_template ? 'Do not set condition' : 'Set condition'}}
|
||||||
</button>
|
</button>
|
||||||
</h5>
|
</h5>
|
||||||
<div *ngIf="gSample.condition.condition_template" [@inOut]>
|
<div *ngIf="sample.condition.condition_template" [@inOut]>
|
||||||
<rb-form-select name="conditionSelect" label="Condition"
|
<rb-form-select name="conditionSelect" label="Condition"
|
||||||
[(ngModel)]="gSample.condition.condition_template">
|
[(ngModel)]="sample.condition.condition_template">
|
||||||
<option *ngFor="let c of d.latest.conditionTemplates" [value]="c._id">{{c.name}}</option>
|
<option *ngFor="let c of d.latest.conditionTemplates" [value]="c._id">{{c.name}}</option>
|
||||||
</rb-form-select>
|
</rb-form-select>
|
||||||
|
|
||||||
<ng-container *ngFor="let parameter of
|
<ng-container *ngFor="let parameter of
|
||||||
d.id.conditionTemplates[gSample.condition.condition_template].parameters; index as i"
|
d.id.conditionTemplates[sample.condition.condition_template].parameters; index as i"
|
||||||
[ngSwitch]="(parameter.range.values ? 1 : 0)">
|
[ngSwitch]="(parameter.range.values ? 1 : 0)">
|
||||||
<rb-form-select *ngSwitchCase="1"
|
<rb-form-select *ngSwitchCase="1"
|
||||||
[name]="'conditionParameter-' + gIndex + '-' + i"
|
[name]="'conditionParameter-' + gIndex + '-' + i"
|
||||||
[label]="parameter.name" [(ngModel)]="gSample.condition[parameter.name]" ngModel>
|
[label]="parameter.name" [(ngModel)]="sample.condition[parameter.name]" ngModel>
|
||||||
<option *ngFor="let value of parameter.range.values" [value]="value">{{value}}</option>
|
<option *ngFor="let value of parameter.range.values" [value]="value">{{value}}</option>
|
||||||
<ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
|
<ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
|
||||||
</rb-form-select>
|
</rb-form-select>
|
||||||
<rb-form-input *ngSwitchDefault
|
<rb-form-input *ngSwitchDefault
|
||||||
[name]="'conditionParameter-' + gIndex + '-' + i"
|
[name]="'conditionParameter-' + gIndex + '-' + i"
|
||||||
[label]="parameter.name" appValidate="string" required
|
[label]="parameter.name" appValidate="string" required
|
||||||
[(ngModel)]="gSample.condition[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>
|
||||||
@ -189,8 +219,14 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="measurements shaded-container space-below">
|
<div class="measurements shaded-container space-below">
|
||||||
<h5>Measurements</h5>
|
<h5>
|
||||||
<div *ngFor="let measurement of gSample.measurements; index as mIndex" [@inOut]>
|
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"
|
<rb-form-select [name]="'measurementTemplateSelect-' + gIndex + '-' + mIndex" label="Template"
|
||||||
[(ngModel)]="measurement.measurement_template"
|
[(ngModel)]="measurement.measurement_template"
|
||||||
(ngModelChange)="clearMeasurement(gIndex, mIndex)">
|
(ngModelChange)="clearMeasurement(gIndex, mIndex)">
|
||||||
@ -237,9 +273,6 @@
|
|||||||
Delete measurement
|
Delete measurement
|
||||||
</rb-icon-button>
|
</rb-icon-button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<rb-icon-button icon="add" mode="secondary" (click)="addMeasurement(gIndex)">
|
<rb-icon-button icon="add" mode="secondary" (click)="addMeasurement(gIndex)">
|
||||||
New measurement
|
New measurement
|
||||||
@ -247,17 +280,45 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<rb-icon-button icon="save" mode="primary" type="submit" (click)="cmSave()" [disabled]="!cmForm.form.valid">
|
<div class="buttons">
|
||||||
Save sample{{generatedSamples.length > 1 ? 's' : ''}}
|
<rb-icon-button icon="summary" mode="primary" type="submit" (click)="view.cm = false; view.cmSum = true"
|
||||||
|
[disabled]="!cmForm.form.valid">
|
||||||
|
Summary
|
||||||
</rb-icon-button>
|
</rb-icon-button>
|
||||||
<rb-icon-button class="delete-sample" icon="delete" mode="danger" *ngIf="!new"
|
<rb-icon-button class="delete-sample" icon="delete" mode="danger" *ngIf="mode !== 'new'"
|
||||||
(click)="deleteConfirm(modalDeleteConfirm)">
|
(click)="deleteConfirm(modalDeleteConfirm)">
|
||||||
Delete sample
|
Delete sample
|
||||||
</rb-icon-button>
|
</rb-icon-button>
|
||||||
<ng-template #modalDeleteConfirm>
|
<ng-template #modalDeleteConfirm>
|
||||||
<rb-alert alertTitle="Are you sure?" type="danger" okBtnLabel="Delete sample" cancelBtnLabel="Cancel">
|
<rb-alert alertTitle="Are you sure?" type="danger" okBtnLabel="Delete sample" cancelBtnLabel="Cancel">
|
||||||
Do you really want to delete {{sample.number}}?
|
Do you really want to delete this sample?
|
||||||
</rb-alert>
|
</rb-alert>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</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>
|
||||||
|
</div>
|
||||||
|
</ng-template>
|
||||||
|
@ -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,30 +156,40 @@ 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);
|
|
||||||
}, spectrumCounter * 20); // generate charts one after another to avoid freezing the UI
|
|
||||||
spectrumCounter ++;
|
|
||||||
}
|
}
|
||||||
|
console.log(this.measurementRestoreData);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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.material = new MaterialModel().deserialize(sData.material); // read material
|
||||||
this.customFields = this.sample.notes.custom_fields && this.sample.notes.custom_fields !== {} ? // read custom fields
|
this.customFields = this.baseSample.notes.custom_fields && this.baseSample.notes.custom_fields !== {} ? // read custom fields
|
||||||
Object.keys(this.sample.notes.custom_fields).map(e => [e, this.sample.notes.custom_fields[e]]) : [];
|
Object.keys(this.baseSample.notes.custom_fields).map(e => [e, this.baseSample.notes.custom_fields[e]]) : [];
|
||||||
if (this.sample.notes.sample_references.length) { // read sample references
|
if (this.baseSample.notes.sample_references.length) { // read sample references
|
||||||
this.sampleReferences = [];
|
this.sampleReferences = [];
|
||||||
this.sampleReferenceAutocomplete = [];
|
this.sampleReferenceAutocomplete = [];
|
||||||
let loadCounter = this.sample.notes.sample_references.length; // count down instances still loading
|
let loadCounter = this.baseSample.notes.sample_references.length; // count down instances still loading
|
||||||
this.sample.notes.sample_references.forEach(reference => {
|
this.baseSample.notes.sample_references.forEach(reference => {
|
||||||
this.api.get<SampleModel>('/sample/' + reference.sample_id, srData => { // get sample numbers for ids
|
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.sampleReferences.push([srData.number, reference.relation, reference.sample_id]);
|
||||||
this.sampleReferenceAutocomplete.push([srData.number]);
|
this.sampleReferenceAutocomplete.push([srData.number]);
|
||||||
@ -178,15 +200,44 @@ export class SampleComponent implements OnInit, AfterContentChecked {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this.loading--;
|
if (this.mode === 'editOne') {
|
||||||
this.checkFormAfterInit = true;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user