Skip to content

Commit

Permalink
Drive to cards (#6841)
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Bykhov <[email protected]>
  • Loading branch information
BykhovDenis authored Oct 8, 2024
1 parent 30c08f4 commit 62e330d
Show file tree
Hide file tree
Showing 25 changed files with 117 additions and 70 deletions.
12 changes: 6 additions & 6 deletions models/drive/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import {
TypeTimestamp,
UX
} from '@hcengineering/model'
import { TAttachedDoc, TDoc, TType, TTypedSpace } from '@hcengineering/model-core'
import { TAttachedDoc, TCard, TType, TTypedSpace } from '@hcengineering/model-core'
import presentation from '@hcengineering/model-presentation'
import print from '@hcengineering/model-print'
import tracker from '@hcengineering/model-tracker'
Expand Down Expand Up @@ -84,19 +84,19 @@ export class TDefaultDriveTypeData extends TDrive implements RolesAssignment {
[key: Ref<Role>]: Ref<Account>[]
}

@Model(drive.class.Resource, core.class.Doc, DOMAIN_DRIVE)
@Model(drive.class.Resource, core.class.Card, DOMAIN_DRIVE)
@UX(drive.string.Resource)
export class TResource extends TDoc implements Resource {
export class TResource extends TCard implements Resource {
declare space: Ref<Drive>

@Prop(TypeString(), drive.string.Name)
@Index(IndexKind.FullText)
name!: string
declare title: string

@Prop(TypeRef(drive.class.Resource), drive.string.Parent)
@Index(IndexKind.Indexed)
@ReadOnly()
parent!: Ref<Resource>
declare parent: Ref<Resource>

@Prop(TypeRef(drive.class.Resource), drive.string.Path)
@ReadOnly()
Expand Down Expand Up @@ -169,7 +169,7 @@ export class TFileVersion extends TAttachedDoc implements FileVersion {

@Prop(TypeString(), drive.string.Name)
@Index(IndexKind.FullText)
name!: string
title!: string

@Prop(TypeRef(core.class.Blob), drive.string.File)
@ReadOnly()
Expand Down
46 changes: 43 additions & 3 deletions models/drive/src/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//

import core, { type Blob, type Ref, DOMAIN_BLOB, generateId, toIdMap } from '@hcengineering/core'
import type { File, FileVersion } from '@hcengineering/drive'
import type { Drive, File, FileVersion, Resource } from '@hcengineering/drive'
import {
type MigrateOperation,
type MigrationClient,
Expand Down Expand Up @@ -56,8 +56,8 @@ async function migrateFileVersions (client: MigrationClient): Promise<void> {
collection: 'versions',
modifiedOn: file.modifiedOn,
modifiedBy: file.modifiedBy,
space: file.space,
name: exfile.name,
space: file.space as Ref<Drive>,
title: exfile.title,
file: blob._id,
size: blob.size,
lastModified: blob.modifiedOn,
Expand Down Expand Up @@ -86,12 +86,52 @@ async function migrateFileVersions (client: MigrationClient): Promise<void> {
}
}

async function renameFields (client: MigrationClient): Promise<void> {
const resources = await client.find<Resource>(DOMAIN_DRIVE, {
_class: { $in: [drive.class.Resource, drive.class.File, drive.class.Folder] },
name: { $exists: true }
})

for (const resource of resources) {
await client.update(
DOMAIN_DRIVE,
{ _id: resource._id },
{
$rename: {
name: 'title'
}
}
)
}

const versions = await client.find<FileVersion>(DOMAIN_DRIVE, {
_class: drive.class.FileVersion,
name: { $exists: true }
})

for (const version of versions) {
await client.update(
DOMAIN_DRIVE,
{ _id: version._id },
{
$rename: {
name: 'title'
}
}
)
}
}

export const driveOperation: MigrateOperation = {
async migrate (client: MigrationClient): Promise<void> {
await tryMigrate(client, driveId, [
{
state: 'file-versions',
func: migrateFileVersions
},
{
state: 'renameFields',
func: renameFields
}
])
},
Expand Down
4 changes: 2 additions & 2 deletions models/server-drive/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ export function createModel (builder: Builder): void {
builder.mixin(drive.class.File, core.class.Class, serverCore.mixin.SearchPresenter, {
searchConfig: {
icon: drive.icon.File,
title: 'name'
title: 'title'
}
})

builder.mixin(drive.class.Folder, core.class.Class, serverCore.mixin.SearchPresenter, {
searchConfig: {
icon: drive.icon.Folder,
title: 'name'
title: 'title'
}
})
}
2 changes: 1 addition & 1 deletion packages/core/src/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export interface Doc<S extends Space = Space> extends Obj {

export interface Card extends Doc {
title: string
description: CollaborativeDoc | null
description?: CollaborativeDoc | null
identifier?: string
parent?: Ref<Card> | null
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/drive-resources/src/components/CreateFolder.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
}
const data: Omit<Data<Folder>, 'path'> = {
name: getTitle(name),
title: getTitle(name),
parent: _parent ?? drive.ids.Root
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
let descendants: Map<Ref<Folder>, Folder[]> = new Map<Ref<Folder>, Folder[]>()
function getDescendants (obj: Ref<Folder>): Ref<Folder>[] {
return (descendants.get(obj) ?? []).sort((a, b) => a.name.localeCompare(b.name)).map((p) => p._id)
return (descendants.get(obj) ?? []).sort((a, b) => a.title.localeCompare(b.title)).map((p) => p._id)
}
let selected: Ref<Doc> | undefined
Expand Down Expand Up @@ -134,7 +134,7 @@
_id={folder._id}
folderIcon
iconProps={{ fill: 'var(--global-accent-IconColor)' }}
title={folder.name}
title={folder.title}
selected
isFold
empty
Expand Down
2 changes: 1 addition & 1 deletion plugins/drive-resources/src/components/EditFile.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</script>

{#if object !== undefined && version !== undefined && blob !== undefined && contentType !== undefined}
<FilePreview file={blob} {contentType} name={version.name} metadata={version.metadata} fit />
<FilePreview file={blob} {contentType} name={version.title} metadata={version.metadata} fit />

{#if object.versions > 1}
<div class="w-full mt-6">
Expand Down
9 changes: 7 additions & 2 deletions plugins/drive-resources/src/components/EditFolder.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@
// limitations under the License.
-->
<script lang="ts">
import { type Folder } from '@hcengineering/drive'
import { type Drive, type Folder } from '@hcengineering/drive'
import { type Ref } from '@hcengineering/core'
import FolderBrowser from './FolderBrowser.svelte'
export let object: Folder
export let readonly: boolean = false
function getSpace (object: Folder): Ref<Drive> {
return object.space as Ref<Drive>
}
</script>

{#if object}
<FolderBrowser space={object.space} parent={object._id} {readonly} type={'folder'} />
<FolderBrowser space={getSpace(object)} parent={object._id} {readonly} type={'folder'} />
{/if}
2 changes: 1 addition & 1 deletion plugins/drive-resources/src/components/FileDropArea.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.
-->
<script lang="ts">
import { type Ref } from '@hcengineering/core'
import { type Ref, type Space } from '@hcengineering/core'
import { type Drive, type Folder } from '@hcengineering/drive'
import { uploadFilesToDrive } from '../utils'
Expand Down
4 changes: 2 additions & 2 deletions plugins/drive-resources/src/components/FilePanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
async (uuid, name, file, path, metadata) => {
const data = {
file: uuid,
name,
title: name,
size: file.size,
type: file.type,
lastModified: file instanceof File ? file.lastModified : Date.now(),
Expand Down Expand Up @@ -108,7 +108,7 @@
</svelte:fragment>

<svelte:fragment slot="utils">
<a class="no-line" href={getFileUrl(version.file, object.name)} download={object.name} bind:this={download}>
<a class="no-line" href={getFileUrl(version.file, object.title)} download={object.title} bind:this={download}>
<Button
icon={IconDownload}
iconProps={{ size: 'medium' }}
Expand Down
8 changes: 4 additions & 4 deletions plugins/drive-resources/src/components/FilePresenter.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@
<ObjectMention object={value} {disabled} {accent} {noUnderline} />
{:else if type === 'link'}
<DocNavLink object={value} {disabled} {accent} {noUnderline}>
<div class="flex-presenter" use:tooltip={{ label: getEmbeddedLabel(value.name) }}>
<div class="flex-presenter" use:tooltip={{ label: getEmbeddedLabel(value.title) }}>
{#if shouldShowAvatar}
<div class="icon">
<Icon {icon} size={'small'} />
</div>
{/if}
<div class="label nowrap flex flex-gap-2" class:no-underline={noUnderline || disabled} class:fs-bold={accent}>
<span>{value.name}</span>
<span>{value.title}</span>
{#if shouldShowVersion}
<span>•</span>
<span>{formatFileVersion(value.version)}</span>
Expand All @@ -58,8 +58,8 @@
</div>
</DocNavLink>
{:else if type === 'text'}
<span class="overflow-label" use:tooltip={{ label: getEmbeddedLabel(value.name) }}>
{value.name}
<span class="overflow-label" use:tooltip={{ label: getEmbeddedLabel(value.title) }}>
{value.title}
</span>
{/if}
{/if}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
<Icon {icon} size={'medium'} />
</div>
<span class="overflow-label">
{value.name}
{value.title}
</span>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
{
file: value.file,
contentType: value.type,
name: value.name,
name: value.title,
metadata: value.metadata
},
'centered'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.
-->
<script lang="ts">
import { type Doc, type DocumentQuery, type Ref, type WithLookup } from '@hcengineering/core'
import { type Doc, type DocumentQuery, type Space, type Ref, type WithLookup } from '@hcengineering/core'
import drive, { type Drive, type Folder } from '@hcengineering/drive'
import { Scroller, SearchInput, Panel, Button, IconMoreH } from '@hcengineering/ui'
import view, { Viewlet, ViewOptions } from '@hcengineering/view'
Expand Down
6 changes: 4 additions & 2 deletions plugins/drive-resources/src/components/FolderPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
-->
<script lang="ts">
import { type Ref } from '@hcengineering/core'
import drive, { type Folder } from '@hcengineering/drive'
import drive, { Drive, type Folder } from '@hcengineering/drive'
import { createQuery } from '@hcengineering/presentation'
import { showMenu } from '@hcengineering/view-resources'
Expand All @@ -34,11 +34,13 @@
$: query.query(drive.class.Folder, { _id }, (res) => {
;[object] = res
})
$: space = object?.space as Ref<Drive>
</script>

{#if object}
<FolderBrowser
space={object.space}
{space}
parent={object._id}
{object}
{embedded}
Expand Down
8 changes: 4 additions & 4 deletions plugins/drive-resources/src/components/FolderPresenter.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@
<ObjectMention object={value} {disabled} {accent} {noUnderline} />
{:else if type === 'link'}
<DocNavLink {disabled} object={value} {accent} {noUnderline}>
<div class="flex-presenter" use:tooltip={{ label: getEmbeddedLabel(value.name) }}>
<div class="flex-presenter" use:tooltip={{ label: getEmbeddedLabel(value.title) }}>
{#if shouldShowAvatar}
<div class="icon">
<Icon icon={FolderIcon} size={'small'} fill="var(--global-accent-IconColor)" />
</div>
{/if}
<span class="label nowrap" class:no-underline={noUnderline || disabled} class:fs-bold={accent}>
{value.name}
{value.title}
</span>
</div>
</DocNavLink>
{:else if type === 'text'}
<span class="overflow-label" use:tooltip={{ label: getEmbeddedLabel(value.name) }}>
{value.name}
<span class="overflow-label" use:tooltip={{ label: getEmbeddedLabel(value.title) }}>
{value.title}
</span>
{/if}
{/if}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
<Icon icon={drive.icon.Folder} size={'medium'} />
</div>
<span class="overflow-label">
{value.name}
{value.title}
</span>
</div>
4 changes: 2 additions & 2 deletions plugins/drive-resources/src/components/FolderTreeLevel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
const dispatch = createEventDispatcher()
function getDescendants (obj: Ref<Folder>): Ref<Folder>[] {
return (descendants.get(obj) ?? []).sort((a, b) => a.name.localeCompare(b.name)).map((p) => p._id)
return (descendants.get(obj) ?? []).sort((a, b) => a.title.localeCompare(b.title)).map((p) => p._id)
}
async function getActions (obj: Folder): Promise<Action[]> {
Expand Down Expand Up @@ -67,7 +67,7 @@
<TreeItem
_id={doc._id}
folderIcon
title={doc.name}
title={doc.title}
selected={selected === doc._id}
isFold
empty={desc.length === 0}
Expand Down
2 changes: 1 addition & 1 deletion plugins/drive-resources/src/components/MoveResource.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
const hierarchy = client.getHierarchy()
const dispatch = createEventDispatcher()
let space: Ref<Drive> = value.space
let space: Ref<Drive> = value.space as Ref<Drive>
let parent: Ref<Folder> = value.parent as Ref<Folder>
async function save (): Promise<void> {
Expand Down
6 changes: 3 additions & 3 deletions plugins/drive-resources/src/components/Thumbnail.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,21 @@
{#if isFolder}
<Icon icon={IconFolderThumbnail} size={'full'} fill={'var(--global-no-priority-PriorityColor)'} />
{:else if previewRef != null && isImage && !isError}
{#await getBlobRef(previewRef, object.name, sizeToWidth(size)) then blobSrc}
{#await getBlobRef(previewRef, object.title, sizeToWidth(size)) then blobSrc}
<img
draggable="false"
class="img-fit"
src={blobSrc.src}
srcset={blobSrc.srcset}
alt={object.name}
alt={object.title}
on:error={() => {
isError = true
}}
/>
{/await}
{:else}
<div class="flex-center ext-icon">
{extensionIconLabel(object.name)}
{extensionIconLabel(object.title)}
</div>
{/if}

Expand Down
Loading

0 comments on commit 62e330d

Please sign in to comment.