|
278 | 278 | <script src="https://cdn.jsdelivr.net/npm/@yaireo/tagify/dist/tagify.polyfills.min.js"></script>
|
279 | 279 | <script type="text/javascript" src="{% static 'js/browser-interaction-time.umd.js' %}"></script>
|
280 | 280 | <script type="text/javascript" src="{% static 'js/utils.js' %}"></script>
|
| 281 | + |
| 282 | +{% if ng_host == "spelunker" %} |
| 283 | +<script type="module" src="{% static 'spelunker-workspace/562.1d0cecad9cc0725955f0.js' %}"></script><script type="module" src="{% static 'spelunker-workspace/993.ca23372ceee17151541a.js' %}"></script><script type="module" src="{% static 'spelunker-workspace/367.ad6071abcab399305157.js' %}"></script><script type="module" src="{% static 'spelunker-workspace/main.cb26101b553ed6b82856.js' %}"></script><link href="{% static 'spelunker-workspace/main.cb26101b553ed6b82856.css' %}" rel="stylesheet"> |
| 284 | +{% else %} |
281 | 285 | <script type="text/javascript" src="{% static 'workspace/main.bundle.js' %}"></script>
|
| 286 | +{% endif %} |
| 287 | + |
282 | 288 | <script type="text/javascript">
|
283 | 289 |
|
284 | 290 | // initialize Tagify on the above input node reference
|
|
299 | 305 | })
|
300 | 306 |
|
301 | 307 | function getLink() {
|
302 |
| - viewer.postJsonState(true, undefined, true, function() { |
303 |
| - let url_prefix = "https://neuroglancer.neuvue.io/?json_url=" |
304 |
| - copyToClipboard(url_prefix.concat(viewer.saver.savedUrl)); |
305 |
| - }); |
| 308 | + {% if ng_host == "neuvue" %} |
| 309 | + viewer.postJsonState(true, undefined, true, function() { |
| 310 | + let url_prefix = "https://neuroglancer.neuvue.io/?json_url=" |
| 311 | + copyToClipboard(url_prefix.concat(viewer.saver.savedUrl)); |
| 312 | + triggerToast("Copied link to clipboard"); |
| 313 | + }); |
| 314 | + {% elif ng_host == "spelunker" %} |
| 315 | + let url_prefix = "https://spelunker.cave-explorer.org/#!"; |
| 316 | + copyToClipboard(url_prefix.concat(JSON.stringify(viewer.state.toJSON()))); |
| 317 | + triggerToast("Copied link to clipboard"); |
| 318 | + {% else %} |
| 319 | + triggerToast("Copy Link unavailable on embedded Neuroglancer task type"); |
| 320 | + {% endif %} |
306 | 321 | }
|
307 | 322 |
|
308 | 323 | function saveState() {
|
309 |
| - {% if not ng_url %} |
| 324 | + {% if ng_host == "neuvue" %} |
310 | 325 | viewer.postJsonState(true, undefined, true, function() {
|
311 | 326 | let state = viewer.saver.savedUrl;
|
312 | 327 | let post_body = JSON.stringify({'task_id':"{{task_id}}", 'ng_state' : state});
|
|
320 | 335 | });
|
321 | 336 | });
|
322 | 337 | {% else %}
|
323 |
| - triggerToast("Autosave disabled for embedded neuroglancer"); |
| 338 | + triggerToast("State saving disabled for non-native Neuroglancer"); |
| 339 | + removeLoadingSpinner("save_state", "Save State"); |
324 | 340 | {% endif %}
|
325 | 341 | }
|
326 | 342 |
|
|
373 | 389 | }
|
374 | 390 | }
|
375 | 391 |
|
| 392 | + function getOperationIdsFromSpelunker(){ |
| 393 | + for (let i = 0; i < viewer.layerManager.managedLayers.length; i++) { |
| 394 | + const layer = viewer.layerManager.managedLayers[i].layer_; |
| 395 | + if (layer.type === 'segmentation') { |
| 396 | + const operationIds = layer.graphConnection.value.operationIds.toString(); |
| 397 | + return operationIds.split(',').map(Number); |
| 398 | + } |
| 399 | + } |
| 400 | + } |
| 401 | + |
376 | 402 | function submitForm(value, form='#mainForm') {
|
377 | 403 | window.removeEventListener('beforeunload', exitAlert);
|
378 | 404 | let duration = Math.round(browserTimer.getTimeInMilliseconds()/1000);
|
|
383 | 409 | $('<input>').attr('type', 'hidden').attr('name', 'duration').attr('value', duration).appendTo(form);
|
384 | 410 | $(form).submit();
|
385 | 411 |
|
386 |
| - {% else %} |
| 412 | + {% elif ng_host == "spelunker" %} |
| 413 | + updateTrackedOperations(getOperationIdsFromSpelunker()) |
| 414 | + let state = JSON.stringify(viewer.state.toJSON()); |
| 415 | + $('<input>').attr('type', 'hidden').attr('name', 'ngState').attr('value', state).appendTo(form); |
| 416 | + $('<input>').attr('type', 'hidden').attr('name', 'button').attr('value', value).appendTo(form); |
| 417 | + $('<input>').attr('type', 'hidden').attr('name', 'duration').attr('value', duration).appendTo(form); |
| 418 | + |
| 419 | + $(form).submit(); |
387 | 420 |
|
| 421 | + {% else %} |
388 | 422 | updateTrackedOperations(operation_ids)
|
389 | 423 | viewer.postJsonState(true, undefined, true, function() {
|
390 | 424 | let state = viewer.saver.savedUrl;
|
|
453 | 487 | selected_button.classList.toggle("active");
|
454 | 488 | }
|
455 | 489 |
|
| 490 | + // Function to attempt restoring the viewer state |
| 491 | + function tryRestoreState() { |
| 492 | + if (typeof viewer !== 'undefined') { |
| 493 | + // Viewer is defined, attempt to restore the state |
| 494 | + try { |
| 495 | + var received_data = {{ ng_state|safe }}; |
| 496 | + viewer.state.restoreState(received_data); |
| 497 | + console.log('Viewer state restored successfully.'); |
| 498 | + } catch (error) { |
| 499 | + console.error('Error restoring viewer state:', error); |
| 500 | + } |
| 501 | + } else { |
| 502 | + // Viewer is not yet defined, retry after a short delay |
| 503 | + setTimeout(tryRestoreState, 100); // Retry every 100 milliseconds |
| 504 | + } |
| 505 | + } |
| 506 | + |
456 | 507 | // Button Submission
|
457 | 508 | $(document).ready(function() {
|
458 | 509 |
|
|
468 | 519 |
|
469 | 520 | // Specific to built-in NG
|
470 | 521 | {% if not ng_url%}
|
471 |
| - var received_data = {{ ng_state|safe }}; |
472 |
| - viewer.state.restoreState(received_data); |
473 |
| - |
474 |
| - |
| 522 | + tryRestoreState() |
475 | 523 | // Track operation IDs every three seconds
|
476 | 524 | window.setInterval(function() {
|
| 525 | + {% if ng_host == "spelunker" %} |
| 526 | + updateTrackedOperations(getOperationIdsFromSpelunker()); |
| 527 | + {% else %} |
477 | 528 | updateTrackedOperations(operation_ids);
|
| 529 | + {% endif %} |
478 | 530 | }, 3000);
|
479 | 531 | {% endif %}
|
480 | 532 |
|
|
0 commit comments