mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-30 13:35:04 +02:00
Sidebar attachments preview (#6797)
Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user