waroca commited on
Commit
8cabdd6
·
verified ·
1 Parent(s): fed48fd

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. components/subscriptions.py +82 -76
components/subscriptions.py CHANGED
@@ -61,7 +61,7 @@ def create_subscriptions_html(subscriptions):
61
  connection_btn_html = ""
62
  if is_active and access_token:
63
  connection_btn_html = f'''
64
- <button class="btn-connect" onclick="openDrawer('{drawer_id}')">
65
  Connect
66
  </button>
67
  '''
@@ -93,14 +93,14 @@ def create_subscriptions_html(subscriptions):
93
 
94
  # Drawer HTML (slides in from right)
95
  drawers_html += f'''
96
- <div id="{drawer_id}" class="drawer-overlay" onclick="if(event.target===this) closeDrawer('{drawer_id}')">
97
  <div class="drawer-panel">
98
  <div class="drawer-header">
99
  <div class="drawer-header-info">
100
  <h3 class="drawer-title">{html.escape(dataset_id)}</h3>
101
  <span class="drawer-status {status_class}">{status_text}</span>
102
  </div>
103
- <button class="drawer-close" onclick="closeDrawer('{drawer_id}')">&times;</button>
104
  </div>
105
  <div class="drawer-body">
106
  <!-- MCP Config - expanded by default -->
@@ -114,7 +114,7 @@ def create_subscriptions_html(subscriptions):
114
  <p class="config-desc">Add to your Claude Desktop config:</p>
115
  <div class="code-wrapper">
116
  <pre class="code-block">{mcp_config_escaped}</pre>
117
- <button class="btn-copy" data-copy-id="{drawer_id}-mcp">Copy</button>
118
  </div>
119
  </div>
120
  </details>
@@ -129,7 +129,7 @@ def create_subscriptions_html(subscriptions):
129
  <div class="config-content">
130
  <div class="code-wrapper">
131
  <pre class="code-block prompt-block">{example_prompt_escaped}</pre>
132
- <button class="btn-copy" data-copy-id="{drawer_id}-prompt">Copy</button>
133
  </div>
134
  </div>
135
  </details>
@@ -144,7 +144,7 @@ def create_subscriptions_html(subscriptions):
144
  <div class="config-content">
145
  <div class="code-wrapper">
146
  <code class="token-block">{html.escape(access_token)}</code>
147
- <button class="btn-copy" data-copy-id="{drawer_id}-token">Copy</button>
148
  </div>
149
  </div>
150
  </details>
@@ -197,81 +197,87 @@ def create_subscriptions_html(subscriptions):
197
  </div>
198
 
199
  <script>
200
- // Store copy data
201
- var copyDataStore = {copy_data_json};
202
-
203
- function openDrawer(id) {{
204
- var drawer = document.getElementById(id);
205
- if (drawer) {{
206
- drawer.classList.add('show');
207
- document.body.style.overflow = 'hidden';
208
- }}
209
- }}
210
-
211
- function closeDrawer(id) {{
212
- var drawer = document.getElementById(id);
213
- if (drawer) {{
214
- drawer.classList.remove('show');
215
- document.body.style.overflow = '';
216
- }}
217
- }}
218
-
219
- function copyFromDataAttr(btn) {{
220
- var copyId = btn.getAttribute('data-copy-id');
221
- if (!copyId || !copyDataStore[copyId]) {{
222
- console.error('Copy data not found for:', copyId);
223
- return;
224
- }}
225
- // Decode base64
226
- var text = atob(copyDataStore[copyId]);
227
- navigator.clipboard.writeText(text).then(function() {{
228
- var originalText = btn.textContent;
229
- btn.textContent = 'Copied!';
230
- btn.classList.add('copied');
231
- setTimeout(function() {{
232
- btn.textContent = originalText;
233
- btn.classList.remove('copied');
234
- }}, 2000);
235
- }}).catch(function(err) {{
236
- console.error('Failed to copy:', err);
237
- // Fallback for older browsers
238
- var textarea = document.createElement('textarea');
239
- textarea.value = text;
240
- textarea.style.position = 'fixed';
241
- textarea.style.opacity = '0';
242
- document.body.appendChild(textarea);
243
- textarea.select();
244
- try {{
245
- document.execCommand('copy');
246
- var originalText = btn.textContent;
247
- btn.textContent = 'Copied!';
248
- btn.classList.add('copied');
249
- setTimeout(function() {{
250
- btn.textContent = originalText;
251
- btn.classList.remove('copied');
252
- }}, 2000);
253
- }} catch (e) {{
254
- console.error('Fallback copy failed:', e);
255
  }}
256
- document.body.removeChild(textarea);
257
- }});
258
- }}
259
-
260
- // Attach click handlers to copy buttons
261
- document.addEventListener('click', function(e) {{
262
- if (e.target.classList.contains('btn-copy')) {{
263
- copyFromDataAttr(e.target);
264
- }}
265
- }});
266
 
267
- document.addEventListener('keydown', function(e) {{
268
- if (e.key === 'Escape') {{
269
- document.querySelectorAll('.drawer-overlay.show').forEach(function(drawer) {{
270
  drawer.classList.remove('show');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
271
  }});
272
- document.body.style.overflow = '';
273
  }}
274
- }});
275
  </script>
276
 
277
  <style>
 
61
  connection_btn_html = ""
62
  if is_active and access_token:
63
  connection_btn_html = f'''
