@osfarm/itineraire-technique 1.1.16 → 1.1.18

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 CHANGED
@@ -52,7 +52,7 @@
52
52
  </button>
53
53
  <ul class="dropdown-menu">
54
54
  <li><a class="dropdown-item" href="#" onclick="showSaveAsModal()"><i class="fa fa-save" aria-hidden="true"></i> Enregistrer sous</a></li>
55
- <li><a class="dropdown-item" href="#" onclick="exportToJsonFile()"><i class="fa fa-download" aria-hidden="true"></i> Exporter</a></li>
55
+ <li><a class="dropdown-item" href="#" onclick="doExportToJsonFile()"><i class="fa fa-download" aria-hidden="true"></i> Exporter</a></li>
56
56
  </ul>
57
57
  </div>
58
58
  </div>
@@ -65,7 +65,7 @@
65
65
  <ul class="dropdown-menu">
66
66
  <li><a class="dropdown-item" href="#" onclick="importFromTestJson()"><i class="fa fa-lightbulb-o" aria-hidden="true"></i> Charger un exemple</a></li>
67
67
  </ul>
68
- </div><button type="button" onclick="exportToJsonFile()" class="btn btn-outline-primary primary-button me-2"><i class="fa fa-download" aria-hidden="true"></i> Exporter (JSON)</button>
68
+ </div><button type="button" onclick="doExportToJsonFile()" class="btn btn-outline-primary primary-button me-2"><i class="fa fa-download" aria-hidden="true"></i> Exporter (JSON)</button>
69
69
  </div>
70
70
 
71
71
  <button type="button" onclick="wipe(crops)" class="btn btn-outline-primary primary-button"><i class="fa fa-trash" aria-hidden="true"></i> Tout effacer</button>
@@ -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
 
@@ -1084,4 +1089,8 @@
1084
1089
  });
1085
1090
  }
1086
1091
 
1092
+ function doExportToJsonFile() {
1093
+ let jsonName = crops.title.replace(/\s+/g, '-').toLowerCase() + ".json";
1094
+ exportToJsonFile(crops, jsonName);
1095
+ }
1087
1096
  </script>
@@ -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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osfarm/itineraire-technique",
3
- "version": "1.1.16",
3
+ "version": "1.1.18",
4
4
  "description": "A visualisation tool to show agricultural technical itineraries based on Echarts",
5
5
  "main": "editor.html",
6
6
  "scripts": {