From 0b89fac21452c2ad47c78d285f25cd99265476be Mon Sep 17 00:00:00 2001 From: Alexander Onnikov Date: Thu, 14 Mar 2024 19:54:35 +0700 Subject: [PATCH] UBERF-5837 Better organize document plugin (#4963) Signed-off-by: Alexander Onnikov --- models/document/src/index.ts | 4 +- models/document/src/migration.ts | 33 ++++- plugins/document-assets/assets/icons.svg | 19 --- plugins/document-assets/lang/en.json | 8 +- plugins/document-assets/lang/ru.json | 8 +- plugins/document-assets/src/index.ts | 4 - .../src/components/CreateDocument.svelte | 2 +- .../src/components/EditDoc.svelte | 2 +- .../teamspace/CreateTeamspace.svelte | 2 +- .../teamspace/TeamspacePresenter.svelte | 2 +- plugins/document-resources/src/plugin.ts | 2 - plugins/document/src/index.ts | 120 +----------------- plugins/document/src/plugin.ts | 83 ++++++++++++ plugins/document/src/types.ts | 56 ++++++++ 14 files changed, 186 insertions(+), 159 deletions(-) create mode 100644 plugins/document/src/plugin.ts create mode 100644 plugins/document/src/types.ts diff --git a/models/document/src/index.ts b/models/document/src/index.ts index 8c8c64094e..12a02f062b 100644 --- a/models/document/src/index.ts +++ b/models/document/src/index.ts @@ -366,7 +366,7 @@ function defineDocument (builder: Builder): void { presentation.class.ObjectSearchCategory, core.space.Model, { - title: document.string.Docs, + title: document.string.Documents, icon: document.icon.Document, label: document.string.SearchDocument, query: document.completion.DocumentQuery, @@ -397,7 +397,7 @@ function defineApplication (builder: Builder): void { addSpaceLabel: document.string.CreateTeamspace, createComponent: document.component.CreateTeamspace, visibleIf: document.function.IsTeamspaceVisible, - icon: document.icon.Library, + icon: document.icon.Teamspace, // intentionally left empty in order to make space presenter working specials: [] } diff --git a/models/document/src/migration.ts b/models/document/src/migration.ts index 440ed5d15c..329fcced51 100644 --- a/models/document/src/migration.ts +++ b/models/document/src/migration.ts @@ -15,7 +15,7 @@ import { type Attachment } from '@hcengineering/attachment' import { type Class, type Doc, type Ref, TxOperations, DOMAIN_TX, getCollaborativeDoc } from '@hcengineering/core' -import { type Document } from '@hcengineering/document' +import { type Document, type Teamspace } from '@hcengineering/document' import { type MigrateOperation, type MigrationClient, @@ -23,7 +23,8 @@ import { tryMigrate } from '@hcengineering/model' import { DOMAIN_ATTACHMENT } from '@hcengineering/model-attachment' -import core from '@hcengineering/model-core' +import core, { DOMAIN_SPACE } from '@hcengineering/model-core' +import { type Asset } from '@hcengineering/platform' import document, { documentId, DOMAIN_DOCUMENT } from './index' async function createSpace (tx: TxOperations): Promise { @@ -159,6 +160,30 @@ async function migrateDeleteCollaboratorDocument (client: MigrationClient): Prom }) } +async function migrateDocumentIcons (client: MigrationClient): Promise { + await client.update( + DOMAIN_SPACE, + { + _class: document.class.Teamspace, + icon: 'document:icon:Library' as Asset + }, + { + icon: 'document:icon:Teamspace' as Asset + } + ) + + await client.update( + DOMAIN_DOCUMENT, + { + _class: document.class.Document, + icon: 'document:icon:Library' as Asset + }, + { + icon: 'document:icon:Teamspace' as Asset + } + ) +} + async function setNoParent (client: MigrationClient): Promise { await client.update( DOMAIN_DOCUMENT, @@ -232,6 +257,10 @@ export const documentOperation: MigrateOperation = { { state: 'deleteCollaboratorDocument', func: migrateDeleteCollaboratorDocument + }, + { + state: 'updateDocumentIcons', + func: migrateDocumentIcons } ]) }, diff --git a/plugins/document-assets/assets/icons.svg b/plugins/document-assets/assets/icons.svg index 1264df684f..b85c321278 100644 --- a/plugins/document-assets/assets/icons.svg +++ b/plugins/document-assets/assets/icons.svg @@ -2,31 +2,12 @@ - - - - - - - - - - - - - - - - - - - diff --git a/plugins/document-assets/lang/en.json b/plugins/document-assets/lang/en.json index 5f9c524164..3a2bb648ee 100644 --- a/plugins/document-assets/lang/en.json +++ b/plugins/document-assets/lang/en.json @@ -1,21 +1,20 @@ { "string": { + "Document": "Document", + "ParentDocument": "Parent document", + "ChildDocument": "Child document", "CreateDocument": "Create a document", "Documents": "Documents", "CreateAnVersion": "Create new version", - "Document": "Document", "DocumentNamePlaceholder": "Untitled", "Name": "Name", "Cancel": "Cancel", "Version": "Version", "SearchDocument": "Search document...", "Snapshot": "Snapshot", - "ParentDocument": "Parent document", - "ChildDocument": "Child document", "NoVersions": "No version's defined", "DocumentApplication": "Documents", "MyDocuments": "My documents", - "Library": "Library", "Teamspace": "Teamspace", "Teamspaces": "Teamspaces", "Labels": "Labels", @@ -56,7 +55,6 @@ "UnassignToDoConfirm": "Do you want to unassign Todo? The Todo will be removed from the assignee planning.", "ReassignToDo": "Change Todo assignee", "ReassignToDoConfirm": "Do you want to change Todo assignee? The Todo will be removed from the current assignee's planning.", - "Docs": "Docs", "Icon": "Icon", "Color": "Color" } diff --git a/plugins/document-assets/lang/ru.json b/plugins/document-assets/lang/ru.json index 1b3195a5f8..f168c6b579 100644 --- a/plugins/document-assets/lang/ru.json +++ b/plugins/document-assets/lang/ru.json @@ -1,21 +1,20 @@ { "string": { + "Document": "Документ", + "ParentDocument": "Родительский документ", + "ChildDocument": "Дочерний документ", "CreateDocument": "Создать документ", "Documents": "Документы", "CreateAnVersion": "Создать новую версию", - "Document": "Документ", "DocumentNamePlaceholder": "Без имени", "Name": "Имя", "Cancel": "Отмена", "Version": "Версия", "SearchDocument": "Найти документ...", "Snapshot": "Снимок", - "ParentDocument": "Родительский документ", - "ChildDocument": "Дочерний документ", "NoVersions": "Версии не определены", "DocumentApplication": "Документы", "MyDocuments": "Мои документы", - "Library": "Библиотека", "Teamspace": "Пространство", "Teamspaces": "Пространства", "Labels": "Метки", @@ -56,7 +55,6 @@ "UnassignToDoConfirm": "Вы хотите отменить назначение Todo? Todo будет удалена из планирования исполнителя.", "ReassignToDo": "Изменить исполнителя Todo", "ReassignToDoConfirm": "Вы хотите изменить исполнителя Todo? Todo будет удалена из планирования текущего исполнителя.", - "Docs": "Документы", "Icon": "Иконка", "Color": "Цвет" } diff --git a/plugins/document-assets/src/index.ts b/plugins/document-assets/src/index.ts index 73ecc92408..20212cdb0d 100644 --- a/plugins/document-assets/src/index.ts +++ b/plugins/document-assets/src/index.ts @@ -19,12 +19,8 @@ import { loadMetadata } from '@hcengineering/platform' const icons = require('../assets/icons.svg') as string // eslint-disable-line loadMetadata(document.icon, { DocumentApplication: `${icons}#documentapplication`, - NewDocument: `${icons}#newdocument`, Document: `${icons}#document`, Add: `${icons}#add`, - Blank: `${icons}#blank`, - Videofile: `${icons}#videofile`, - Library: `${icons}#library`, Teamspace: `${icons}#teamspace`, References: `${icons}#references`, History: `${icons}#history`, diff --git a/plugins/document-resources/src/components/CreateDocument.svelte b/plugins/document-resources/src/components/CreateDocument.svelte index b2176bc397..90e04cef2d 100644 --- a/plugins/document-resources/src/components/CreateDocument.svelte +++ b/plugins/document-resources/src/components/CreateDocument.svelte @@ -63,7 +63,7 @@ function chooseIcon (): void { const { icon, color } = object - const icons = [document.icon.Document, document.icon.Library] + const icons = [document.icon.Document, document.icon.Teamspace] showPopup(IconPicker, { icon, color, icons }, 'top', (result) => { if (result !== undefined && result !== null) { object.icon = result.icon diff --git a/plugins/document-resources/src/components/EditDoc.svelte b/plugins/document-resources/src/components/EditDoc.svelte index 1003e2f80b..7664beb3cb 100644 --- a/plugins/document-resources/src/components/EditDoc.svelte +++ b/plugins/document-resources/src/components/EditDoc.svelte @@ -160,7 +160,7 @@ async function chooseIcon (): Promise { if (doc !== undefined) { const { icon, color } = doc - const icons = [document.icon.Document, document.icon.Library] + const icons = [document.icon.Document, document.icon.Teamspace] const update = async (result: any): Promise => { if (result !== undefined && result !== null && doc !== undefined) { await client.update(doc, { icon: result.icon, color: result.color }) diff --git a/plugins/document-resources/src/components/teamspace/CreateTeamspace.svelte b/plugins/document-resources/src/components/teamspace/CreateTeamspace.svelte index 824ceec549..8108d09974 100644 --- a/plugins/document-resources/src/components/teamspace/CreateTeamspace.svelte +++ b/plugins/document-resources/src/components/teamspace/CreateTeamspace.svelte @@ -127,7 +127,7 @@ } function chooseIcon (ev: MouseEvent): void { - const icons = [document.icon.Document, document.icon.Library] + const icons = [document.icon.Document, document.icon.Teamspace] const update = (result: any): void => { if (result !== undefined && result !== null) { icon = result.icon diff --git a/plugins/document-resources/src/components/teamspace/TeamspacePresenter.svelte b/plugins/document-resources/src/components/teamspace/TeamspacePresenter.svelte index f3fa5d5440..e177a3a586 100644 --- a/plugins/document-resources/src/components/teamspace/TeamspacePresenter.svelte +++ b/plugins/document-resources/src/components/teamspace/TeamspacePresenter.svelte @@ -27,7 +27,7 @@
, IconProps { - attachedTo: Ref - - name: string - content: CollaborativeDoc - - snapshots?: number - - attachments?: number - children?: number - comments?: number - embeddings?: number - labels?: number - references?: number -} - -/** - * @public - */ -export interface DocumentSnapshot extends AttachedDoc { - attachedTo: Ref - name: string - content: CollaborativeDoc -} - -/** - * @public - */ -export interface SavedDocument extends Preference { - attachedTo: Ref -} - -/** - * @public - */ -export interface DocumentEmbedding extends Attachment { - attachedTo: Ref - attachedToClass: Ref> -} - -/** - * @public - */ -export const documentId = 'document' as Plugin - -/** - * @public - */ -const documentPlugin = plugin(documentId, { - class: { - Document: '' as Ref>, - DocumentSnapshot: '' as Ref>, - DocumentEmbedding: '' as Ref>, - SavedDocument: '' as Ref>, - Teamspace: '' as Ref> - }, - component: { - CreateDocument: '' as AnyComponent, - DocumentSearchIcon: '' as AnyComponent - }, - action: { - CopyDocumentLink: '' as Ref>, - CreateChildDocument: '' as Ref, - CreateDocument: '' as Ref, - EditTeamspace: '' as Ref - }, - icon: { - DocumentApplication: '' as Asset, - NewDocument: '' as Asset, - Document: '' as Asset, - Add: '' as Asset, - Blank: '' as Asset, - Videofile: '' as Asset, - Library: '' as Asset, - Teamspace: '' as Asset, - References: '' as Asset, - History: '' as Asset, - Star: '' as Asset, - Starred: '' as Asset - }, - space: { - Documents: '' as Ref - }, - app: { - Documents: '' as Ref - }, - resolver: { - Location: '' as Resource<(loc: Location) => Promise> - }, - string: { - ConfigLabel: '' as IntlString, - CreateDocument: '' as IntlString - }, - ids: { - NoParent: '' as Ref, - DocumentNotificationGroup: '' as Ref, - ContentNotification: '' as Ref - } -}) +export * from './types' +export { documentId } export default documentPlugin diff --git a/plugins/document/src/plugin.ts b/plugins/document/src/plugin.ts new file mode 100644 index 0000000000..f99df521da --- /dev/null +++ b/plugins/document/src/plugin.ts @@ -0,0 +1,83 @@ +// +// Copyright © 2024 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. +// + +import { Class, Doc, Ref, Space } from '@hcengineering/core' +import { NotificationGroup, NotificationType } from '@hcengineering/notification' +import type { Asset, Plugin, Resource } from '@hcengineering/platform' +import { IntlString, plugin } from '@hcengineering/platform' +import type { AnyComponent, Location, ResolvedLocation } from '@hcengineering/ui' +import { Action, Viewlet } from '@hcengineering/view' +import { Document, DocumentEmbedding, DocumentSnapshot, SavedDocument, Teamspace } from './types' + +/** + * @public + */ +export const documentId = 'document' as Plugin + +/** + * @public + */ +export const documentPlugin = plugin(documentId, { + class: { + Document: '' as Ref>, + DocumentSnapshot: '' as Ref>, + DocumentEmbedding: '' as Ref>, + SavedDocument: '' as Ref>, + Teamspace: '' as Ref> + }, + component: { + CreateDocument: '' as AnyComponent, + DocumentSearchIcon: '' as AnyComponent + }, + action: { + CopyDocumentLink: '' as Ref>, + CreateChildDocument: '' as Ref, + CreateDocument: '' as Ref, + EditTeamspace: '' as Ref + }, + icon: { + Document: '' as Asset, + DocumentApplication: '' as Asset, + Add: '' as Asset, + Teamspace: '' as Asset, + References: '' as Asset, + History: '' as Asset, + Star: '' as Asset, + Starred: '' as Asset + }, + space: { + Documents: '' as Ref + }, + app: { + Documents: '' as Ref + }, + resolver: { + Location: '' as Resource<(loc: Location) => Promise> + }, + string: { + ConfigLabel: '' as IntlString, + CreateDocument: '' as IntlString + }, + ids: { + NoParent: '' as Ref, + DocumentNotificationGroup: '' as Ref, + ContentNotification: '' as Ref + }, + viewlet: { + TableBranches: '' as Ref + } +}) + +export default documentPlugin diff --git a/plugins/document/src/types.ts b/plugins/document/src/types.ts new file mode 100644 index 0000000000..636f5b5314 --- /dev/null +++ b/plugins/document/src/types.ts @@ -0,0 +1,56 @@ +// +// Copyright © 2024 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. +// + +import { Attachment } from '@hcengineering/attachment' +import { AttachedDoc, Class, CollaborativeDoc, Ref, Space } from '@hcengineering/core' +import { Preference } from '@hcengineering/preference' +import { IconProps } from '@hcengineering/view' + +/** @public */ +export interface Teamspace extends Space, IconProps {} + +/** @public */ +export interface Document extends AttachedDoc, IconProps { + attachedTo: Ref + + name: string + content: CollaborativeDoc + + snapshots?: number + attachments?: number + children?: number + comments?: number + embeddings?: number + labels?: number + references?: number +} + +/** @public */ +export interface DocumentSnapshot extends AttachedDoc { + attachedTo: Ref + name: string + content: CollaborativeDoc +} + +/** @public */ +export interface SavedDocument extends Preference { + attachedTo: Ref +} + +/** @public */ +export interface DocumentEmbedding extends Attachment { + attachedTo: Ref + attachedToClass: Ref> +}