Skip to content

Commit 675acd1

Browse files
committed
new feature
add the ability to configure the API URL in the frontend and save it in localstorage
1 parent 1ae3cf2 commit 675acd1

File tree

1 file changed

+75
-2
lines changed

1 file changed

+75
-2
lines changed

index.html

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@
6868
.search-form .form-check {
6969
margin-top: 0.5rem;
7070
}
71+
.config-button {
72+
position: fixed;
73+
top: 10px;
74+
right: 10px;
75+
z-index: 1000;
76+
}
7177
</style>
7278
<style>
7379
#filesNavigator {
@@ -88,6 +94,11 @@
8894
</style>
8995
</head>
9096
<body>
97+
<!-- Configuration Button -->
98+
<button class="btn btn-outline-secondary btn-sm config-button" onclick="showConfigModal()" title="Configure API URL">
99+
<i class="fa-solid fa-cog"></i>
100+
</button>
101+
91102
<div class="sidebar">
92103
<h4 class="mb-4">CSV File Manager</h4>
93104

@@ -164,6 +175,29 @@ <h4>${filename}</h4>
164175
</template>
165176
</div>
166177

178+
<!-- Configuration Modal -->
179+
<div class="modal fade" id="configModal" tabindex="-1">
180+
<div class="modal-dialog">
181+
<div class="modal-content">
182+
<div class="modal-header">
183+
<h5 class="modal-title">API Configuration</h5>
184+
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
185+
</div>
186+
<div class="modal-body">
187+
<div class="form-group mb-3">
188+
<label for="apiUrl" class="form-label">API URL</label>
189+
<input type="url" class="form-control" id="apiUrl" placeholder="https://example.com/api.php">
190+
<div class="form-text">Enter the full URL to your CSV API endpoint</div>
191+
</div>
192+
</div>
193+
<div class="modal-footer">
194+
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
195+
<button type="button" class="btn btn-primary" onclick="saveConfig()">Save</button>
196+
</div>
197+
</div>
198+
</div>
199+
</div>
200+
167201
<!-- Edit Modal -->
168202
<div class="modal fade" id="editModal" tabindex="-1">
169203
<div class="modal-dialog">
@@ -199,12 +233,50 @@ <h5 class="modal-title">New Record</h5>
199233
</div>
200234

201235
<script>
202-
const API_URL = 'api.php';
236+
let API_URL = 'api.php';
203237
let currentFile = null;
204238
let currentPage = 0;
205239
let pageSize = 50;
206240
let authToken = null;
207241

242+
// Configuration functions
243+
function loadConfig() {
244+
const savedApiUrl = localStorage.getItem('csvApiUrl');
245+
if (savedApiUrl) {
246+
API_URL = savedApiUrl;
247+
}
248+
}
249+
250+
function showConfigModal() {
251+
document.getElementById('apiUrl').value = API_URL;
252+
new bootstrap.Modal(document.getElementById('configModal')).show();
253+
}
254+
255+
function saveConfig() {
256+
const newApiUrl = document.getElementById('apiUrl').value.trim();
257+
if (!newApiUrl) {
258+
alert('Please enter a valid API URL');
259+
return;
260+
}
261+
262+
// Validate URL format
263+
try {
264+
new URL(newApiUrl);
265+
} catch (e) {
266+
alert('Please enter a valid URL');
267+
return;
268+
}
269+
270+
API_URL = newApiUrl;
271+
localStorage.setItem('csvApiUrl', newApiUrl);
272+
273+
// Close modal
274+
bootstrap.Modal.getInstance(document.getElementById('configModal')).hide();
275+
276+
// Show success message
277+
alert('API URL saved successfully!');
278+
}
279+
208280
// Input sanitization functions
209281
function sanitizeInput(input) {
210282
if (typeof input !== 'string') return input;
@@ -504,8 +576,9 @@ <h5 class="modal-title">New Record</h5>
504576
});
505577
}
506578

507-
// Check for existing token on page load
579+
// Initialize on page load
508580
$(document).ready(function() {
581+
loadConfig();
509582
checkExistingToken();
510583
});
511584
</script>

0 commit comments

Comments
 (0)