Space presenter (#3100)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2023-04-28 07:59:25 +06:00 committed by GitHub
parent f839c072ff
commit c5a4af2be1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 92 additions and 46 deletions

View File

@ -923,6 +923,10 @@ export function createModel (builder: Builder): void {
presenter: tracker.component.ProjectPresenter presenter: tracker.component.ProjectPresenter
}) })
builder.mixin(tracker.class.Project, core.class.Class, view.mixin.SpacePresenter, {
presenter: tracker.component.ProjectSpacePresenter
})
classPresenter( classPresenter(
builder, builder,
tracker.class.Component, tracker.class.Component,

View File

@ -57,6 +57,7 @@ import type {
ObjectValidator, ObjectValidator,
PreviewPresenter, PreviewPresenter,
SortFunc, SortFunc,
SpacePresenter,
SpaceHeader, SpaceHeader,
SpaceName, SpaceName,
ViewAction, ViewAction,
@ -170,6 +171,11 @@ export class TActivityAttributePresenter extends TClass implements ActivityAttri
presenter!: AnyComponent presenter!: AnyComponent
} }
@Mixin(view.mixin.SpacePresenter, core.class.Class)
export class TSpacePresenter extends TClass implements SpacePresenter {
presenter!: AnyComponent
}
@Mixin(view.mixin.ObjectPresenter, core.class.Class) @Mixin(view.mixin.ObjectPresenter, core.class.Class)
export class TObjectPresenter extends TClass implements ObjectPresenter { export class TObjectPresenter extends TClass implements ObjectPresenter {
presenter!: AnyComponent presenter!: AnyComponent
@ -369,6 +375,7 @@ export function createModel (builder: Builder): void {
TObjectEditorFooter, TObjectEditorFooter,
TSpaceHeader, TSpaceHeader,
TSpaceName, TSpaceName,
TSpacePresenter,
TIgnoreActions, TIgnoreActions,
TPreviewPresenter, TPreviewPresenter,
TLinkPresenter, TLinkPresenter,

View File

@ -1,5 +1,5 @@
<!-- <!--
// Copyright © 2022 Hardcore Engineering Inc. // Copyright © 2023 Hardcore Engineering Inc.
// //
// Licensed under the Eclipse Public License, Version 2.0 (the "License"); // 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 // you may not use this file except in compliance with the License. You may
@ -13,31 +13,17 @@
// limitations under the License. // limitations under the License.
--> -->
<script lang="ts"> <script lang="ts">
import { Ref, Space } from '@hcengineering/core' import tracker, { Project } from '@hcengineering/tracker'
import { Project } from '@hcengineering/tracker' import { Icon } from '@hcengineering/ui'
import { TreeNode, NavLink } from '@hcengineering/view-resources'
import { SpacesNavModel } from '@hcengineering/workbench'
import { SpecialElement } from '@hcengineering/workbench-resources'
export let space: Project export let value: Project
export let model: SpacesNavModel
export let currentSpace: Ref<Space> | undefined
export let currentSpecial: string | undefined
export let getActions: Function
export let deselect: boolean = false
</script> </script>
{#if model?.specials} <div class="flex-presenter cursor-default inline-presenter">
<TreeNode icon={space?.icon ?? model.icon} title={space.name} actions={() => getActions(space)}> <div class="icon">
{#each model.specials as special} <Icon icon={value.icon ?? tracker.icon.Home} size="small" />
<NavLink space={space._id} special={special.id}> </div>
<SpecialElement <span class="label no-underline nowrap">
indent={'ml-2'} {value.name}
label={special.label} </span>
icon={special.icon} </div>
selected={deselect ? false : currentSpace === space._id && special.id === currentSpecial}
/>
</NavLink>
{/each}
</TreeNode>
{/if}

View File

@ -0,0 +1,43 @@
<!--
// Copyright © 2022 Hardcore Engineering Inc.
//
// 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">
import { Ref, Space } from '@hcengineering/core'
import { Project } from '@hcengineering/tracker'
import { TreeNode, NavLink } from '@hcengineering/view-resources'
import { SpacesNavModel } from '@hcengineering/workbench'
import { SpecialElement } from '@hcengineering/workbench-resources'
export let space: Project
export let model: SpacesNavModel
export let currentSpace: Ref<Space> | undefined
export let currentSpecial: string | undefined
export let getActions: Function
export let deselect: boolean = false
</script>
{#if model.specials}
<TreeNode icon={space?.icon ?? model.icon} title={space.name} actions={() => getActions(space)}>
{#each model.specials as special}
<NavLink space={space._id} special={special.id}>
<SpecialElement
indent={'ml-2'}
label={special.label}
icon={special.icon}
selected={deselect ? false : currentSpace === space._id && special.id === currentSpecial}
/>
</NavLink>
{/each}
</TreeNode>
{/if}

View File

@ -128,6 +128,7 @@ import StatusRefPresenter from './components/issues/StatusRefPresenter.svelte'
import TimeSpendReportPopup from './components/issues/timereport/TimeSpendReportPopup.svelte' import TimeSpendReportPopup from './components/issues/timereport/TimeSpendReportPopup.svelte'
import CreateProject from './components/projects/CreateProject.svelte' import CreateProject from './components/projects/CreateProject.svelte'
import ProjectPresenter from './components/projects/ProjectPresenter.svelte' import ProjectPresenter from './components/projects/ProjectPresenter.svelte'
import ProjectSpacePresenter from './components/projects/ProjectSpacePresenter.svelte'
import MoveIssues from './components/issues/Move.svelte' import MoveIssues from './components/issues/Move.svelte'
import IssueStatistics from './components/sprints/IssueStatistics.svelte' import IssueStatistics from './components/sprints/IssueStatistics.svelte'
import SprintRefPresenter from './components/sprints/SprintRefPresenter.svelte' import SprintRefPresenter from './components/sprints/SprintRefPresenter.svelte'
@ -433,6 +434,7 @@ export default async (): Promise<Resources> => ({
TemplateEstimationEditor, TemplateEstimationEditor,
CreateProject, CreateProject,
ProjectPresenter, ProjectPresenter,
ProjectSpacePresenter,
IssueStatistics, IssueStatistics,
StatusRefPresenter, StatusRefPresenter,
RelatedIssuesSection, RelatedIssuesSection,

View File

@ -336,6 +336,7 @@ export default mergeIds(trackerId, tracker, {
DueDatePresenter: '' as AnyComponent, DueDatePresenter: '' as AnyComponent,
EditIssueTemplate: '' as AnyComponent, EditIssueTemplate: '' as AnyComponent,
CreateProject: '' as AnyComponent, CreateProject: '' as AnyComponent,
ProjectSpacePresenter: '' as AnyComponent,
ProjectPresenter: '' as AnyComponent, ProjectPresenter: '' as AnyComponent,
NewIssueHeader: '' as AnyComponent, NewIssueHeader: '' as AnyComponent,
IconPresenter: '' as AnyComponent, IconPresenter: '' as AnyComponent,

View File

@ -166,6 +166,13 @@ export interface ActivityAttributePresenter extends Class<Doc> {
presenter: AnyComponent presenter: AnyComponent
} }
/**
* @public
*/
export interface SpacePresenter extends Class<Doc> {
presenter: AnyComponent
}
/** /**
* @public * @public
*/ */
@ -627,7 +634,8 @@ const view = plugin(viewId, {
SortFuncs: '' as Ref<Mixin<ClassSortFuncs>>, SortFuncs: '' as Ref<Mixin<ClassSortFuncs>>,
AllValuesFunc: '' as Ref<Mixin<AllValuesFunc>>, AllValuesFunc: '' as Ref<Mixin<AllValuesFunc>>,
ObjectPanel: '' as Ref<Mixin<ObjectPanel>>, ObjectPanel: '' as Ref<Mixin<ObjectPanel>>,
LinkProvider: '' as Ref<Mixin<LinkProvider>> LinkProvider: '' as Ref<Mixin<LinkProvider>>,
SpacePresenter: '' as Ref<Mixin<SpacePresenter>>
}, },
class: { class: {
ViewletPreference: '' as Ref<Class<ViewletPreference>>, ViewletPreference: '' as Ref<Class<ViewletPreference>>,

View File

@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
--> -->
<script lang="ts"> <script lang="ts">
import type { Doc, Ref, Space } from '@hcengineering/core' import type { Class, Doc, Ref, Space } from '@hcengineering/core'
import core from '@hcengineering/core' import core from '@hcengineering/core'
import notification, { LastView } from '@hcengineering/notification' import notification, { LastView } from '@hcengineering/notification'
import { NotificationClientImpl } from '@hcengineering/notification-resources' import { NotificationClientImpl } from '@hcengineering/notification-resources'
@ -22,20 +22,16 @@
import { getClient } from '@hcengineering/presentation' import { getClient } from '@hcengineering/presentation'
import { import {
Action, Action,
AnySvelteComponent,
IconAdd, IconAdd,
IconEdit, IconEdit,
IconSearch, IconSearch,
navigate,
getCurrentResolvedLocation, getCurrentResolvedLocation,
navigate,
showPopup showPopup
} from '@hcengineering/ui' } from '@hcengineering/ui'
import { import view from '@hcengineering/view'
NavLink, import { NavLink, TreeItem, TreeNode, getActions as getContributedActions } from '@hcengineering/view-resources'
TreeItem,
TreeNode,
getActions as getContributedActions,
getObjectPresenter
} from '@hcengineering/view-resources'
import { SpacesNavModel } from '@hcengineering/workbench' import { SpacesNavModel } from '@hcengineering/workbench'
import { createEventDispatcher } from 'svelte' import { createEventDispatcher } from 'svelte'
import plugin from '../../plugin' import plugin from '../../plugin'
@ -121,6 +117,13 @@
function getParentActions (): Action[] { function getParentActions (): Action[] {
return hasSpaceBrowser ? [browseSpaces, addSpace] : [addSpace] return hasSpaceBrowser ? [browseSpaces, addSpace] : [addSpace]
} }
async function getPresenter (_class: Ref<Class<Doc>>): Promise<AnySvelteComponent | undefined> {
const value = hierarchy.classHierarchyMixin(_class, view.mixin.SpacePresenter)
if (value?.presenter !== undefined) {
return await getResource(value.presenter)
}
}
</script> </script>
<TreeNode <TreeNode
@ -130,18 +133,10 @@
shortDropbox={model.specials !== undefined} shortDropbox={model.specials !== undefined}
> >
{#each spaces as space, i (space._id)} {#each spaces as space, i (space._id)}
{#await getObjectPresenter(client, space._class, { key: '' }) then presenter} {#await getPresenter(space._class) then presenter}
{#if separate && model.specials && i !== 0}<TreeSeparator line />{/if} {#if separate && model.specials && i !== 0}<TreeSeparator line />{/if}
{#if model.specials && presenter} {#if model.specials && presenter}
<svelte:component <svelte:component this={presenter} {space} {model} {currentSpace} {currentSpecial} {getActions} {deselect} />
this={presenter.presenter}
{space}
{model}
{currentSpace}
{currentSpecial}
{getActions}
{deselect}
/>
{:else} {:else}
<NavLink space={space._id}> <NavLink space={space._id}>
{#await getSpaceName(client, space) then name} {#await getSpaceName(client, space) then name}