definma-ui/src/app/sample/sample.component.ts

634 lines
25 KiB
TypeScript
Raw Normal View History

2020-07-30 14:23:51 +02:00
import cloneDeep from 'lodash/cloneDeep';
import merge from 'lodash/merge';
import omit from 'lodash/omit';
2020-08-27 15:45:52 +02:00
import pick from 'lodash/pick';
2020-08-21 16:11:57 +02:00
import isEqual from 'lodash/isEqual';
import strCompare from 'str-compare';
import {
AfterContentChecked,
Component,
OnInit, TemplateRef,
ViewChild
} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {AutocompleteService} from '../services/autocomplete.service';
import {ApiService} from '../services/api.service';
import {MaterialModel} from '../models/material.model';
import {SampleModel} from '../models/sample.model';
import {NgForm, Validators} from '@angular/forms';
import {ValidationService} from '../services/validation.service';
import {MeasurementModel} from '../models/measurement.model';
import { ChartOptions } from 'chart.js';
import {animate, style, transition, trigger} from '@angular/animations';
2020-07-22 10:45:34 +02:00
import {Observable} from 'rxjs';
import {ModalService} from '@inst-iot/bosch-angular-ui-components';
import {DataService} from '../services/data.service';
2020-08-21 16:11:57 +02:00
import {LoginService} from '../services/login.service';
@Component({
selector: 'app-sample',
templateUrl: './sample.component.html',
styleUrls: ['./sample.component.scss'],
animations: [
trigger(
'inOut', [
transition(':enter', [
style({height: 0, opacity: 0}),
animate('0.5s ease-out', style({height: '*', opacity: 1}))
]),
transition(':leave', [
style({height: '*', opacity: 1}),
animate('0.5s ease-in', style({height: 0, opacity: 0}))
])
]
)
]
})
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
2020-07-22 10:45:34 +02:00
sampleReferences: [string, string, string][] = [['', '', '']];
sampleReferenceFinds: {_id: string, number: string}[] = []; // Raw sample reference data from db
currentSRIndex = 0; // Index of last entered sample reference
2020-07-22 10:45:34 +02:00
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
// Component mode, either new for generating new samples, editOne or editMulti, editing one or multiple samples
2020-08-21 16:11:57 +02:00
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
2020-08-21 16:11:57 +02:00
};
loading = 0; // Number of currently loading instances
checkFormAfterInit = false;
modalText = {list: '', suggestion: ''};
2020-08-21 16:11:57 +02:00
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
2020-09-03 15:51:53 +02:00
measurementRestoreData: MeasurementModel[] = [];
charts = [[]]; // Chart data for spectra
readonly chartInit = [{
data: [],
label: 'Spectrum',
showLine: true,
fill: false,
pointRadius: 0,
borderColor: '#00a8b0',
borderWidth: 2
}];
readonly chartOptions: ChartOptions = {
scales: {
xAxes: [{ticks: {min: 400, max: 4000, stepSize: 400, reverse: true}}],
yAxes: [{ticks: {min: 0, max: 1}}]
},
responsive: true,
tooltips: {enabled: false},
hover: {mode: null},
maintainAspectRatio: true,
plugins: {datalabels: {display: false}}
};
constructor(
private router: Router,
private route: ActivatedRoute,
private api: ApiService,
private validation: ValidationService,
public autocomplete: AutocompleteService,
private modal: ModalService,
2020-08-21 16:11:57 +02:00
public d: DataService,
private login: LoginService
) { }
ngOnInit(): void {
2020-08-21 16:11:57 +02:00
this.mode = this.router.url === '/samples/new' ? 'new' : '';
2020-07-22 10:45:34 +02:00
this.loading = 7;
this.d.load('materials', () => {
this.materialNames = this.d.arr.materials.map(e => e.name);
this.loading--;
});
this.d.load('materialSuppliers', () => {
this.loading--;
});
this.d.load('materialGroups', () => {
this.loading--;
});
this.d.load('conditionTemplates', () => {
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');
});
2020-07-22 10:45:34 +02:00
this.loading--;
});
this.d.load('materialTemplates', () => {
if (!this.material.properties.material_template) {
2020-09-03 15:51:53 +02:00
this.material.properties.material_template =
this.d.latest.materialTemplates.find(e => e.name === 'plastic')._id;
2020-07-22 10:45:34 +02:00
}
this.loading--;
});
this.d.load('sampleNotesFields', () => {
this.availableCustomFields = this.d.arr.sampleNotesFields.map(e => e.name);
this.loading--;
});
2020-08-21 16:11:57 +02:00
if (this.mode !== 'new') {
const sampleIds = this.route.snapshot.paramMap.get('id').split(',');
if (sampleIds.length === 1) {
this.mode = 'editOne';
this.view.baseSum = true;
this.view.cm = true;
if (this.login.isLevel.dev) { // Load measurement restore data
2020-08-21 16:11:57 +02:00
this.api.get<MeasurementModel[]>('/measurement/sample/' + sampleIds[0], (data, ignore) => {
if (data) {
2020-09-03 15:51:53 +02:00
this.measurementRestoreData =
data.filter(e => e.status === 'deleted').map(e => new MeasurementModel().deserialize(e));
2020-08-21 16:11:57 +02:00
}
});
}
}
else {
this.mode = 'editMulti';
this.view.base = true;
}
this.loading += sampleIds.length;
this.api.get<SampleModel>('/sample/' + sampleIds[0], sData => { // Special treatment for first id
2020-08-24 12:43:39 +02:00
this.samples = [new SampleModel().deserialize(sData)];
this.baseSample.deserialize(sData);
this.material = new MaterialModel().deserialize(sData.material); // Read material
// Read custom fields
2020-09-03 15:51:53 +02:00
this.customFields = this.baseSample.notes.custom_fields && this.baseSample.notes.custom_fields !== {} ?
2020-08-24 12:43:39 +02:00
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
2020-08-24 12:43:39 +02:00
this.sampleReferences = [];
this.sampleReferenceAutocomplete = [];
let loadCounter = this.baseSample.notes.sample_references.length; // Count down instances still loading
2020-08-24 12:43:39 +02:00
this.baseSample.notes.sample_references.forEach(reference => {
this.api.get<SampleModel>('/sample/' + reference.sample_id, srData => { // Get sample numbers for ids
2020-08-24 12:43:39 +02:00
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
2020-08-24 12:43:39 +02:00
this.sampleReferences.push(['', '', '']);
this.sampleReferenceAutocomplete.push([]);
}
});
});
}
if (this.mode === 'editOne') {
this.charts = [[]];
let spectrumCounter = 0; // Generate charts for spectrum measurements
2020-08-24 12:43:39 +02:00
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
2020-08-24 12:43:39 +02:00
spectrumCounter ++;
2020-08-21 16:11:57 +02:00
}
2020-08-24 12:43:39 +02:00
});
}
2020-08-27 15:45:52 +02:00
this.checkFormAfterInit = true;
2020-08-24 12:43:39 +02:00
this.loading--;
sampleIds.slice(1).forEach(sampleId => { // Load further samples for batch edit
2020-08-24 12:43:39 +02:00
this.api.get<SampleModel>('/sample/' + sampleId, data => {
this.samples.push(new SampleModel().deserialize(data));
2020-08-21 16:11:57 +02:00
['type', 'color', 'batch', 'notes'].forEach((key) => {
2020-08-24 12:43:39 +02:00
if (!isEqual(data[key], this.baseSample[key])) {
2020-08-21 16:11:57 +02:00
this.baseSample[key] = undefined;
}
});
2020-08-24 12:43:39 +02:00
if (!isEqual(data.material.name, this.baseSample.material.name)) {
2020-08-21 16:11:57 +02:00
this.baseSample.material.name = undefined;
}
2020-08-24 12:43:39 +02:00
this.loading--;
this.checkFormAfterInit = true;
});
2020-08-21 16:11:57 +02:00
});
});
}
2020-08-21 16:11:57 +02:00
else {
this.view.base = true;
}
}
ngAfterContentChecked() {
// Attach validators
if (this.samples.length) { // Conditions are displayed
2020-08-21 16:11:57 +02:00
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) => {
2020-08-24 15:24:55 +02:00
this.attachValidator(this.cmForm, `conditionParameter-${gIndex}-${pIndex}`, parameter.range);
});
}
gSample.measurements.forEach((measurement, mIndex) => {
this.d.id.measurementTemplates[measurement.measurement_template].parameters.forEach((parameter, pIndex) => {
2020-08-24 15:24:55 +02:00
this.attachValidator(this.cmForm, `measurementParameter-${gIndex}-${mIndex}-${pIndex}`, parameter.range);
});
});
});
}
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) => {
2020-08-24 15:24:55 +02:00
this.attachValidator(this.sampleForm, 'materialParameter' + i, parameter.range);
});
2020-07-22 10:45:34 +02:00
}
// Revalidate inputs
if (this.checkFormAfterInit) {
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 => {
this.sampleForm.form.get(field).updateValueAndValidity();
});
}
}
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-' +
2020-08-21 16:11:57 +02:00
(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
2020-09-03 15:51:53 +02:00
formReady = formReady &&
this.cmForm.form.get('measurementParameter-0-' + (this.samples[0].measurements.length - 1) +
2020-08-21 16:11:57 +02:00
'-' + (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
this.checkFormAfterInit = false;
Object.keys(this.cmForm.form.controls).forEach(field => {
this.cmForm.form.get(field).updateValueAndValidity();
});
}
}
}
}
// Attach validators specified in range to input with name
2020-08-24 15:24:55 +02:00
attachValidator(form, name: string, range: {[prop: string]: any}) {
if (form && form.form.get(name)) {
const validators = [];
2020-08-24 15:24:55 +02:00
if (range.hasOwnProperty('required')) {
validators.push(Validators.required);
}
if (range.hasOwnProperty('values')) {
validators.push(this.validation.generate('stringOf', [range.values]));
}
else if (range.hasOwnProperty('min') && range.hasOwnProperty('max')) {
validators.push(this.validation.generate('minMax', [range.min, range.max]));
}
else if (range.hasOwnProperty('min')) {
validators.push(this.validation.generate('min', [range.min]));
}
else if (range.hasOwnProperty('max')) {
validators.push(this.validation.generate('max', [range.max]));
}
form.form.get(name).setValidators(validators);
}
}
2020-08-27 15:45:52 +02:00
reValidate() {
setTimeout(() => this.checkFormAfterInit = true, 0);
}
// Save base sample
saveSample() {
2020-08-21 16:11:57 +02:00
if (this.samples.length === 0) {
this.loading = this.sampleCount; // Set up loading spinner
}
new Promise<void>(resolve => {
if (this.newMaterial) { // Save material first if new one exists
2020-08-10 16:15:17 +02:00
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.material = data;
this.baseSample.material_id = data._id; // Add new material id to sample data
resolve();
});
}
else {
resolve();
}
}).then(() => { // Save sample
2020-08-26 19:25:31 +02:00
if (this.baseSample.notes) {
this.baseSample.notes.custom_fields = {};
this.customFields.forEach(element => {
if (element[0] !== '') {
this.baseSample.notes.custom_fields[element[0]] = element[1];
}
});
this.baseSample.notes.sample_references = this.sampleReferences
.filter(e => e[0] && e[1] && e[2]) // Filter empty values
2020-08-26 19:25:31 +02:00
.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
for (let i = 0; i < this.sampleCount; i ++) {
2020-08-21 16:11:57 +02:00
this.api.post<SampleModel>('/sample/new', this.baseSample.sendFormat(), data => {
this.samples[i] = new SampleModel().deserialize(data);
this.samples[i].material = this.d.arr.materials.find(e => e._id === this.samples[i].material_id);
this.loading --;
});
}
2020-08-21 16:11:57 +02:00
this.view.base = false;
this.view.baseSum = true;
this.view.cm = true;
}
else {
2020-08-21 16:11:57 +02:00
this.samples.forEach((sample, i) => {
2020-08-27 13:56:55 +02:00
this.api.put<SampleModel>('/sample/' + sample._id, this.baseSample.sendFormat(false), data => {
2020-08-21 16:11:57 +02:00
merge(this.samples[i], omit(data, ['condition']));
this.samples[i].material = this.d.arr.materials.find(e => e._id === this.samples[0].material_id);
this.view.base = false;
this.view.baseSum = true;
});
});
}
});
}
// Save conditions and measurements
cmSave() { // Save measurements and conditions
2020-08-21 16:11:57 +02:00
this.samples.forEach(sample => {
if (sample.condition.condition_template) { // Condition was set
2020-08-27 15:45:52 +02:00
this.api.put('/sample/' + sample._id,
{condition: pick(sample.condition,
2020-09-03 15:51:53 +02:00
[
'condition_template',
...this.d.id.conditionTemplates[sample.condition.condition_template].parameters.map(e => e.name)
]
2020-08-27 15:45:52 +02:00
)}
);
}
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
measurement.values[key] = measurement.values[key] === '' ? null : measurement.values[key];
});
if (measurement._id === null) { // New measurement
measurement.sample_id = sample._id;
this.api.post<MeasurementModel>('/measurement/new', measurement.sendFormat());
}
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
this.api.delete('/measurement/' + measurement._id);
}
});
2020-08-21 16:11:57 +02:00
this.measurementDeleteList.forEach(measurement => {
this.api.delete('/measurement/' + measurement);
});
});
this.router.navigate(['/samples']);
}
2020-08-21 16:11:57 +02:00
restoreMeasurements() {
let spectrumCounter = 0; // Generate charts for spectrum measurements
2020-08-21 16:11:57 +02:00
const measurementCount = this.samples[0].measurements.length;
this.measurementRestoreData.forEach((measurement, i) => {
this.api.put('/measurement/restore/' + measurement._id, {}, () => {
this.samples[0].measurements.push(measurement);
this.charts[0].push(cloneDeep(this.chartInit));
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
2020-08-21 16:11:57 +02:00
spectrumCounter ++;
}
this.checkFormAfterInit = true;
});
});
}
// 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
2020-07-30 14:23:51 +02:00
this.material = cloneDeep(res);
2020-08-21 16:11:57 +02:00
this.baseSample.material_id = this.material._id;
}
else { // No matching material found
if (this.baseSample.material_id !== null) { // Reset previous match
2020-07-22 10:45:34 +02:00
this.material = new MaterialModel();
2020-09-03 15:51:53 +02:00
this.material.properties.material_template =
this.d.latest.materialTemplates.find(e => e.name === 'plastic')._id;
2020-07-22 10:45:34 +02:00
}
2020-08-21 16:11:57 +02:00
this.baseSample.material_id = null;
}
this.setNewMaterial();
}
// Set newMaterial, if value === null -> toggle
setNewMaterial(value = null) {
if (value === null) { // Toggle dialog
2020-08-21 16:11:57 +02:00
this.newMaterial = !this.baseSample.material_id;
} // Set to false only if material already exists
2020-09-03 15:51:53 +02:00
else if (value || (!value && this.baseSample.material_id !== null )) {
this.newMaterial = value;
}
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
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
addMeasurement(gIndex) {
2020-08-21 16:11:57 +02:00
this.samples[gIndex].measurements.push(
2020-08-10 16:15:17 +02:00
new MeasurementModel(this.d.latest.measurementTemplates.find(e => e.name === 'spectrum')._id)
);
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
2020-09-03 15:51:53 +02:00
removeMeasurement(gIndex, mIndex) {
2020-08-21 16:11:57 +02:00
if (this.samples[gIndex].measurements[mIndex]._id !== null) {
this.measurementDeleteList.push(this.samples[gIndex].measurements[mIndex]._id);
2020-07-22 10:45:34 +02:00
}
2020-08-21 16:11:57 +02:00
this.samples[gIndex].measurements.splice(mIndex, 1);
this.charts[gIndex].splice(mIndex, 1);
2020-07-22 10:45:34 +02:00
}
// Clear entered measurement data at the specified index due to template change
clearMeasurement(gIndex, mIndex) {
this.charts[gIndex][mIndex][0].data = [];
2020-08-21 16:11:57 +02:00
this.samples[gIndex].measurements[mIndex].values = {};
}
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
this.addMeasurement(gIndex);
2020-08-21 16:11:57 +02:00
index = this.samples[gIndex].measurements.length - 1;
}
// Autofill further parameters
2020-08-21 16:11:57 +02:00
this.samples[gIndex].measurements[index].values.device =
this.samples[gIndex].measurements[mIndex].values.device;
this.samples[gIndex].measurements[index].values.filename = files[i].name;
this.samples[gIndex].measurements[index].values[parameter] =
fileReader.result.toString().split('\r\n').map(e => e.split(',')).filter(el => el.length === 2);
this.generateChart(this.samples[gIndex].measurements[index].values[parameter], gIndex, index);
};
fileReader.readAsText(files[i]);
}
}
}
generateChart(spectrum, gIndex, mIndex) {
this.charts[gIndex][mIndex][0].data = spectrum.map(e => ({x: parseFloat(e[0]), y: parseFloat(e[1])}));
}
toggleCondition(sample) {
if (sample.condition.condition_template) {
sample.condition.condition_template = null;
}
else {
2020-08-10 16:15:17 +02:00
sample.condition.condition_template = this.d.latest.conditionTemplates[0]._id;
}
}
checkTypo(event, list, mKey, modal: TemplateRef<any>) {
// 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
.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
this.material[mKey] = this.modalText.suggestion;
}
});
}
}
deleteConfirm(modal) {
this.modal.open(modal).then(result => {
if (result) {
2020-08-24 12:43:39 +02:00
this.samples.forEach(sample => {
this.api.delete('/sample/' + sample._id);
});
this.router.navigate(['/samples']);
}
});
}
2020-07-22 10:45:34 +02:00
checkSampleReference(value, index) {
if (value) {
this.sampleReferences[index][0] = value;
}
this.currentSRIndex = index;
const fieldNo = this.sampleReferences.length;
let filledFields = 0;
this.sampleReferences.forEach(field => {
if (field[0] !== '') {
filledFields ++;
}
});
// Append new field
2020-07-22 10:45:34 +02:00
if (filledFields === fieldNo) {
this.sampleReferences.push(['', '', '']);
this.sampleReferenceAutocomplete.push([]);
}
// Remove if two end fields are empty
2020-07-22 10:45:34 +02:00
if (fieldNo > 1 && this.sampleReferences[fieldNo - 1][0] === '' && this.sampleReferences[fieldNo - 2][0] === '') {
this.sampleReferences.pop();
this.sampleReferenceAutocomplete.pop();
}
this.sampleReferenceIdFind(value);
}
sampleReferenceList(value) { // Get list of sample reference number suggestions
2020-07-22 10:45:34 +02:00
return new Observable(observer => {
if (value !== '') {
this.api.get<{ _id: string, number: string }[]>(
2020-08-10 13:30:26 +02:00
'/samples?status[]=validated&status[]=new&page-size=25&sort=number-asc&fields[]=number&fields[]=_id&' +
2020-09-03 15:51:53 +02:00
'filters[]=%7B%22mode%22%3A%22stringin%22%2C%22field%22%3A%22number%22%2C%22values%22%3A%5B%22' + value +
'%22%5D%7D', data => {
this.sampleReferenceAutocomplete[this.currentSRIndex] = data.map(e => e.number);
this.sampleReferenceFinds = data;
observer.next(data.map(e => e.number));
observer.complete();
this.sampleReferenceIdFind(value);
});
}
else {
observer.next([]);
2020-07-22 10:45:34 +02:00
observer.complete();
}
2020-07-22 10:45:34 +02:00
});
}
sampleReferenceIdFind(value) { // Sample reference id from number
2020-07-22 10:45:34 +02:00
const idFind = this.sampleReferenceFinds.find(e => e.number === value);
if (idFind) {
this.sampleReferences[this.currentSRIndex][2] = idFind._id;
}
else {
this.sampleReferences[this.currentSRIndex][2] = '';
}
}
sampleReferenceListBind() {
return this.sampleReferenceList.bind(this);
}
2020-08-28 08:14:57 +02:00
sampleNames() {
return this.samples.map(e => e.number).join(', ');
}
uniqueCfValues(index) { // Returns all names until index for unique check
return this.customFields ? this.customFields.slice(0, index).map(e => e[0]) : [];
}
preventDefault(event) {
if (event.key && event.key === 'Enter' || event.type === 'dragover') {
event.preventDefault();
}
}
}