feat: ✨ device tags
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
// API Documentation Interactive Functions
|
||||
|
||||
function getApiKey() {
|
||||
return document.getElementById('apiKey').value;
|
||||
}
|
||||
|
||||
function showStatus(message, isError = false) {
|
||||
const status = document.getElementById('connectionStatus');
|
||||
status.textContent = message;
|
||||
status.className = `mt-2 text-sm ${isError ? 'text-red-600 dark:text-red-400' : 'text-green-600 dark:text-green-400'}`;
|
||||
}
|
||||
|
||||
async function testConnection() {
|
||||
const apiKey = getApiKey();
|
||||
if (!apiKey) {
|
||||
showStatus('Please enter your API key', true);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await axios.get('/api/v1/devices', {
|
||||
headers: { 'X-API-Key': apiKey }
|
||||
});
|
||||
showStatus('✓ Connection successful');
|
||||
} catch (error) {
|
||||
if (error.response?.status === 401) {
|
||||
showStatus('✗ Invalid API key', true);
|
||||
} else if (error.response?.status === 403) {
|
||||
showStatus('✗ Insufficient permissions', true);
|
||||
} else {
|
||||
showStatus('✗ Connection failed', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function tryEndpoint(method, url, data, responseId) {
|
||||
const apiKey = getApiKey();
|
||||
if (!apiKey) {
|
||||
showStatus('Please enter your API key first', true);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const config = {
|
||||
method: method,
|
||||
url: url,
|
||||
headers: { 'X-API-Key': apiKey }
|
||||
};
|
||||
|
||||
if (data) {
|
||||
config.data = data;
|
||||
}
|
||||
|
||||
const response = await axios(config);
|
||||
document.getElementById(responseId + '-response').classList.remove('hidden');
|
||||
document.getElementById(responseId).textContent = JSON.stringify(response.data, null, 2);
|
||||
} catch (error) {
|
||||
document.getElementById(responseId + '-response').classList.remove('hidden');
|
||||
const errorMessage = error.response?.data?.error || error.message;
|
||||
document.getElementById(responseId).textContent = `Error (${error.response?.status || 'Network'}): ${errorMessage}`;
|
||||
}
|
||||
}
|
||||
|
||||
async function tryEndpointWithId(method, baseUrl, inputId, responseId) {
|
||||
const id = document.getElementById(inputId).value;
|
||||
if (!id) {
|
||||
alert('Please enter an ID');
|
||||
return;
|
||||
}
|
||||
await tryEndpoint(method, baseUrl + encodeURIComponent(id), null, responseId);
|
||||
}
|
||||
|
||||
// Auto-populate API key if user is logged in
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const apiKeyInput = document.getElementById('apiKey');
|
||||
if (apiKeyInput && apiKeyInput.value) {
|
||||
testConnection();
|
||||
}
|
||||
});
|
||||
@@ -1,5 +1,18 @@
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
// Tag filter functionality
|
||||
const tagFilter = document.getElementById('tag-filter');
|
||||
if (tagFilter) {
|
||||
tagFilter.addEventListener('change', function() {
|
||||
const selectedTag = this.value;
|
||||
if (selectedTag) {
|
||||
window.location.href = '/devices?tag=' + encodeURIComponent(selectedTag);
|
||||
} else {
|
||||
window.location.href = '/devices';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Expand/collapse site groups
|
||||
document.querySelectorAll('.site-header').forEach(header => {
|
||||
header.addEventListener('click', function(e) {
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
// Tag Management JavaScript
|
||||
|
||||
function showAddTagModal() {
|
||||
document.getElementById('add-tag-modal').classList.remove('hidden');
|
||||
document.getElementById('add-tag-name').value = '';
|
||||
document.getElementById('add-tag-color').value = '#6B7280';
|
||||
document.getElementById('add-tag-description').value = '';
|
||||
updateColorPreview('add');
|
||||
}
|
||||
|
||||
function closeAddTagModal() {
|
||||
document.getElementById('add-tag-modal').classList.add('hidden');
|
||||
}
|
||||
|
||||
function editTag(tagId, name, color, description) {
|
||||
document.getElementById('edit-tag-id').value = tagId;
|
||||
document.getElementById('edit-tag-name').value = name;
|
||||
document.getElementById('edit-tag-color').value = color;
|
||||
document.getElementById('edit-tag-description').value = description || '';
|
||||
updateColorPreview('edit');
|
||||
document.getElementById('edit-tag-modal').classList.remove('hidden');
|
||||
}
|
||||
|
||||
function closeEditTagModal() {
|
||||
document.getElementById('edit-tag-modal').classList.add('hidden');
|
||||
}
|
||||
|
||||
function updateColorPreview(mode) {
|
||||
const colorInput = document.getElementById(`${mode}-tag-color`);
|
||||
const preview = document.getElementById(`${mode}-color-preview`);
|
||||
preview.textContent = colorInput.value.toUpperCase();
|
||||
}
|
||||
|
||||
// Event listeners
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const addColorInput = document.getElementById('add-tag-color');
|
||||
const editColorInput = document.getElementById('edit-tag-color');
|
||||
|
||||
if (addColorInput) {
|
||||
addColorInput.addEventListener('input', () => updateColorPreview('add'));
|
||||
}
|
||||
|
||||
if (editColorInput) {
|
||||
editColorInput.addEventListener('input', () => updateColorPreview('edit'));
|
||||
}
|
||||
|
||||
// Handle edit tag button clicks
|
||||
document.querySelectorAll('.edit-tag-btn').forEach(button => {
|
||||
button.addEventListener('click', function() {
|
||||
const tagId = this.dataset.tagId;
|
||||
const tagName = this.dataset.tagName;
|
||||
const tagColor = this.dataset.tagColor;
|
||||
const tagDescription = this.dataset.tagDescription;
|
||||
editTag(tagId, tagName, tagColor, tagDescription);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Close modals when clicking outside
|
||||
window.onclick = function(event) {
|
||||
const addModal = document.getElementById('add-tag-modal');
|
||||
const editModal = document.getElementById('edit-tag-modal');
|
||||
if (event.target === addModal) {
|
||||
closeAddTagModal();
|
||||
}
|
||||
if (event.target === editModal) {
|
||||
closeEditTagModal();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user