64
+ <button class="btn-connect" onclick="window.openDrawer('{drawer_id}')">
65
  Connect
66
  </button>
67
  '''
 
93
 
94
  # Drawer HTML (slides in from right)
95
  drawers_html += f'''
96
+ <div id="{drawer_id}" class="drawer-overlay" onclick="if(event.target===this) window.closeDrawer('{drawer_id}')">
97
  <div class="drawer-panel">
98
  <div class="drawer-header">
99
  <div class="drawer-header-info">
100
  <h3 class="drawer-title">{html.escape(dataset_id)}</h3>
101
  <span class="drawer-status {status_class}">{status_text}</span>
102
  </div>
103
+ <button class="drawer-close" onclick="window.closeDrawer('{drawer_id}')">&times;</button>
104
  </div>
105
  <div class="drawer-body">
106
  <!-- MCP Config - expanded by default -->
 
114
  <p class="config-desc">Add to your Claude Desktop config:</p>
115
  <div class="code-wrapper">
116
  <pre class="code-block">{mcp_config_escaped}</pre>
117
+ <button class="btn-copy" data-copy-id="{drawer_id}-mcp" onclick="window.copyDatapassField('{drawer_id}-mcp')">Copy</button>
118
  </div>
119
  </div>
120
  </details>
 
129
  <div class="config-content">
130
  <div class="code-wrapper">
131
  <pre class="code-block prompt-block">{example_prompt_escaped}</pre>
132
+ <button class="btn-copy" data-copy-id="{drawer_id}-prompt" onclick="window.copyDatapassField('{drawer_id}-prompt')">Copy</button>
133
  </div>
134
  </div>
135
  </details>
 
144
  <div class="config-content">
145
  <div class="code-wrapper">
146
  <code class="token-block">{html.escape(access_token)}</code>
147
+ <button class="btn-copy" data-copy-id="{drawer_id}-token" onclick="window.copyDatapassField('{drawer_id}-token')">Copy</button>
148
  </div>
149
  </div>
150
  </details>
 
197
  </div>
198
 
199
  <script>
200
+ (function() {{
201
+ // Store copy data globally on window
202
+ window.datapassCopyData = window.datapassCopyData || {{}};
203
+ Object.assign(window.datapassCopyData, {copy_data_json});
204
+
205
+ // Define functions on window for global access
206
+ window.openDrawer = function(id) {{
207
+ var drawer = document.getElementById(id);
208
+ if (drawer) {{
209
+ drawer.classList.add('show');
210
+ document.body.style.overflow = 'hidden';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
  }}
212
+ }};
 
 
 
 
 
 
 
 
 
213
 
214
+ window.closeDrawer = function(id) {{
215
+ var drawer = document.getElementById(id);
216
+ if (drawer) {{
217
  drawer.classList.remove('show');
218
+ document.body.style.overflow = '';
219
+ }}
220
+ }};
221
+
222
+ window.copyDatapassField = function(copyId) {{
223
+ if (!copyId || !window.datapassCopyData[copyId]) {{
224
+ console.error('Copy data not found for:', copyId);
225
+ return;
226
+ }}
227
+ // Decode base64
228
+ var text = atob(window.datapassCopyData[copyId]);
229
+ var btn = document.querySelector('[data-copy-id="' + copyId + '"]');
230
+
231
+ navigator.clipboard.writeText(text).then(function() {{
232
+ if (btn) {{
233
+ var originalText = btn.textContent;
234
+ btn.textContent = 'Copied!';
235
+ btn.classList.add('copied');
236
+ setTimeout(function() {{
237
+ btn.textContent = originalText;
238
+ btn.classList.remove('copied');
239
+ }}, 2000);
240
+ }}
241
+ }}).catch(function(err) {{
242
+ console.error('Failed to copy:', err);
243
+ // Fallback for older browsers or non-HTTPS
244
+ var textarea = document.createElement('textarea');
245
+ textarea.value = text;
246
+ textarea.style.position = 'fixed';
247
+ textarea.style.opacity = '0';
248
+ document.body.appendChild(textarea);
249
+ textarea.select();
250
+ try {{
251
+ document.execCommand('copy');
252
+ if (btn) {{
253
+ var originalText = btn.textContent;
254
+ btn.textContent = 'Copied!';
255
+ btn.classList.add('copied');
256
+ setTimeout(function() {{
257
+ btn.textContent = originalText;
258
+ btn.classList.remove('copied');
259
+ }}, 2000);
260
+ }}
261
+ }} catch (e) {{
262
+ console.error('Fallback copy failed:', e);
263
+ }}
264
+ document.body.removeChild(textarea);
265
+ }});
266
+ }};
267
+
268
+ // Listen for Escape key to close drawers
269
+ if (!window.datapassEscapeListenerAdded) {{
270
+ window.datapassEscapeListenerAdded = true;
271
+ document.addEventListener('keydown', function(e) {{
272
+ if (e.key === 'Escape') {{
273
+ document.querySelectorAll('.drawer-overlay.show').forEach(function(drawer) {{
274
+ drawer.classList.remove('show');
275
+ }});
276
+ document.body.style.overflow = '';
277
+ }}
278
  }});
 
279
  }}
280
+ }})();
281
  </script>
282
 
283
  <style>