Connection.svelte 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <script lang="ts">
  2. import { getContext, tick } from 'svelte';
  3. const i18n = getContext('i18n');
  4. import Tooltip from '$lib/components/common/Tooltip.svelte';
  5. import SensitiveInput from '$lib/components/common/SensitiveInput.svelte';
  6. import Cog6 from '$lib/components/icons/Cog6.svelte';
  7. import ConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
  8. import AddServerModal from '$lib/components/AddServerModal.svelte';
  9. export let onDelete = () => {};
  10. export let onSubmit = () => {};
  11. export let connection = null;
  12. let showConfigModal = false;
  13. let showDeleteConfirmDialog = false;
  14. </script>
  15. <AddServerModal
  16. edit
  17. direct
  18. bind:show={showConfigModal}
  19. {connection}
  20. onDelete={() => {
  21. showDeleteConfirmDialog = true;
  22. }}
  23. onSubmit={(c) => {
  24. connection = c;
  25. onSubmit(c);
  26. }}
  27. />
  28. <ConfirmDialog
  29. bind:show={showDeleteConfirmDialog}
  30. on:confirm={() => {
  31. onDelete();
  32. showConfigModal = false;
  33. }}
  34. />
  35. <div class="flex w-full gap-2 items-center">
  36. <Tooltip
  37. className="w-full relative"
  38. content={$i18n.t(`WebUI will make requests to "{{url}}{{path}}"`, {
  39. url: connection?.url,
  40. path: connection?.path ?? '/openapi.json'
  41. })}
  42. placement="top-start"
  43. >
  44. {#if !(connection?.config?.enable ?? true)}
  45. <div
  46. class="absolute top-0 bottom-0 left-0 right-0 opacity-60 bg-white dark:bg-gray-900 z-10"
  47. ></div>
  48. {/if}
  49. <div class="flex w-full">
  50. <div class="flex-1 relative">
  51. <input
  52. class=" outline-hidden w-full bg-transparent"
  53. placeholder={$i18n.t('API Base URL')}
  54. bind:value={connection.url}
  55. autocomplete="off"
  56. />
  57. </div>
  58. {#if (connection?.auth_type ?? 'bearer') === 'bearer'}
  59. <SensitiveInput
  60. inputClassName=" outline-hidden bg-transparent w-full"
  61. placeholder={$i18n.t('API Key')}
  62. bind:value={connection.key}
  63. required={false}
  64. />
  65. {/if}
  66. </div>
  67. </Tooltip>
  68. <div class="flex gap-1">
  69. <Tooltip content={$i18n.t('Configure')} className="self-start">
  70. <button
  71. class="self-center p-1 bg-transparent hover:bg-gray-100 dark:bg-gray-900 dark:hover:bg-gray-850 rounded-lg transition"
  72. on:click={() => {
  73. showConfigModal = true;
  74. }}
  75. type="button"
  76. >
  77. <Cog6 />
  78. </button>
  79. </Tooltip>
  80. </div>
  81. </div>