Merge pull request #30 in ~VLE2FE/definma-ui from development to master

* commit '819666c3444181dbe6e08ab155b4b027149217e2':
  condition fix
  template fixes
This commit is contained in:
Veit Lukas (PEA4-Fe) 2020-08-27 15:47:00 +02:00
commit 2d1b1a83aa
7 changed files with 78 additions and 19 deletions

View File

@ -37,7 +37,7 @@
</ng-container>
<div *rbSubBrandHeader>
<rb-icon-button icon="bug" mode="secondary" class="space-right" [rbModal]="bugModal" *ngIf="false">
<rb-icon-button icon="bug" mode="secondary" class="space-right" [rbModal]="bugModal">
Bug
</rb-icon-button>
<ng-template let-close="close" #bugModal>
@ -48,7 +48,7 @@
<rb-icon-button icon="mail" mode="primary" (mouseup)="closeBugReport(close)">Send report</rb-icon-button>
</a>
</ng-template>
<span class="dev-label" *ngIf="devMode && false">DEVELOPMENT</span>
<span class="dev-label" *ngIf="devMode">DEVELOPMENT</span>
DeFinMa
</div>
</rb-full-header>

View File

@ -41,8 +41,12 @@ export class SampleModel extends BaseModel {
return this;
}
sendFormat() {
const tmp = pick(this.conditionTemplateCheck(), ['color', 'type', 'batch', 'condition', 'material_id', 'notes']);
sendFormat(pickCondition = true) {
const pickFields = ['color', 'type', 'batch', 'material_id', 'notes'];
if (pickCondition) {
pickFields.push('condition');
}
const tmp = pick(this.conditionTemplateCheck(), pickFields);
Object.keys(tmp).forEach(key => {
if (tmp[key] === undefined) {
delete tmp[key];

View File

@ -1,5 +1,4 @@
<h2>{{mode === 'new' ? 'Add new sample' : 'Edit sample '}}</h2>
<!--TODO: title-->
<h2>{{mode === 'new' ? 'Add new sample' : 'Edit sample'}}</h2>
<rb-loading-spinner *ngIf="loading; else content"></rb-loading-spinner>
@ -14,13 +13,13 @@
[rbFormInputAutocomplete]="autocomplete.bind(this, materialNames)" appValidate="stringOf"
(keydown)="preventDefault($event)" (ngModelChange)="findMaterial($event)" ngModel
[appValidateArgs]="[materialNames]" required [(ngModel)]="material.name" [autofocus]="true"
*ngIf="baseSample.material !== undefined || mode === 'new'"
*ngIf="baseSample.material.name !== undefined || mode === 'new'"
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)" *ngIf="baseSample.material !== undefined">
(click)="setNewMaterial(!newMaterial)" *ngIf="baseSample.material.name !== undefined">
New material
</rb-icon-button>
</div>
@ -197,8 +196,12 @@
</button>
</h5>
<div *ngIf="sample.condition.condition_template" [@inOut]>
<rb-form-select name="conditionSelect" label="Condition"
[(ngModel)]="sample.condition.condition_template">
<rb-form-select [name]="'conditionSelect-' + gIndex" label="Condition"
[(ngModel)]="sample.condition.condition_template"
(ngModelChange)="reValidate()">
<option [value]="sample.condition.condition_template">
{{d.id.conditionTemplates[sample.condition.condition_template].name}} - current
</option>
<option *ngFor="let c of d.latest.conditionTemplates" [value]="c._id">{{c.name}}</option>
</rb-form-select>
@ -211,7 +214,7 @@
<option *ngFor="let value of parameter.range.values" [value]="value">{{value}}</option>
<ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
</rb-form-select>
<rb-form-input *ngSwitchDefault
<rb-form-input *ngSwitchDefault (focus)="checkFormAfterInit = true"
[name]="'conditionParameter-' + gIndex + '-' + i"
[label]="parameter.name" appValidate="string" required
[(ngModel)]="sample.condition[parameter.name]" #parameterInput="ngModel">
@ -234,9 +237,11 @@
<rb-form-select [name]="'measurementTemplateSelect-' + gIndex + '-' + mIndex" label="Template"
[(ngModel)]="measurement.measurement_template"
(ngModelChange)="clearMeasurement(gIndex, mIndex)">
<option [value]="sample.condition.condition_template">
{{d.id.measurementTemplates[measurement.measurement_template].name}} - current
</option>
<option *ngFor="let m of d.latest.measurementTemplates" [value]="m._id">{{m.name}}</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)">
@ -328,3 +333,4 @@
Do you really want to delete {{samples.length > 1 ? 'these samples' : 'this sample'}}?
</rb-alert>
</ng-template>

View File

@ -1,6 +1,7 @@
import cloneDeep from 'lodash/cloneDeep';
import merge from 'lodash/merge';
import omit from 'lodash/omit';
import pick from 'lodash/pick';
import isEqual from 'lodash/isEqual';
import strCompare from 'str-compare';
import {
@ -210,6 +211,7 @@ export class SampleComponent implements OnInit, AfterContentChecked {
}
});
}
this.checkFormAfterInit = true;
this.loading--;
sampleIds.slice(1).forEach(sampleId => {
this.api.get<SampleModel>('/sample/' + sampleId, data => {
@ -225,6 +227,7 @@ export class SampleComponent implements OnInit, AfterContentChecked {
}
this.loading--;
this.checkFormAfterInit = true;
console.log(this.baseSample.material.name);
});
});
});
@ -279,6 +282,7 @@ export class SampleComponent implements OnInit, AfterContentChecked {
}
if (formReady) { // fields are ready, do validation
this.checkFormAfterInit = false;
console.log('init');
Object.keys(this.cmForm.form.controls).forEach(field => {
this.cmForm.form.get(field).updateValueAndValidity();
});
@ -310,6 +314,10 @@ export class SampleComponent implements OnInit, AfterContentChecked {
}
}
reValidate() {
setTimeout(() => this.checkFormAfterInit = true, 0);
}
// save base sample
saveSample() {
if (this.samples.length === 0) {
@ -355,7 +363,7 @@ export class SampleComponent implements OnInit, AfterContentChecked {
else {
this.samples.forEach((sample, i) => {
console.log(sample._id);
this.api.put<SampleModel>('/sample/' + sample._id, this.baseSample.sendFormat(), data => {
this.api.put<SampleModel>('/sample/' + sample._id, this.baseSample.sendFormat(false), data => {
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;
@ -370,7 +378,13 @@ export class SampleComponent implements OnInit, AfterContentChecked {
cmSave() { // save measurements and conditions
this.samples.forEach(sample => {
if (sample.condition.condition_template) { // condition was set
this.api.put('/sample/' + sample._id, {condition: sample.condition});
console.log(sample.condition);
console.log(this.d.id.conditionTemplates[sample.condition.condition_template]);
this.api.put('/sample/' + sample._id,
{condition: pick(sample.condition,
['condition_template', ...this.d.id.conditionTemplates[sample.condition.condition_template].parameters.map(e => e.name)]
)}
);
}
sample.measurements.forEach(measurement => { // save measurements
if (Object.keys(measurement.values).map(e => measurement.values[e]).join('') !== '') {

View File

@ -340,7 +340,7 @@ export class SamplesComponent implements OnInit {
updateFilterFields(field) {
const filter = this.filters.filters.find(e => e.field === field);
filter.active = true;
filter.active = !(filter.values.length === 1 && filter.values[0] === '');
}
setSort(string) {

View File

@ -56,7 +56,6 @@
<th>Device</th>
<th>Models</th>
<th></th>
<th></th>
</tr>
<tr *ngFor="let user of users">
@ -71,8 +70,7 @@
{{(i > 0 ? ', ' : '') + modelIds[model]}}
</ng-container>
</td>
<td><span [class]="'rb-ic clickable ' + (user.status === 'new' ? 'rb-ic-edit': 'rb-ic-undo')"
(click)="user.status === 'new' ? user.edit = true: restoreUser(user)"></span></td>
<td><span class="rb-ic clickable rb-ic-edit" (click)="user.edit = true"></span></td>
</ng-container>
<ng-template #editUser>
<td>
@ -134,6 +132,37 @@
</tr>
</rb-table>
<rb-accordion>
<rb-accordion-title [open]="false"><span class="rb-ic rb-ic-delete"></span>&nbsp; Deleted users</rb-accordion-title>
<rb-accordion-body>
<rb-table scrollTop>
<tr>
<th>Name</th>
<th>Email</th>
<th>Level</th>
<th>Location</th>
<th>Device</th>
<th>Models</th>
<th></th>
</tr>
<tr *ngFor="let user of deletedUsers">
<td>{{user.name}}</td>
<td>{{user.email}}</td>
<td>{{user.level}}</td>
<td>{{user.location}}</td>
<td>{{user.devices}}</td>
<td>
<ng-container *ngFor="let model of user.models; index as i">
{{(i > 0 ? ', ' : '') + modelIds[model]}}
</ng-container>
</td>
<td><span class="rb-ic clickable rb-ic-undo" (click)="restoreUser(user)"></span></td>
</tr>
</rb-table>
</rb-accordion-body>
</rb-accordion>
<ng-template #modelOptions>
<option value=""></option>
<ng-container *ngFor="let model of modelSelect">

View File

@ -14,6 +14,7 @@ import {DataService} from '../services/data.service';
export class UsersComponent implements OnInit {
users: UserModel[] = [];
deletedUsers: UserModel[] = [];
newUser: UserModel | null = null;
newUserPass = '';
modelSelect: {id: string, name: string}[] = [];
@ -28,7 +29,8 @@ export class UsersComponent implements OnInit {
ngOnInit(): void {
this.api.get<UserModel[]>('/users', data => {
this.users = data.map(e => new UserModel().deserialize(e));
this.users = data.map(e => new UserModel().deserialize(e)).filter(e => e.status !== 'deleted');
this.deletedUsers = data.map(e => new UserModel().deserialize(e)).filter(e => e.status === 'deleted');
});
this.d.load('modelGroups', () => {
this.d.arr.modelGroups.forEach(group => {
@ -63,6 +65,8 @@ export class UsersComponent implements OnInit {
this.api.delete('/user/' + user.name, () => {
user.status = 'deleted';
user.edit = false;
this.deletedUsers.push(user);
this.users.splice(this.users.findIndex(e => e.name === user.name), 1);
});
}
});
@ -71,6 +75,8 @@ export class UsersComponent implements OnInit {
restoreUser(user) {
this.api.put('/user/restore/' + user.name, {}, () => {
user.status = 'new';
this.users.push(user);
this.deletedUsers.splice(this.deletedUsers.findIndex(e => e.name === user.name), 1);
});
}
}