Merge pull request #9 in ~VLE2FE/dfop-ui from development to master

* commit '56cd4dcbcca94e5db18af4710dce45879031a450':
  convert values range from templates to option element
  changed device_name to devices
This commit is contained in:
Veit Lukas (PEA4-Fe) 2020-08-06 15:25:31 +02:00
commit 732f86d4b8
9 changed files with 3840 additions and 47 deletions

View File

@ -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;
}
}

View File

@ -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');
}

View File

@ -160,14 +160,23 @@
<option *ngFor="let c of d.arr.conditionTemplates" [value]="c._id">{{c.name}}</option>
</rb-form-select>
<rb-form-input *ngFor="let parameter of
<ng-container *ngFor="let parameter of
d.id.conditionTemplates[gSample.condition.condition_template].parameters; index as i"
[ngSwitch]="(parameter.range.values ? 1 : 0)">
<rb-form-select *ngSwitchCase="1"
[name]="'conditionParameter-' + gIndex + '-' + i"
[label]="parameter.name" [(ngModel)]="gSample.condition[parameter.name]" ngModel>
<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
[name]="'conditionParameter-' + gIndex + '-' + i"
[label]="parameter.name" appValidate="string" required
[(ngModel)]="gSample.condition[parameter.name]" #parameterInput="ngModel">
<ng-template rbFormValidationMessage="failure">{{parameterInput.errors.failure}}</ng-template>
<ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
</rb-form-input>
</ng-container>
</div>
</div>
@ -182,21 +191,30 @@
<div *ngFor="let parameter of d.id.measurementTemplates[measurement.measurement_template].parameters;
index as pIndex">
<rb-form-input *ngIf="!parameter.range.type"
<ng-container [ngSwitch]="(parameter.range.type ? 1 : 0) + (parameter.range.values ? 2 : 0)">
<rb-form-file *ngSwitchCase="1"
[name]="'measurementParameter-' + gIndex + '-' + mIndex + '-' + pIndex"
[label]="parameter.name" maxSize="10000000" multiple
[required]="measurement.values[parameter.name] &&
!measurement.values[parameter.name].length"
(ngModelChange)="fileToArray($event, gIndex, mIndex, parameter.name)"
placeholder="Select file or drag and drop" dragDrop ngModel>
<ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
</rb-form-file>
<rb-form-select *ngSwitchCase="2"
[name]="'measurementParameter-' + gIndex + '-' + mIndex + '-' + pIndex"
[label]="parameter.name" [(ngModel)]="measurement.values[parameter.name]" ngModel>
<option *ngFor="let device of d.d.user.devices" [value]="device">{{device}}</option>
<ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
</rb-form-select>
<rb-form-input *ngSwitchDefault
[name]="'measurementParameter-' + gIndex + '-' + mIndex + '-' + pIndex"
[label]="parameter.name" appValidate="string"
[(ngModel)]="measurement.values[parameter.name]" #parameterInput="ngModel">
<ng-template rbFormValidationMessage="failure">{{parameterInput.errors.failure}}</ng-template>
<ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
</rb-form-input>
<rb-form-file *ngIf="parameter.range.type"
[name]="'measurementParameter-' + gIndex + '-' + mIndex + '-' + pIndex"
[label]="parameter.name" maxSize="10000000" multiple
[required]="measurement.values[parameter.name] && !measurement.values[parameter.name].length"
(ngModelChange)="fileToArray($event, gIndex, mIndex, parameter.name)"
placeholder="Select file or drag and drop" dragDrop ngModel>
<ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
</rb-form-file>
</ng-container>
<canvas baseChart *ngIf="parameter.range.type && charts[gIndex][mIndex][0].data.length > 0"
class="dpt-chart"
[@inOut]

View File

@ -124,6 +124,17 @@ export class SampleComponent implements OnInit, AfterContentChecked {
this.loading--;
});
this.d.load('measurementTemplates', () => {
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.device_name;
});
if (!this.new) {
this.loading++;
this.api.get<SampleModel>('/sample/' + this.route.snapshot.paramMap.get('id'), sData => {

View File

@ -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;

View File

@ -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; }, {});
}
}

