@osfarm/itineraire-technique 1.2.6 → 1.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/js/editor-interventions.js +31 -23
- package/js/editor-main.js +23 -17
- package/package.json +1 -1
|
@@ -6,7 +6,7 @@ class InterventionTable {
|
|
|
6
6
|
// Constructor
|
|
7
7
|
constructor(interventionsTopTitle, interventionsBottomTitle, tikaEditorInstance) {
|
|
8
8
|
this.selectedStep = null;
|
|
9
|
-
|
|
9
|
+
|
|
10
10
|
this.interventionsTopTitle = interventionsTopTitle;
|
|
11
11
|
this.interventionsBottomTitle = interventionsBottomTitle;
|
|
12
12
|
this.tikaEditorInstance = tikaEditorInstance;
|
|
@@ -43,10 +43,10 @@ class InterventionTable {
|
|
|
43
43
|
</div>
|
|
44
44
|
</div>
|
|
45
45
|
`);
|
|
46
|
-
|
|
46
|
+
|
|
47
47
|
// Insert after the step's details
|
|
48
48
|
$('#cropDetailView').after(interventionsTableDiv);
|
|
49
|
-
|
|
49
|
+
|
|
50
50
|
const self = this;
|
|
51
51
|
|
|
52
52
|
$('#newInterventionButton').on('click', function(e) {
|
|
@@ -69,8 +69,8 @@ class InterventionTable {
|
|
|
69
69
|
|
|
70
70
|
if (this.selectedStep.getStep().interventions) {
|
|
71
71
|
// Sort all interventions by day
|
|
72
|
-
this.selectedStep.getStep().interventions = this.selectedStep.getStep().interventions.sort((a, b) => a.day - b.day);
|
|
73
|
-
|
|
72
|
+
this.selectedStep.getStep().interventions = this.selectedStep.getStep().interventions.sort((a, b) => a.day - b.day);
|
|
73
|
+
|
|
74
74
|
this.selectedStep.getStep().interventions.forEach((intervention) => {
|
|
75
75
|
const rowDiv = this.createInterventionRow(intervention);
|
|
76
76
|
|
|
@@ -160,7 +160,7 @@ class InterventionTable {
|
|
|
160
160
|
day: "numeric",
|
|
161
161
|
});
|
|
162
162
|
}
|
|
163
|
-
|
|
163
|
+
|
|
164
164
|
let nameValueDiv = document.createElement("div");
|
|
165
165
|
nameValueDiv.className = "col";
|
|
166
166
|
nameValueDiv.innerHTML = `<strong>${intervention.name}</strong> (${absoluteDate})</br> ${intervention.description}`;
|
|
@@ -180,7 +180,7 @@ class InterventionTable {
|
|
|
180
180
|
let absoluteDate = "";
|
|
181
181
|
if (day === "")
|
|
182
182
|
day = 0;
|
|
183
|
-
|
|
183
|
+
|
|
184
184
|
if (this.selectedStep && this.selectedStep.getStep().startDate) {
|
|
185
185
|
const stepStartDate = new Date(this.selectedStep.getStep().startDate);
|
|
186
186
|
const interventionDate = new Date(stepStartDate);
|
|
@@ -212,9 +212,9 @@ class InterventionTable {
|
|
|
212
212
|
</div>
|
|
213
213
|
<div class="col-12 mb-2">
|
|
214
214
|
<select id="interventionType" class="form-select" aria-label="Type">
|
|
215
|
-
<option value="intervention_top"
|
|
215
|
+
<option value="intervention_top"
|
|
216
216
|
${type === "intervention_top" ? "selected" : ""}>${this.interventionsTopTitle}</option>
|
|
217
|
-
<option value="intervention_bottom"
|
|
217
|
+
<option value="intervention_bottom"
|
|
218
218
|
${type === "intervention_bottom" ? "selected" : ""}>${this.interventionsBottomTitle}</option>
|
|
219
219
|
</select>
|
|
220
220
|
</div>
|
|
@@ -261,14 +261,14 @@ class InterventionTable {
|
|
|
261
261
|
} else {
|
|
262
262
|
$("#interventionsBottomContainer").append(newRowDiv);
|
|
263
263
|
}
|
|
264
|
-
|
|
264
|
+
|
|
265
265
|
// Remove the form
|
|
266
266
|
formContainer.remove();
|
|
267
|
-
}
|
|
267
|
+
}
|
|
268
268
|
|
|
269
269
|
self.tikaEditorInstance.renderChart();
|
|
270
270
|
});
|
|
271
|
-
|
|
271
|
+
|
|
272
272
|
if (row) { //we are editing an intervention
|
|
273
273
|
row.replaceWith(formContainer);
|
|
274
274
|
} else { //we are adding an intervention
|
|
@@ -286,7 +286,7 @@ class InterventionTable {
|
|
|
286
286
|
form.find("#interventionDate").on("change", function() {
|
|
287
287
|
self.updateRelativeDayFromAbsolute();
|
|
288
288
|
});
|
|
289
|
-
|
|
289
|
+
|
|
290
290
|
form.find("#interventionName").focus();
|
|
291
291
|
}
|
|
292
292
|
|
|
@@ -299,7 +299,7 @@ class InterventionTable {
|
|
|
299
299
|
const stepStartDate = new Date(this.selectedStep.getStep().startDate);
|
|
300
300
|
const interventionDate = new Date(stepStartDate);
|
|
301
301
|
interventionDate.setDate(stepStartDate.getDate() + parseInt(relativeDay));
|
|
302
|
-
|
|
302
|
+
|
|
303
303
|
const absoluteDateStr = interventionDate.toISOString().split('T')[0];
|
|
304
304
|
$("#interventionDate").val(absoluteDateStr);
|
|
305
305
|
}
|
|
@@ -310,11 +310,11 @@ class InterventionTable {
|
|
|
310
310
|
if (absoluteDate !== "" && this.selectedStep && this.selectedStep.getStep().startDate) {
|
|
311
311
|
const stepStartDate = new Date(this.selectedStep.getStep().startDate);
|
|
312
312
|
const interventionDate = new Date(absoluteDate);
|
|
313
|
-
|
|
313
|
+
|
|
314
314
|
// Calculate difference in days
|
|
315
315
|
const timeDiff = interventionDate.getTime() - stepStartDate.getTime();
|
|
316
316
|
const dayDiff = Math.round(timeDiff / (1000 * 60 * 60 * 24));
|
|
317
|
-
|
|
317
|
+
|
|
318
318
|
$("#interventionDay").val(dayDiff);
|
|
319
319
|
}
|
|
320
320
|
}
|
|
@@ -326,15 +326,23 @@ class InterventionTable {
|
|
|
326
326
|
let originalIntervention = this.selectedStep.getStep().interventions.find(interv => interv.id === interventionId);
|
|
327
327
|
if (!originalIntervention) return;
|
|
328
328
|
|
|
329
|
-
//
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
description: originalIntervention.description
|
|
329
|
+
// Clone full JSON to preserve all existing fields.
|
|
330
|
+
const deepClone = (value) => {
|
|
331
|
+
if (typeof structuredClone === 'function') {
|
|
332
|
+
return structuredClone(value);
|
|
333
|
+
}
|
|
334
|
+
return JSON.parse(JSON.stringify(value));
|
|
336
335
|
};
|
|
337
336
|
|
|
337
|
+
let newIntervention = deepClone(originalIntervention);
|
|
338
|
+
newIntervention.id = crypto.randomUUID();
|
|
339
|
+
|
|
340
|
+
// Keep existing behavior: place duplicate a bit later to avoid overlap.
|
|
341
|
+
const originalDay = Number(newIntervention.day);
|
|
342
|
+
if (!Number.isNaN(originalDay)) {
|
|
343
|
+
newIntervention.day = originalDay + 15;
|
|
344
|
+
}
|
|
345
|
+
|
|
338
346
|
// Add the duplicated intervention to the selected step
|
|
339
347
|
this.selectedStep.getStep().interventions.push(newIntervention);
|
|
340
348
|
|
package/js/editor-main.js
CHANGED
|
@@ -775,25 +775,31 @@ class TikaEditor {
|
|
|
775
775
|
newEndDate.setFullYear(originalEnd.getFullYear() + yearsToAdd);
|
|
776
776
|
}
|
|
777
777
|
|
|
778
|
-
//
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
description: originalStep.description,
|
|
785
|
-
secondary_crop: originalStep.secondary_crop || false,
|
|
786
|
-
useDefaultColor: originalStep.useDefaultColor,
|
|
787
|
-
useDefaultStartDate: originalStep.useDefaultStartDate,
|
|
788
|
-
useDefaultEndDate: originalStep.useDefaultEndDate,
|
|
789
|
-
interventions: originalStep.interventions ? originalStep.interventions.map(i => ({
|
|
790
|
-
day: i.day,
|
|
791
|
-
name: i.name,
|
|
792
|
-
type: i.type,
|
|
793
|
-
description: i.description
|
|
794
|
-
})) : []
|
|
778
|
+
// Clone the full JSON so no extra properties are lost.
|
|
779
|
+
const deepClone = (value) => {
|
|
780
|
+
if (typeof structuredClone === 'function') {
|
|
781
|
+
return structuredClone(value);
|
|
782
|
+
}
|
|
783
|
+
return JSON.parse(JSON.stringify(value));
|
|
795
784
|
};
|
|
796
785
|
|
|
786
|
+
let newStep = deepClone(originalStep);
|
|
787
|
+
|
|
788
|
+
// Regenerate IDs for the new step and all copied interventions.
|
|
789
|
+
newStep.id = crypto.randomUUID();
|
|
790
|
+
newStep.startDate = newStartDate;
|
|
791
|
+
newStep.endDate = newEndDate;
|
|
792
|
+
|
|
793
|
+
if (Array.isArray(newStep.interventions)) {
|
|
794
|
+
newStep.interventions = newStep.interventions.map((intervention) => {
|
|
795
|
+
let clonedIntervention = deepClone(intervention);
|
|
796
|
+
clonedIntervention.id = crypto.randomUUID();
|
|
797
|
+
return clonedIntervention;
|
|
798
|
+
});
|
|
799
|
+
} else {
|
|
800
|
+
newStep.interventions = [];
|
|
801
|
+
}
|
|
802
|
+
|
|
797
803
|
// Create a StepModel instance to ensure proper initialization
|
|
798
804
|
let stepModel = new StepModel(newStep);
|
|
799
805
|
|