ask password works!

This commit is contained in:
Jan Prochazka
2022-12-25 17:12:12 +01:00
parent 783f26b500
commit 8d1d6537a4
6 changed files with 50 additions and 13 deletions

View File

@@ -8,6 +8,7 @@
export let name; export let name;
export let disabled = false; export let disabled = false;
export let saveOnInput = false;
const { values, setFieldValue } = getFormContext(); const { values, setFieldValue } = getFormContext();
@@ -23,6 +24,11 @@
{disabled} {disabled}
value={isCrypted ? '' : value} value={isCrypted ? '' : value}
on:change={e => setFieldValue(name, e.target['value'])} on:change={e => setFieldValue(name, e.target['value'])}
on:input={e => {
if (saveOnInput) {
setFieldValue(name, e.target['value']);
}
}}
placeholder={isCrypted ? '(Password is encrypted)' : undefined} placeholder={isCrypted ? '(Password is encrypted)' : undefined}
type={isCrypted || showPassword ? 'text' : 'password'} type={isCrypted || showPassword ? 'text' : 'password'}
/> />

View File

@@ -4,6 +4,7 @@
export let name; export let name;
export let defaultValue; export let defaultValue;
export let saveOnInput = false;
const { values, setFieldValue } = getFormContext(); const { values, setFieldValue } = getFormContext();
</script> </script>
@@ -12,4 +13,9 @@
{...$$restProps} {...$$restProps}
value={$values[name] ?? defaultValue} value={$values[name] ?? defaultValue}
on:input={e => setFieldValue(name, e.target['value'])} on:input={e => setFieldValue(name, e.target['value'])}
on:input={e => {
if (saveOnInput) {
setFieldValue(name, e.target['value']);
}
}}
/> />

View File

