From 56cd4dcbcca94e5db18af4710dce45879031a450 Mon Sep 17 00:00:00 2001 From: VLE2FE Date: Thu, 6 Aug 2020 15:23:44 +0200 Subject: [PATCH] convert values range from templates to option element --- src/app/models/template.model.ts | 6 +++ src/app/sample/sample.component.html | 64 ++++++++++++++++++---------- src/app/sample/sample.component.ts | 14 ++++-- src/app/services/data.service.ts | 6 ++- 4 files changed, 63 insertions(+), 27 deletions(-) diff --git a/src/app/models/template.model.ts b/src/app/models/template.model.ts index 23cbbe6..94be281 100644 --- a/src/app/models/template.model.ts +++ b/src/app/models/template.model.ts @@ -7,4 +7,10 @@ export class TemplateModel extends BaseModel { version = 0; first_id: IdModel = null; parameters: {name: string, range: {[prop: string]: any}, rangeString?: string}[] = []; + + deserialize(input: any): this { + Object.assign(this, input); + + return this; + } } diff --git a/src/app/sample/sample.component.html b/src/app/sample/sample.component.html index 6260eda..b8f1818 100644 --- a/src/app/sample/sample.component.html +++ b/src/app/sample/sample.component.html @@ -160,14 +160,23 @@ - - {{parameterInput.errors.failure}} - Cannot be empty - + + + + Cannot be empty + + + {{parameterInput.errors.failure}} + Cannot be empty + + @@ -182,21 +191,30 @@
- - {{parameterInput.errors.failure}} - Cannot be empty - - - Cannot be empty - + + + Cannot be empty + + + + Cannot be empty + + + {{parameterInput.errors.failure}} + Cannot be empty + + { + this.d.load('user', () => { + this.defaultDevice = this.d.d.user.devices[0]; + // spectrum device must be from user's devices list + this.d.arr.measurementTemplates.forEach(template => { + const device = template.parameters.find(e => e.name === 'device'); + if (device) { + device.range.values = this.d.d.user.devices; + } + }); + this.d.idReload('measurementTemplates'); + }); this.loading--; }); this.d.load('materialTemplates', () => { @@ -136,9 +147,6 @@ export class SampleComponent implements OnInit, AfterContentChecked { this.availableCustomFields = this.d.arr.sampleNotesFields.map(e => e.name); this.loading--; }); - this.d.load('user', () => { - this.defaultDevice = this.d.d.user.devices[0]; - }); if (!this.new) { this.loading++; this.api.get('/sample/' + this.route.snapshot.paramMap.get('id'), sData => { diff --git a/src/app/services/data.service.ts b/src/app/services/data.service.ts index b3196e4..497b643 100644 --- a/src/app/services/data.service.ts +++ b/src/app/services/data.service.ts @@ -40,7 +40,7 @@ export class DataService { if (this.collectionMap[collection].array) { // array data this.arr[collection] = data .map(e => this.collectionMap[collection].model ? new this.collectionMap[collection].model().deserialize(e) : e); - this.id[collection] = this.arr[collection].reduce((s, e) => {s[e._id] = e; return s; }, {}); + this.idReload(collection); } else { // not array data this.d[collection] = new this.collectionMap[collection].model().deserialize(data); @@ -49,4 +49,8 @@ export class DataService { }); } } + + idReload(collection) { + this.id[collection] = this.arr[collection].reduce((s, e) => {s[e._id] = e; return s; }, {}); + } }