RoyAalekh commited on
Commit
f0004a7
·
1 Parent(s): 9e903d1

fix(ui): include location_name in POST/PUT JSON and display it in Recent Trees

Browse files
static/js/modules/api-client.js CHANGED
@@ -60,6 +60,9 @@ export class ApiClient {
60
  async saveTree(treeData) {
61
  const response = await this.authenticatedFetch('/api/trees', {
62
  method: 'POST',
 
 
 
63
  body: JSON.stringify(treeData)
64
  });
65
 
@@ -76,6 +79,9 @@ export class ApiClient {
76
  async updateTree(treeId, treeData) {
77
  const response = await this.authenticatedFetch(`/api/trees/${treeId}`, {
78
  method: 'PUT',
 
 
 
79
  body: JSON.stringify(treeData)
80
  });
81
 
 
60
  async saveTree(treeData) {
61
  const response = await this.authenticatedFetch('/api/trees', {
62
  method: 'POST',
63
+ headers: {
64
+ 'Content-Type': 'application/json'
65
+ },
66
  body: JSON.stringify(treeData)
67
  });
68
 
 
79
  async updateTree(treeId, treeData) {
80
  const response = await this.authenticatedFetch(`/api/trees/${treeId}`, {
81
  method: 'PUT',
82
+ headers: {
83
+ 'Content-Type': 'application/json'
84
+ },
85
  body: JSON.stringify(treeData)
86
  });
87
 
static/js/modules/ui-manager.js CHANGED
@@ -93,6 +93,7 @@ export class UIManager {
93
  </div>
94
  <div class="tree-info">
95
  ${tree.scientific_name || tree.common_name || tree.local_name || 'Unnamed'}
 
96
  <br>${tree.latitude.toFixed(4)}, ${tree.longitude.toFixed(4)}
97
  ${tree.tree_code ? `<br>Code: ${tree.tree_code}` : ''}
98
  <br>${new Date(tree.created_at).toLocaleDateString()}
@@ -103,6 +104,16 @@ export class UIManager {
103
  }).join('');
104
  }
105
 
 
 
 
 
 
 
 
 
 
 
106
  showLoadingState(containerId, message = 'Loading...') {
107
  const container = document.getElementById(containerId);
108
  if (!container) return;
 
93
  </div>
94
  <div class="tree-info">
95
  ${tree.scientific_name || tree.common_name || tree.local_name || 'Unnamed'}
96
+ ${tree.location_name ? `<br><strong>Location:</strong> ${this.escapeHtml(tree.location_name)}` : ''}
97
  <br>${tree.latitude.toFixed(4)}, ${tree.longitude.toFixed(4)}
98
  ${tree.tree_code ? `<br>Code: ${tree.tree_code}` : ''}
99
  <br>${new Date(tree.created_at).toLocaleDateString()}
 
104
  }).join('');
105
  }
106
 
107
+ escapeHtml(text) {
108
+ if (typeof text !== 'string') return text;
109
+ return text
110
+ .replace(/&/g, '&amp;')
111
+ .replace(/</g, '&lt;')
112
+ .replace(/>/g, '&gt;')
113
+ .replace(/"/g, '&quot;')
114
+ .replace(/'/g, '&#039;');
115
+ }
116
+
117
  showLoadingState(containerId, message = 'Loading...') {
118
  const container = document.getElementById(containerId);
119
  if (!container) return;