From 4376adc1ebcae2d6bbb109cc07c6308ce19eb140 Mon Sep 17 00:00:00 2001 From: VLE2FE Date: Thu, 6 Aug 2020 14:08:11 +0200 Subject: [PATCH 1/2] changed device_name to devices --- src/app/models/user.model.ts | 4 +- src/app/sample/sample.component.ts | 2 +- src/app/samples/samples.component.ts | 1 + src/app/settings/settings.component.html | 11 +- src/app/users/users.component.html | 32 +- src/assets/imgs/db_structure_latest.svg | 3749 +++++++++++++++++++++- 6 files changed, 3778 insertions(+), 21 deletions(-) diff --git a/src/app/models/user.model.ts b/src/app/models/user.model.ts index 5e1488f..a3f7cd7 100644 --- a/src/app/models/user.model.ts +++ b/src/app/models/user.model.ts @@ -9,7 +9,7 @@ export class UserModel extends BaseModel{ email = ''; level = ''; location = ''; - device_name = ''; + devices = ['']; edit = false; deserialize(input: any): this { @@ -19,7 +19,7 @@ export class UserModel extends BaseModel{ } sendFormat(mode = 'user') { - const keys = ['name', 'email', 'location', 'device_name']; + const keys = ['name', 'email', 'location', 'devices']; if (mode === 'admin') { keys.push('level'); } diff --git a/src/app/sample/sample.component.ts b/src/app/sample/sample.component.ts index e484f4f..5388889 100644 --- a/src/app/sample/sample.component.ts +++ b/src/app/sample/sample.component.ts @@ -137,7 +137,7 @@ export class SampleComponent implements OnInit, AfterContentChecked { this.loading--; }); this.d.load('user', () => { - this.defaultDevice = this.d.d.user.device_name; + this.defaultDevice = this.d.d.user.devices[0]; }); if (!this.new) { this.loading++; diff --git a/src/app/samples/samples.component.ts b/src/app/samples/samples.component.ts index 0bfc48a..45a7ee6 100644 --- a/src/app/samples/samples.component.ts +++ b/src/app/samples/samples.component.ts @@ -97,6 +97,7 @@ export class SamplesComponent implements OnInit { this.filters.filters.find(e => e.field === 'color').autocomplete = [...new Set(this.d.arr.materials.reduce((s, e) => {s.push(...e.numbers.map(el => el.color)); return s; }, []))]; this.loadSamples(); + console.log(this.d.id.materials); }); this.d.load('materialSuppliers', () => { this.filters.filters.find(e => e.field === 'material.supplier').autocomplete = this.d.arr.materialSuppliers; diff --git a/src/app/settings/settings.component.html b/src/app/settings/settings.component.html index 8e73ba1..2b5b9b4 100644 --- a/src/app/settings/settings.component.html +++ b/src/app/settings/settings.component.html @@ -15,10 +15,13 @@ {{locationInput.errors.failure}} Cannot be empty - - {{deviceInput.errors.failure}} - + + + {{deviceInput.errors.failure}} + + Save change diff --git a/src/app/users/users.component.html b/src/app/users/users.component.html index b176428..fbff322 100644 --- a/src/app/users/users.component.html +++ b/src/app/users/users.component.html @@ -21,10 +21,13 @@ {{locationInput.errors.failure}} Cannot be empty - - {{deviceInput.errors.failure}} - + + + {{deviceInput.errors.failure}} + + {{passAInput.errors.failure}} @@ -54,12 +57,13 @@ {{user.email}} {{user.level}} {{user.location}} - {{user.device_name}} + {{user.devices}} - + {{nameInput.errors.failure}} Cannot be empty @@ -83,12 +87,18 @@ - - {{deviceInput.errors.failure}} - + + + + + + + + Save + - Save diff --git a/src/assets/imgs/db_structure_latest.svg b/src/assets/imgs/db_structure_latest.svg index 5dccaf4..e5f79fc 100644 --- a/src/assets/imgs/db_structure_latest.svg +++ b/src/assets/imgs/db_structure_latest.svg @@ -1,3 +1,3746 @@ - - -
measurements
measurements
materials
materials
samples
samples
_id
_id
_id
_id
values
values
_id
_id
number
number
numbers
numbers
material_name
material_name
batch
batch
comment
comment
location
location
models
models
name
name
status
status
notes
notes
data
data
_id
_id
users
users
name
name
pass
pass
level
level
_id
_id
type
type
measurement_templates
measurement_templates
_id
_id
parameters
parameters
range
range
name
name
name
name
color
color
sample_references
sample_references
device_name
device_name
condition_templates
condition_templates
_id
_id
parameters
parameters
range
range
name
name
name
name
custom fields
custom fields
key
key
email
email
note_fields
note_fields
name
name
qty
qty
sample_id
sample_id
relation
relation
version
version
version
version
status
status
status
status
condition
condition
parameters
parameters
material_groups
material_groups
material_suppliers
material_suppliers
_id
_id
name
name
_id
_id
name
name
first_id
first_id
first_id
first_id
changelog
changelog
_id
_id
collection
collection
data
data
condition
condition
action
action
material_templates
material_templates
_id
_id
parameters
parameters
range
range
name
name
name
name
version
version
first_id
first_id
properties
properties
parameters
parameters
Viewer does not support full SVG 1.1
\ No newline at end of file + + + + + + image/svg+xml + + + + + + + + + + + + + + + measurements + + + + measurements + + + + + + + + + materials + + + + materials + + + + + + + + + samples + + + + samples + + + + + + + + + _id + + + + _id + + + + + + + + + _id + + + + _id + + + + + + + + + values + + + + values + + + + + + + + + _id + + + + _id + + + + + + + + + number + + + + number + + + + + + + + + numbers + + + + numbers + + + + + + + + + material_name + + + + material_name + + + + + + + + + batch + + + + batch + + + + + + + + + comment + + + + comment + + + + + + + + + location + + + + location + + + + + + + + + + + models + + + + models + + + + + + + + + name + + + + name + + + + + + + + + status + + + + status + + + + + + + + + notes + + + + notes + + + + + + + + + + data + + + + data + + + + + + + + + _id + + + + _id + + + + + + + + + users + + + + users + + + + + + + + + name + + + + name + + + + + + + + + pass + + + + pass + + + + + + + + + level + + + + level + + + + + + + + + + + _id + + + + _id + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + type + + + + type + + + + + + + + + + measurement_templates + + + + measurement_templates + + + + + + + + + + + _id + + + + _id + + + + + + + + + + parameters + + + + parameters + + + + + + + + + range + + + + range + + + + + + + + + name + + + + name + + + + + + + + + name + + + + name + + + + + + + + + + + + + color + + + + color + + + + + + + + + + sample_references + + + + sample_references + + + + + + + + + devices + + + + devices + + + + + + + + + + + + + + condition_templates + + + + condition_templates + + + + + + + + + _id + + + + _id + + + + + + + + + + parameters + + + + parameters + + + + + + + + + range + + + + range + + + + + + + + + name + + + + name + + + + + + + + + name + + + + name + + + + + + + + + + + + + + custom fields + + + + custom fields + + + + + + + + + key + + + + key + + + + + + + + + email + + + + email + + + + + + + + + note_fields + + + + note_fields + + + + + + + + + name + + + + name + + + + + + + + + qty + + + + qty + + + + + + + + + + + + + sample_id + + + + sample_id + + + + + + + + + relation + + + + relation + + + + + + + + + + + + + version + + + + version + + + + + + + + + + + version + + + + version + + + + + + + + + + + status + + + + status + + + + + + + + + status + + + + status + + + + + + + + + + + condition + + + + condition + + + + + + + + + + + + parameters + + + + parameters + + + + + + + + + + material_groups + + + + material_groups + + + + + + + + + material_suppliers + + + + material_suppliers + + + + + + + + + _id + + + + _id + + + + + + + + + name + + + + name + + + + + + + + + _id + + + + _id + + + + + + + + + name + + + + name + + + + + + + + + + + + + first_id + + + + first_id + + + + + + + + + + first_id + + + + first_id + + + + + + + + + + changelog + + + + changelog + + + + + + + + + _id + + + + _id + + + + + + + + + collection + + + + collection + + + + + + + + + data + + + + data + + + + + + + + + + + + + + condition + + + + condition + + + + + + + + + action + + + + action + + + + + + + + + + + + + + material_templates + + + + material_templates + + + + + + + + + _id + + + + _id + + + + + + + + + + parameters + + + + parameters + + + + + + + + + range + + + + range + + + + + + + + + name + + + + name + + + + + + + + + name + + + + name + + + + + + + + + + + + + version + + + + version + + + + + + + + + + + first_id + + + + first_id + + + + + + + + + + properties + + + + properties + + + + + + + + + + parameters + + + + parameters + + + + + From 56cd4dcbcca94e5db18af4710dce45879031a450 Mon Sep 17 00:00:00 2001 From: VLE2FE Date: Thu, 6 Aug 2020 15:23:44 +0200 Subject: [PATCH 2/2] 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; }, {}); + } }