Merge pull request #909 from scshiv29-dev/main

changed copypassword fields in databases
This commit is contained in:
Andras Bacsai 2023-02-20 09:06:35 +01:00 committed by GitHub
commit c3e0237696
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 161 additions and 102 deletions

View File

@ -0,0 +1,38 @@
<script>
import { addToast } from '$lib/store';
export let value = "";
let isHttps = window.location.protocol === 'https:';
function copyToClipboard() {
if (isHttps && navigator.clipboard) {
navigator.clipboard.writeText(value);
addToast({
message: 'Copied to clipboard.',
type: 'success'
});
}
}
</script>
<style>
.box {
position: relative;
border: 1px dashed #202020;
border-radius: 5px;
padding: 5px;
}
</style>
<div class="w-full relative box">
<p class="text-white p-2">{value}</p>
<div class="absolute top-0 right-0 flex justify-center items-center h-full cursor-pointer text-stone-600 mr-3">
<div on:click={copyToClipboard}>
<svg width="24px" height="24px" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" class="stroke-gray-700 hover:stroke-white">
<path fill="none" stroke-width="2" d="M9,15 L17,15 L9,15 Z M9,11 L19,11 L9,11 Z M9,7 L13,7 L9,7 Z M16,1 L16,7 L22,7 M6,5 L2,5 L2,23 L18,23 L18,19 M22,19 L6,19 L6,1 L17,1 L22,6 L22,19 L22,19 Z"/>
</svg>
</div>
</div>
</div>

View File

