mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-11 02:38:49 +00:00
289 lines
8.2 KiB
TypeScript
289 lines
8.2 KiB
TypeScript
//
|
|
// Copyright © 2020, 2021 Anticrm Platform Contributors.
|
|
//
|
|
// 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.
|
|
//
|
|
|
|
import activity from '@hcengineering/activity'
|
|
import type {
|
|
Attachment,
|
|
AttachmentMetadata,
|
|
Photo,
|
|
SavedAttachments,
|
|
AttachmentPreviewExtension
|
|
} from '@hcengineering/attachment'
|
|
import presentation, { TComponentPointExtension } from '@hcengineering/model-presentation'
|
|
import { type Domain, IndexKind, type Ref } from '@hcengineering/core'
|
|
import {
|
|
type Builder,
|
|
Index,
|
|
Model,
|
|
Prop,
|
|
TypeAttachment,
|
|
TypeBoolean,
|
|
TypeRef,
|
|
TypeString,
|
|
TypeTimestamp,
|
|
UX
|
|
} from '@hcengineering/model'
|
|
import core, { TAttachedDoc } from '@hcengineering/model-core'
|
|
import preference, { TPreference } from '@hcengineering/model-preference'
|
|
import view, { createAction } from '@hcengineering/model-view'
|
|
import { type Resource } from '@hcengineering/platform'
|
|
|
|
import attachment from './plugin'
|
|
|
|
export { attachmentId } from '@hcengineering/attachment'
|
|
export { attachmentOperation } from './migration'
|
|
|
|
export const DOMAIN_ATTACHMENT = 'attachment' as Domain
|
|
|
|
@Model(attachment.class.Attachment, core.class.AttachedDoc, DOMAIN_ATTACHMENT)
|
|
@UX(attachment.string.File)
|
|
export class TAttachment extends TAttachedDoc implements Attachment {
|
|
@Prop(TypeString(), attachment.string.Name)
|
|
@Index(IndexKind.FullText)
|
|
name!: string
|
|
|
|
@Prop(TypeAttachment(), attachment.string.File)
|
|
file!: string
|
|
|
|
@Prop(TypeString(), attachment.string.Size)
|
|
size!: number
|
|
|
|
@Prop(TypeString(), attachment.string.Type)
|
|
type!: string
|
|
|
|
@Prop(TypeTimestamp(), attachment.string.LastModified)
|
|
lastModified!: number
|
|
|
|
@Prop(TypeString(), attachment.string.Description)
|
|
@Index(IndexKind.FullText)
|
|
description!: string
|
|
|
|
@Prop(TypeBoolean(), attachment.string.Pinned)
|
|
pinned!: boolean
|
|
|
|
metadata?: AttachmentMetadata
|
|
}
|
|
|
|
@Model(attachment.class.Photo, attachment.class.Attachment)
|
|
@UX(attachment.string.Photo)
|
|
export class TPhoto extends TAttachment implements Photo {}
|
|
|
|
@Model(attachment.class.SavedAttachments, preference.class.Preference)
|
|
export class TSavedAttachments extends TPreference implements SavedAttachments {
|
|
@Prop(TypeRef(attachment.class.Attachment), attachment.string.SavedAttachments)
|
|
declare attachedTo: Ref<Attachment>
|
|
}
|
|
|
|
@Model(attachment.class.AttachmentPreviewExtension, presentation.class.ComponentPointExtension)
|
|
export class TAttachmentPreviewExtension extends TComponentPointExtension implements AttachmentPreviewExtension {
|
|
@Prop(TypeString(), attachment.string.ContentType)
|
|
contentType!: string | string[]
|
|
|
|
alignment?: string
|
|
availabilityChecker?: Resource<() => Promise<boolean>>
|
|
}
|
|
|
|
export function createModel (builder: Builder): void {
|
|
builder.createModel(TAttachment, TPhoto, TSavedAttachments, TAttachmentPreviewExtension)
|
|
|
|
builder.mixin(attachment.class.Attachment, core.class.Class, view.mixin.ObjectPresenter, {
|
|
presenter: attachment.component.AttachmentPresenter
|
|
})
|
|
|
|
builder.mixin(attachment.class.Attachment, core.class.Class, view.mixin.CollectionPresenter, {
|
|
presenter: attachment.component.AttachmentsPresenter
|
|
})
|
|
|
|
builder.mixin(attachment.class.Attachment, core.class.Class, view.mixin.CollectionEditor, {
|
|
editor: attachment.component.Attachments
|
|
})
|
|
|
|
builder.mixin(attachment.class.Photo, core.class.Class, view.mixin.CollectionEditor, {
|
|
editor: attachment.component.Photos
|
|
})
|
|
|
|
builder.createDoc(
|
|
activity.class.TxViewlet,
|
|
core.space.Model,
|
|
{
|
|
objectClass: attachment.class.Attachment,
|
|
icon: attachment.icon.Attachment,
|
|
txClass: core.class.TxCreateDoc,
|
|
component: attachment.activity.TxAttachmentCreate,
|
|
label: attachment.string.AddAttachment,
|
|
display: 'emphasized'
|
|
},
|
|
attachment.ids.TxAttachmentCreate
|
|
)
|
|
|
|
builder.createDoc(
|
|
activity.class.TxViewlet,
|
|
core.space.Model,
|
|
{
|
|
objectClass: attachment.class.Attachment,
|
|
icon: attachment.icon.Attachment,
|
|
txClass: core.class.TxRemoveDoc,
|
|
component: attachment.activity.TxAttachmentCreate,
|
|
label: attachment.string.RemovedAttachment,
|
|
display: 'inline'
|
|
},
|
|
attachment.ids.TxAttachmentRemove
|
|
)
|
|
|
|
builder.createDoc(
|
|
activity.class.DocUpdateMessageViewlet,
|
|
core.space.Model,
|
|
{
|
|
objectClass: attachment.class.Attachment,
|
|
action: 'create',
|
|
icon: attachment.icon.Attachment,
|
|
label: attachment.string.AddAttachment,
|
|
component: attachment.activity.AttachmentsUpdatedMessage
|
|
},
|
|
attachment.ids.AttachmentCreatedActivityViewlet
|
|
)
|
|
|
|
builder.createDoc(
|
|
activity.class.DocUpdateMessageViewlet,
|
|
core.space.Model,
|
|
{
|
|
objectClass: attachment.class.Attachment,
|
|
action: 'remove',
|
|
icon: attachment.icon.Attachment,
|
|
label: attachment.string.RemovedAttachment,
|
|
component: attachment.activity.AttachmentsUpdatedMessage
|
|
},
|
|
attachment.ids.AttachmentRemovedActivityViewlet
|
|
)
|
|
|
|
builder.createDoc(activity.class.ActivityMessagesFilter, core.space.Model, {
|
|
label: attachment.string.FilterAttachments,
|
|
position: 50,
|
|
filter: attachment.filter.AttachmentsFilter
|
|
})
|
|
|
|
builder.createDoc(
|
|
view.class.ActionCategory,
|
|
core.space.Model,
|
|
{ label: attachment.string.Attachments, visible: true },
|
|
attachment.category.Attachments
|
|
)
|
|
|
|
builder.createDoc(
|
|
attachment.class.AttachmentPreviewExtension,
|
|
core.space.Model,
|
|
{
|
|
contentType: 'image/*',
|
|
alignment: 'centered',
|
|
component: attachment.component.PDFViewer,
|
|
extension: attachment.extension.AttachmentPreview
|
|
},
|
|
attachment.previewExtension.Image
|
|
)
|
|
|
|
builder.createDoc(
|
|
attachment.class.AttachmentPreviewExtension,
|
|
core.space.Model,
|
|
{
|
|
contentType: ['video/*', 'audio/*'],
|
|
alignment: 'centered',
|
|
component: attachment.component.MediaViewer,
|
|
extension: attachment.extension.AttachmentPreview
|
|
},
|
|
attachment.previewExtension.Media
|
|
)
|
|
|
|
builder.createDoc(
|
|
attachment.class.AttachmentPreviewExtension,
|
|
core.space.Model,
|
|
{
|
|
contentType: ['application/pdf', 'application/json', 'text/*'],
|
|
alignment: 'float',
|
|
component: attachment.component.PDFViewer,
|
|
extension: attachment.extension.AttachmentPreview
|
|
},
|
|
attachment.previewExtension.PDF
|
|
)
|
|
|
|
createAction(builder, {
|
|
action: view.actionImpl.ShowEditor,
|
|
actionProps: {
|
|
attribute: 'description'
|
|
},
|
|
label: attachment.string.Description,
|
|
icon: view.icon.Open,
|
|
input: 'focus',
|
|
category: attachment.category.Attachments,
|
|
target: attachment.class.Attachment,
|
|
context: {
|
|
mode: ['context', 'browser'],
|
|
group: 'edit'
|
|
}
|
|
})
|
|
|
|
createAction(builder, {
|
|
action: view.actionImpl.UpdateDocument,
|
|
actionProps: {
|
|
key: 'pinned',
|
|
value: true
|
|
},
|
|
query: {
|
|
pinned: { $in: [false, undefined, null] }
|
|
},
|
|
label: attachment.string.PinAttachment,
|
|
input: 'focus',
|
|
icon: view.icon.Pin,
|
|
category: attachment.category.Attachments,
|
|
target: attachment.class.Attachment,
|
|
context: {
|
|
mode: ['context', 'browser'],
|
|
group: 'edit'
|
|
}
|
|
})
|
|
|
|
createAction(builder, {
|
|
action: view.actionImpl.UpdateDocument,
|
|
actionProps: {
|
|
key: 'pinned',
|
|
value: false
|
|
},
|
|
query: {
|
|
pinned: true
|
|
},
|
|
label: attachment.string.UnPinAttachment,
|
|
input: 'focus',
|
|
icon: view.icon.Pin,
|
|
category: attachment.category.Attachments,
|
|
target: attachment.class.Attachment,
|
|
context: {
|
|
mode: ['context', 'browser'],
|
|
group: 'edit'
|
|
}
|
|
})
|
|
builder.createDoc(core.class.DomainIndexConfiguration, core.space.Model, {
|
|
domain: DOMAIN_ATTACHMENT,
|
|
disabled: [
|
|
{ attachedToClass: 1 },
|
|
{ modifiedOn: 1 },
|
|
{ modifiedBy: 1 },
|
|
{ createdBy: 1 },
|
|
{ createdOn: -1 },
|
|
{ state: 1 }
|
|
]
|
|
})
|
|
}
|
|
|
|
export default attachment
|