diff --git a/packages/presentation/src/utils.ts b/packages/presentation/src/utils.ts index c0d53468f8..5fa7794e73 100644 --- a/packages/presentation/src/utils.ts +++ b/packages/presentation/src/utils.ts @@ -143,6 +143,13 @@ export async function refreshClient (): Promise { } } +/** + * @public + */ +export async function closeClient (): Promise { + await client?.close() +} + const globalQueries: LiveQuery[] = [] /** diff --git a/plugins/login-resources/src/components/LoginApp.svelte b/plugins/login-resources/src/components/LoginApp.svelte index d661fadd5e..fcea6a91ad 100644 --- a/plugins/login-resources/src/components/LoginApp.svelte +++ b/plugins/login-resources/src/components/LoginApp.svelte @@ -19,6 +19,7 @@ import { getMetadata } from '@hcengineering/platform' import presentation from '@hcengineering/presentation' import { themeStore } from '@hcengineering/theme' + import workbench from '@hcengineering/workbench' import { onDestroy } from 'svelte' import Confirmation from './Confirmation.svelte' import ConfirmationSend from './ConfirmationSend.svelte' @@ -30,7 +31,6 @@ import SelectWorkspace from './SelectWorkspace.svelte' import SignupForm from './SignupForm.svelte' import LoginIcon from './icons/LoginIcon.svelte' - import workbench from '@hcengineering/workbench' import loginBack from '../../img/login_back.png' import loginBack2x from '../../img/login_back_2x.png' @@ -50,9 +50,23 @@ } $: token = getToken($ticker) + const pages = [ + 'login', + 'signup', + 'createWorkspace', + 'password', + 'recovery', + 'selectWorkspace', + 'join', + 'confirm', + 'confirmationSend' + ] onDestroy( location.subscribe(async (loc) => { page = loc.path[1] ?? (token ? 'selectWorkspace' : 'login') + if (!pages.includes(page)) { + page = 'login' + } navigateUrl = loc.query?.navigateUrl ?? undefined }) diff --git a/plugins/setting-resources/src/components/Settings.svelte b/plugins/setting-resources/src/components/Settings.svelte index 545011fbc8..58d18574d0 100644 --- a/plugins/setting-resources/src/components/Settings.svelte +++ b/plugins/setting-resources/src/components/Settings.svelte @@ -17,7 +17,7 @@ import { AccountRole, getCurrentAccount } from '@hcengineering/core' import login, { loginId } from '@hcengineering/login' import { setMetadata } from '@hcengineering/platform' - import presentation, { createQuery } from '@hcengineering/presentation' + import presentation, { closeClient, createQuery } from '@hcengineering/presentation' import setting, { SettingsCategory } from '@hcengineering/setting' import { Component, @@ -76,6 +76,7 @@ setMetadata(presentation.metadata.Token, null) setMetadataLocalStorage(login.metadata.LoginEndpoint, null) setMetadataLocalStorage(login.metadata.LoginEmail, null) + closeClient() navigate({ path: [loginId] }) } function selectWorkspace (): void { diff --git a/plugins/tracker-resources/src/components/AccountPopup.svelte b/plugins/tracker-resources/src/components/AccountPopup.svelte index d90c7d5b47..6631dc8005 100644 --- a/plugins/tracker-resources/src/components/AccountPopup.svelte +++ b/plugins/tracker-resources/src/components/AccountPopup.svelte @@ -18,7 +18,7 @@ import { getCurrentAccount } from '@hcengineering/core' import login, { loginId } from '@hcengineering/login' import { setMetadata } from '@hcengineering/platform' - import presentation from '@hcengineering/presentation' + import presentation, { closeClient } from '@hcengineering/presentation' import setting, { SettingsCategory, settingId } from '@hcengineering/setting' import { Icon, @@ -57,6 +57,7 @@ setMetadata(presentation.metadata.Token, null) setMetadataLocalStorage(login.metadata.LoginEndpoint, null) setMetadataLocalStorage(login.metadata.LoginEmail, null) + closeClient() navigate({ path: [loginId] }) } diff --git a/plugins/workbench-resources/src/components/AccountPopup.svelte b/plugins/workbench-resources/src/components/AccountPopup.svelte index 9288185426..8fa2ce9468 100644 --- a/plugins/workbench-resources/src/components/AccountPopup.svelte +++ b/plugins/workbench-resources/src/components/AccountPopup.svelte @@ -17,7 +17,7 @@ import { AccountRole, getCurrentAccount } from '@hcengineering/core' import login, { loginId } from '@hcengineering/login' import { setMetadata } from '@hcengineering/platform' - import presentation, { createQuery } from '@hcengineering/presentation' + import presentation, { closeClient, createQuery } from '@hcengineering/presentation' import setting, { SettingsCategory, settingId } from '@hcengineering/setting' import { Action, @@ -87,6 +87,7 @@ setMetadata(presentation.metadata.Token, null) setMetadataLocalStorage(login.metadata.LoginEndpoint, null) setMetadataLocalStorage(login.metadata.LoginEmail, null) + closeClient() navigate({ path: [loginId] }) } diff --git a/plugins/workbench-resources/src/components/ServerManager.svelte b/plugins/workbench-resources/src/components/ServerManager.svelte index fc3754e533..7fa60905fb 100644 --- a/plugins/workbench-resources/src/components/ServerManager.svelte +++ b/plugins/workbench-resources/src/components/ServerManager.svelte @@ -12,11 +12,12 @@ export let token: string let data: any - + let admin = false onDestroy( ticker.subscribe(() => { fetch(endpoint + `/api/v1/statistics?token=${token}`, {}).then(async (json) => { data = await json.json() + admin = data?.admin ?? false }) }) ) @@ -87,7 +88,7 @@ {#if data} {#if selectedTab === 'general'} - + {#if admin}
1.
@@ -120,44 +121,42 @@ />
-
+ {/if} {:else if selectedTab === 'users'} -
- - {#each Object.entries(activeSessions) as act} - -
- Workspace: {act[0]}: {act[1].length} -
+
+ {#each Object.entries(activeSessions) as act} + +
+ Workspace: {act[0]}: {act[1].length} +
-
- {#each act[1] as user} - {@const employee = employees.get(user.userId)} -
- {#if employee} - - {:else} - {user.userId} - {/if} -
- Total: {user.total.find}/{user.total.tx} -
-
- Previous 5 mins: {user.mins5.find}/{user.mins5.tx} -
-
- Current 5 mins: {user.current.find}/{user.current.tx} -
+
+ {#each act[1] as user} + {@const employee = employees.get(user.userId)} +
+ {#if employee} + + {:else} + {user.userId} + {/if} +
+ Total: {user.total.find}/{user.total.tx}
- {/each} -
- - {/each} - +
+ Previous 5 mins: {user.mins5.find}/{user.mins5.tx} +
+
+ Current 5 mins: {user.current.find}/{user.current.tx} +
+
+ {/each} +
+ + {/each}
{:else if selectedTab === 'statistics'} diff --git a/plugins/workbench-resources/src/components/Workbench.svelte b/plugins/workbench-resources/src/components/Workbench.svelte index 2875a23b53..0468f840c3 100644 --- a/plugins/workbench-resources/src/components/Workbench.svelte +++ b/plugins/workbench-resources/src/components/Workbench.svelte @@ -289,7 +289,7 @@ const specialRef = getMetadata(workbench.metadata.DefaultSpecial) as Ref const loc = getCurrentLocation() // Be sure URI is not yet changed - if (loc.path[2] === undefined) { + if (loc.path[2] === undefined && loc.path[0] === 'workbench') { loc.path[2] = appShort let len = 3 if (spaceRef !== undefined && specialRef !== undefined) { diff --git a/plugins/workbench-resources/src/connect.ts b/plugins/workbench-resources/src/connect.ts index bd69a5c6c5..36867ec495 100644 --- a/plugins/workbench-resources/src/connect.ts +++ b/plugins/workbench-resources/src/connect.ts @@ -1,15 +1,16 @@ import client from '@hcengineering/client' import core, { + AccountClient, AccountRole, Client, - AccountClient, - setCurrentAccount, Version, + getCurrentAccount, + setCurrentAccount, versionToString } from '@hcengineering/core' import login, { loginId } from '@hcengineering/login' import { addEventListener, getMetadata, getResource, setMetadata } from '@hcengineering/platform' -import presentation, { refreshClient, setClient } from '@hcengineering/presentation' +import presentation, { closeClient, refreshClient, setClient } from '@hcengineering/presentation' import ui, { fetchMetadataLocalStorage, getCurrentLocation, @@ -153,14 +154,19 @@ export async function connect (title: string): Promise { ep = ep.substring(0, ep.length - 1) } setMetadata(ui.metadata.ShowNetwork, (evt: MouseEvent) => { - showPopup( - ServerManager, - { - endpoint: ep, - token - }, - 'content' - ) + if (getMetadata(presentation.metadata.Token) == null) { + return + } + if (getCurrentAccount()?.role === AccountRole.Owner) { + showPopup( + ServerManager, + { + endpoint: ep, + token + }, + 'content' + ) + } }) } @@ -178,4 +184,5 @@ function clearMetadata (ws: string): void { setMetadata(presentation.metadata.Token, null) setMetadataLocalStorage(login.metadata.LoginEndpoint, null) setMetadataLocalStorage(login.metadata.LoginEmail, null) + void closeClient() }