Sanoopsn commited on
Commit
b21db35
·
verified ·
1 Parent(s): 28fa7d6

load errorModal dynamically using javascript

Browse files
Files changed (2) hide show
  1. script.js +86 -12
  2. style.css +0 -12
script.js CHANGED
@@ -58,11 +58,11 @@ const sampleLogs = [
58
  ];
59
  // DOM elements
60
  const logsTable = document.getElementById('logsTable');
61
- const errorModal = document.getElementById('errorModal');
62
- const closeModal = document.getElementById('closeModal');
63
- const closeModalBtn = document.getElementById('closeModalBtn');
64
- const submitTicket = document.getElementById('submitTicket');
65
  const searchInput = document.querySelector('input[type="text"]');
 
 
 
 
66
  // Current selected log
67
  let currentLog = null;
68
  // Function to render logs table with optional filter
@@ -125,9 +125,90 @@ function getStatusClass(status) {
125
  function getMethodClass(method) {
126
  return `method-${method.toLowerCase()}`;
127
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  // Function to show error details in modal
129
  function showErrorDetails(log) {
130
- // Request Info
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  document.getElementById('modalStatus').textContent = log.status;
132
  document.getElementById('modalStatus').className = `status-badge ${getStatusClass(log.status)}`;
133
  document.getElementById('modalMethod').textContent = log.method;
@@ -164,13 +245,6 @@ function closeErrorModal() {
164
  document.body.style.overflow = 'auto';
165
  currentLog = null;
166
  }
167
- // Event listeners
168
- closeModal.addEventListener('click', closeErrorModal);
169
- closeModalBtn.addEventListener('click', closeErrorModal);
170
- submitTicket.addEventListener('click', () => {
171
- alert(`Ticket submitted for error: ${currentLog.errorCode}\nAn engineer will review this issue shortly.`);
172
- closeErrorModal();
173
- });
174
  // Initialize the page
175
  document.addEventListener('DOMContentLoaded', () => {
176
  renderLogsTable();
 
58
  ];
59
  // DOM elements
60
  const logsTable = document.getElementById('logsTable');
 
 
 
 
61
  const searchInput = document.querySelector('input[type="text"]');
62
+ let errorModal;
63
+ let closeModal;
64
+ let closeModalBtn;
65
+ let submitTicket;
66
  // Current selected log
67
  let currentLog = null;
68
  // Function to render logs table with optional filter
 
125
  function getMethodClass(method) {
126
  return `method-${method.toLowerCase()}`;
127
  }
128
+ // Function to create modal elements
129
+ function createModalElements() {
130
+ const modal = document.createElement('div');
131
+ modal.id = 'errorModal';
132
+ modal.className = 'fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden';
133
+ modal.innerHTML = `
134
+ <div class="bg-white rounded-lg shadow-xl w-full max-w-2xl max-h-[90vh] overflow-y-auto">
135
+ <div class="p-6">
136
+ <div class="flex justify-between items-center mb-4">
137
+ <h2 class="text-xl font-bold text-gray-800">Error Details</h2>
138
+ <button id="closeModal" class="text-gray-500 hover:text-gray-700 p-2">
139
+ <i data-feather="x" class="w-5 h-5"></i>
140
+ </button>
141
+ </div>
142
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
143
+ <div>
144
+ <h3 class="font-medium text-gray-700 mb-2">Request Information</h3>
145
+ <div class="space-y-2">
146
+ <p><span class="font-medium">Status:</span> <span id="modalStatus" class="px-2 py-1 rounded text-xs"></span></p>
147
+ <p><span class="font-medium">Method:</span> <span id="modalMethod" class="px-2 py-1 rounded text-xs"></span></p>
148
+ <p><span class="font-medium">Endpoint:</span> <span id="modalEndpoint" class="break-all"></span></p>
149
+ <p><span class="font-medium">Timestamp:</span> <span id="modalTime" class="font-mono"></span></p>
150
+ <p><span class="font-medium">Request Duration:</span> <span id="modalDuration" class="font-mono">-</span></p>
151
+ </div>
152
+ </div>
153
+ <div>
154
+ <h3 class="font-medium text-gray-700 mb-2">Error Information</h3>
155
+ <div class="space-y-2">
156
+ <p><span class="font-medium">Error Code:</span> <span id="modalErrorCode" class="font-mono"></span></p>
157
+ <p><span class="font-medium">Error Type:</span> <span id="modalErrorType" class="px-2 py-1 rounded text-xs"></span></p>
158
+ <p><span class="font-medium">Occurrences:</span> <span id="modalOccurrences" class="font-mono">1</span></p>
159
+ <p><span class="font-medium">First Occurred:</span> <span id="modalFirstOccurred" class="font-mono">-</span></p>
160
+ <p><span class="font-medium">Last Occurred:</span> <span id="modalLastOccurred" class="font-mono">-</span></p>
161
+ </div>
162
+ </div>
163
+ </div>
164
+ <div class="mb-6">
165
+ <h3 class="font-medium text-gray-700 mb-2">Full Error Message</h3>
166
+ <div class="bg-gray-50 p-4 rounded">
167
+ <pre id="modalErrorMessage" class="text-sm whitespace-pre-wrap overflow-x-auto font-mono"></pre>
168
+ </div>
169
+ </div>
170
+ <div class="mb-6 hidden" id="requestDetails">
171
+ <h3 class="font-medium text-gray-700 mb-2">Request Details</h3>
172
+ <div class="bg-gray-50 p-4 rounded">
173
+ <pre id="modalRequestDetails" class="text-sm whitespace-pre-wrap overflow-x-auto font-mono"></pre>
174
+ </div>
175
+ </div>
176
+ <div class="mb-6">
177
+ <h3 class="font-medium text-gray-700 mb-2">Resolution Steps</h3>
178
+ <div id="modalResolution" class="bg-blue-50 p-4 rounded text-sm"></div>
179
+ </div>
180
+ <div class="flex justify-end space-x-3">
181
+ <button id="submitTicket" class="px-4 py-2 bg-secondary-500 text-white rounded-md hover:bg-secondary-600 transition flex items-center">
182
+ <i data-feather="plus" class="mr-2 w-4 h-4"></i> Submit Ticket
183
+ </button>
184
+ <button id="closeModalBtn" class="px-4 py-2 bg-gray-200 text-gray-700 rounded-md hover:bg-gray-300 transition">
185
+ Close
186
+ </button>
187
+ </div>
188
+ </div>
189
+ </div>
190
+ `;
191
+ document.body.appendChild(modal);
192
+ return modal;
193
+ }
194
+
195
  // Function to show error details in modal
196
  function showErrorDetails(log) {
197
+ if (!errorModal) {
198
+ errorModal = createModalElements();
199
+ closeModal = document.getElementById('closeModal');
200
+ closeModalBtn = document.getElementById('closeModalBtn');
201
+ submitTicket = document.getElementById('submitTicket');
202
+
203
+ // Setup event listeners for modal
204
+ closeModal.addEventListener('click', closeErrorModal);
205
+ closeModalBtn.addEventListener('click', closeErrorModal);
206
+ submitTicket.addEventListener('click', () => {
207
+ alert(`Ticket submitted for error: ${currentLog.errorCode}\nAn engineer will review this issue shortly.`);
208
+ closeErrorModal();
209
+ });
210
+ }
211
+ // Request Info
212
  document.getElementById('modalStatus').textContent = log.status;
213
  document.getElementById('modalStatus').className = `status-badge ${getStatusClass(log.status)}`;
214
  document.getElementById('modalMethod').textContent = log.method;
 
245
  document.body.style.overflow = 'auto';
246
  currentLog = null;
247
  }
 
 
 
 
 
 
 
248
  // Initialize the page
249
  document.addEventListener('DOMContentLoaded', () => {
250
  renderLogsTable();
style.css CHANGED
@@ -49,18 +49,6 @@
49
  .modal-content {
50
  scroll-behavior: smooth;
51
  }
52
- /* Modal styles */
53
- #errorModal {
54
- display: none;
55
- position: fixed;
56
- top: 0;
57
- left: 0;
58
- width: 100%;
59
- height: 100%;
60
- z-index: 9999;
61
- align-items: center;
62
- justify-content: center;
63
- }
64
  #errorModal .bg-white {
65
  max-height: 90vh;
66
  overflow-y: auto;
 
49
  .modal-content {
50
  scroll-behavior: smooth;
51
  }
 
 
 
 
 
 
 
 
 
 
 
 
52
  #errorModal .bg-white {
53
  max-height: 90vh;
54
  overflow-y: auto;