From 2fb5d846d6d17d49e8a4d3e126c96dffc30e801e Mon Sep 17 00:00:00 2001 From: VLE2FE Date: Thu, 30 Jul 2020 14:23:51 +0200 Subject: [PATCH] cherry picking for lodash --- cf_config/Staticfile | 2 +- cf_config/nginx.conf | 9 +++++++++ src/app/app-routing.module.ts | 3 +-- src/app/app.component.ts | 11 ++--------- src/app/models/material.model.ts | 4 ++-- src/app/models/measurement.model.ts | 7 ++++--- src/app/models/sample.model.ts | 10 +++++++--- src/app/models/user.model.ts | 4 ++-- src/app/object.pipe.ts | 6 +++--- .../rb-array-input/rb-array-input.component.ts | 9 ++++----- src/app/sample/sample.component.ts | 9 ++++----- src/app/samples/samples.component.scss | 2 +- src/app/samples/samples.component.ts | 10 +++++----- src/app/templates/templates.component.ts | 12 +++++++----- 14 files changed, 52 insertions(+), 46 deletions(-) create mode 100644 cf_config/nginx.conf diff --git a/cf_config/Staticfile b/cf_config/Staticfile index b6f086b..9357ba4 100644 --- a/cf_config/Staticfile +++ b/cf_config/Staticfile @@ -1,4 +1,4 @@ pushstate: enabled force_https: true root: UI -location_include: ../../headers.conf +location_include: ../../*.conf diff --git a/cf_config/nginx.conf b/cf_config/nginx.conf new file mode 100644 index 0000000..841957f --- /dev/null +++ b/cf_config/nginx.conf @@ -0,0 +1,9 @@ +gzip on; +gzip_disable "msie6"; + +gzip_vary on; +gzip_proxied any; +gzip_comp_level 6; +gzip_buffers 16 8k; +gzip_http_version 1.1; +gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript; diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 8fa4f6c..e17a583 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -17,8 +17,7 @@ const routes: Routes = [ {path: 'samples/new', component: SampleComponent, canActivate: [LoginService]}, {path: 'samples/edit/:id', component: SampleComponent, canActivate: [LoginService]}, {path: 'templates', component: TemplatesComponent, canActivate: [LoginService]}, - // {path: 'users', component: UsersComponent, canActivate: [LoginService]}, - {path: 'users', component: UsersComponent}, // TODO: change + {path: 'users', component: UsersComponent, canActivate: [LoginService]}, {path: 'settings', component: SettingsComponent, canActivate: [LoginService]}, {path: 'documentation', component: DocumentationComponent}, diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 77cccbb..22ec18b 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -3,18 +3,11 @@ import {LoginService} from './services/login.service'; import {Router} from '@angular/router'; // TODO: add multiple samples at once -// TODO: guess properties from material name -// TODO: validation: VZ, Humidity: min/max value, DPT: filename +// TODO: validation: DPT: filename // TODO: filter by not completely filled/no measurements -// TODO: account -// TODO: admin user handling, template pages, validation of samples -// TODO: activate filter on start typing +// TODO: validation of samples -// TODO: Build IconComponent free lib version because of CSP -// TODO: more helmet headers, UI presentatin plan -// TODO: sort material numbers, filter field measurements // TODO: get rid of chart.js (+moment.js) and lodash -// TODO: look into CSS/XHR/Anfragen tab of console @Component({ selector: 'app-root', diff --git a/src/app/models/material.model.ts b/src/app/models/material.model.ts index 30e37f6..d69cc7f 100644 --- a/src/app/models/material.model.ts +++ b/src/app/models/material.model.ts @@ -1,4 +1,4 @@ -import _ from 'lodash'; +import pick from 'lodash/pick'; import {IdModel} from './id.model'; import {BaseModel} from './base.model'; @@ -11,6 +11,6 @@ export class MaterialModel extends BaseModel { numbers: string[] = ['']; sendFormat() { - return _.pick(this, ['name', 'supplier', 'group', 'numbers', 'properties']); + return pick(this, ['name', 'supplier', 'group', 'numbers', 'properties']); } } diff --git a/src/app/models/measurement.model.ts b/src/app/models/measurement.model.ts index 4539430..8002bc5 100644 --- a/src/app/models/measurement.model.ts +++ b/src/app/models/measurement.model.ts @@ -1,4 +1,5 @@ -import _ from 'lodash'; +import omit from 'lodash/omit'; +import pick from 'lodash/pick'; import {IdModel} from './id.model'; import {BaseModel} from './base.model'; @@ -23,7 +24,7 @@ export class MeasurementModel extends BaseModel { return this; } - sendFormat(omit = []) { - return _.omit(_.pick(this, ['sample_id', 'measurement_template', 'values']), omit); + sendFormat(omitValues = []) { + return omit(pick(this, ['sample_id', 'measurement_template', 'values']), omitValues); } } diff --git a/src/app/models/sample.model.ts b/src/app/models/sample.model.ts index 18cbfc1..26cea2b 100644 --- a/src/app/models/sample.model.ts +++ b/src/app/models/sample.model.ts @@ -1,4 +1,4 @@ -import _ from 'lodash'; +import pick from 'lodash/pick'; import {IdModel} from './id.model'; import {MaterialModel} from './material.model'; import {MeasurementModel} from './measurement.model'; @@ -16,7 +16,11 @@ export class SampleModel extends BaseModel { measurements: MeasurementModel[] = []; note_id: IdModel = null; user_id: IdModel = null; - notes: {comment: string, sample_references: {sample_id: IdModel, relation: string}[], custom_fields: {[prop: string]: string}} = {comment: '', sample_references: [], custom_fields: {}}; + notes: { + comment: string, + sample_references: {sample_id: IdModel, relation: string}[], + custom_fields: {[prop: string]: string} + } = {comment: '', sample_references: [], custom_fields: {}}; added: Date = null; deserialize(input: any): this { @@ -35,6 +39,6 @@ export class SampleModel extends BaseModel { } sendFormat() { - return _.pick(this, ['color', 'type', 'batch', 'condition', 'material_id', 'notes']); + return pick(this, ['color', 'type', 'batch', 'condition', 'material_id', 'notes']); } } diff --git a/src/app/models/user.model.ts b/src/app/models/user.model.ts index 66f62fe..5e1488f 100644 --- a/src/app/models/user.model.ts +++ b/src/app/models/user.model.ts @@ -1,4 +1,4 @@ -import _ from 'lodash'; +import pick from 'lodash/pick'; import {BaseModel} from './base.model'; import {IdModel} from './id.model'; @@ -23,6 +23,6 @@ export class UserModel extends BaseModel{ if (mode === 'admin') { keys.push('level'); } - return _.pick(this, keys); + return pick(this, keys); } } diff --git a/src/app/object.pipe.ts b/src/app/object.pipe.ts index 27c101b..eed5e53 100644 --- a/src/app/object.pipe.ts +++ b/src/app/object.pipe.ts @@ -1,5 +1,5 @@ import { Pipe, PipeTransform } from '@angular/core'; -import _ from 'lodash'; +import omit from 'lodash/omit'; @Pipe({ name: 'object', @@ -7,8 +7,8 @@ import _ from 'lodash'; }) export class ObjectPipe implements PipeTransform { - transform(value: object, omit: string[] = []): string { - const res = _.omit(value, omit); + transform(value: object, omitValue: string[] = []): string { + const res = omit(value, omitValue); return res && Object.keys(res).length ? JSON.stringify(res) : ''; } diff --git a/src/app/rb-custom-inputs/rb-array-input/rb-array-input.component.ts b/src/app/rb-custom-inputs/rb-array-input/rb-array-input.component.ts index 82501eb..f7b7d50 100644 --- a/src/app/rb-custom-inputs/rb-array-input/rb-array-input.component.ts +++ b/src/app/rb-custom-inputs/rb-array-input/rb-array-input.component.ts @@ -10,7 +10,7 @@ import { TemplateRef } from '@angular/core'; import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms'; -import _ from 'lodash'; +import cloneDeep from 'lodash/cloneDeep'; import {ArrayInputHelperService} from './array-input-helper.service'; @@ -87,7 +87,6 @@ export class RbArrayInputComponent implements ControlValueAccessor, OnInit, Afte else { this.values[data.index] = data.value; } - console.log(111, this.values); this.updateArray(); }); }, 0); @@ -104,7 +103,7 @@ export class RbArrayInputComponent implements ControlValueAccessor, OnInit, Afte } // add element if last all are filled else if (this.values.filter(e => e[this.pushPath] !== '').length === this.values.length) { - this.values.push(_.cloneDeep(this.pushTemplate)); + this.values.push(cloneDeep(this.pushTemplate)); } res = this.values.filter(e => e[this.pushPath] !== ''); } @@ -114,7 +113,7 @@ export class RbArrayInputComponent implements ControlValueAccessor, OnInit, Afte this.values.pop(); } else if (this.values.filter(e => e !== '').length === this.values.length) { // add element if all are is filled - this.values.push(_.cloneDeep(this.pushTemplate)); + this.values.push(cloneDeep(this.pushTemplate)); } res = this.values.filter(e => e !== ''); } @@ -134,7 +133,7 @@ export class RbArrayInputComponent implements ControlValueAccessor, OnInit, Afte if (this.values.length === 0 || this.values[0] !== '') { // add empty last field if pushTemplate is specified if (this.pushTemplate !== null) { - this.values.push(_.cloneDeep(this.pushTemplate)); + this.values.push(cloneDeep(this.pushTemplate)); } } } diff --git a/src/app/sample/sample.component.ts b/src/app/sample/sample.component.ts index c03ab0f..2bd4f6d 100644 --- a/src/app/sample/sample.component.ts +++ b/src/app/sample/sample.component.ts @@ -1,4 +1,4 @@ -import _ from 'lodash'; +import cloneDeep from 'lodash/cloneDeep'; import strCompare from 'str-compare'; import { AfterContentChecked, @@ -22,7 +22,6 @@ import {ModalService} from '@inst-iot/bosch-angular-ui-components'; import {UserModel} from '../models/user.model'; -// TODO: work on better recognition for file input // TODO: only show condition (if not set) and measurements in edit sample dialog at first // TODO: multiple samples for base data, extend multiple measurements, conditions @@ -144,7 +143,7 @@ export class SampleComponent implements OnInit, AfterContentChecked { const spectrumTemplate = this.measurementTemplates.find(e => e.name === 'spectrum')._id; let spectrumCounter = 0; this.sample.measurements.forEach((measurement, i) => { - this.charts.push(_.cloneDeep(this.chartInit)); + this.charts.push(cloneDeep(this.chartInit)); if (measurement.measurement_template === spectrumTemplate) { setTimeout(() => { this.generateChart(measurement.values.dpt, i); @@ -313,7 +312,7 @@ export class SampleComponent implements OnInit, AfterContentChecked { findMaterial(name) { const res = this.materials.find(e => e.name === name); // search for match if (res) { - this.material = _.cloneDeep(res); + this.material = cloneDeep(res); this.sample.material_id = this.material._id; } else { @@ -371,7 +370,7 @@ export class SampleComponent implements OnInit, AfterContentChecked { addMeasurement() { this.sample.measurements.push(new MeasurementModel(this.measurementTemplates.filter(e => e.name === 'spectrum').reverse()[0]._id)); this.sample.measurements[this.sample.measurements.length - 1].values.device = this.defaultDevice; - this.charts.push(_.cloneDeep(this.chartInit)); + this.charts.push(cloneDeep(this.chartInit)); } removeMeasurement(index) { diff --git a/src/app/samples/samples.component.scss b/src/app/samples/samples.component.scss index 7c2cc64..7d9f0d4 100644 --- a/src/app/samples/samples.component.scss +++ b/src/app/samples/samples.component.scss @@ -8,7 +8,7 @@ margin-bottom: 10px; } - button { + rb-icon-button { float: right; } } diff --git a/src/app/samples/samples.component.ts b/src/app/samples/samples.component.ts index 3523e14..a4dd544 100644 --- a/src/app/samples/samples.component.ts +++ b/src/app/samples/samples.component.ts @@ -1,7 +1,8 @@ import {Component, ElementRef, isDevMode, OnInit, ViewChild} from '@angular/core'; import {ApiService} from '../services/api.service'; import {AutocompleteService} from '../services/autocomplete.service'; -import _ from 'lodash'; +import cloneDeep from 'lodash/cloneDeep'; +import pick from 'lodash/pick'; import {SampleModel} from '../models/sample.model'; @@ -24,7 +25,6 @@ interface KeyInterface { }) -// TODO: check if custom-header.conf works, add headers from helmet https://docs.cloudfoundry.org/buildpacks/staticfile/index.html export class SamplesComponent implements OnInit { @@ -214,7 +214,7 @@ export class SamplesComponent implements OnInit { } }); - query.push(..._.cloneDeep(this.filters.filters) + query.push(...cloneDeep(this.filters.filters) .map(e => { e.values = e.values.filter(el => el !== ''); // do not include empty values if (e.field === 'added') { // correct timezone @@ -223,7 +223,7 @@ export class SamplesComponent implements OnInit { return e; }) .filter(e => e.active && e.values.length > 0) - .map(e => 'filters[]=' + encodeURIComponent(JSON.stringify(_.pick(e, ['mode', 'field', 'values'])))) + .map(e => 'filters[]=' + encodeURIComponent(JSON.stringify(pick(e, ['mode', 'field', 'values'])))) ); if (!options.export) { additionalTableKeys.forEach(key => { @@ -269,7 +269,7 @@ export class SamplesComponent implements OnInit { .map(el => decodeURIComponent(el))); this.activeTemplateKeys.measurements = this.keys.filter(e => e.id.indexOf('measurements.') >= 0 && e.active) .map(e => e.id.split('.') - .map(el => decodeURIComponent(el))); // TODO: glass fiber filter not working + .map(el => decodeURIComponent(el))); } calcFieldSelectKeys() { diff --git a/src/app/templates/templates.component.ts b/src/app/templates/templates.component.ts index c86e07c..f858665 100644 --- a/src/app/templates/templates.component.ts +++ b/src/app/templates/templates.component.ts @@ -3,7 +3,8 @@ import {ApiService} from '../services/api.service'; import {TemplateModel} from '../models/template.model'; import {animate, style, transition, trigger} from '@angular/animations'; import {ValidationService} from '../services/validation.service'; -import _ from 'lodash'; +import cloneDeep from 'lodash/cloneDeep'; +import omit from 'lodash/omit'; @Component({ selector: 'app-templates', @@ -62,8 +63,9 @@ export class TemplatesComponent implements OnInit { }); Object.keys(this.templateGroups).forEach(id => { this.templateGroups[id] = this.templateGroups[id].sort((a, b) => a.version - b.version); - this.templateEdit[id] = _.cloneDeep(this.templateGroups[id][this.templateGroups[id].length - 1]); - this.templateEdit[id].parameters = this.templateEdit[id].parameters.map(e => {e.rangeString = JSON.stringify(e.range, null, 2); return e; }); + this.templateEdit[id] = cloneDeep(this.templateGroups[id][this.templateGroups[id].length - 1]); + this.templateEdit[id].parameters = this.templateEdit[id].parameters + .map(e => {e.rangeString = JSON.stringify(e.range, null, 2); return e; }); }); this.groupsView = Object.values(this.templateGroups) .map(e => ({ @@ -77,7 +79,7 @@ export class TemplatesComponent implements OnInit { } saveTemplate(first_id) { - const template = _.cloneDeep(this.templateEdit[first_id]); + const template = cloneDeep(this.templateEdit[first_id]); template.parameters = template.parameters.filter(e => e.name !== ''); let valid = true; valid = valid && this.validate.string(template.name).ok; @@ -90,7 +92,7 @@ export class TemplatesComponent implements OnInit { }); if (valid) { console.log('valid', template); - const sendData = {name: template.name, parameters: template.parameters.map(e => _.omit(e, ['rangeString']))}; + const sendData = {name: template.name, parameters: template.parameters.map(e => omit(e, ['rangeString']))}; if (first_id === 'null') { this.api.post(`/template/${this.collection}/new`, sendData, data => { if (data.version > template.version) { // there were actual changes and a new version was created