From 04c2ff2678a447a97dd82ed7260b85cdd3126623 Mon Sep 17 00:00:00 2001 From: VLE2FE Date: Thu, 27 Aug 2020 13:56:55 +0200 Subject: [PATCH 1/2] template fixes --- src/app/app.component.html | 4 ++-- src/app/models/sample.model.ts | 8 +++++-- src/app/sample/sample.component.html | 16 ++++++++----- src/app/sample/sample.component.ts | 3 ++- src/app/samples/samples.component.ts | 2 +- src/app/users/users.component.html | 35 +++++++++++++++++++++++++--- src/app/users/users.component.ts | 8 ++++++- 7 files changed, 60 insertions(+), 16 deletions(-) diff --git a/src/app/app.component.html b/src/app/app.component.html index dd81ca9..d026c27 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -37,7 +37,7 @@
- + Bug @@ -48,7 +48,7 @@ Send report - DEVELOPMENT + DEVELOPMENT DeFinMa
diff --git a/src/app/models/sample.model.ts b/src/app/models/sample.model.ts index e1d3c86..966d2b7 100644 --- a/src/app/models/sample.model.ts +++ b/src/app/models/sample.model.ts @@ -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]; diff --git a/src/app/sample/sample.component.html b/src/app/sample/sample.component.html index ad1f03c..17c94f6 100644 --- a/src/app/sample/sample.component.html +++ b/src/app/sample/sample.component.html @@ -1,5 +1,4 @@ -

{{mode === 'new' ? 'Add new sample' : 'Edit sample '}}

- +

{{mode === 'new' ? 'Add new sample' : 'Edit sample'}}

@@ -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"> Cannot be empty Unknown material, add properties for new material + (click)="setNewMaterial(!newMaterial)" *ngIf="baseSample.material.name !== undefined"> New material @@ -197,8 +196,11 @@
- + @@ -234,9 +236,11 @@ + -
diff --git a/src/app/sample/sample.component.ts b/src/app/sample/sample.component.ts index dadcfc1..18046cf 100644 --- a/src/app/sample/sample.component.ts +++ b/src/app/sample/sample.component.ts @@ -225,6 +225,7 @@ export class SampleComponent implements OnInit, AfterContentChecked { } this.loading--; this.checkFormAfterInit = true; + console.log(this.baseSample.material.name); }); }); }); @@ -355,7 +356,7 @@ export class SampleComponent implements OnInit, AfterContentChecked { else { this.samples.forEach((sample, i) => { console.log(sample._id); - this.api.put('/sample/' + sample._id, this.baseSample.sendFormat(), data => { + this.api.put('/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; diff --git a/src/app/samples/samples.component.ts b/src/app/samples/samples.component.ts index 33ce4fd..4cdf0f3 100644 --- a/src/app/samples/samples.component.ts +++ b/src/app/samples/samples.component.ts @@ -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) { diff --git a/src/app/users/users.component.html b/src/app/users/users.component.html index 2b7a457..16c5fb9 100644 --- a/src/app/users/users.component.html +++ b/src/app/users/users.component.html @@ -56,7 +56,6 @@ Device Models - @@ -71,8 +70,7 @@ {{(i > 0 ? ', ' : '') + modelIds[model]}} - + @@ -134,6 +132,37 @@ + +   Deleted users + + + + Name + Email + Level + Location + Device + Models + + + + + {{user.name}} + {{user.email}} + {{user.level}} + {{user.location}} + {{user.devices}} + + + {{(i > 0 ? ', ' : '') + modelIds[model]}} + + + + + + + + diff --git a/src/app/users/users.component.ts b/src/app/users/users.component.ts index 27c587f..fad50dd 100644 --- a/src/app/users/users.component.ts +++ b/src/app/users/users.component.ts @@ -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('/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); }); } } From 819666c3444181dbe6e08ab155b4b027149217e2 Mon Sep 17 00:00:00 2001 From: VLE2FE Date: Thu, 27 Aug 2020 15:45:52 +0200 Subject: [PATCH 2/2] condition fix --- src/app/sample/sample.component.html | 6 ++++-- src/app/sample/sample.component.ts | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/app/sample/sample.component.html b/src/app/sample/sample.component.html index 17c94f6..3448b5b 100644 --- a/src/app/sample/sample.component.html +++ b/src/app/sample/sample.component.html @@ -197,7 +197,8 @@
+ [(ngModel)]="sample.condition.condition_template" + (ngModelChange)="reValidate()"> @@ -213,7 +214,7 @@ Cannot be empty - @@ -332,3 +333,4 @@ Do you really want to delete {{samples.length > 1 ? 'these samples' : 'this sample'}}? + diff --git a/src/app/sample/sample.component.ts b/src/app/sample/sample.component.ts index 18046cf..9fa4ba0 100644 --- a/src/app/sample/sample.component.ts +++ b/src/app/sample/sample.component.ts @@ -1,6 +1,7 @@ import cloneDeep from 'lodash/cloneDeep'; import merge from 'lodash/merge'; import omit from 'lodash/omit'; +import pick from 'lodash/pick'; import isEqual from 'lodash/isEqual'; import strCompare from 'str-compare'; import { @@ -210,6 +211,7 @@ export class SampleComponent implements OnInit, AfterContentChecked { } }); } + this.checkFormAfterInit = true; this.loading--; sampleIds.slice(1).forEach(sampleId => { this.api.get('/sample/' + sampleId, data => { @@ -280,6 +282,7 @@ export class SampleComponent implements OnInit, AfterContentChecked { } if (formReady) { // fields are ready, do validation this.checkFormAfterInit = false; + console.log('init'); Object.keys(this.cmForm.form.controls).forEach(field => { this.cmForm.form.get(field).updateValueAndValidity(); }); @@ -311,6 +314,10 @@ export class SampleComponent implements OnInit, AfterContentChecked { } } + reValidate() { + setTimeout(() => this.checkFormAfterInit = true, 0); + } + // save base sample saveSample() { if (this.samples.length === 0) { @@ -371,7 +378,13 @@ export class SampleComponent implements OnInit, AfterContentChecked { cmSave() { // save measurements and conditions this.samples.forEach(sample => { if (sample.condition.condition_template) { // condition was set - this.api.put('/sample/' + sample._id, {condition: sample.condition}); + console.log(sample.condition); + console.log(this.d.id.conditionTemplates[sample.condition.condition_template]); + this.api.put('/sample/' + sample._id, + {condition: pick(sample.condition, + ['condition_template', ...this.d.id.conditionTemplates[sample.condition.condition_template].parameters.map(e => e.name)] + )} + ); } sample.measurements.forEach(measurement => { // save measurements if (Object.keys(measurement.values).map(e => measurement.values[e]).join('') !== '') {