@osfarm/itineraire-technique 1.1.16 → 1.1.17
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/editor.html +6 -1
- package/js/editor-crops.js +61 -0
- package/package.json +1 -1
package/editor.html
CHANGED
|
@@ -946,7 +946,7 @@
|
|
|
946
946
|
return latestEndDate;
|
|
947
947
|
}
|
|
948
948
|
|
|
949
|
-
function addEditAndRemoveButtons(rowDiv, deleteId, editFunction, deleteFunction) {
|
|
949
|
+
function addEditAndRemoveButtons(rowDiv, deleteId, editFunction, deleteFunction, duplicateFunction) {
|
|
950
950
|
rowDiv = $(rowDiv);
|
|
951
951
|
|
|
952
952
|
let actionContainer = $('<div class="col-auto edit-buttons"></div>');
|
|
@@ -961,6 +961,11 @@
|
|
|
961
961
|
editFunction();
|
|
962
962
|
}));
|
|
963
963
|
|
|
964
|
+
actionContainer.append($('<button class="btn btn-outline-secondary float-end me-1"><i class="fa fa-copy"></i></button>').click(function (event) {
|
|
965
|
+
event.stopPropagation(); // Prevent other onclick events from triggering
|
|
966
|
+
duplicateFunction(deleteId);
|
|
967
|
+
}));
|
|
968
|
+
|
|
964
969
|
rowDiv.append(actionContainer);
|
|
965
970
|
}
|
|
966
971
|
|
package/js/editor-crops.js
CHANGED
|
@@ -58,6 +58,9 @@ function createCropRow(crop) {
|
|
|
58
58
|
|
|
59
59
|
refreshAllTables();
|
|
60
60
|
displayCropListView();
|
|
61
|
+
},
|
|
62
|
+
function(id) {
|
|
63
|
+
duplicateStep(id);
|
|
61
64
|
});
|
|
62
65
|
|
|
63
66
|
rowDiv.click();
|
|
@@ -65,6 +68,64 @@ function createCropRow(crop) {
|
|
|
65
68
|
return rowDiv;
|
|
66
69
|
}
|
|
67
70
|
|
|
71
|
+
function duplicateStep(stepId) {
|
|
72
|
+
// Find the step to duplicate
|
|
73
|
+
let originalStep = crops.steps.find(crop => crop.id === stepId);
|
|
74
|
+
if (!originalStep) return;
|
|
75
|
+
|
|
76
|
+
// Get the latest end date in the rotation
|
|
77
|
+
let latestEndDate = getRotationEndDate();
|
|
78
|
+
|
|
79
|
+
// Calculate the duration of the original step
|
|
80
|
+
let originalStart = new Date(originalStep.startDate);
|
|
81
|
+
let originalEnd = new Date(originalStep.endDate);
|
|
82
|
+
|
|
83
|
+
// Calculate how many years to add to position after the latest step
|
|
84
|
+
let yearsToAdd = 0;
|
|
85
|
+
let newStartDate = new Date(originalStart);
|
|
86
|
+
let newEndDate = new Date(originalEnd);
|
|
87
|
+
|
|
88
|
+
// Keep adding years until the new start date is after the latest end date
|
|
89
|
+
while (newStartDate < latestEndDate) {
|
|
90
|
+
yearsToAdd++;
|
|
91
|
+
newStartDate = new Date(originalStart);
|
|
92
|
+
newStartDate.setFullYear(originalStart.getFullYear() + yearsToAdd);
|
|
93
|
+
newEndDate.setFullYear(originalEnd.getFullYear() + yearsToAdd);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Create the new step with all properties cloned
|
|
97
|
+
let newStep = {
|
|
98
|
+
name: originalStep.name,
|
|
99
|
+
color: originalStep.color,
|
|
100
|
+
startDate: newStartDate,
|
|
101
|
+
endDate: newEndDate,
|
|
102
|
+
description: originalStep.description,
|
|
103
|
+
secondary_crop: originalStep.secondary_crop || false,
|
|
104
|
+
useDefaultColor: originalStep.useDefaultColor,
|
|
105
|
+
useDefaultStartDate: originalStep.useDefaultStartDate,
|
|
106
|
+
useDefaultEndDate: originalStep.useDefaultEndDate,
|
|
107
|
+
interventions: originalStep.interventions ? originalStep.interventions.map(i => ({
|
|
108
|
+
day: i.day,
|
|
109
|
+
name: i.name,
|
|
110
|
+
type: i.type,
|
|
111
|
+
description: i.description
|
|
112
|
+
})) : [],
|
|
113
|
+
attributes: originalStep.attributes ? originalStep.attributes.map(a => ({
|
|
114
|
+
name: a.name,
|
|
115
|
+
value: a.value
|
|
116
|
+
})) : []
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// Create a StepModel instance to ensure proper initialization
|
|
120
|
+
let stepModel = new StepModel(newStep);
|
|
121
|
+
|
|
122
|
+
// Add the duplicated step to the rotation
|
|
123
|
+
crops.steps.push(stepModel.getStep());
|
|
124
|
+
|
|
125
|
+
// Refresh the UI
|
|
126
|
+
refreshAllTables();
|
|
127
|
+
}
|
|
128
|
+
|
|
68
129
|
function SelectStep(crop) {
|
|
69
130
|
selectedStep = crop;
|
|
70
131
|
loadSelectedStepToEditor(selectedStep);
|