2021-08-06 08:31:17 +00:00
|
|
|
<!--
|
2022-04-14 05:30:30 +00:00
|
|
|
// Copyright © 2022 Hardcore Engineering Inc.
|
|
|
|
//
|
2021-08-06 08:31:17 +00:00
|
|
|
// 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
|
2022-04-14 05:30:30 +00:00
|
|
|
//
|
2021-08-06 08:31:17 +00:00
|
|
|
// 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.
|
2022-04-14 05:30:30 +00:00
|
|
|
//
|
2021-08-06 08:31:17 +00:00
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
-->
|
|
|
|
<script lang="ts">
|
2022-04-22 03:13:15 +00:00
|
|
|
import core, { Doc, Ref, SortingOrder, Space, getCurrentAccount } from '@anticrm/core'
|
2022-02-03 09:03:53 +00:00
|
|
|
import { getResource } from '@anticrm/platform'
|
2022-03-04 09:04:21 +00:00
|
|
|
import { createQuery, getClient } from '@anticrm/presentation'
|
2022-02-03 09:03:53 +00:00
|
|
|
import { Scroller } from '@anticrm/ui'
|
|
|
|
import type { NavigatorModel, SpecialNavModel } from '@anticrm/workbench'
|
|
|
|
import { createEventDispatcher } from 'svelte'
|
2022-04-14 05:30:30 +00:00
|
|
|
import preferece, { SpacePreference } from '@anticrm/preference'
|
2022-03-04 09:01:46 +00:00
|
|
|
import { getSpecialSpaceClass } from '../utils'
|
2022-04-14 05:30:30 +00:00
|
|
|
import preference from '@anticrm/preference'
|
2021-08-06 08:31:17 +00:00
|
|
|
import SpacesNav from './navigator/SpacesNav.svelte'
|
2021-11-22 12:06:14 +00:00
|
|
|
import SpecialElement from './navigator/SpecialElement.svelte'
|
2022-04-14 05:30:30 +00:00
|
|
|
import StarredNav from './navigator/StarredNav.svelte'
|
2022-02-03 09:03:53 +00:00
|
|
|
import TreeSeparator from './navigator/TreeSeparator.svelte'
|
2021-08-06 08:31:17 +00:00
|
|
|
|
|
|
|
export let model: NavigatorModel | undefined
|
2022-02-03 09:03:53 +00:00
|
|
|
export let currentSpace: Ref<Space> | undefined
|
|
|
|
export let currentSpecial: string | undefined
|
2022-04-14 05:30:30 +00:00
|
|
|
|
2022-03-04 09:04:21 +00:00
|
|
|
const client = getClient()
|
|
|
|
const hierarchy = client.getHierarchy()
|
2021-12-21 09:08:22 +00:00
|
|
|
const query = createQuery()
|
2022-04-22 03:13:15 +00:00
|
|
|
const myAccId = getCurrentAccount()._id
|
2022-04-14 05:30:30 +00:00
|
|
|
|
2022-02-03 09:03:53 +00:00
|
|
|
let spaces: Space[] = []
|
2022-04-14 05:30:30 +00:00
|
|
|
let starred: Space[] = []
|
2022-02-03 09:03:53 +00:00
|
|
|
let shownSpaces: Space[] = []
|
2022-04-14 05:30:30 +00:00
|
|
|
|
2021-12-21 09:08:22 +00:00
|
|
|
$: if (model) {
|
|
|
|
query.query(
|
|
|
|
core.class.Space,
|
|
|
|
{
|
2022-03-04 09:01:46 +00:00
|
|
|
_class: { $in: getSpecialSpaceClass(model) }
|
2022-04-21 15:47:04 +00:00
|
|
|
// temp disabled, need way for default spaces
|
|
|
|
// members: getCurrentAccount()._id
|
|
|
|
},
|
|
|
|
(result) => {
|
|
|
|
spaces = result
|
2021-12-21 09:08:22 +00:00
|
|
|
},
|
2022-04-21 15:47:04 +00:00
|
|
|
{ sort: { name: SortingOrder.Ascending } }
|
|
|
|
)
|
2021-12-21 09:08:22 +00:00
|
|
|
}
|
2021-11-22 12:06:14 +00:00
|
|
|
|
2022-05-11 05:36:35 +00:00
|
|
|
let specials: SpecialNavModel[] = []
|
2022-02-03 09:03:53 +00:00
|
|
|
|
2022-04-14 05:30:30 +00:00
|
|
|
let preferences: Map<Ref<Doc>, SpacePreference> = new Map<Ref<Doc>, SpacePreference>()
|
|
|
|
|
|
|
|
const preferenceQuery = createQuery()
|
|
|
|
|
|
|
|
preferenceQuery.query(preferece.class.SpacePreference, {}, (res) => {
|
2022-04-21 15:47:04 +00:00
|
|
|
preferences = new Map(
|
|
|
|
res.map((r) => {
|
|
|
|
return [r.attachedTo, r]
|
|
|
|
})
|
|
|
|
)
|
2022-04-14 05:30:30 +00:00
|
|
|
})
|
|
|
|
|
2022-04-29 05:27:17 +00:00
|
|
|
async function update (model: NavigatorModel, spaces: Space[], preferences: Map<Ref<Doc>, SpacePreference>) {
|
2022-02-03 09:03:53 +00:00
|
|
|
if (model.specials !== undefined) {
|
2022-05-11 05:36:35 +00:00
|
|
|
const sp = await updateSpecials(model.specials, spaces)
|
|
|
|
const topSpecials = sp.get('top') ?? []
|
|
|
|
const bottomSpecials = sp.get('bottom') ?? []
|
|
|
|
sp.delete('top')
|
|
|
|
sp.delete('bottom')
|
|
|
|
|
|
|
|
const result = [...topSpecials]
|
|
|
|
|
|
|
|
for (const k of Array.from(sp.keys()).sort()) {
|
|
|
|
result.push(...(sp.get(k) ?? []))
|
|
|
|
}
|
|
|
|
|
|
|
|
result.push(...bottomSpecials)
|
|
|
|
specials = result
|
2022-02-09 09:06:53 +00:00
|
|
|
} else {
|
2022-05-11 05:36:35 +00:00
|
|
|
specials = []
|
2022-01-21 09:07:24 +00:00
|
|
|
}
|
2022-04-29 05:27:17 +00:00
|
|
|
shownSpaces = spaces.filter(
|
|
|
|
(sp) => !sp.archived && !preferences.has(sp._id) && (!sp.members.length || sp.members.includes(myAccId))
|
|
|
|
)
|
2022-04-14 05:30:30 +00:00
|
|
|
starred = spaces.filter((sp) => preferences.has(sp._id))
|
2022-01-21 09:07:24 +00:00
|
|
|
}
|
|
|
|
|
2022-04-14 05:30:30 +00:00
|
|
|
$: if (model) update(model, spaces, preferences)
|
|
|
|
|
2022-05-11 05:36:35 +00:00
|
|
|
async function updateSpecials (specials: SpecialNavModel[], spaces: Space[]): Promise<Map<string, SpecialNavModel[]>> {
|
|
|
|
const result = new Map<string, SpecialNavModel[]>()
|
2022-02-03 09:03:53 +00:00
|
|
|
for (const sp of specials) {
|
2022-05-11 05:36:35 +00:00
|
|
|
const pos = sp.position ?? 'top'
|
|
|
|
let visible = true
|
|
|
|
if (sp.visibleIf !== undefined) {
|
|
|
|
const f = await getResource(sp.visibleIf)
|
|
|
|
visible = f(spaces)
|
|
|
|
}
|
|
|
|
if (visible) {
|
|
|
|
const list = result.get(pos) ?? []
|
|
|
|
list.push(sp)
|
|
|
|
result.set(pos, list)
|
2022-02-03 09:03:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result
|
2021-12-30 09:04:32 +00:00
|
|
|
}
|
2022-02-03 09:03:53 +00:00
|
|
|
const dispatch = createEventDispatcher()
|
2021-08-06 08:31:17 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
{#if model}
|
2022-01-21 09:07:24 +00:00
|
|
|
<Scroller>
|
|
|
|
{#if model.specials}
|
2022-05-11 05:36:35 +00:00
|
|
|
{#each specials as special, row}
|
|
|
|
{#if row > 0 && specials[row].position !== specials[row - 1].position}
|
|
|
|
<TreeSeparator />
|
|
|
|
{/if}
|
2022-04-21 15:47:04 +00:00
|
|
|
<SpecialElement
|
|
|
|
label={special.label}
|
|
|
|
icon={special.icon}
|
|
|
|
on:click={() => dispatch('special', special.id)}
|
|
|
|
selected={special.id === currentSpecial}
|
|
|
|
indent={'ml-2'}
|
|
|
|
/>
|
2022-04-02 04:06:48 +00:00
|
|
|
{/each}
|
2022-01-21 09:07:24 +00:00
|
|
|
{/if}
|
|
|
|
|
2022-05-11 05:36:35 +00:00
|
|
|
{#if specials.length > 0}<TreeSeparator />{/if}
|
2022-01-21 09:07:24 +00:00
|
|
|
|
2022-04-14 05:30:30 +00:00
|
|
|
{#if starred.length}
|
|
|
|
<StarredNav label={preference.string.Starred} spaces={starred} on:space {currentSpace} />
|
|
|
|
{/if}
|
|
|
|
|
2022-01-21 09:07:24 +00:00
|
|
|
{#each model.spaces as m (m.label)}
|
2022-04-21 15:47:04 +00:00
|
|
|
<SpacesNav
|
|
|
|
spaces={shownSpaces.filter((it) => hierarchy.isDerived(it._class, m.spaceClass))}
|
|
|
|
{currentSpace}
|
|
|
|
hasSpaceBrowser={model.specials?.find((p) => p.id === 'spaceBrowser') !== undefined}
|
|
|
|
model={m}
|
|
|
|
on:space
|
2022-04-27 05:50:07 +00:00
|
|
|
on:open
|
2022-04-21 15:47:04 +00:00
|
|
|
{currentSpecial}
|
|
|
|
/>
|
2021-12-30 09:04:32 +00:00
|
|
|
{/each}
|
2022-01-21 09:07:24 +00:00
|
|
|
<div class="antiNav-space" />
|
|
|
|
</Scroller>
|
2021-08-06 08:31:17 +00:00
|
|
|
{/if}
|