2022-06-08 14:03:26 +00:00
|
|
|
<script lang="ts">
|
2022-06-16 10:33:52 +00:00
|
|
|
import { DocumentQuery, Ref, SortingOrder, WithLookup } from '@anticrm/core'
|
2022-06-08 14:03:26 +00:00
|
|
|
import { Component } from '@anticrm/ui'
|
2022-06-16 10:33:52 +00:00
|
|
|
import { BuildModelKey, Viewlet, ViewletPreference } from '@anticrm/view'
|
|
|
|
import { Issue, IssueStatus, Team, ViewOptions } from '@anticrm/tracker'
|
|
|
|
import tracker from '../../plugin'
|
|
|
|
import { createQuery } from '@anticrm/presentation'
|
2022-06-08 14:03:26 +00:00
|
|
|
|
|
|
|
export let currentSpace: Ref<Team>
|
2022-06-16 10:33:52 +00:00
|
|
|
export let viewlet: WithLookup<Viewlet>
|
2022-06-15 18:04:37 +00:00
|
|
|
export let query: DocumentQuery<Issue> = {}
|
2022-06-10 09:44:46 +00:00
|
|
|
export let viewOptions: ViewOptions
|
2022-06-16 10:33:52 +00:00
|
|
|
|
|
|
|
const statusesQuery = createQuery()
|
|
|
|
const spaceQuery = createQuery()
|
|
|
|
let currentTeam: Team | undefined
|
|
|
|
let statusesById: ReadonlyMap<Ref<IssueStatus>, WithLookup<IssueStatus>> = new Map()
|
|
|
|
|
|
|
|
$: statusesQuery.query(
|
|
|
|
tracker.class.IssueStatus,
|
|
|
|
{ attachedTo: currentSpace },
|
|
|
|
(issueStatuses) => {
|
|
|
|
statusesById = new Map(issueStatuses.map((status) => [status._id, status]))
|
|
|
|
},
|
|
|
|
{
|
|
|
|
lookup: { category: tracker.class.IssueStatusCategory },
|
|
|
|
sort: { rank: SortingOrder.Ascending }
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
$: spaceQuery.query(tracker.class.Team, { _id: currentSpace }, (res) => {
|
|
|
|
currentTeam = res.shift()
|
|
|
|
})
|
|
|
|
|
|
|
|
$: statuses = [...statusesById.values()]
|
|
|
|
|
|
|
|
const replacedKeys: Map<string, BuildModelKey> = new Map<string, BuildModelKey>([
|
|
|
|
['@currentTeam', { key: '', presenter: tracker.component.IssuePresenter, props: { currentTeam } }],
|
|
|
|
['@statuses', { key: '', presenter: tracker.component.StatusEditor, props: { statuses } }]
|
|
|
|
])
|
|
|
|
|
|
|
|
function createConfig (descr: Viewlet, preference: ViewletPreference | undefined): (string | BuildModelKey)[] {
|
|
|
|
const base = preference?.config ?? descr.config
|
|
|
|
const result: (string | BuildModelKey)[] = []
|
|
|
|
for (const key of base) {
|
|
|
|
if (typeof key === 'string') {
|
|
|
|
result.push(replacedKeys.get(key) ?? key)
|
|
|
|
} else {
|
|
|
|
result.push(replacedKeys.get(key.key) ?? key)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
2022-06-08 14:03:26 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
{#if viewlet?.$lookup?.descriptor?.component}
|
|
|
|
<Component
|
|
|
|
is={viewlet.$lookup?.descriptor?.component}
|
|
|
|
props={{
|
|
|
|
currentSpace,
|
2022-06-16 10:33:52 +00:00
|
|
|
config: createConfig(viewlet, undefined),
|
2022-06-08 14:03:26 +00:00
|
|
|
options: viewlet.options,
|
|
|
|
viewlet,
|
|
|
|
query,
|
|
|
|
viewOptions
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
{/if}
|