Change the first character of all end-of-line comments to upper case

This commit is contained in:
2021-01-18 14:26:40 +01:00
parent c2aead6799
commit f0ed0a0e68
27 changed files with 305 additions and 305 deletions

View File

@ -49,41 +49,41 @@ export class SampleComponent implements OnInit, AfterContentChecked {
@ViewChild('sampleForm') sampleForm: NgForm;
@ViewChild('cmForm') cmForm: NgForm;
baseSample = new SampleModel(); // base sample which is saved
sampleCount = 1; // number of samples to be generated
samples: SampleModel[] = []; // gets filled with response data after saving the sample
baseSample = new SampleModel(); // Base sample which is saved
sampleCount = 1; // Number of samples to be generated
samples: SampleModel[] = []; // Gets filled with response data after saving the sample
sampleReferences: [string, string, string][] = [['', '', '']];
sampleReferenceFinds: {_id: string, number: string}[] = []; // raw sample reference data from db
currentSRIndex = 0; // index of last entered sample reference
sampleReferenceFinds: {_id: string, number: string}[] = []; // Raw sample reference data from db
currentSRIndex = 0; // Index of last entered sample reference
sampleReferenceAutocomplete: string[][] = [[]];
customFields: [string, string][] = [];
availableCustomFields: string[] = [];
newMaterial = false; // true if new material should be created
materials: MaterialModel[] = []; // all materials
materialNames = []; // only names for autocomplete
material = new MaterialModel(); // object of current selected material
defaultDevice = ''; // default device for spectra
newMaterial = false; // True if new material should be created
materials: MaterialModel[] = []; // All materials
materialNames = []; // Only names for autocomplete
material = new MaterialModel(); // Object of current selected material
defaultDevice = ''; // Default device for spectra
// component mode, either new for generating new samples, editOne or editMulti, editing one or multiple samples
// Component mode, either new for generating new samples, editOne or editMulti, editing one or multiple samples
mode = 'new';
view = { // active views
base: false, // base sample
baseSum: false, // base sample summary
cm: false, // conditions and measurements
cmSum: false // conditions and measurements summary
view = { // Active views
base: false, // Base sample
baseSum: false, // Base sample summary
cm: false, // Conditions and measurements
cmSum: false // Conditions and measurements summary
};
loading = 0; // number of currently loading instances
loading = 0; // Number of currently loading instances
checkFormAfterInit = false;
modalText = {list: '', suggestion: ''};
cmSampleIndex = '0';
measurementDeleteList = []; // buffer with measurements to delete, if the user confirms and saves the cm changes
// deleted measurements if user is allowed and measurements are available
measurementDeleteList = []; // Buffer with measurements to delete, if the user confirms and saves the cm changes
// Deleted measurements if user is allowed and measurements are available
measurementRestoreData: MeasurementModel[] = [];
charts = [[]]; // chart data for spectra
charts = [[]]; // Chart data for spectra
readonly chartInit = [{
data: [],
label: 'Spectrum',
@ -135,7 +135,7 @@ export class SampleComponent implements OnInit, AfterContentChecked {
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
// 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) {
@ -163,7 +163,7 @@ export class SampleComponent implements OnInit, AfterContentChecked {
this.mode = 'editOne';
this.view.baseSum = true;
this.view.cm = true;
if (this.login.isLevel.dev) { // load measurement restore data
if (this.login.isLevel.dev) { // Load measurement restore data
this.api.get<MeasurementModel[]>('/measurement/sample/' + sampleIds[0], (data, ignore) => {
if (data) {
this.measurementRestoreData =
@ -177,22 +177,22 @@ export class SampleComponent implements OnInit, AfterContentChecked {
this.view.base = true;
}
this.loading += sampleIds.length;
this.api.get<SampleModel>('/sample/' + sampleIds[0], sData => { // special treatment for first id
this.api.get<SampleModel>('/sample/' + sampleIds[0], sData => { // Special treatment for first id
this.samples = [new SampleModel().deserialize(sData)];
this.baseSample.deserialize(sData);
this.material = new MaterialModel().deserialize(sData.material); // read material
// read custom fields
this.material = new MaterialModel().deserialize(sData.material); // Read material
// Read custom fields
this.customFields = this.baseSample.notes.custom_fields && this.baseSample.notes.custom_fields !== {} ?
Object.keys(this.baseSample.notes.custom_fields).map(e => [e, this.baseSample.notes.custom_fields[e]]) : [];
if (this.baseSample.notes.sample_references.length) { // read sample references
if (this.baseSample.notes.sample_references.length) { // Read sample references
this.sampleReferences = [];
this.sampleReferenceAutocomplete = [];
let loadCounter = this.baseSample.notes.sample_references.length; // count down instances still loading
let loadCounter = this.baseSample.notes.sample_references.length; // Count down instances still loading
this.baseSample.notes.sample_references.forEach(reference => {
this.api.get<SampleModel>('/sample/' + reference.sample_id, srData => { // get sample numbers for ids
this.api.get<SampleModel>('/sample/' + reference.sample_id, srData => { // Get sample numbers for ids
this.sampleReferences.push([srData.number, reference.relation, reference.sample_id]);
this.sampleReferenceAutocomplete.push([srData.number]);
if (!--loadCounter) { // insert empty template when all instances were loaded
if (!--loadCounter) { // Insert empty template when all instances were loaded
this.sampleReferences.push(['', '', '']);
this.sampleReferenceAutocomplete.push([]);
}
@ -201,20 +201,20 @@ export class SampleComponent implements OnInit, AfterContentChecked {
}
if (this.mode === 'editOne') {
this.charts = [[]];
let spectrumCounter = 0; // generate charts for spectrum measurements
let spectrumCounter = 0; // Generate charts for spectrum measurements
this.samples[0].measurements.forEach((measurement, i) => {
this.charts[0].push(cloneDeep(this.chartInit));
if (measurement.values.dpt) {
setTimeout(() => {
this.generateChart(measurement.values.dpt, 0, i);
}, spectrumCounter * 20); // generate charts one after another to avoid freezing the UI
}, spectrumCounter * 20); // Generate charts one after another to avoid freezing the UI
spectrumCounter ++;
}
});
}
this.checkFormAfterInit = true;
this.loading--;
sampleIds.slice(1).forEach(sampleId => { // load further samples for batch edit
sampleIds.slice(1).forEach(sampleId => { // Load further samples for batch edit
this.api.get<SampleModel>('/sample/' + sampleId, data => {
this.samples.push(new SampleModel().deserialize(data));
['type', 'color', 'batch', 'notes'].forEach((key) => {
@ -237,8 +237,8 @@ export class SampleComponent implements OnInit, AfterContentChecked {
}
ngAfterContentChecked() {
// attach validators
if (this.samples.length) { // conditions are displayed
// Attach validators
if (this.samples.length) { // Conditions are displayed
this.samples.forEach((gSample, gIndex) => {
if (this.d.id.conditionTemplates[gSample.condition.condition_template]) {
this.d.id.conditionTemplates[gSample.condition.condition_template].parameters.forEach((parameter, pIndex) => {
@ -253,15 +253,15 @@ export class SampleComponent implements OnInit, AfterContentChecked {
});
}
if (this.sampleForm && this.material.properties.material_template) { // material template is set
if (this.sampleForm && this.material.properties.material_template) { // Material template is set
this.d.id.materialTemplates[this.material.properties.material_template].parameters.forEach((parameter, i) => {
this.attachValidator(this.sampleForm, 'materialParameter' + i, parameter.range);
});
}
// revalidate inputs
// Revalidate inputs
if (this.checkFormAfterInit) {
if (this.view.base) { // validate sampleForm
if (this.view.base) { // Validate sampleForm
if (this.sampleForm !== undefined && this.sampleForm.form.get('cf-key0')) {
this.checkFormAfterInit = false;
Object.keys(this.sampleForm.form.controls).forEach(field => {
@ -269,20 +269,20 @@ export class SampleComponent implements OnInit, AfterContentChecked {
});
}
}
else { // validate cmForm
// check that all fields are ready for validation
let formReady: boolean = this.cmForm !== undefined; // forms exist
if (this.samples[0].condition.condition_template) { // if condition is set, last condition field exists
else { // Validate cmForm
// Check that all fields are ready for validation
let formReady: boolean = this.cmForm !== undefined; // Forms exist
if (this.samples[0].condition.condition_template) { // If condition is set, last condition field exists
formReady = formReady && this.cmForm.form.get('conditionParameter-0-' +
(this.d.id.conditionTemplates[this.samples[0].condition.condition_template].parameters.length - 1)) as any;
}
if (this.samples[0].measurements.length) { // if there are measurements, last measurement field exists
if (this.samples[0].measurements.length) { // If there are measurements, last measurement field exists
formReady = formReady &&
this.cmForm.form.get('measurementParameter-0-' + (this.samples[0].measurements.length - 1) +
'-' + (this.d.id.measurementTemplates[this.samples[0].measurements[this.samples[0].measurements.length - 1]
.measurement_template].parameters.length - 1)) as any;
}
if (formReady) { // fields are ready, do validation
if (formReady) { // Fields are ready, do validation
this.checkFormAfterInit = false;
Object.keys(this.cmForm.form.controls).forEach(field => {
this.cmForm.form.get(field).updateValueAndValidity();
@ -292,7 +292,7 @@ export class SampleComponent implements OnInit, AfterContentChecked {
}
}
// attach validators specified in range to input with name
// Attach validators specified in range to input with name
attachValidator(form, name: string, range: {[prop: string]: any}) {
if (form && form.form.get(name)) {
const validators = [];
@ -319,25 +319,25 @@ export class SampleComponent implements OnInit, AfterContentChecked {
setTimeout(() => this.checkFormAfterInit = true, 0);
}
// save base sample
// Save base sample
saveSample() {
if (this.samples.length === 0) {
this.loading = this.sampleCount; // set up loading spinner
this.loading = this.sampleCount; // Set up loading spinner
}
new Promise<void>(resolve => {
if (this.newMaterial) { // save material first if new one exists
if (this.newMaterial) { // Save material first if new one exists
this.material.numbers = this.material.numbers.filter(e => e !== '');
this.api.post<MaterialModel>('/material/new', this.material.sendFormat(), data => {
this.d.arr.materials.push(data); // add material to data
this.d.arr.materials.push(data); // Add material to data
this.material = data;
this.baseSample.material_id = data._id; // add new material id to sample data
this.baseSample.material_id = data._id; // Add new material id to sample data
resolve();
});
}
else {
resolve();
}
}).then(() => { // save sample
}).then(() => { // Save sample
if (this.baseSample.notes) {
this.baseSample.notes.custom_fields = {};
this.customFields.forEach(element => {
@ -346,10 +346,10 @@ export class SampleComponent implements OnInit, AfterContentChecked {
}
});
this.baseSample.notes.sample_references = this.sampleReferences
.filter(e => e[0] && e[1] && e[2]) // filter empty values
.filter(e => e[0] && e[1] && e[2]) // Filter empty values
.map(e => ({sample_id: e[2], relation: e[1]}));
}
if (this.samples.length === 0) { // only save new sample for the first time in mode new, otherwise save changes
if (this.samples.length === 0) { // Only save new sample for the first time in mode new, otherwise save changes
for (let i = 0; i < this.sampleCount; i ++) {
this.api.post<SampleModel>('/sample/new', this.baseSample.sendFormat(), data => {
this.samples[i] = new SampleModel().deserialize(data);
@ -374,10 +374,10 @@ export class SampleComponent implements OnInit, AfterContentChecked {
});
}
// save conditions and measurements
cmSave() { // save measurements and conditions
// Save conditions and measurements
cmSave() { // Save measurements and conditions
this.samples.forEach(sample => {
if (sample.condition.condition_template) { // condition was set
if (sample.condition.condition_template) { // Condition was set
this.api.put('/sample/' + sample._id,
{condition: pick(sample.condition,
[
@ -387,21 +387,21 @@ export class SampleComponent implements OnInit, AfterContentChecked {
)}
);
}
sample.measurements.forEach(measurement => { // save measurements
sample.measurements.forEach(measurement => { // Save measurements
if (Object.keys(measurement.values).map(e => measurement.values[e]).join('') !== '') {
Object.keys(measurement.values).forEach(key => { // map empty values to null
Object.keys(measurement.values).forEach(key => { // Map empty values to null
measurement.values[key] = measurement.values[key] === '' ? null : measurement.values[key];
});
if (measurement._id === null) { // new measurement
if (measurement._id === null) { // New measurement
measurement.sample_id = sample._id;
this.api.post<MeasurementModel>('/measurement/new', measurement.sendFormat());
}
else { // update measurement
else { // Update measurement
this.api.put<MeasurementModel>('/measurement/' + measurement._id,
measurement.sendFormat(['sample_id', 'measurement_template']));
}
}
else if (measurement._id !== null) { // existing measurement was left empty to delete
else if (measurement._id !== null) { // Existing measurement was left empty to delete
this.api.delete('/measurement/' + measurement._id);
}
});
@ -414,7 +414,7 @@ export class SampleComponent implements OnInit, AfterContentChecked {
}
restoreMeasurements() {
let spectrumCounter = 0; // generate charts for spectrum measurements
let spectrumCounter = 0; // Generate charts for spectrum measurements
const measurementCount = this.samples[0].measurements.length;
this.measurementRestoreData.forEach((measurement, i) => {
this.api.put('/measurement/restore/' + measurement._id, {}, () => {
@ -423,7 +423,7 @@ export class SampleComponent implements OnInit, AfterContentChecked {
if (measurement.values.dpt) {
setTimeout(() => {
this.generateChart(measurement.values.dpt, 0, measurementCount + i);
}, spectrumCounter * 20); // generate charts one after another to avoid freezing the UI
}, spectrumCounter * 20); // Generate charts one after another to avoid freezing the UI
spectrumCounter ++;
}
this.checkFormAfterInit = true;
@ -431,15 +431,15 @@ export class SampleComponent implements OnInit, AfterContentChecked {
});
}
// set material based on found material name
// Set material based on found material name
findMaterial(name) {
const res = this.d.arr.materials.find(e => e.name === name); // search for match
if (res) { // material found
const res = this.d.arr.materials.find(e => e.name === name); // Search for match
if (res) { // Material found
this.material = cloneDeep(res);
this.baseSample.material_id = this.material._id;
}
else { // no matching material found
if (this.baseSample.material_id !== null) { // reset previous match
else { // No matching material found
if (this.baseSample.material_id !== null) { // Reset previous match
this.material = new MaterialModel();
this.material.properties.material_template =
this.d.latest.materialTemplates.find(e => e.name === 'plastic')._id;
@ -449,36 +449,36 @@ export class SampleComponent implements OnInit, AfterContentChecked {
this.setNewMaterial();
}
// set newMaterial, if value === null -> toggle
// Set newMaterial, if value === null -> toggle
setNewMaterial(value = null) {
if (value === null) { // toggle dialog
if (value === null) { // Toggle dialog
this.newMaterial = !this.baseSample.material_id;
} // set to false only if material already exists
} // Set to false only if material already exists
else if (value || (!value && this.baseSample.material_id !== null )) {
this.newMaterial = value;
}
if (this.newMaterial) { // set validators if dialog is open
if (this.newMaterial) { // Set validators if dialog is open
this.sampleForm.form.get('materialname').setValidators([Validators.required]);
}
else { // material name must be from list if dialog is closed
else { // Material name must be from list if dialog is closed
this.sampleForm.form.get('materialname')
.setValidators([Validators.required, this.validation.generate('stringOf', [this.materialNames])]);
}
this.sampleForm.form.get('materialname').updateValueAndValidity();
}
// add a new measurement for generated sample at index
// Add a new measurement for generated sample at index
addMeasurement(gIndex) {
this.samples[gIndex].measurements.push(
new MeasurementModel(this.d.latest.measurementTemplates.find(e => e.name === 'spectrum')._id)
);
if (!this.charts[gIndex]) { // add array if there are no charts yet
if (!this.charts[gIndex]) { // Add array if there are no charts yet
this.charts[gIndex] = [];
}
this.charts[gIndex].push(cloneDeep(this.chartInit));
}
// remove the measurement at the specified index
// Remove the measurement at the specified index
removeMeasurement(gIndex, mIndex) {
if (this.samples[gIndex].measurements[mIndex]._id !== null) {
this.measurementDeleteList.push(this.samples[gIndex].measurements[mIndex]._id);
@ -487,23 +487,23 @@ export class SampleComponent implements OnInit, AfterContentChecked {
this.charts[gIndex].splice(mIndex, 1);
}
// clear entered measurement data at the specified index due to template change
// Clear entered measurement data at the specified index due to template change
clearMeasurement(gIndex, mIndex) {
this.charts[gIndex][mIndex][0].data = [];
this.samples[gIndex].measurements[mIndex].values = {};
}
fileToArray(files, gIndex, mIndex, parameter) { // process spectrum file input
fileToArray(files, gIndex, mIndex, parameter) { // Process spectrum file input
for (const i in files) {
if (files.hasOwnProperty(i)) {
const fileReader = new FileReader();
fileReader.onload = () => {
let index: number = mIndex;
if (Number(i) > 0) { // append further spectra
if (Number(i) > 0) { // Append further spectra
this.addMeasurement(gIndex);
index = this.samples[gIndex].measurements.length - 1;
}
// autofill further parameters
// Autofill further parameters
this.samples[gIndex].measurements[index].values.device =
this.samples[gIndex].measurements[mIndex].values.device;
this.samples[gIndex].measurements[index].values.filename = files[i].name;
@ -530,16 +530,16 @@ export class SampleComponent implements OnInit, AfterContentChecked {
}
checkTypo(event, list, mKey, modal: TemplateRef<any>) {
// user did not click on suggestion and entry is not in list
// User did not click on suggestion and entry is not in list
if (!(event.relatedTarget && (event.relatedTarget.className.indexOf('rb-dropdown-item') >= 0 ||
event.relatedTarget.className.indexOf('close-btn rb-btn rb-passive-link') >= 0)) &&
this.d.arr[list].indexOf(this.material[mKey]) < 0) {
this.modalText.list = mKey;
this.modalText.suggestion = this.d.arr[list] // find possible entry from list
this.modalText.suggestion = this.d.arr[list] // Find possible entry from list
.map(e => ({v: e, s: strCompare.sorensenDice(e, this.material[mKey])}))
.sort((a, b) => b.s - a.s)[0].v;
this.modal.open(modal).then(result => {
if (result) { // use suggestion
if (result) { // Use suggestion
this.material[mKey] = this.modalText.suggestion;
}
});
@ -569,12 +569,12 @@ export class SampleComponent implements OnInit, AfterContentChecked {
filledFields ++;
}
});
// append new field
// Append new field
if (filledFields === fieldNo) {
this.sampleReferences.push(['', '', '']);
this.sampleReferenceAutocomplete.push([]);
}
// remove if two end fields are empty
// Remove if two end fields are empty
if (fieldNo > 1 && this.sampleReferences[fieldNo - 1][0] === '' && this.sampleReferences[fieldNo - 2][0] === '') {
this.sampleReferences.pop();
this.sampleReferenceAutocomplete.pop();
@ -582,7 +582,7 @@ export class SampleComponent implements OnInit, AfterContentChecked {
this.sampleReferenceIdFind(value);
}
sampleReferenceList(value) { // get list of sample reference number suggestions
sampleReferenceList(value) { // Get list of sample reference number suggestions
return new Observable(observer => {
if (value !== '') {
this.api.get<{ _id: string, number: string }[]>(
@ -603,7 +603,7 @@ export class SampleComponent implements OnInit, AfterContentChecked {
});
}
sampleReferenceIdFind(value) { // sample reference id from number
sampleReferenceIdFind(value) { // Sample reference id from number
const idFind = this.sampleReferenceFinds.find(e => e.number === value);
if (idFind) {
this.sampleReferences[this.currentSRIndex][2] = idFind._id;
@ -621,7 +621,7 @@ export class SampleComponent implements OnInit, AfterContentChecked {
return this.samples.map(e => e.number).join(', ');
}
uniqueCfValues(index) { // returns all names until index for unique check
uniqueCfValues(index) { // Returns all names until index for unique check
return this.customFields ? this.customFields.slice(0, index).map(e => e[0]) : [];
}