File size: 6,719 Bytes
32d70d7 4c9761f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
// Function to view YAML file
function viewYaml(element) {
const filename = element.getAttribute('data-filename');
// Make an AJAX request to fetch the YAML content
fetch(`/get_yaml?filename=${encodeURIComponent(filename)}`)
.then(response => response.text())
.then(yamlContent => {
// Display the YAML content in a modal
const modal = document.createElement('div');
modal.style.position = 'fixed';
modal.style.top = '0';
modal.style.left = '0';
modal.style.width = '100%';
modal.style.height = '100%';
modal.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
modal.style.zIndex = '1000';
modal.style.display = 'flex';
modal.style.justifyContent = 'center';
modal.style.alignItems = 'center';
const modalContent = document.createElement('div');
modalContent.style.backgroundColor = 'white';
modalContent.style.padding = '20px';
modalContent.style.borderRadius = '5px';
modalContent.style.maxWidth = '80%';
modalContent.style.maxHeight = '80%';
modalContent.style.overflow = 'auto';
const closeButton = document.createElement('button');
closeButton.textContent = 'Close';
closeButton.style.marginBottom = '10px';
closeButton.style.padding = '5px 10px';
closeButton.style.cursor = 'pointer';
closeButton.onclick = () => {
document.body.removeChild(modal);
};
const yamlPre = document.createElement('pre');
yamlPre.textContent = yamlContent;
yamlPre.style.whiteSpace = 'pre-wrap';
yamlPre.style.wordBreak = 'break-word';
modalContent.appendChild(closeButton);
modalContent.appendChild(yamlPre);
modal.appendChild(modalContent);
document.body.appendChild(modal);
})
.catch(error => {
console.error('Error fetching YAML content:', error);
alert('Error fetching YAML content: ' + error.message);
});
}
// Function to visualize coverage scores
function visualizeCoverage(scoreDetails) {
const chartContainer = document.getElementById('coverage-chart');
// Create a bar chart using a visualization library
// This is just a placeholder - you would use a library like Chart.js
let html = `<div style="margin-top: 20px;">
<h3>Coverage by Section</h3>
<div style="display: flex; flex-direction: column; gap: 5px;">`;
for (const [section, details] of Object.entries(scoreDetails)) {
const percentage = details.completion_rate;
html += `
<div>
<div style="display: flex; justify-content: space-between; margin-bottom: 2px;">
<span>${section}</span>
<span>${percentage}%</span>
</div>
<div style="width: 100%; background-color: #eee; height: 10px; border-radius: 5px;">
<div style="width: ${percentage}%; background-color: #3273dc; height: 10px; border-radius: 5px;"></div>
</div>
</div>`;
}
html += '</div></div>';
chartContainer.innerHTML = html;
}
// Initialize any client-side functionality when the document loads
document.addEventListener('DOMContentLoaded', function() {
// This could be used to initialize charts or other client-side features
console.log('Client-side JavaScript initialized');
});
// Add this to script.js
// Function to show the YAML content in a modal
function viewYAML(filename) {
// Use Gradio's client.query to get the YAML content
gradioApp().querySelector('#file_action_component').querySelector('textarea').value = filename;
gradioApp().querySelector('#file_action_type_component').querySelector('textarea').value = 'view';
// Trigger the event
const viewButton = gradioApp().querySelector('#trigger_file_action');
viewButton.click();
// The result will show up in the modal that's created by the event handler
}
// Function to download a file
function downloadFile(filename, format) {
let actionType;
if (format === 'yaml') actionType = 'download_yaml';
else if (format === 'markdown') actionType = 'download_md';
else if (format === 'latex') actionType = 'download_latex';
else return;
// Set the filename and action type
gradioApp().querySelector('#file_action_component').querySelector('textarea').value = filename;
gradioApp().querySelector('#file_action_type_component').querySelector('textarea').value = actionType;
// Trigger the event
const downloadButton = gradioApp().querySelector('#trigger_file_action');
downloadButton.click();
// The download will be handled by the event response
}
// Helper function to get the Gradio app element
function gradioApp() {
return document.getElementsByTagName('gradio-app')[0].shadowRoot || document;
}
// Function to create and display a modal with content
function showModal(content) {
// Create the modal elements
const modal = document.createElement('div');
modal.style.position = 'fixed';
modal.style.top = '0';
modal.style.left = '0';
modal.style.width = '100%';
modal.style.height = '100%';
modal.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
modal.style.zIndex = '1000';
modal.style.display = 'flex';
modal.style.justifyContent = 'center';
modal.style.alignItems = 'center';
const modalContent = document.createElement('div');
modalContent.style.backgroundColor = 'white';
modalContent.style.padding = '20px';
modalContent.style.borderRadius = '5px';
modalContent.style.maxWidth = '80%';
modalContent.style.maxHeight = '80%';
modalContent.style.overflow = 'auto';
const closeButton = document.createElement('button');
closeButton.textContent = 'Close';
closeButton.style.marginBottom = '10px';
closeButton.style.padding = '5px 10px';
closeButton.style.cursor = 'pointer';
closeButton.onclick = () => {
document.body.removeChild(modal);
};
const contentPre = document.createElement('pre');
contentPre.textContent = content;
contentPre.style.whiteSpace = 'pre-wrap';
contentPre.style.wordBreak = 'break-word';
modalContent.appendChild(closeButton);
modalContent.appendChild(contentPre);
modal.appendChild(modalContent);
document.body.appendChild(modal);
} |