@osfarm/itineraire-technique 1.2.1 → 1.2.2

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.
@@ -45,18 +45,40 @@ class ItineraLoader extends DefaultLoader {
45
45
 
46
46
  const urlParams = new URLSearchParams(window.location.search);
47
47
  self.systemID = urlParams.get('itinera');
48
+ const uuid = urlParams.get('uuid');
48
49
 
49
50
  if (!self.systemID)
50
51
  return; // No page title provided, we are not in wiki edit mode
51
52
 
53
+ // Build API URL with UUID if provided
54
+ const apiUrl = uuid
55
+ ? `/api/systems/${encodeURIComponent(self.systemID)}?uuid=${encodeURIComponent(uuid)}`
56
+ : `/api/systems/${encodeURIComponent(self.systemID)}`;
57
+
52
58
  // If a page title is provided, load its content from /api/systems/1
53
- fetch(`/api/systems/${encodeURIComponent(self.systemID)}`, {
59
+ fetch(apiUrl, {
54
60
  credentials: 'same-origin'
55
61
  })
56
62
  .then(response => {
57
63
  let res = response.json();
58
64
  return res;
59
65
  })
66
+ .then(data => {
67
+ // Handle redirect response (only if UUID wasn't already in URL)
68
+ if (!uuid && data.shouldRedirect && data.redirectTo) {
69
+ // Extract UUID from redirectTo path (format: /project/22/UUID)
70
+ const pathParts = data.redirectTo.split('/');
71
+ const redirectUuid = pathParts[pathParts.length - 1];
72
+
73
+ if (redirectUuid) {
74
+ // Retry with UUID parameter
75
+ return fetch(`/api/systems/${encodeURIComponent(self.systemID)}?uuid=${redirectUuid}`, {
76
+ credentials: 'same-origin'
77
+ }).then(response => response.json());
78
+ }
79
+ }
80
+ return data;
81
+ })
60
82
  .then(data => {
61
83
  if (data.json) {
62
84
  try {
@@ -82,7 +104,7 @@ class ItineraLoader extends DefaultLoader {
82
104
  jsonErrorModal.show();
83
105
  }
84
106
  } else {
85
- wipe();
107
+ self.wipe();
86
108
  }
87
109
  });
88
110
 
@@ -110,16 +132,17 @@ class ItineraLoader extends DefaultLoader {
110
132
  json: self.tikaeditorInstance.system
111
133
  })
112
134
  });
135
+ const toast = $('#liveToast');
136
+
137
+ // Update the time and message
138
+ const now = new Date();
139
+ const hours = now.getHours().toString().padStart(2, '0');
140
+ const minutes = now.getMinutes().toString().padStart(2, '0');
141
+ toast.find('small').text(`${hours}:${minutes}`);
113
142
 
114
143
  if (response.ok) {
115
144
  // Successfully saved - show a toast
116
- const toast = $('#liveToast');
117
145
 
118
- // Update the time and message
119
- const now = new Date();
120
- const hours = now.getHours().toString().padStart(2, '0');
121
- const minutes = now.getMinutes().toString().padStart(2, '0');
122
- toast.find('small').text(`${hours}:${minutes}`);
123
146
  toast.find('.toast-body').text('Sauvegardé dans Itinéra !');
124
147
 
125
148
  const toastBootstrap = bootstrap.Toast.getOrCreateInstance(toast);
@@ -127,8 +150,11 @@ class ItineraLoader extends DefaultLoader {
127
150
 
128
151
  } else {
129
152
  // Error saving
130
- const errorModal = new bootstrap.Modal(document.getElementById('saveErrorModal'));
131
- errorModal.show();
153
+
154
+ toast.find('.toast-body').text("Erreur lors de la sauvegarde dans Itinéra.\n" + response.statusText);
155
+
156
+ const toastBootstrap = bootstrap.Toast.getOrCreateInstance(toast);
157
+ toastBootstrap.show();
132
158
  }
133
159
  }
134
160
 
@@ -142,7 +142,7 @@ class WikiLoader extends DefaultLoader {
142
142
 
143
143
  if (data.error.code == "missingtitle") {
144
144
  // The page doesn't exist yet, we can start with a blank rotation
145
- wipe();
145
+ self.wipe();
146
146
  } else {
147
147
  console.error("Erreur lors du chargement de la page :", data);
148
148
  $('#jsonErrorMessage').text("Impossible de charger le contenu de la page.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osfarm/itineraire-technique",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "A visualisation tool to show agricultural technical itineraries based on Echarts",
5
5
  "main": "editor.html",
6
6
  "scripts": {