CodeExecutionModal.svelte 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <script lang="ts">
  2. import { getContext } from 'svelte';
  3. import CodeBlock from './CodeBlock.svelte';
  4. import Modal from '$lib/components/common/Modal.svelte';
  5. const i18n = getContext('i18n');
  6. export let show = false;
  7. export let code_execution = null;
  8. </script>
  9. <Modal size="lg" bind:show>
  10. <div>
  11. <div class="flex justify-between dark:text-gray-300 px-5 pt-4 pb-2">
  12. <div class="text-lg font-medium self-center capitalize">
  13. {#if code_execution?.status == 'OK'}
  14. &#x2705; <!-- Checkmark -->
  15. {:else if code_execution?.status == 'ERROR'}
  16. &#x274C; <!-- X mark -->
  17. {:else if code_execution?.status == 'PENDING'}
  18. &#x23F3; <!-- Hourglass -->
  19. {:else}
  20. &#x2049;&#xFE0F; <!-- Interrobang -->
  21. {/if}
  22. {#if code_execution?.name}
  23. {$i18n.t('Code execution')}: {code_execution?.name}
  24. {:else}
  25. {$i18n.t('Code execution')}
  26. {/if}
  27. </div>
  28. <button
  29. class="self-center"
  30. on:click={() => {
  31. show = false;
  32. code_execution = null;
  33. }}
  34. >
  35. <svg
  36. xmlns="http://www.w3.org/2000/svg"
  37. viewBox="0 0 20 20"
  38. fill="currentColor"
  39. class="w-5 h-5"
  40. >
  41. <path
  42. d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
  43. />
  44. </svg>
  45. </button>
  46. </div>
  47. <div class="flex flex-col md:flex-row w-full px-6 pb-5 md:space-x-4">
  48. <div
  49. class="flex flex-col w-full dark:text-gray-200 overflow-y-scroll max-h-[22rem] scrollbar-hidden"
  50. >
  51. <div class="flex flex-col w-full">
  52. <div class="text-sm font-medium dark:text-gray-300">
  53. {$i18n.t('Code')}
  54. </div>
  55. <CodeBlock
  56. id="codeexec-{code_execution?.id}-code"
  57. lang={code_execution?.language}
  58. code={code_execution?.code}
  59. allow_execution={false}
  60. />
  61. </div>
  62. {#if code_execution?.error}
  63. <div class="flex flex-col w-full">
  64. <hr class=" dark:border-gray-850 my-3" />
  65. <div class="text-sm dark:text-gray-400">
  66. {$i18n.t('Error')}
  67. </div>
  68. <CodeBlock
  69. id="codeexec-{code_execution?.id}-error"
  70. lang=""
  71. code={code_execution?.error}
  72. allow_execution={false}
  73. />
  74. </div>
  75. {/if}
  76. {#if code_execution?.output}
  77. <div class="flex flex-col w-full">
  78. <hr class=" dark:border-gray-850 my-3" />
  79. <div class="text-sm dark:text-gray-400">
  80. {$i18n.t('Output')}
  81. </div>
  82. <CodeBlock
  83. id="codeexec-{code_execution?.id}-output"
  84. lang=""
  85. code={code_execution?.output}
  86. allow_execution={false}
  87. />
  88. </div>
  89. {/if}
  90. {#if code_execution?.files && code_execution?.files.length > 0}
  91. <div class="flex flex-col w-full">
  92. <hr class=" dark:border-gray-850 my-3" />
  93. <div class=" text-sm font-medium dark:text-gray-300">
  94. {$i18n.t('Files')}
  95. </div>
  96. <ul class="mt-1 list-disc pl-4 text-xs">
  97. {#each code_execution?.files as file}
  98. <li>
  99. &#x1F4BE; <!-- Floppy disk -->
  100. <a href={file.url} target="_blank">{file.name}</a>
  101. </li>
  102. {/each}
  103. </ul>
  104. </div>
  105. {/if}
  106. </div>
  107. </div>
  108. </div>
  109. </Modal>