Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev
2022-02-03 10:03:53 +01:00
committed by GitHub
parent e7c0f2406a
commit 8c51a4ec2c
12 changed files with 233 additions and 174 deletions
@@ -13,15 +13,15 @@
// limitations under the License.
-->
<script lang="ts">
import { Client, getCurrentAccount, Ref, Space } from '@anticrm/core'
import core from '@anticrm/core'
import contact, { Employee, EmployeeAccount } from '@anticrm/contact'
import core, { Client, getCurrentAccount, Ref, Space } from '@anticrm/core'
import { Avatar, createQuery, setClient } from '@anticrm/presentation'
import {
AnyComponent,
AnySvelteComponent,
closeTooltip,
AnyComponent, closeTooltip,
Component,
getCurrentLocation,
location,
navigate,
Popup,
showPopup,
TooltipInstance
@@ -33,62 +33,93 @@
import ActivityStatus from './ActivityStatus.svelte'
import AppItem from './AppItem.svelte'
import Applications from './Applications.svelte'
import Archive from './Archive.svelte'
import TopMenu from './icons/TopMenu.svelte'
import NavHeader from './NavHeader.svelte'
import Navigator from './Navigator.svelte'
import SpaceView from './SpaceView.svelte'
import contact, { Employee, EmployeeAccount } from '@anticrm/contact'
export let client: Client
setClient(client)
let currentApp: Ref<Application> | undefined
let currentApplication: Application | undefined
let currentSpace: Ref<Space> | undefined
let ownSpecialComponent: AnySvelteComponent | undefined
let currentSpecial: string | undefined
let specialComponent: AnyComponent | undefined
let currentApplication: Application | undefined
let currentView: ViewConfiguration | undefined
let createItemDialog: AnyComponent | undefined
let navigatorModel: NavigatorModel | undefined
onDestroy(
location.subscribe(async (loc) => {
currentApp = loc.path[1] as Ref<Application>
currentApplication = await client.findOne(workbench.class.Application, { _id: currentApp })
navigatorModel = currentApplication?.navigatorModel
if (currentApp !== loc.path[1]) {
currentApp = loc.path[1] as Ref<Application>
currentApplication = await client.findOne(workbench.class.Application, { _id: currentApp })
navigatorModel = currentApplication?.navigatorModel
}
const currentFolder = loc.path[2] as Ref<Space>
ownSpecialComponent = getOwnSpecialComponent(currentFolder)
if (ownSpecialComponent !== undefined) {
return
if (currentSpecial !== currentFolder) {
specialComponent = getSpecialComponent(currentFolder)
if (specialComponent !== undefined) {
currentSpecial = currentFolder
return
}
}
specialComponent = getSpecialComponent(currentFolder)
if (specialComponent !== undefined) {
return
}
const space = await client.findOne(core.class.Space, { _id: currentFolder })
currentSpace = currentFolder
if (space) {
const spaceClass = client.getHierarchy().getClass(space._class) // (await client.findAll(core.class.Class, { _id: space._class }))[0]
const view = client.getHierarchy().as(spaceClass, workbench.mixin.SpaceView)
currentView = view.view
createItemDialog = currentView.createItemDialog
} else {
currentView = undefined
createItemDialog = undefined
}
updateSpace(currentSpace)
})
)
function getOwnSpecialComponent (id: string): AnySvelteComponent | undefined {
if (id === 'archive') {
return Archive
async function updateSpace (spaceId?: Ref<Space>): Promise<void> {
if (spaceId === currentSpace) {
return
}
if (spaceId === undefined) {
return
}
const space = await client.findOne(core.class.Space, { _id: spaceId })
if (space) {
currentSpace = spaceId
currentSpecial = undefined
const spaceClass = client.getHierarchy().getClass(space._class) // (await client.findAll(core.class.Class, { _id: space._class }))[0]
const view = client.getHierarchy().as(spaceClass, workbench.mixin.SpaceView)
currentView = view.view
createItemDialog = currentView.createItemDialog
const loc = getCurrentLocation()
loc.path[2] = spaceId
loc.path.length = 3
navigate(loc)
} else {
currentView = undefined
createItemDialog = undefined
}
}
$: updateSpace(currentSpace)
function selectSpecial (id: string): void {
specialComponent = getSpecialComponent(id)
if (specialComponent !== undefined) {
currentSpecial = id
currentSpace = undefined
const loc = getCurrentLocation()
loc.path[2] = id
loc.path.length = 3
navigate(loc)
}
}
function selectArchive (): void {
currentSpace = undefined
currentSpecial = undefined
const loc = getCurrentLocation()
loc.path[2] = 'archive'
loc.path.length = 3
navigate(loc)
}
function getSpecialComponent (id: string): AnyComponent | undefined {
@@ -112,17 +143,28 @@
let employee: Employee | undefined
const accountQ = createQuery()
const employeeQ = createQuery()
$: accountQ.query(contact.class.EmployeeAccount, {
_id: getCurrentAccount()._id as Ref<EmployeeAccount>
}, (res) => {
account = res[0]
}, { limit: 1 })
$: accountQ.query(
contact.class.EmployeeAccount,
{
_id: getCurrentAccount()._id as Ref<EmployeeAccount>
},
(res) => {
account = res[0]
},
{ limit: 1 }
)
$: account && employeeQ.query(contact.class.Employee, {
_id: account.employee
}, (res) => {
employee = res[0]
}, { limit: 1 })
$: account &&
employeeQ.query(
contact.class.Employee,
{
_id: account.employee
},
(res) => {
employee = res[0]
},
{ limit: 1 }
)
</script>
{#if client}
@@ -145,6 +187,7 @@
label={visibileNav ? workbench.string.HideMenu : workbench.string.ShowMenu}
selected={!visibileNav}
action={toggleNav}
notify={false}
/>
</div>
<Applications {apps} active={currentApp} />
@@ -166,20 +209,23 @@
{#if currentApplication}
<NavHeader label={currentApplication.label} />
{/if}
<Navigator model={navigatorModel} />
</div>
<Navigator
{currentSpace}
{currentSpecial}
model={navigatorModel}
on:special={(evt) => selectSpecial(evt.detail)}
on:space={(evt) => updateSpace(evt.detail)}
on:archive={(evt) => selectArchive()}
/>
</div>
{/if}
<div class="antiPanel-component filled indent">
{#if currentApplication && currentApplication.component}
<Component is={currentApplication.component} />
<Component is={currentApplication.component} />
{:else if specialComponent}
<Component is={specialComponent} />
{:else}
{#if ownSpecialComponent}
<svelte:component this={ownSpecialComponent} model={navigatorModel} />
{:else if specialComponent}
<Component is={specialComponent} />
{:else}
<SpaceView {currentSpace} {currentView} {createItemDialog} />
{/if}
<SpaceView {currentSpace} {currentView} {createItemDialog} />
{/if}
</div>
<!-- <div class="aside"><Chat thread/></div> -->