2022-03-31 08:32:42 +00:00
|
|
|
<!--
|
|
|
|
// Copyright © 2020 Anticrm Platform Contributors.
|
|
|
|
//
|
|
|
|
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License. You may
|
|
|
|
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
//
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
-->
|
|
|
|
<script lang="ts">
|
2023-03-17 16:05:22 +00:00
|
|
|
import { EmployeeAccount, formatName } from '@hcengineering/contact'
|
2023-04-21 16:24:45 +00:00
|
|
|
import { Avatar, employeeByIdStore } from '@hcengineering/contact-resources'
|
2022-09-21 08:08:25 +00:00
|
|
|
import { getCurrentAccount } from '@hcengineering/core'
|
2023-01-16 04:30:47 +00:00
|
|
|
import login, { loginId } from '@hcengineering/login'
|
2022-09-21 08:08:25 +00:00
|
|
|
import { setMetadata } from '@hcengineering/platform'
|
2023-04-21 16:24:45 +00:00
|
|
|
import presentation from '@hcengineering/presentation'
|
|
|
|
import setting, { SettingsCategory, settingId } from '@hcengineering/setting'
|
2022-07-06 07:02:01 +00:00
|
|
|
import {
|
|
|
|
Icon,
|
|
|
|
Label,
|
2023-04-21 16:24:45 +00:00
|
|
|
closePopup,
|
|
|
|
fetchMetadataLocalStorage,
|
|
|
|
getCurrentResolvedLocation,
|
2022-07-06 07:02:01 +00:00
|
|
|
navigate,
|
|
|
|
setMetadataLocalStorage
|
2022-09-21 08:08:25 +00:00
|
|
|
} from '@hcengineering/ui'
|
2022-03-31 08:32:42 +00:00
|
|
|
|
|
|
|
// const client = getClient()
|
|
|
|
async function getItems (): Promise<SettingsCategory[]> {
|
|
|
|
return []
|
|
|
|
}
|
|
|
|
|
|
|
|
const account = getCurrentAccount() as EmployeeAccount
|
2023-03-17 16:05:22 +00:00
|
|
|
$: employee = $employeeByIdStore.get(account.employee)
|
2022-03-31 08:32:42 +00:00
|
|
|
|
|
|
|
function selectCategory (sp: SettingsCategory): void {
|
|
|
|
closePopup()
|
2023-04-21 16:24:45 +00:00
|
|
|
const loc = getCurrentResolvedLocation()
|
2022-07-06 07:02:01 +00:00
|
|
|
loc.path[2] = settingId
|
|
|
|
loc.path[3] = sp.name
|
|
|
|
loc.path.length = 4
|
2022-03-31 08:32:42 +00:00
|
|
|
navigate(loc)
|
|
|
|
}
|
|
|
|
|
|
|
|
function signOut (): void {
|
2022-07-06 07:02:01 +00:00
|
|
|
const tokens = fetchMetadataLocalStorage(login.metadata.LoginTokens)
|
|
|
|
if (tokens !== null) {
|
2023-04-21 16:24:45 +00:00
|
|
|
const loc = getCurrentResolvedLocation()
|
2022-07-06 07:02:01 +00:00
|
|
|
delete tokens[loc.path[1]]
|
|
|
|
setMetadataLocalStorage(login.metadata.LoginTokens, tokens)
|
|
|
|
}
|
2023-03-22 02:48:57 +00:00
|
|
|
setMetadata(presentation.metadata.Token, null)
|
2022-03-31 08:32:42 +00:00
|
|
|
setMetadataLocalStorage(login.metadata.LoginEndpoint, null)
|
|
|
|
setMetadataLocalStorage(login.metadata.LoginEmail, null)
|
2023-01-16 04:30:47 +00:00
|
|
|
navigate({ path: [loginId] })
|
2022-03-31 08:32:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function selectWorkspace (): void {
|
2023-01-16 04:30:47 +00:00
|
|
|
navigate({ path: [loginId, 'selectWorkspace'] })
|
2022-03-31 08:32:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function filterItems (items: SettingsCategory[]): SettingsCategory[] {
|
|
|
|
return items?.filter((p) => p.name !== 'profile' && p.name !== 'password')
|
|
|
|
}
|
|
|
|
|
|
|
|
function editProfile (items: SettingsCategory[] | undefined): void {
|
|
|
|
const profile = items?.find((p) => p.name === 'profile')
|
|
|
|
if (profile === undefined) return
|
|
|
|
selectCategory(profile)
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<div class="antiPopup">
|
|
|
|
<div class="ap-space" />
|
2022-04-29 05:27:17 +00:00
|
|
|
<div class="ap-scroll">
|
|
|
|
<div class="ap-box">
|
|
|
|
{#await getItems() then items}
|
2023-01-18 05:14:59 +00:00
|
|
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
2022-04-29 05:27:17 +00:00
|
|
|
<div
|
|
|
|
class="ap-menuItem flex-row-center"
|
|
|
|
on:click={() => {
|
|
|
|
editProfile(items)
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{#if employee}
|
|
|
|
<Avatar avatar={employee.avatar} size={'medium'} />
|
2022-03-31 08:32:42 +00:00
|
|
|
{/if}
|
2022-04-29 05:27:17 +00:00
|
|
|
<div class="ml-2 flex-col">
|
|
|
|
{#if account}
|
|
|
|
<div class="overflow-label fs-bold caption-color">{formatName(account.name)}</div>
|
|
|
|
<div class="overflow-label text-sm content-dark-color">{account.email}</div>
|
|
|
|
{/if}
|
|
|
|
</div>
|
2022-03-31 08:32:42 +00:00
|
|
|
</div>
|
2022-04-29 05:27:17 +00:00
|
|
|
{#if items}
|
|
|
|
{#each filterItems(items) as item}
|
|
|
|
<button class="ap-menuItem" on:click={() => selectCategory(item)}>
|
|
|
|
<div class="mr-2">
|
|
|
|
<Icon icon={item.icon} size={'small'} />
|
|
|
|
</div>
|
|
|
|
<Label label={item.label} />
|
|
|
|
</button>
|
|
|
|
{/each}
|
|
|
|
{/if}
|
|
|
|
<button class="ap-menuItem" on:click={selectWorkspace}>
|
|
|
|
<div class="mr-2">
|
|
|
|
<Icon icon={setting.icon.SelectWorkspace} size={'small'} />
|
|
|
|
</div>
|
|
|
|
<Label label={setting.string.SelectWorkspace} />
|
|
|
|
</button>
|
|
|
|
<button class="ap-menuItem" on:click={signOut}>
|
|
|
|
<div class="mr-2">
|
|
|
|
<Icon icon={setting.icon.Signout} size={'small'} />
|
|
|
|
</div>
|
|
|
|
<Label label={setting.string.Signout} />
|
|
|
|
</button>
|
|
|
|
{/await}
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-03-31 08:32:42 +00:00
|
|
|
<div class="ap-space" />
|
|
|
|
</div>
|