EZQMS-1393: implemented folders in controlled documents (#7803)

* EZQMS-1393: implemented folders in controlled documents

Signed-off-by: Victor Ilyushchenko <alt13ri@gmail.com>

* formatting

Signed-off-by: Victor Ilyushchenko <alt13ri@gmail.com>

---------

Signed-off-by: Victor Ilyushchenko <alt13ri@gmail.com>
This commit is contained in:
Victor Ilyushchenko
2025-01-28 10:02:13 +03:00
committed by GitHub
parent f8a8c94bc2
commit 40931c81ca
21 changed files with 633 additions and 83 deletions
@@ -0,0 +1,83 @@
<!--
//
// Copyright © 2025 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 documents, {
createNewFolder,
DocumentMeta,
type DocumentSpace,
type Project,
type ProjectDocument
} from '@hcengineering/controlled-documents'
import core, { Ref } from '@hcengineering/core'
import { Card, getClient } from '@hcengineering/presentation'
import { EditBox, FocusHandler, createFocusManager } from '@hcengineering/ui'
import view from '@hcengineering/view'
import { createEventDispatcher } from 'svelte'
export function canClose (): boolean {
return name === ''
}
export let folder: DocumentMeta | undefined
export let name: string = ''
export let space: Ref<DocumentSpace> | undefined
export let project: Ref<Project<DocumentSpace>> | undefined
export let parent: Ref<ProjectDocument> | undefined
const dispatch = createEventDispatcher()
const client = getClient()
$: canSave = getTitle(name).length > 0 && (folder !== undefined || space !== undefined)
function getTitle (value: string): string {
return value.trim()
}
async function create (): Promise<void> {
const title = getTitle(name)
if (title.length < 1) {
return
}
if (folder !== undefined) {
await client.update(folder, { title })
} else if (space !== undefined) {
await createNewFolder(client, space, project ?? documents.ids.NoProject, parent, title)
}
dispatch('close')
}
const manager = createFocusManager()
</script>
<FocusHandler {manager} />
<Card
label={folder ? documents.string.RenameFolder : documents.string.CreateFolder}
okAction={create}
accentHeader
{canSave}
on:close={() => {
dispatch('close')
}}
on:changeContent
>
<div class="flex-row-center clear-mins">
<EditBox placeholder={core.string.Name} bind:value={name} autoFocus focusIndex={1} />
</div>
</Card>
@@ -14,7 +14,7 @@
-->
<script lang="ts">
import { createEventDispatcher } from 'svelte'
import { type Ref, type Doc, SortingOrder, getCurrentAccount, WithLookup } from '@hcengineering/core'
import { type Ref, type Doc, SortingOrder, getCurrentAccount, WithLookup, toIdMap } from '@hcengineering/core'
import { createQuery } from '@hcengineering/presentation'
import type { PersonAccount } from '@hcengineering/contact'
import { type Action } from '@hcengineering/ui'
@@ -80,6 +80,11 @@
let lastSeqNumber = -1
for (const prjdoc of result) {
if (prjdoc.document === documents.ids.Folder) {
docs.push(prjdoc)
continue
}
const doc = prjdoc.$lookup?.document as ControlledDocument | undefined
if (doc === undefined) continue
if (doc.state === DocumentState.Deleted) continue
@@ -120,29 +125,45 @@
}
)
let docsMeta: DocumentMeta[] = []
const metaQuery = createQuery()
$: metaQuery.query(documents.class.DocumentMeta, { _id: { $in: projectMeta.map((p) => p.meta) } }, (result) => {
docsMeta = result
})
async function getDocMoreActions (obj: Doc): Promise<Action[]> {
return getMoreActions !== undefined ? await getMoreActions(obj) : []
}
$: projectMetaById = toIdMap(projectMeta)
$: docsMetaById = toIdMap(docsMeta)
</script>
{#each docs as prjdoc}
{@const pjmeta = projectMetaById.get(prjdoc.attachedTo)}
{@const doc = prjdoc.$lookup?.document}
{@const metaid = pjmeta?.meta}
{@const meta = metaid ? docsMetaById.get(metaid) : undefined}
{@const title = doc ? getDocumentName(doc) : meta?.title ?? ''}
{@const docid = doc?._id ?? prjdoc._id}
{@const isFolder = prjdoc.document === documents.ids.Folder}
{#if doc}
{@const children = childrenByParent[doc.attachedTo] ?? []}
{@const isDraggedOver = draggedOver === doc.attachedTo}
{#if metaid}
{@const children = childrenByParent[metaid] ?? []}
{@const isDraggedOver = draggedOver === metaid}
<div class="flex-col relative">
{#if isDraggedOver}
<DropArea />
{/if}
<TreeItem
_id={doc._id}
icon={documents.icon.Document}
_id={docid}
icon={isFolder ? documents.icon.Folder : documents.icon.Document}
iconProps={{
fill: 'currentColor'
}}
title={getDocumentName(doc)}
selected={selected === doc._id || selected === prjdoc._id}
{title}
selected={selected === docid || selected === prjdoc._id}
isFold
empty={children.length === 0 || children === undefined}
actions={getMoreActions !== undefined ? () => getDocMoreActions(prjdoc) : undefined}
@@ -154,16 +175,16 @@
}}
draggable={onDragStart !== undefined}
on:dragstart={(evt) => {
onDragStart?.(evt, doc.attachedTo)
onDragStart?.(evt, metaid)
}}
on:dragover={(evt) => {
onDragOver?.(evt, doc.attachedTo)
onDragOver?.(evt, metaid)
}}
on:dragend={(evt) => {
onDragEnd?.(evt, doc.attachedTo)
onDragEnd?.(evt, metaid)
}}
on:drop={(evt) => {
onDrop?.(evt, doc.attachedTo)
onDrop?.(evt, metaid)
}}
>
<svelte:fragment slot="dropbox">
@@ -51,7 +51,9 @@
canCreateChildDocument,
moveDocument,
moveDocumentBefore,
moveDocumentAfter
moveDocumentAfter,
canCreateChildFolder,
createFolder
} from '../../utils'
import documents from '../../plugin'
@@ -178,6 +180,21 @@
})
}
if (
spaceType?.projects === true &&
(await isEditableProject(project)) &&
(await canCreateChildFolder(space, true))
) {
actions.push({
icon: documents.icon.Folder,
label: documents.string.CreateFolder,
group: 'create',
action: async () => {
await createFolder(space)
}
})
}
return orderActions(actions)
}