File size: 10,366 Bytes
2d9b352
 
 
 
 
 
5970584
2d9b352
5970584
2d9b352
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5970584
2d9b352
 
 
 
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
<!DOCTYPE html>
<html>
  <head>
    <title>API Comparison Results</title>
    <link
      rel="stylesheet"
      href="{{url_for('static', path='css/styles.css') }}"
    />

    <style>
      .diff-highlight-add {
        background-color: #e6ffe6;
        color: green;
      }
      .diff-highlight-remove {
        background-color: #ffe6e6;
        color: red;
      }
      .spinner {
        display: none;
        width: 50px;
        height: 50px;
        border: 5px solid #f3f3f3;
        border-top: 5px solid #4caf50;
        border-radius: 50%;
        animation: spin 1s linear infinite;
        margin: 20px auto;
      }
      @keyframes spin {
        0% {
          transform: rotate(0deg);
        }
        100% {
          transform: rotate(360deg);
        }
      }
      .api-info {
        background-color: #f8f9fa;
        padding: 10px;
        border-radius: 4px;
        margin-bottom: 10px;
        border-left: 4px solid #4caf50;
      }
      .api-endpoint {
        font-family: monospace;
        color: #0056b3;
        word-break: break-all;
      }
      .session-timeout-warning {
        display: none;
        background-color: #fff3cd;
        border: 1px solid #ffeeba;
        padding: 10px;
        border-radius: 4px;
        margin: 20px auto;
        text-align: center;
      }
      .session-timeout-warning h3 {
        margin: 0;
        font-size: 18px;
        color: #856404;
      }
      .session-timeout-warning p {
        margin: 10px 0;
        font-size: 14px;
        color: #856404;
      }
      .session-timeout-warning button {
        margin: 5px;
        padding: 5px 10px;
        border: none;
        border-radius: 4px;
        cursor: pointer;
      }
      .session-timeout-warning .continue {
        background-color: #4caf50;
        color: white;
      }
      .session-timeout-warning .logout {
        background-color: #f44336;
        color: white;
      }
      .alert {
        padding: 15px;
        margin-bottom: 20px;
        border: 1px solid transparent;
        border-radius: 4px;
      }
      .alert-error {
        color: #721c24;
        background-color: #f8d7da;
        border-color: #f5c6cb;
      }
      .alert-error .close {
        float: right;
        font-size: 20px;
        font-weight: bold;
        line-height: 20px;
        cursor: pointer;
      }
    </style>
  </head>
  <body>
    <div class="container">
      <div class="header">
        <a href="/compare">
          <img
            src="{{ url_for('static', path='/images/TD-logo.jpeg') }}"
            alt="Logo"
            class="logo"
          />
        </a>
        <div class="user-menu">
          <div>Welcome, {{ username }}!</div>
          <div class="user-menu-content">
            <a href="/logout">Logout</a>
          </div>
        </div>
      </div>

      <div id="errorAlert" class="alert alert-error" style="display: none">
        <span class="close" onclick="this.parentElement.style.display='none';"
          >&times;</span
        >
        <strong>Error!</strong> <span id="errorMessage"></span>
      </div>

      <div id="session-timeout" class="session-timeout-warning">
        <h3>Session Timeout Warning</h3>
        <p>
          Your session will expire in
          <span id="timeout-countdown">60</span> seconds due to inactivity.
        </p>
        <button class="continue" onclick="extendSession()">
          Continue Session
        </button>
        <button class="logout" onclick="window.location.href='/logout'">
          Logout
        </button>
      </div>

      <div class="results">
        <h2>API Comparison Results</h2>
        <div id="loading-spinner" class="spinner"></div>

        <div class="grid">
          <div>
            <h3>First API</h3>
            <div class="api-info">
              <p>
                <strong>Endpoint:</strong>
                <span class="api-endpoint"
                  >{{ api1_url }} ({{ api1_method }})</span
                >
              </p>
              <p>Execution Time: {{ execution_time_api1 }}s</p>
              <p>Status Code: {{ status_code1 }}</p>
            </div>
            <form
              method="POST"
              action="/download/"
              style="display: inline"
              onsubmit="return handleDownload(event, this)"
            >
              <input type="hidden" name="content" value="{{ api1_result }}" />
              <input type="hidden" name="filename" value="api1_result.json" />
              <input type="hidden" name="username" value="{{ username }}" />
              <button type="submit" class="download-button">
                Download API 1 Result
              </button>
            </form>
            <div class="json-content">
              <pre id="api1-content">{{ api1_result | safe }}</pre>
            </div>
          </div>

          <div>
            <h3>Second API</h3>
            <div class="api-info">
              <p>
                <strong>Endpoint:</strong>
                <span class="api-endpoint"
                  >{{ api2_url }} ({{ api2_method }})</span
                >
              </p>
              <p>Execution Time: {{ execution_time_api2 }}s</p>
              <p>Status Code: {{ status_code2 }}</p>
            </div>
            <form
              method="POST"
              action="/download/"
              style="display: inline"
              onsubmit="return handleDownload(event, this)"
            >
              <input type="hidden" name="content" value="{{ api2_result }}" />
              <input type="hidden" name="filename" value="api2_result.json" />
              <input type="hidden" name="username" value="{{ username }}" />
              <button type="submit" class="download-button">
                Download API 2 Result
              </button>
            </form>
            <div class="json-content">
              <pre id="api2-content">{{ api2_result | safe }}</pre>
            </div>
          </div>
        </div>

        <div class="comparison-results">
          <h3>Differences</h3>
          <form
            method="POST"
            action="/download/"
            style="display: inline"
            onsubmit="return handleDownload(event, this)"
          >
            <input type="hidden" name="content" value="{{ diff_text }}" />
            <input
              type="hidden"
              name="filename"
              value="comparison_result.txt"
            />
            <input type="hidden" name="username" value="{{ username }}" />
            <button type="submit" class="download-button">
              Download Comparison Result
            </button>
          </form>

          <div class="results-view">
            {% if view_mode == "line" %} {% if diff_result.strip() == '' %}
            <div class="success">Both responses are identical.</div>
            {% else %}
            <div class="diff-content">{{ diff_result | safe }}</div>
            {% endif %} {% else %}
            <pre>{{ diff_result | safe }}</pre>
            {% endif %}
          </div>
        </div>

        <div style="margin-top: 20px">
          <a href="/compare" class="button">Compare More APIs</a>
        </div>
      </div>
    </div>

    <script>
      function highlightDifferences() {
        const api1Content = document.getElementById("api1-content");
        const api2Content = document.getElementById("api2-content");

        if (!api1Content || !api2Content) return;

        const lines1 = api1Content.textContent.split("\n");
        const lines2 = api2Content.textContent.split("\n");

        let html1 = "";
        let html2 = "";

        const maxLines = Math.max(lines1.length, lines2.length);

        for (let i = 0; i < maxLines; i++) {
          const line1 = lines1[i] || "";
          const line2 = lines2[i] || "";

          if (line1 !== line2) {
            html1 += `<span class="diff-highlight-remove">${line1}</span>\n`;
            html2 += `<span class="diff-highlight-remove">${line2}</span>\n`;
          } else {
            html1 += line1 + "\n";
            html2 += line2 + "\n";
          }
        }

        api1Content.innerHTML = html1;
        api2Content.innerHTML = html2;
      }

      document.addEventListener("DOMContentLoaded", highlightDifferences);

      function extendSession() {
        document.getElementById("session-timeout").style.display = "none";
      }

      setTimeout(() => {
        document.getElementById("session-timeout").style.display = "block";
      }, 300000);

      async function handleDownload(event, form) {
        event.preventDefault();

        try {
          const formData = new FormData(form);
          const response = await fetch(form.action, {
            method: "POST",
            body: formData,
          });

          if (!response.ok) {
            const data = await response.json().catch(() => null);
            throw new Error(
              data?.detail || "Failed to download file. Please try again."
            );
          }

          const blob = await response.blob();
          const url = window.URL.createObjectURL(blob);
          const a = document.createElement("a");
          a.href = url;
          a.download = formData.get("filename");
          document.body.appendChild(a);
          a.click();
          window.URL.revokeObjectURL(url);
          document.body.removeChild(a);
        } catch (error) {
          showError(error.message || "Something went wrong. Please try again.");
        }
        return false;
      }

      function showError(message) {
        const errorAlert = document.getElementById("errorAlert");
        const errorMessage = document.getElementById("errorMessage");
        errorMessage.textContent = message;
        errorAlert.style.display = "block";

        setTimeout(() => {
          errorAlert.style.display = "none";
        }, 5000);
      }

      window.addEventListener("unhandledrejection", function (event) {
        showError(
          "Network error occurred. Please check your connection and try again."
        );
      });
    </script>

    <div
      style="text-align: center; margin-top: 20px; color: #666; font-size: 12px"
    >
      Copyright © 2025 TELUS Digital. All rights reserved.<br />
      For internal use only.
    </div>
  </body>
</html>