added notes.comments field
This commit is contained in:
@ -139,6 +139,10 @@
|
||||
[disabled]="!sampleForm.form.valid">
|
||||
Save sample
|
||||
</rb-icon-button>
|
||||
<rb-icon-button class="delete-sample" icon="delete" mode="danger" *ngIf="samples.length > 1"
|
||||
(click)="deleteConfirm(modalDeleteConfirm)">
|
||||
Delete samples
|
||||
</rb-icon-button>
|
||||
</div>
|
||||
<ng-template #generateSamples>
|
||||
<rb-form-input type="number" name="sample-count" label="number of samples" pattern="^\d+?$" required
|
||||
@ -285,15 +289,10 @@
|
||||
[disabled]="!cmForm.form.valid">
|
||||
Summary
|
||||
</rb-icon-button>
|
||||
<rb-icon-button class="delete-sample" icon="delete" mode="danger" *ngIf="mode !== 'new'"
|
||||
<rb-icon-button class="delete-sample" icon="delete" mode="danger" *ngIf="samples.length === 1"
|
||||
(click)="deleteConfirm(modalDeleteConfirm)">
|
||||
Delete sample
|
||||
</rb-icon-button>
|
||||
<ng-template #modalDeleteConfirm>
|
||||
<rb-alert alertTitle="Are you sure?" type="danger" okBtnLabel="Delete sample" cancelBtnLabel="Cancel">
|
||||
Do you really want to delete this sample?
|
||||
</rb-alert>
|
||||
</ng-template>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@ -322,3 +321,9 @@
|
||||
</rb-icon-button>
|
||||
</div>
|
||||
</ng-template>
|
||||
|
||||
<ng-template #modalDeleteConfirm>
|
||||
<rb-alert alertTitle="Are you sure?" type="danger" [okBtnLabel]="'Delete sample' + (samples.length > 1 ? 's' : '')" cancelBtnLabel="Cancel">
|
||||
Do you really want to delete {{samples.length > 1 ? 'these samples' : 'this sample'}}?
|
||||
</rb-alert>
|
||||
</ng-template>
|
||||
|
@ -176,57 +176,56 @@ export class SampleComponent implements OnInit, AfterContentChecked {
|
||||
this.view.base = true;
|
||||
}
|
||||
this.loading += sampleIds.length;
|
||||
this.samples = [];
|
||||
sampleIds.forEach((sampleId, i) => {
|
||||
this.api.get<SampleModel>('/sample/' + sampleId, sData => {
|
||||
this.samples.push(new SampleModel().deserialize(sData));
|
||||
if (i === 0) {
|
||||
this.baseSample.deserialize(sData);
|
||||
this.material = new MaterialModel().deserialize(sData.material); // read material
|
||||
this.customFields = this.baseSample.notes.custom_fields && this.baseSample.notes.custom_fields !== {} ? // read 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
|
||||
this.sampleReferences = [];
|
||||
this.sampleReferenceAutocomplete = [];
|
||||
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.sampleReferences.push([srData.number, reference.relation, reference.sample_id]);
|
||||
this.sampleReferenceAutocomplete.push([srData.number]);
|
||||
if (!--loadCounter) { // insert empty template when all instances were loaded
|
||||
this.sampleReferences.push(['', '', '']);
|
||||
this.sampleReferenceAutocomplete.push([]);
|
||||
}
|
||||
});
|
||||
});
|
||||
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
|
||||
this.customFields = this.baseSample.notes.custom_fields && this.baseSample.notes.custom_fields !== {} ? // read 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
|
||||
this.sampleReferences = [];
|
||||
this.sampleReferenceAutocomplete = [];
|
||||
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.sampleReferences.push([srData.number, reference.relation, reference.sample_id]);
|
||||
this.sampleReferenceAutocomplete.push([srData.number]);
|
||||
if (!--loadCounter) { // insert empty template when all instances were loaded
|
||||
this.sampleReferences.push(['', '', '']);
|
||||
this.sampleReferenceAutocomplete.push([]);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
if (this.mode === 'editOne') {
|
||||
this.charts = [[]];
|
||||
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 ++;
|
||||
}
|
||||
if (this.mode === 'editOne') {
|
||||
this.charts = [[]];
|
||||
let spectrumCounter = 0; // generate charts for spectrum measurements
|
||||
this.samples[i].measurements.forEach((measurement, j) => {
|
||||
this.charts[i].push(cloneDeep(this.chartInit));
|
||||
if (measurement.values.dpt) {
|
||||
setTimeout(() => {
|
||||
this.generateChart(measurement.values.dpt, 0, j);
|
||||
}, spectrumCounter * 20); // generate charts one after another to avoid freezing the UI
|
||||
spectrumCounter ++;
|
||||
}
|
||||
});
|
||||
}
|
||||
this.checkFormAfterInit = true;
|
||||
}
|
||||
else {
|
||||
});
|
||||
}
|
||||
this.loading--;
|
||||
sampleIds.slice(1).forEach(sampleId => {
|
||||
this.api.get<SampleModel>('/sample/' + sampleId, data => {
|
||||
this.samples.push(new SampleModel().deserialize(data));
|
||||
['type', 'color', 'batch', 'notes'].forEach((key) => {
|
||||
console.log(isEqual(sData[key], this.baseSample[key]));
|
||||
if (!isEqual(sData[key], this.baseSample[key])) {
|
||||
console.log(isEqual(data[key], this.baseSample[key]));
|
||||
if (!isEqual(data[key], this.baseSample[key])) {
|
||||
this.baseSample[key] = undefined;
|
||||
}
|
||||
});
|
||||
if (!isEqual(sData.material.name, this.baseSample.material.name)) {
|
||||
if (!isEqual(data.material.name, this.baseSample.material.name)) {
|
||||
this.baseSample.material.name = undefined;
|
||||
}
|
||||
}
|
||||
this.loading--;
|
||||
this.loading--;
|
||||
this.checkFormAfterInit = true;
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -531,7 +530,9 @@ export class SampleComponent implements OnInit, AfterContentChecked {
|
||||
deleteConfirm(modal) {
|
||||
this.modal.open(modal).then(result => {
|
||||
if (result) {
|
||||
this.api.delete('/sample/' + this.baseSample._id);
|
||||
this.samples.forEach(sample => {
|
||||
this.api.delete('/sample/' + sample._id);
|
||||
});
|
||||
this.router.navigate(['/samples']);
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user