View File

@ -15,10 +15,13 @@
<ng-template rbFormValidationMessage="failure">{{locationInput.errors.failure}}</ng-template>
<ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
</rb-form-input>
<rb-form-input name="device" label="device" appValidate="string" [(ngModel)]="user.device_name"
<rb-array-input [(ngModel)]="user.devices" name="devices" [pushTemplate]="''">
<rb-form-input *rbArrayInputItem="let item" rbArrayInputListener="devices" [index]="item.i"
label="device" appValidate="string" [name]="'device-' + item.i" [ngModel]="item.value"
#deviceInput="ngModel">
<ng-template rbFormValidationMessage="failure">{{deviceInput.errors.failure}}</ng-template>
</rb-form-input>
</rb-array-input>
<rb-icon-button icon="save" mode="primary" type="submit" [disabled]="!userForm.form.valid" (click)="saveUser()">
Save change
</rb-icon-button>

View File

@ -21,10 +21,13 @@
<ng-template rbFormValidationMessage="failure">{{locationInput.errors.failure}}</ng-template>
<ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
</rb-form-input>
<rb-form-input name="device" label="device" appValidate="string" [(ngModel)]="newUser.device_name"
<rb-array-input [(ngModel)]="newUser.devices" name="devices" [pushTemplate]="''">
<rb-form-input *rbArrayInputItem="let item" rbArrayInputListener="devices" [index]="item.i"
label="device" appValidate="string" [name]="'device-' + item.i" [ngModel]="item.value"
#deviceInput="ngModel">
<ng-template rbFormValidationMessage="failure">{{deviceInput.errors.failure}}</ng-template>
</rb-form-input>
</rb-array-input>
<rb-form-input name="passA" type="password" label="new password" appValidate="password" required
[(ngModel)]="newUserPass" #passAInput="ngModel">
<ng-template rbFormValidationMessage="failure">{{passAInput.errors.failure}}</ng-template>
@ -54,12 +57,13 @@
<td>{{user.email}}</td>
<td>{{user.level}}</td>
<td>{{user.location}}</td>
<td>{{user.device_name}}</td>
<td>{{user.devices}}</td>
<td><span class="rb-ic rb-ic-edit clickable" (click)="user.edit = true"></span></td>
</ng-container>
<ng-template #editUser>
<td>
<rb-form-input [name]="'name-' + user.name" appValidate="username" required [(ngModel)]="user.name" #nameInput="ngModel">
<rb-form-input [name]="'name-' + user.name" appValidate="username" required [(ngModel)]="user.name"
#nameInput="ngModel">
<ng-template rbFormValidationMessage="failure">{{nameInput.errors.failure}}</ng-template>
<ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
</rb-form-input>
@ -83,12 +87,18 @@
</rb-form-input>
</td>
<td>
<rb-form-input [name]="'device-' + user.name" appValidate="string" [(ngModel)]="user.device_name"
#deviceInput="ngModel">
<ng-template rbFormValidationMessage="failure">{{deviceInput.errors.failure}}</ng-template>
<rb-array-input [(ngModel)]="user.devices" name="devices" [pushTemplate]="''">
<rb-form-input *rbArrayInputItem="let item" rbArrayInputListener="devices" [index]="item.i"
label="device" appValidate="string" [name]="'device-' + item.i" [ngModel]="item.value">
</rb-form-input>
</rb-array-input>
</td>
<td>
<rb-icon-button icon="save" mode="primary" (click)="saveUser(user)"
[disabled]="nameInput.invalid || emailInput.invalid || locationInput.invalid">
Save
</rb-icon-button>
</td>
<td><rb-icon-button icon="save" mode="primary" (click)="saveUser(user)" [disabled]="nameInput.invalid || emailInput.invalid || locationInput.invalid || deviceInput.invalid">Save</rb-icon-button></td>
</ng-template>
</tr>
</rb-table>

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 90 KiB

After

Width:  |  Height:  |  Size: 129 KiB