Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UBER-460: Fix admin view #3420

Merged
merged 1 commit into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/presentation/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ export async function refreshClient (): Promise<void> {
}
}

/**
* @public
*/
export async function closeClient (): Promise<void> {
await client?.close()
}

const globalQueries: LiveQuery[] = []

/**
Expand Down
16 changes: 15 additions & 1 deletion plugins/login-resources/src/components/LoginApp.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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
})
Expand Down
3 changes: 2 additions & 1 deletion plugins/setting-resources/src/components/Settings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion plugins/tracker-resources/src/components/AccountPopup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -57,6 +57,7 @@
setMetadata(presentation.metadata.Token, null)
setMetadataLocalStorage(login.metadata.LoginEndpoint, null)
setMetadataLocalStorage(login.metadata.LoginEmail, null)
closeClient()
navigate({ path: [loginId] })
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -87,6 +87,7 @@
setMetadata(presentation.metadata.Token, null)
setMetadataLocalStorage(login.metadata.LoginEndpoint, null)
setMetadataLocalStorage(login.metadata.LoginEmail, null)
closeClient()
navigate({ path: [loginId] })
}

Expand Down
73 changes: 36 additions & 37 deletions plugins/workbench-resources/src/components/ServerManager.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
})
)
Expand Down Expand Up @@ -87,7 +88,7 @@
</svelte:fragment>
{#if data}
{#if selectedTab === 'general'}
<Scroller>
{#if admin}
<div class="flex flex-col">
<div class="flex-row-center p-1">
<div class="p-3">1.</div>
Expand Down Expand Up @@ -120,44 +121,42 @@
/>
</div>
</div>
</Scroller>
{/if}
{:else if selectedTab === 'users'}
<div class="flex-column p-3">
<Scroller>
{#each Object.entries(activeSessions) as act}
<span class="flex-col">
<div class="fs-title">
Workspace: {act[0]}: {act[1].length}
</div>
<div class="flex-column p-3 h-full" style:overflow="auto">
{#each Object.entries(activeSessions) as act}
<span class="flex-col">
<div class="fs-title">
Workspace: {act[0]}: {act[1].length}
</div>

<div class="flex-col">
{#each act[1] as user}
{@const employee = employees.get(user.userId)}
<div class="p-1 flex-row-center">
{#if employee}
<ObjectPresenter
_class={contact.class.Employee}
objectId={employee.employee}
props={{ shouldShowAvatar: true }}
/>
{:else}
{user.userId}
{/if}
<div class="p-1">
Total: {user.total.find}/{user.total.tx}
</div>
<div class="p-1">
Previous 5 mins: {user.mins5.find}/{user.mins5.tx}
</div>
<div class="p-1">
Current 5 mins: {user.current.find}/{user.current.tx}
</div>
<div class="flex-col">
{#each act[1] as user}
{@const employee = employees.get(user.userId)}
<div class="p-1 flex-row-center">
{#if employee}
<ObjectPresenter
_class={contact.class.Employee}
objectId={employee.employee}
props={{ shouldShowAvatar: true }}
/>
{:else}
{user.userId}
{/if}
<div class="p-1">
Total: {user.total.find}/{user.total.tx}
</div>
{/each}
</div>
</span>
{/each}
</Scroller>
<div class="p-1">
Previous 5 mins: {user.mins5.find}/{user.mins5.tx}
</div>
<div class="p-1">
Current 5 mins: {user.current.find}/{user.current.tx}
</div>
</div>
{/each}
</div>
</span>
{/each}
</div>
{:else if selectedTab === 'statistics'}
<Scroller>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@
const specialRef = getMetadata(workbench.metadata.DefaultSpecial) as Ref<Space>
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) {
Expand Down
29 changes: 18 additions & 11 deletions plugins/workbench-resources/src/connect.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -153,14 +154,19 @@ export async function connect (title: string): Promise<Client | undefined> {
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'
)
}
})
}

Expand All @@ -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()
}