@ -7,12 +7,23 @@
import { del, post } from '$lib/api'; import { del, post } from '$lib/api';
import { page } from '$app/stores'; import { page } from '$app/stores';
import { createEventDispatcher } from 'svelte'; import { createEventDispatcher } from 'svelte';
import { browser } from '$app/env';
import { t } from '$lib/translations'; import { t } from '$lib/translations';
import { errorNotification } from '$lib/common'; import { errorNotification } from '$lib/common';
import { addToast } from '$lib/store'; import { addToast } from '$lib/store';
import CopyVolumeField from '$lib/components/CopyVolumeField.svelte';
const { id } = $page.params; const { id } = $page.params;
let isHttps = browser && window.location.protocol === 'https:';
export let value: string;
function copyToClipboard() {
if (isHttps && navigator.clipboard) {
navigator.clipboard.writeText(value);
addToast({
message: 'Copied to clipboard.',
type: 'success'
});
}
}
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();
async function saveStorage(newStorage = false) { async function saveStorage(newStorage = false) {
try { try {
@ -69,18 +80,14 @@
<div class="flex gap-4 pb-2" class:pt-8={isNew}> <div class="flex gap-4 pb-2" class:pt-8={isNew}>
{#if storage.applicationId} {#if storage.applicationId}
{#if storage.oldPath} {#if storage.oldPath}
<input
disabled <CopyVolumeField
readonly
class="w-full"
value="{storage.applicationId}{storage.path.replace(/\//gi, '-').replace('-app', '')}" value="{storage.applicationId}{storage.path.replace(/\//gi, '-').replace('-app', '')}"
/> />
{:else} {:else}
<input
disabled <CopyVolumeField
readonly value="{storage.applicationId}{storage.path.replace(/\//gi, '-').replace('-app', '')}"
class="w-full"
value="{storage.applicationId}{storage.path.replace(/\//gi, '-')}"
/> />
{/if} {/if}
{/if} {/if}

View File

@ -2,6 +2,8 @@
export let database: any; export let database: any;
import CopyPasswordField from '$lib/components/CopyPasswordField.svelte'; import CopyPasswordField from '$lib/components/CopyPasswordField.svelte';
import { t } from '$lib/translations'; import { t } from '$lib/translations';
import { status } from '$lib/store';
import Explainer from '$lib/components/Explainer.svelte';
</script> </script>
<div class="flex space-x-1 py-5 font-bold"> <div class="flex space-x-1 py-5 font-bold">
@ -9,11 +11,13 @@
</div> </div>
<div class="space-y-2 lg:px-10 px-2"> <div class="space-y-2 lg:px-10 px-2">
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center">
<label for="defaultDatabase">{$t('database.default_database')}</label> <label for="defaultDatabase">{$t('database.default_database')}
<Explainer explanation="Can only be modified when the database is not active."/>
</label>
<CopyPasswordField <CopyPasswordField
required required
readonly={database.defaultDatabase} readonly={$status.database.isRunning}
disabled={database.defaultDatabase} disabled={$status.database.isRunning}
placeholder="{$t('forms.eg')}: mydb" placeholder="{$t('forms.eg')}: mydb"
id="defaultDatabase" id="defaultDatabase"
name="defaultDatabase" name="defaultDatabase"
@ -21,49 +25,57 @@
/> />
</div> </div>
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center">
<label for="dbUser">{$t('forms.user')}</label> <label for="dbUser">{$t('forms.user')}
<Explainer explanation="Can only be modified when the database is not active."/>
</label>
<CopyPasswordField <CopyPasswordField
readonly readonly={$status.database.isRunning}
disabled disabled={$status.database.isRunning}
placeholder={$t('forms.generated_automatically_after_start')} placeholder={$t('forms.generated_automatically_after_start')}
id="dbUser" id="dbUser"
name="dbUser" name="dbUser"
value={database.dbUser} bind:value={database.dbUser}
/> />
</div> </div>
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center">
<label for="dbUserPassword">{$t('forms.password')}</label> <label for="dbUserPassword">{$t('forms.password')}
<Explainer explanation="Can be modified even when the database is active." />
</label>
<CopyPasswordField <CopyPasswordField
readonly readonly={false}
disabled disabled={false}
placeholder={$t('forms.generated_automatically_after_start')} placeholder={$t('forms.generated_automatically_after_start')}
isPasswordField isPasswordField
id="dbUserPassword" id="dbUserPassword"
name="dbUserPassword" name="dbUserPassword"
value={database.dbUserPassword} bind:value={database.dbUserPassword}
/> />
</div> </div>
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center">
<label for="rootUser">{$t('forms.root_user')}</label> <label for="rootUser">{$t('forms.root_user')}
<Explainer explanation="Can only be modified when the database is not active."/>
</label>
<CopyPasswordField <CopyPasswordField
readonly readonly={$status.database.isRunning}
disabled disabled={$status.database.isRunning}
placeholder={$t('forms.generated_automatically_after_start')} placeholder={$t('forms.generated_automatically_after_start')}
id="rootUser" id="rootUser"
name="rootUser" name="rootUser"
value={database.rootUser} bind:value={database.rootUser}
/> />
</div> </div>
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center">
<label for="rootUserPassword">{$t('forms.roots_password')}</label> <label for="rootUserPassword">{$t('forms.roots_password')}
<Explainer explanation="Can be modified even when the database is active." />
</label>
<CopyPasswordField <CopyPasswordField
readonly readonly={false}
disabled disabled={false}
placeholder={$t('forms.generated_automatically_after_start')} placeholder={$t('forms.generated_automatically_after_start')}
isPasswordField isPasswordField
id="rootUserPassword" id="rootUserPassword"
name="rootUserPassword" name="rootUserPassword"
value={database.rootUserPassword} bind:value={database.rootUserPassword}
/> />
</div> </div>
</div> </div>

View File

@ -11,11 +11,12 @@
</div> </div>
<div class="space-y-2 lg:px-10 px-2"> <div class="space-y-2 lg:px-10 px-2">
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center">
<label for="defaultDatabase">{$t('database.default_database')}</label> <label for="defaultDatabase">{$t('database.default_database')}
<Explainer explanation="Can only be modified when the database is not active."/></label>
<CopyPasswordField <CopyPasswordField
required required
readonly={database.defaultDatabase} readonly={$status.database.isRunning}
disabled={database.defaultDatabase} disabled={$status.database.isRunning}
placeholder="{$t('forms.eg')}: edgedb" placeholder="{$t('forms.eg')}: edgedb"
id="defaultDatabase" id="defaultDatabase"
name="defaultDatabase" name="defaultDatabase"
@ -23,10 +24,11 @@
/> />
</div> </div>
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center">
<label for="rootUser">{$t('forms.root_user')}</label> <label for="rootUser">{$t('forms.root_user')}
<Explainer explanation="Can only be modified when the database is not active."/></label>
<CopyPasswordField <CopyPasswordField
readonly readonly={$status.database.isRunning}
disabled disabled={$status.database.isRunning}
placeholder={$t('forms.generated_automatically_after_start')} placeholder={$t('forms.generated_automatically_after_start')}
id="rootUser" id="rootUser"
name="rootUser" name="rootUser"
@ -35,18 +37,16 @@
</div> </div>
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center">
<label for="rootUser" <label for="rootUser"
>Root Password <Explainer >Root Password <Explainer explanation="Can be modified even when the database is active." /></label
explanation="Could be changed while the database is running."
/></label
> >
<CopyPasswordField <CopyPasswordField
readonly readonly={false}
disabled disabled={false}
placeholder="Generated automatically after start" placeholder="Generated automatically after start"
isPasswordField isPasswordField
id="rootUserPassword" id="rootUserPassword"
name="rootUserPassword" name="rootUserPassword"
value={database.rootUserPassword} bind:value={database.rootUserPassword}
/> />
</div> </div>
</div> </div>

View File

@ -12,12 +12,12 @@
<div class="space-y-2 lg:px-10 px-2"> <div class="space-y-2 lg:px-10 px-2">
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center">
<label for="defaultDatabase" <label for="defaultDatabase"
>{$t('database.default_database')}</label >{$t('database.default_database')}<Explainer explanation="Can only be modified when the database is not active."/></label
> >
<CopyPasswordField <CopyPasswordField
required required
readonly={database.defaultDatabase} readonly={$status.database.isRunning}
disabled={database.defaultDatabase} disabled={$status.database.isRunning}
placeholder="{$t('forms.eg')}: mydb" placeholder="{$t('forms.eg')}: mydb"
id="defaultDatabase" id="defaultDatabase"
name="defaultDatabase" name="defaultDatabase"
@ -25,24 +25,24 @@
/> />
</div> </div>
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center">
<label for="dbUser" >{$t('forms.user')}</label> <label for="dbUser" >{$t('forms.user')}<Explainer explanation="Can only be modified when the database is not active."/></label>
<CopyPasswordField <CopyPasswordField
readonly readonly={$status.database.isRunning}
disabled disabled={$status.database.isRunning}
placeholder={$t('forms.generated_automatically_after_start')} placeholder={$t('forms.generated_automatically_after_start')}
id="dbUser" id="dbUser"
name="dbUser" name="dbUser"
value={database.dbUser} bind:value={database.dbUser}
/> />
</div> </div>
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center">
<label for="dbUserPassword" <label for="dbUserPassword"
>{$t('forms.password')} >{$t('forms.password')}
<Explainer explanation="Could be changed while the database is running." /></label <Explainer explanation="Can be modified even when the database is active." /></label
> >
<CopyPasswordField <CopyPasswordField
disabled={!$status.database.isRunning} readonly={false}
readonly={!$status.database.isRunning} disabled={false}
placeholder={$t('forms.generated_automatically_after_start')} placeholder={$t('forms.generated_automatically_after_start')}
isPasswordField isPasswordField
id="dbUserPassword" id="dbUserPassword"
@ -51,24 +51,24 @@
/> />
</div> </div>
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center">
<label for="rootUser" >{$t('forms.root_user')}</label> <label for="rootUser" >{$t('forms.root_user')}<Explainer explanation="Can only be modified when the database is not active."/></label>
<CopyPasswordField <CopyPasswordField
readonly readonly={$status.database.isRunning}
disabled disabled={$status.database.isRunning}
placeholder={$t('forms.generated_automatically_after_start')} placeholder={$t('forms.generated_automatically_after_start')}
id="rootUser" id="rootUser"
name="rootUser" name="rootUser"
value={database.rootUser} bind:value={database.rootUser}
/> />
</div> </div>
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center">
<label for="rootUserPassword" <label for="rootUserPassword"
>{$t('forms.roots_password')} >{$t('forms.roots_password')}
<Explainer explanation="Could be changed while the database is running." /></label <Explainer explanation="Can be modified even when the database is active." /></label
> >
<CopyPasswordField <CopyPasswordField
disabled={!$status.database.isRunning} readonly={false}
readonly={!$status.database.isRunning} disabled={false}
placeholder={$t('forms.generated_automatically_after_start')} placeholder={$t('forms.generated_automatically_after_start')}
isPasswordField isPasswordField
id="rootUserPassword" id="rootUserPassword"

View File

@ -11,24 +11,26 @@
</div> </div>
<div class="space-y-2 lg:px-10 px-2"> <div class="space-y-2 lg:px-10 px-2">
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center">
<label for="rootUser">{$t('forms.root_user')}</label> <label for="rootUser">{$t('forms.root_user')}
<Explainer explanation="Can only be modified when the database is not active." /></label
>
<CopyPasswordField <CopyPasswordField
placeholder={$t('forms.generated_automatically_after_start')} placeholder={$t('forms.generated_automatically_after_start')}
id="rootUser" id="rootUser"
readonly readonly={$status.database.isRunning}
disabled disabled={$status.database.isRunning}
name="rootUser" name="rootUser"
value={database.rootUser} bind:value={database.rootUser}
/> />
</div> </div>
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center">
<label for="rootUserPassword" <label for="rootUserPassword"
>{$t('forms.roots_password')} >{$t('forms.roots_password')}
<Explainer explanation="Could be changed while the database is running." /></label <Explainer explanation="Can be modified even when the database is active." /></label
> >
<CopyPasswordField <CopyPasswordField
disabled={!$status.database.isRunning} disabled={false}
readonly={!$status.database.isRunning} readonly={false}
placeholder={$t('forms.generated_automatically_after_start')} placeholder={$t('forms.generated_automatically_after_start')}
isPasswordField={true} isPasswordField={true}
id="rootUserPassword" id="rootUserPassword"

View File

@ -11,11 +11,11 @@
</div> </div>
<div class="space-y-2 lg:px-10 px-2"> <div class="space-y-2 lg:px-10 px-2">
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center">
<label for="defaultDatabase">{$t('database.default_database')}</label> <label for="defaultDatabase">{$t('database.default_database')}<Explainer explanation="Can only be modified when the database is not active."/></label>
<CopyPasswordField <CopyPasswordField
required required
readonly={database.defaultDatabase} readonly={$status.database.isRunning}
disabled={database.defaultDatabase} disabled={$status.database.isRunning}
placeholder="{$t('forms.eg')}: mydb" placeholder="{$t('forms.eg')}: mydb"
id="defaultDatabase" id="defaultDatabase"
name="defaultDatabase" name="defaultDatabase"
@ -23,24 +23,24 @@
/> />
</div> </div>
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center">
<label for="dbUser">{$t('forms.user')}</label> <label for="dbUser">{$t('forms.user')}<Explainer explanation="Can only be modified when the database is not active."/></label>
<CopyPasswordField <CopyPasswordField
readonly readonly={$status.database.isRunning}
disabled disabled={$status.database.isRunning}
placeholder={$t('forms.generated_automatically_after_start')} placeholder={$t('forms.generated_automatically_after_start')}
id="dbUser" id="dbUser"
name="dbUser" name="dbUser"
value={database.dbUser} bind:value={database.dbUser}
/> />
</div> </div>
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center">
<label for="dbUserPassword" <label for="dbUserPassword"
>{$t('forms.password')} >{$t('forms.password')}
<Explainer explanation="Could be changed while the database is running." /></label <Explainer explanation="Can be modified even when the database is active." /></label
> >
<CopyPasswordField <CopyPasswordField
disabled={!$status.database.isRunning} disabled={false}
readonly={!$status.database.isRunning} readonly={false}
placeholder={$t('forms.generated_automatically_after_start')} placeholder={$t('forms.generated_automatically_after_start')}
isPasswordField isPasswordField
id="dbUserPassword" id="dbUserPassword"
@ -49,24 +49,26 @@
/> />
</div> </div>
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center">
<label for="rootUser">{$t('forms.root_user')}</label> <label for="rootUser">{$t('forms.root_user')}
<Explainer explanation="Can only be modified when the database is not active."/>
</label>
<CopyPasswordField <CopyPasswordField
readonly readonly={$status.database.isRunning}
disabled disabled={$status.database.isRunning}
placeholder={$t('forms.generated_automatically_after_start')} placeholder={$t('forms.generated_automatically_after_start')}
id="rootUser" id="rootUser"
name="rootUser" name="rootUser"
value={$appSession.isARM ? 'root' : database.rootUser} bind:value={database.rootUser}
/> />
</div> </div>
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center">
<label for="rootUserPassword" <label for="rootUserPassword"
>{$t('forms.roots_password')} >{$t('forms.roots_password')}
<Explainer explanation="Could be changed while the database is running." /></label <Explainer explanation="Can be modified even when the database is active." /></label
> >
<CopyPasswordField <CopyPasswordField
disabled={!$status.database.isRunning} disabled={false}
readonly={!$status.database.isRunning} readonly={false}
placeholder={$t('forms.generated_automatically_after_start')} placeholder={$t('forms.generated_automatically_after_start')}
isPasswordField isPasswordField
id="rootUserPassword" id="rootUserPassword"

View File

@ -11,11 +11,11 @@
</div> </div>
<div class="space-y-2 lg:px-10 px-2"> <div class="space-y-2 lg:px-10 px-2">
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center">
<label for="defaultDatabase">{$t('database.default_database')}</label> <label for="defaultDatabase">{$t('database.default_database')}<Explainer explanation="Can only be modified when the database is not active."/></label>
<CopyPasswordField <CopyPasswordField
required required
readonly={database.defaultDatabase} readonly={$status.database.isRunning}
disabled={database.defaultDatabase} disabled={$status.database.isRunning}
placeholder="{$t('forms.eg')}: mydb" placeholder="{$t('forms.eg')}: mydb"
id="defaultDatabase" id="defaultDatabase"
name="defaultDatabase" name="defaultDatabase"
@ -25,13 +25,11 @@
{#if !$appSession.isARM} {#if !$appSession.isARM}
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center">
<label for="rootUser" <label for="rootUser"
>Postgres User Password <Explainer >Postgres User Password <Explainer explanation="Can be modified even when the database is active." /></label
explanation="Could be changed while the database is running."
/></label
> >
<CopyPasswordField <CopyPasswordField
disabled={!$status.database.isRunning} readonly={false}
readonly={!$status.database.isRunning} disabled={false}
placeholder="Generated automatically after start" placeholder="Generated automatically after start"
isPasswordField isPasswordField
id="rootUserPassword" id="rootUserPassword"
@ -41,24 +39,24 @@
</div> </div>
{/if} {/if}
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center">
<label for="dbUser">{$t('forms.user')}</label> <label for="dbUser">{$t('forms.user')}<Explainer explanation="Can only be modified when the database is not active."/></label>
<CopyPasswordField <CopyPasswordField
readonly readonly={$status.database.isRunning}
disabled disabled={$status.database.isRunning}
placeholder={$t('forms.generated_automatically_after_start')} placeholder={$t('forms.generated_automatically_after_start')}
id="dbUser" id="dbUser"
name="dbUser" name="dbUser"
value={database.dbUser} bind:value={database.dbUser}
/> />
</div> </div>
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center">
<label for="dbUserPassword" <label for="dbUserPassword"
>{$t('forms.password')} >{$t('forms.password')}
<Explainer explanation="Could be changed while the database is running." /></label <Explainer explanation="Can be modified even when the database is active." /></label
> >
<CopyPasswordField <CopyPasswordField
disabled={!$status.database.isRunning} readonly={false}
readonly={!$status.database.isRunning} disabled={false}
placeholder={$t('forms.generated_automatically_after_start')} placeholder={$t('forms.generated_automatically_after_start')}
isPasswordField isPasswordField
id="dbUserPassword" id="dbUserPassword"

View File

@ -13,11 +13,11 @@
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center">
<label for="dbUserPassword" <label for="dbUserPassword"
>{$t('forms.password')} >{$t('forms.password')}
<Explainer explanation="Could be changed while the database is running." /></label <Explainer explanation="Can be modified even when the database is active." /></label
> >
<CopyPasswordField <CopyPasswordField
disabled={!$status.database.isRunning} readonly={false}
readonly={!$status.database.isRunning} disabled={false}
placeholder={$t('forms.generated_automatically_after_start')} placeholder={$t('forms.generated_automatically_after_start')}
isPasswordField isPasswordField
id="dbUserPassword" id="dbUserPassword"