diff --git a/models/drive/src/index.ts b/models/drive/src/index.ts index 0bc5efd3a8..97d74fc32f 100644 --- a/models/drive/src/index.ts +++ b/models/drive/src/index.ts @@ -350,6 +350,25 @@ function defineFolder (builder: Builder): void { }, drive.action.CreateChildFolder ) + + createAction( + builder, + { + action: drive.actionImpl.RenameFolder, + label: drive.string.Rename, + icon: view.icon.Edit, + category: drive.category.Drive, + input: 'none', + target: drive.class.Folder, + context: { + mode: ['context', 'browser'], + application: drive.app.Drive, + group: 'edit' + }, + visibilityTester: drive.function.CanRenameFolder + }, + drive.action.RenameFolder + ) } function defineFile (builder: Builder): void { @@ -362,7 +381,12 @@ function defineFile (builder: Builder): void { // Actions builder.mixin(drive.class.File, core.class.Class, view.mixin.IgnoreActions, { - actions: [view.action.OpenInNewTab, tracker.action.EditRelatedTargets, tracker.action.NewRelatedIssue] + actions: [ + view.action.Open, + view.action.OpenInNewTab, + tracker.action.EditRelatedTargets, + tracker.action.NewRelatedIssue + ] }) createAction( @@ -382,6 +406,25 @@ function defineFile (builder: Builder): void { }, drive.action.DownloadFile ) + + createAction( + builder, + { + action: drive.actionImpl.RenameFile, + label: drive.string.Rename, + icon: view.icon.Edit, + category: drive.category.Drive, + input: 'none', + target: drive.class.File, + context: { + mode: ['context', 'browser'], + application: drive.app.Drive, + group: 'edit' + }, + visibilityTester: drive.function.CanRenameFile + }, + drive.action.RenameFile + ) } function defineApplication (builder: Builder): void { diff --git a/models/drive/src/plugin.ts b/models/drive/src/plugin.ts index 3ce59411c2..a2787ce011 100644 --- a/models/drive/src/plugin.ts +++ b/models/drive/src/plugin.ts @@ -23,6 +23,7 @@ import { type Action, type ActionCategory, type ViewAction, + type ViewActionAvailabilityFunction, type Viewlet, type ViewletDescriptor } from '@hcengineering/view' @@ -44,7 +45,9 @@ export default mergeIds(driveId, drive, { }, function: { DriveLinkProvider: '' as Resource<(doc: Doc, props: Record) => Promise>, - FolderLinkProvider: '' as Resource<(doc: Doc, props: Record) => Promise> + FolderLinkProvider: '' as Resource<(doc: Doc, props: Record) => Promise>, + CanRenameFile: '' as Resource, + CanRenameFolder: '' as Resource }, viewlet: { Grid: '' as Ref, @@ -59,13 +62,17 @@ export default mergeIds(driveId, drive, { CreateChildFolder: '' as Ref, CreateRootFolder: '' as Ref, EditDrive: '' as Ref, - DownloadFile: '' as Ref + DownloadFile: '' as Ref, + RenameFile: '' as Ref, + RenameFolder: '' as Ref }, actionImpl: { CreateChildFolder: '' as ViewAction, CreateRootFolder: '' as ViewAction, EditDrive: '' as ViewAction, - DownloadFile: '' as ViewAction + DownloadFile: '' as ViewAction, + RenameFile: '' as ViewAction, + RenameFolder: '' as ViewAction }, string: { Name: '' as IntlString, diff --git a/plugins/drive-assets/lang/en.json b/plugins/drive-assets/lang/en.json index 0742c38616..d6bcb8bb25 100644 --- a/plugins/drive-assets/lang/en.json +++ b/plugins/drive-assets/lang/en.json @@ -18,6 +18,7 @@ "UploadFile": "Upload File", "UploadFolder": "Upload Folder", "EditDrive": "Edit Drive", + "Rename": "Rename", "RoleLabel": "Role", "Root": "/" } diff --git a/plugins/drive-assets/lang/ru.json b/plugins/drive-assets/lang/ru.json index 1c9d2f27b5..c20489d2af 100644 --- a/plugins/drive-assets/lang/ru.json +++ b/plugins/drive-assets/lang/ru.json @@ -18,6 +18,7 @@ "UploadFile": "Загрузить файл", "UploadFolder": "Загрузить папку", "EditDrive": "Редактировать", + "Rename": "Переименовать", "RoleLabel": "Роль", "Root": "/" } diff --git a/plugins/drive-resources/src/components/RenamePopup.svelte b/plugins/drive-resources/src/components/RenamePopup.svelte new file mode 100644 index 0000000000..29b10347c6 --- /dev/null +++ b/plugins/drive-resources/src/components/RenamePopup.svelte @@ -0,0 +1,39 @@ + + + + + + + diff --git a/plugins/drive-resources/src/index.ts b/plugins/drive-resources/src/index.ts index 4777749dbf..e94f5bebf3 100644 --- a/plugins/drive-resources/src/index.ts +++ b/plugins/drive-resources/src/index.ts @@ -33,7 +33,7 @@ import GridView from './components/GridView.svelte' import ResourcePresenter from './components/ResourcePresenter.svelte' import { getDriveLink, getFolderLink, resolveLocation } from './navigation' -import { createFolder } from './utils' +import { createFolder, renameResource } from './utils' async function CreateRootFolder (doc: Drive): Promise { await createFolder(doc._id, drive.ids.Root) @@ -68,6 +68,26 @@ async function FolderLinkProvider (doc: Doc): Promise { return getFolderLink(doc._id as Ref) } +async function RenameFile (doc: File | File[]): Promise { + if (!Array.isArray(doc)) { + await renameResource(doc) + } +} + +async function RenameFolder (doc: Folder | Folder[]): Promise { + if (!Array.isArray(doc)) { + await renameResource(doc) + } +} + +export async function CanRenameFile (doc: File | File[] | undefined): Promise { + return doc !== undefined && !Array.isArray(doc) +} + +export async function CanRenameFolder (doc: Folder | Folder[] | undefined): Promise { + return doc !== undefined && !Array.isArray(doc) +} + export default async (): Promise => ({ component: { CreateDrive, @@ -87,11 +107,15 @@ export default async (): Promise => ({ CreateChildFolder, CreateRootFolder, EditDrive, - DownloadFile + DownloadFile, + RenameFile, + RenameFolder }, function: { DriveLinkProvider, - FolderLinkProvider + FolderLinkProvider, + CanRenameFile, + CanRenameFolder }, resolver: { Location: resolveLocation diff --git a/plugins/drive-resources/src/plugin.ts b/plugins/drive-resources/src/plugin.ts index 96071d4a0b..bf9aa28714 100644 --- a/plugins/drive-resources/src/plugin.ts +++ b/plugins/drive-resources/src/plugin.ts @@ -24,6 +24,7 @@ export default mergeIds(driveId, drive, { UploadFile: '' as IntlString, UploadFolder: '' as IntlString, EditDrive: '' as IntlString, + Rename: '' as IntlString, RoleLabel: '' as IntlString, Root: '' as IntlString } diff --git a/plugins/drive-resources/src/utils.ts b/plugins/drive-resources/src/utils.ts index c69a9d3098..6e90d225e8 100644 --- a/plugins/drive-resources/src/utils.ts +++ b/plugins/drive-resources/src/utils.ts @@ -14,7 +14,7 @@ // import { type Class, type Doc, type Ref } from '@hcengineering/core' -import drive, { type Drive, type Folder } from '@hcengineering/drive' +import drive, { type Drive, type Folder, type Resource } from '@hcengineering/drive' import { setPlatformStatus, unknownError } from '@hcengineering/platform' import { getClient, getFileMetadata, uploadFile } from '@hcengineering/presentation' import { showPopup } from '@hcengineering/ui' @@ -22,6 +22,7 @@ import { openDoc } from '@hcengineering/view-resources' import CreateDrive from './components/CreateDrive.svelte' import CreateFolder from './components/CreateFolder.svelte' +import RenamePopup from './components/RenamePopup.svelte' async function navigateToDoc (_id: Ref, _class: Ref>): Promise { const client = getClient() @@ -81,3 +82,12 @@ export async function createFile (file: File, space: Ref, parent: Folder void setPlatformStatus(unknownError(e)) } } + +export async function renameResource (resource: Resource): Promise { + showPopup(RenamePopup, { value: resource.name, format: 'text' }, undefined, async (res) => { + if (res != null && res !== resource.name) { + const client = getClient() + await client.update(resource, { name: res }) + } + }) +}