@@ -18,7 +18,7 @@
import FormTextField from '../forms/FormTextField.svelte'; import FormTextField from '../forms/FormTextField.svelte';
import FontIcon from '../icons/FontIcon.svelte'; import FontIcon from '../icons/FontIcon.svelte';
import { apiCall, setVolatileConnectionRemapping } from '../utility/api'; import { apiCall, setVolatileConnectionRemapping } from '../utility/api';
import { dispatchCacheChange } from '../utility/cache'; import { batchDispatchCacheTriggers, dispatchCacheChange } from '../utility/cache';
import createRef from '../utility/createRef'; import createRef from '../utility/createRef';
import { getConnectionInfo } from '../utility/metadataLoaders'; import { getConnectionInfo } from '../utility/metadataLoaders';
@@ -64,16 +64,16 @@
const testid = testIdRef.get(); const testid = testIdRef.get();
const resp = await apiCall('connections/save-volatile', { const resp = await apiCall('connections/save-volatile', {
conid, conid,
user: ev.detail.user, user: $values['user'],
password: ev.detail.password, password: $values['password'],
test: true, test: true,
}); });
if (testIdRef.get() != testid) return; if (testIdRef.get() != testid) return;
isTesting = false; isTesting = false;
if (resp.msgtype == 'connected') { if (resp.msgtype == 'connected') {
setVolatileConnectionRemapping(conid, resp._id); setVolatileConnectionRemapping(conid, resp._id);
dispatchCacheChange(`database-list-changed-${conid}`); dispatchCacheChange({ key: `server-status-changed` });
dispatchCacheChange(`server-status-changed`); batchDispatchCacheTriggers(x => x.conid == conid);
closeCurrentModal(); closeCurrentModal();
} else { } else {
sqlConnectResult = resp; sqlConnectResult = resp;
@@ -92,12 +92,14 @@
autocomplete="username" autocomplete="username"
disabled={passwordMode == 'askPassword'} disabled={passwordMode == 'askPassword'}
focused={passwordMode == 'askUser'} focused={passwordMode == 'askUser'}
saveOnInput
/> />
<FormPasswordField <FormPasswordField
label="Password" label="Password"
name="password" name="password"
autocomplete="current-password" autocomplete="current-password"
focused={passwordMode == 'askPassword'} focused={passwordMode == 'askPassword'}
saveOnInput
/> />
{#if isTesting} {#if isTesting}

View File

@@ -16,6 +16,7 @@ let apiDisabled = false;
const disabledOnOauth = isOauthCallback(); const disabledOnOauth = isOauthCallback();
const volatileConnectionMap = {}; const volatileConnectionMap = {};
const volatileConnectionMapInv = {};
export function disableApi() { export function disableApi() {
apiDisabled = true; apiDisabled = true;
@@ -27,12 +28,17 @@ export function enableApi() {
export function setVolatileConnectionRemapping(existingConnectionId, volatileConnectionId) { export function setVolatileConnectionRemapping(existingConnectionId, volatileConnectionId) {
volatileConnectionMap[existingConnectionId] = volatileConnectionId; volatileConnectionMap[existingConnectionId] = volatileConnectionId;
volatileConnectionMapInv[volatileConnectionId] = existingConnectionId;
} }
export function getVolatileRemapping(conid) { export function getVolatileRemapping(conid) {
return volatileConnectionMap[conid] || conid; return volatileConnectionMap[conid] || conid;
} }
export function getVolatileRemappingInv(conid) {
return volatileConnectionMapInv[conid] || conid;
}
function wantEventSource() { function wantEventSource() {
if (!eventSource) { if (!eventSource) {
eventSource = new EventSource(`${resolveApi()}/stream`); eventSource = new EventSource(`${resolveApi()}/stream`);
@@ -64,7 +70,7 @@ function processApiResponse(route, args, resp) {
return resp; return resp;
} }
function transformApiArgs(args) { export function transformApiArgs(args) {
return _.mapValues(args, (v, k) => { return _.mapValues(args, (v, k) => {
if (k == 'conid' && v && volatileConnectionMap[v]) return volatileConnectionMap[v]; if (k == 'conid' && v && volatileConnectionMap[v]) return volatileConnectionMap[v];
if (k == 'conidArray' && _.isArray(v)) return v.map(x => volatileConnectionMap[x] || x); if (k == 'conidArray' && _.isArray(v)) return v.map(x => volatileConnectionMap[x] || x);
@@ -72,6 +78,14 @@ function transformApiArgs(args) {
}); });
} }
export function transformApiArgsInv(args) {
return _.mapValues(args, (v, k) => {
if (k == 'conid' && v && volatileConnectionMapInv[v]) return volatileConnectionMapInv[v];
if (k == 'conidArray' && _.isArray(v)) return v.map(x => volatileConnectionMapInv[x] || x);
return v;
});
}
export async function apiCall(route: string, args: {} = undefined) { export async function apiCall(route: string, args: {} = undefined) {
if (apiLogging) { if (apiLogging) {
console.log('>>> API CALL', route, args); console.log('>>> API CALL', route, args);

View File

@@ -1,4 +1,4 @@
import { apiOn } from './api'; import { apiOn, transformApiArgsInv } from './api';
import getAsArray from './getAsArray'; import getAsArray from './getAsArray';
import stableStringify from 'json-stable-stringify'; import stableStringify from 'json-stable-stringify';
@@ -34,7 +34,7 @@ function cacheSet(cacheKey, value, reloadTrigger, generation) {
function cacheClean(reloadTrigger) { function cacheClean(reloadTrigger) {
cacheGeneration += 1; cacheGeneration += 1;
for (const item of getAsArray(reloadTrigger)) { for (const item of getAsArray(reloadTrigger)) {
const itemString = stableStringify(item); const itemString = stableStringify(transformApiArgsInv(item));
const keys = cachedKeysByReloadTrigger[itemString]; const keys = cachedKeysByReloadTrigger[itemString];
if (keys) { if (keys) {
for (const key of keys) { for (const key of keys) {
@@ -80,7 +80,8 @@ export async function loadCachedValue(reloadTrigger, cacheKey, func) {
} }
} catch (err) { } catch (err) {
console.error('Error when using cached promise', err); console.error('Error when using cached promise', err);
cacheClean(cacheKey); // cacheClean(cacheKey);
cacheClean(reloadTrigger);
const res = await func(); const res = await func();
cacheSet(cacheKey, res, reloadTrigger, generation); cacheSet(cacheKey, res, reloadTrigger, generation);
return res; return res;
@@ -113,11 +114,10 @@ export async function unsubscribeCacheChange(reloadTrigger, cacheKey, reloadHand
} }
export function dispatchCacheChange(reloadTrigger) { export function dispatchCacheChange(reloadTrigger) {
// console.log('CHANGE', reloadTrigger);
cacheClean(reloadTrigger); cacheClean(reloadTrigger);
for (const item of getAsArray(reloadTrigger)) { for (const item of getAsArray(reloadTrigger)) {
const itemString = stableStringify(item); const itemString = stableStringify(transformApiArgsInv(item));
if (subscriptionsByReloadTrigger[itemString]) { if (subscriptionsByReloadTrigger[itemString]) {
for (const handler of subscriptionsByReloadTrigger[itemString]) { for (const handler of subscriptionsByReloadTrigger[itemString]) {
handler(); handler();
@@ -126,4 +126,13 @@ export function dispatchCacheChange(reloadTrigger) {
} }
} }
export function batchDispatchCacheTriggers(predicate) {
for (const key in subscriptionsByReloadTrigger) {
const relaodTrigger = JSON.parse(key);
if (predicate(relaodTrigger)) {
dispatchCacheChange(relaodTrigger);
}
}
}
apiOn('changed-cache', reloadTrigger => dispatchCacheChange(reloadTrigger)); apiOn('changed-cache', reloadTrigger => dispatchCacheChange(reloadTrigger));

View File

@@ -29,12 +29,12 @@ export function subscribeConnectionPingers() {
openedConnections.subscribe(value => { openedConnections.subscribe(value => {
doServerPing(value); doServerPing(value);
if (openedConnectionsHandle) window.clearInterval(openedConnectionsHandle); if (openedConnectionsHandle) window.clearInterval(openedConnectionsHandle);
openedConnectionsHandle = window.setInterval(() => doServerPing(value), 30 * 1000); openedConnectionsHandle = window.setInterval(() => doServerPing(value), 20 * 1000);
}); });
currentDatabase.subscribe(value => { currentDatabase.subscribe(value => {
doDatabasePing(value); doDatabasePing(value);
if (currentDatabaseHandle) window.clearInterval(currentDatabaseHandle); if (currentDatabaseHandle) window.clearInterval(currentDatabaseHandle);
currentDatabaseHandle = window.setInterval(() => doDatabasePing(value), 30 * 1000); currentDatabaseHandle = window.setInterval(() => doDatabasePing(value), 20 * 1000);
}); });
} }