Sidebar attachments preview (#6797)

Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
Kristina
2024-10-03 22:30:32 +07:00
committed by GitHub
parent e09a24cbc1
commit d3a7759ef7
31 changed files with 376 additions and 83 deletions
+40 -3
View File
@@ -14,7 +14,7 @@
// limitations under the License.
//
import { type Attachment } from '@hcengineering/attachment'
import { type BlobMetadata, type Attachment } from '@hcengineering/attachment'
import {
type Blob,
type Class,
@@ -24,8 +24,10 @@ import {
type Ref,
type Space
} from '@hcengineering/core'
import { setPlatformStatus, unknownError } from '@hcengineering/platform'
import { type FileOrBlob, getFileMetadata, uploadFile } from '@hcengineering/presentation'
import { getResource, setPlatformStatus, unknownError } from '@hcengineering/platform'
import { type FileOrBlob, getClient, getFileMetadata, uploadFile } from '@hcengineering/presentation'
import workbench, { type WidgetTab } from '@hcengineering/workbench'
import view from '@hcengineering/view'
import attachment from './plugin'
@@ -98,3 +100,38 @@ export function getType (type: string): 'image' | 'text' | 'json' | 'video' | 'a
return 'other'
}
export async function openAttachmentInSidebar (value: Attachment): Promise<void> {
await openFilePreviewInSidebar(value.file, value.name, value.type, value.metadata)
}
export async function openFilePreviewInSidebar (
file: Ref<Blob>,
name: string,
contentType: string,
metadata?: BlobMetadata
): Promise<void> {
const client = getClient()
const widget = client.getModel().findAllSync(workbench.class.Widget, { _id: attachment.ids.PreviewWidget })[0]
const createFn = await getResource(workbench.function.CreateWidgetTab)
let icon = attachment.icon.Attachment
if (contentType.startsWith('image/')) {
icon = view.icon.Image
} else if (contentType.startsWith('video/')) {
icon = view.icon.Video
} else if (contentType.startsWith('audio/')) {
icon = view.icon.Audio
} else {
icon = view.icon.File
}
const tab: WidgetTab = {
id: file,
icon,
name,
widget: attachment.ids.PreviewWidget,
data: { file, name, contentType, metadata }
}
await createFn(widget, tab, true)
}