From b09466453dea917eb82d402e9438c579d0399c24 Mon Sep 17 00:00:00 2001 From: Anna No Date: Wed, 13 Apr 2022 00:28:46 +0700 Subject: [PATCH 01/16] Board: add attachments support Signed-off-by: Anna No --- .../src/components/AddAttachment.svelte | 52 ++++++++ .../src/components/AttachmentDroppable.svelte | 51 ++++++++ .../src/components/Attachments.svelte | 117 +++++------------- plugins/attachment-resources/src/index.ts | 4 +- plugins/attachment-resources/src/utils.ts | 26 +++- plugins/board-assets/lang/en.json | 1 + plugins/board-assets/lang/ru.json | 1 + plugins/board-resources/package.json | 1 + .../src/components/EditCard.svelte | 3 +- .../src/components/KanbanCard.svelte | 71 +++++++---- .../src/components/editor/CardActions.svelte | 10 +- .../src/components/editor/CardActivity.svelte | 2 - .../components/editor/CardAttachments.svelte | 63 ++++++++++ .../presenters/AttachmentPresenter.svelte | 12 ++ plugins/board-resources/src/plugin.ts | 1 + 15 files changed, 289 insertions(+), 126 deletions(-) create mode 100644 plugins/attachment-resources/src/components/AddAttachment.svelte create mode 100644 plugins/attachment-resources/src/components/AttachmentDroppable.svelte create mode 100644 plugins/board-resources/src/components/editor/CardAttachments.svelte create mode 100644 plugins/board-resources/src/components/presenters/AttachmentPresenter.svelte diff --git a/plugins/attachment-resources/src/components/AddAttachment.svelte b/plugins/attachment-resources/src/components/AddAttachment.svelte new file mode 100644 index 0000000000..32811da319 --- /dev/null +++ b/plugins/attachment-resources/src/components/AddAttachment.svelte @@ -0,0 +1,52 @@ + + +
+ {#if $$slots.control} +
+ +
+ {:else} + + {/if} + +
diff --git a/plugins/attachment-resources/src/components/AttachmentDroppable.svelte b/plugins/attachment-resources/src/components/AttachmentDroppable.svelte new file mode 100644 index 0000000000..94701dea5a --- /dev/null +++ b/plugins/attachment-resources/src/components/AttachmentDroppable.svelte @@ -0,0 +1,51 @@ + + + +
{ + dragover = true + }} + on:dragleave={() => { + dragover = false + }} + on:drop|preventDefault|stopPropagation={fileDrop}> + +
diff --git a/plugins/attachment-resources/src/components/Attachments.svelte b/plugins/attachment-resources/src/components/Attachments.svelte index 43688320ef..7047f03933 100644 --- a/plugins/attachment-resources/src/components/Attachments.svelte +++ b/plugins/attachment-resources/src/components/Attachments.svelte @@ -15,119 +15,55 @@ -->
- {#if loading} - - {:else} - { - inputFile.click() - }} - /> - {/if} - +
- - {#if (attachments === 0) && !loading} -
{ - dragover = true - }} - on:dragleave={() => { - dragover = false - }} - on:drop|preventDefault|stopPropagation={fileDrop} - > - -
-
+ {:else} + loadingProps={{ length: attachments ?? 0 }} /> {/if} @@ -150,6 +86,9 @@ background: var(--theme-bg-accent-color); border: 1px dashed var(--theme-zone-border-lite); border-radius: 0.75rem; - &.solid { border-style: solid; } + &.solid { + border-style: solid; + } } + diff --git a/plugins/attachment-resources/src/index.ts b/plugins/attachment-resources/src/index.ts index 82554a6bb3..04b7d96a4a 100644 --- a/plugins/attachment-resources/src/index.ts +++ b/plugins/attachment-resources/src/index.ts @@ -13,6 +13,8 @@ // limitations under the License. // +import AddAttachment from './components/AddAttachment.svelte' +import AttachmentDroppable from './components/AttachmentDroppable.svelte' import AttachmentsPresenter from './components/AttachmentsPresenter.svelte' import AttachmentPresenter from './components/AttachmentPresenter.svelte' import AttachmentDocList from './components/AttachmentDocList.svelte' @@ -24,7 +26,7 @@ import Photos from './components/Photos.svelte' import { Resources } from '@anticrm/platform' import { uploadFile, deleteFile } from './utils' -export { Attachments, AttachmentsPresenter, AttachmentPresenter, AttachmentRefInput, AttachmentList, AttachmentDocList } +export { AddAttachment, AttachmentDroppable, Attachments, AttachmentsPresenter, AttachmentPresenter, AttachmentRefInput, AttachmentList, AttachmentDocList } export default async (): Promise => ({ component: { diff --git a/plugins/attachment-resources/src/utils.ts b/plugins/attachment-resources/src/utils.ts index 341cfec351..5019e1f8e7 100644 --- a/plugins/attachment-resources/src/utils.ts +++ b/plugins/attachment-resources/src/utils.ts @@ -14,9 +14,11 @@ // limitations under the License. // -import type { Doc, Ref, Space } from '@anticrm/core' +import type { Class, Doc, Ref, Space, TxOperations as Client } from '@anticrm/core' import login from '@anticrm/login' -import { getMetadata } from '@anticrm/platform' +import { getMetadata, setPlatformStatus, unknownError } from '@anticrm/platform' + +import attachment from './plugin' export async function uploadFile (file: File, opts?: { space: Ref, attachedTo: Ref }): Promise { const uploadUrl = getMetadata(login.metadata.UploadUrl) @@ -68,6 +70,26 @@ export async function deleteFile (id: string): Promise { } } +export async function createAttachment (client: Client, file: File, loading: number, attachTo: {objectClass: Ref>, space: Ref, objectId: Ref}) { + loading++ + const {objectClass, objectId, space} = attachTo + try { + const uuid = await uploadFile(file, { space, attachedTo: objectId }) + console.log('uploaded file uuid', uuid) + client.addCollection(attachment.class.Attachment, space, objectId, objectClass, 'attachments', { + name: file.name, + file: uuid, + type: file.type, + size: file.size, + lastModified: file.lastModified + }) + } catch (err: any) { + setPlatformStatus(unknownError(err)) + } finally { + loading-- + } +} + export function getType (type: string): 'image' | 'video' | 'audio' | 'pdf' | 'other' { if (type.startsWith('image/')) { return 'image' diff --git a/plugins/board-assets/lang/en.json b/plugins/board-assets/lang/en.json index b092f60269..c137c3714c 100644 --- a/plugins/board-assets/lang/en.json +++ b/plugins/board-assets/lang/en.json @@ -33,6 +33,7 @@ "Checklist": "Checklist", "Dates": "Dates", "Attachments": "Attachments", + "AddAttachment": "Add an attachment", "CustomFields": "Custom Fields", "Automation": "Automation", "AddButton": "Add Button", diff --git a/plugins/board-assets/lang/ru.json b/plugins/board-assets/lang/ru.json index 7c457c9673..a8dcf5f91a 100644 --- a/plugins/board-assets/lang/ru.json +++ b/plugins/board-assets/lang/ru.json @@ -33,6 +33,7 @@ "Checklist": "Списки", "Dates": "Дата", "Attachments": "Прикрепленное", + "AddAttachment": "Прикрепить", "CustomFields": "Дополнительно", "Automation": "Автоматизация", "AddButton": "Добавить", diff --git a/plugins/board-resources/package.json b/plugins/board-resources/package.json index 3461c2e718..065f81761a 100644 --- a/plugins/board-resources/package.json +++ b/plugins/board-resources/package.json @@ -31,6 +31,7 @@ }, "dependencies": { "@anticrm/activity": "~0.6.0", + "@anticrm/attachment": "~0.6.1", "@anticrm/attachment-resources": "~0.6.0", "@anticrm/board": "~0.6.0", "@anticrm/chunter": "~0.6.1", diff --git a/plugins/board-resources/src/components/EditCard.svelte b/plugins/board-resources/src/components/EditCard.svelte index aed1925ff5..59d59e0aa9 100644 --- a/plugins/board-resources/src/components/EditCard.svelte +++ b/plugins/board-resources/src/components/EditCard.svelte @@ -29,6 +29,7 @@ import { updateCard } from '../utils/CardUtils' import CardActions from './editor/CardActions.svelte' import CardActivity from './editor/CardActivity.svelte' + import CardAttachments from './editor/CardAttachments.svelte' import CardDetails from './editor/CardDetails.svelte' export let _id: Ref @@ -125,7 +126,7 @@ /> - + diff --git a/plugins/board-resources/src/components/KanbanCard.svelte b/plugins/board-resources/src/components/KanbanCard.svelte index 53318cafb0..d4de151c00 100644 --- a/plugins/board-resources/src/components/KanbanCard.svelte +++ b/plugins/board-resources/src/components/KanbanCard.svelte @@ -14,7 +14,7 @@ // limitations under the License. --> -
-
-
{object.title}
-
-
-
- + +
+
+
+
{object.title}
+
+
+
+ +
+ { + showMenu(evt) + }} + icon={IconMoreH} + size="small" /> +
+
+
+
+ {#if (object.attachments ?? 0) > 0} +
+ +
+ {/if} + {#if (object.comments ?? 0) > 0} +
+ +
+ {/if}
- { - showMenu(evt) - }} - icon={IconMoreH} - size={'small'} - /> -
-
-
-
- {#if (object.attachments ?? 0) > 0} -
- {/if} - {#if (object.comments ?? 0) > 0} -
- {/if}
+
+ diff --git a/plugins/board-resources/src/components/editor/CardActions.svelte b/plugins/board-resources/src/components/editor/CardActions.svelte index 731ff0dd4c..687c554f52 100644 --- a/plugins/board-resources/src/components/editor/CardActions.svelte +++ b/plugins/board-resources/src/components/editor/CardActions.svelte @@ -34,7 +34,8 @@ let actionGroups: { label: IntlString; actions: CardAction[] }[] = [] - getCardActions(client).then(async (result) => { + async function fetch() { + const result = await getCardActions(client) for (const action of result) { let supported = true if (action.supported) { @@ -74,7 +75,9 @@ actions: actions.sort(cardActionSorter) } ] - }) + } + + $: fetch() {#if value} @@ -99,8 +102,7 @@ const handler = await getResource(action.handler) handler(value, client) } - }} - /> + }} /> {/if} {/each}
diff --git a/plugins/board-resources/src/components/editor/CardActivity.svelte b/plugins/board-resources/src/components/editor/CardActivity.svelte index 324f038adf..9491938d25 100644 --- a/plugins/board-resources/src/components/editor/CardActivity.svelte +++ b/plugins/board-resources/src/components/editor/CardActivity.svelte @@ -26,8 +26,6 @@ {#if value !== undefined}
- -
diff --git a/plugins/board-resources/src/components/editor/CardAttachments.svelte b/plugins/board-resources/src/components/editor/CardAttachments.svelte new file mode 100644 index 0000000000..47ce37f961 --- /dev/null +++ b/plugins/board-resources/src/components/editor/CardAttachments.svelte @@ -0,0 +1,63 @@ + + + +{#if value !== undefined && value.attachments !== undefined && value.attachments > 0} +
+
+
+ +
+
+
+
+
+
+
+ {#each attachments as attach} + + {/each} +
+ +
+
+
+
+{/if} diff --git a/plugins/board-resources/src/components/presenters/AttachmentPresenter.svelte b/plugins/board-resources/src/components/presenters/AttachmentPresenter.svelte new file mode 100644 index 0000000000..bf5d0cc0f3 --- /dev/null +++ b/plugins/board-resources/src/components/presenters/AttachmentPresenter.svelte @@ -0,0 +1,12 @@ + + +
+ +
+ \ No newline at end of file diff --git a/plugins/board-resources/src/plugin.ts b/plugins/board-resources/src/plugin.ts index 52183d47a3..9b4a749076 100644 --- a/plugins/board-resources/src/plugin.ts +++ b/plugins/board-resources/src/plugin.ts @@ -54,6 +54,7 @@ export default mergeIds(boardId, board, { Checklist: '' as IntlString, Dates: '' as IntlString, Attachments: '' as IntlString, + AddAttachment: '' as IntlString, CustomFields: '' as IntlString, Automation: '' as IntlString, AddButton: '' as IntlString, From 543e7616f8d25ff518c9bae6de8b508529336f06 Mon Sep 17 00:00:00 2001 From: Anna No Date: Wed, 13 Apr 2022 10:44:13 +0700 Subject: [PATCH 02/16] Fix AddAttachment control Signed-off-by: Anna No --- .../src/components/AddAttachment.svelte | 4 +- .../src/components/KanbanCard.svelte | 59 +++++++++---------- .../components/editor/CardAttachments.svelte | 4 +- 3 files changed, 33 insertions(+), 34 deletions(-) diff --git a/plugins/attachment-resources/src/components/AddAttachment.svelte b/plugins/attachment-resources/src/components/AddAttachment.svelte index 32811da319..979b1e70fa 100644 --- a/plugins/attachment-resources/src/components/AddAttachment.svelte +++ b/plugins/attachment-resources/src/components/AddAttachment.svelte @@ -31,9 +31,7 @@
{#if $$slots.control} -
- -
+ {:else}
-
-
-
{object.title}
-
-
-
- +
+
+
{object.title}
+
+
+
+ +
+ { + showMenu(evt) + }} + icon={IconMoreH} + size="small" /> +
+
+
+
+ {#if (object.attachments ?? 0) > 0} +
+ +
+ {/if} + {#if (object.comments ?? 0) > 0} +
+ +
+ {/if}
- { - showMenu(evt) - }} - icon={IconMoreH} - size="small" />
-
-
- {#if (object.attachments ?? 0) > 0} -
- -
- {/if} - {#if (object.comments ?? 0) > 0} -
- -
- {/if} -
-
-
- diff --git a/plugins/board-resources/src/components/editor/CardAttachments.svelte b/plugins/board-resources/src/components/editor/CardAttachments.svelte index 47ce37f961..64e1ff2a6d 100644 --- a/plugins/board-resources/src/components/editor/CardAttachments.svelte +++ b/plugins/board-resources/src/components/editor/CardAttachments.svelte @@ -54,7 +54,9 @@ {/each}
-
From 6bc49f596dae0dde93d8a46acbb6a764708b1efc Mon Sep 17 00:00:00 2001 From: Anna No Date: Wed, 13 Apr 2022 11:14:41 +0700 Subject: [PATCH 03/16] Remove paddings from card-container Signed-off-by: Anna No --- packages/kanban/src/components/Kanban.svelte | 5 -- packages/theme/styles/_layouts.scss | 7 ++ .../src/components/KanbanCard.svelte | 56 +++++++------- .../src/components/KanbanCard.svelte | 62 ++++++++------- .../src/components/KanbanCard.svelte | 75 ++++++++++--------- .../src/components/KanbanCard.svelte | 74 +++++++++--------- .../src/components/issues/Board.svelte | 2 +- 7 files changed, 152 insertions(+), 129 deletions(-) diff --git a/packages/kanban/src/components/Kanban.svelte b/packages/kanban/src/components/Kanban.svelte index 49ab4e8558..2fbd3e9c26 100644 --- a/packages/kanban/src/components/Kanban.svelte +++ b/packages/kanban/src/components/Kanban.svelte @@ -246,11 +246,7 @@ height: 100%; } .card-container { - display: flex; - flex-direction: column; - padding: .5rem 1rem; background-color: var(--board-card-bg-color); - border: 1px solid var(--board-card-bg-color); border-radius: .25rem; user-select: none; @@ -263,7 +259,6 @@ &.dragged { padding: 1rem; background-color: var(--board-bg-color); - border: unset; } } diff --git a/packages/theme/styles/_layouts.scss b/packages/theme/styles/_layouts.scss index e13120e4d2..dae2ebc471 100644 --- a/packages/theme/styles/_layouts.scss +++ b/packages/theme/styles/_layouts.scss @@ -318,9 +318,16 @@ p:last-child { margin-block-end: 0; } .mx-2 { margin: 0 .5rem; } .mx-3 { margin: 0 .75rem; } +.pl-2 { padding-left: .5rem; } +.pl-4 { padding-left: 1rem; } .pr-1 { padding-right: .25rem; } +.pr-2 { padding-right: .5rem; } .pr-4 { padding-right: 1rem; } .pr-24 { padding-right: 6rem; } +.pt-2 { padding-top: .5rem; } +.pt-4 { padding-top: 1rem; } +.pb-2 { padding-bottom: .5rem; } +.pb-4 { padding-bottom: 1rem; } .p-2 { padding: .5rem; } .p-3 { padding: .75rem; } diff --git a/plugins/board-resources/src/components/KanbanCard.svelte b/plugins/board-resources/src/components/KanbanCard.svelte index 53318cafb0..911c174f23 100644 --- a/plugins/board-resources/src/components/KanbanCard.svelte +++ b/plugins/board-resources/src/components/KanbanCard.svelte @@ -33,33 +33,39 @@ function showLead() { showPanel(board.component.EditCard, object._id, object._class, 'middle') } + -
-
-
{object.title}
-
-
-
- +
+
+
+
{object.title}
+
+
+
+ +
+ { + showMenu(evt) + }} + icon={IconMoreH} + size={'small'} /> +
+
+
+
+ {#if (object.attachments ?? 0) > 0} +
+ +
+ {/if} + {#if (object.comments ?? 0) > 0} +
+ +
+ {/if}
- { - showMenu(evt) - }} - icon={IconMoreH} - size={'small'} - /> -
-
-
-
- {#if (object.attachments ?? 0) > 0} -
- {/if} - {#if (object.comments ?? 0) > 0} -
- {/if}
diff --git a/plugins/lead-resources/src/components/KanbanCard.svelte b/plugins/lead-resources/src/components/KanbanCard.svelte index d52a403d7c..312d7fa279 100644 --- a/plugins/lead-resources/src/components/KanbanCard.svelte +++ b/plugins/lead-resources/src/components/KanbanCard.svelte @@ -35,36 +35,42 @@ function showLead() { showPanel(view.component.EditDoc, object._id, object._class, 'full') } + -
-
-
{object.title}
-
-
-
- +
+
+
+
{object.title}
+
+
+
+ +
+ { + showMenu(evt) + }} + icon={IconMoreH} + size={'small'} /> +
+
+
+ {#if object.$lookup?.attachedTo} + + {/if} +
+ {#if (object.attachments ?? 0) > 0} +
+ +
+ {/if} + {#if (object.comments ?? 0) > 0} +
+ +
+ {/if}
- { - showMenu(evt) - }} - icon={IconMoreH} - size={'small'} - /> -
-
-
- {#if object.$lookup?.attachedTo} - - {/if} -
- {#if (object.attachments ?? 0) > 0} -
- {/if} - {#if (object.comments ?? 0) > 0} -
- {/if}
diff --git a/plugins/recruit-resources/src/components/KanbanCard.svelte b/plugins/recruit-resources/src/components/KanbanCard.svelte index 8ec6cb2155..aebeb060f5 100644 --- a/plugins/recruit-resources/src/components/KanbanCard.svelte +++ b/plugins/recruit-resources/src/components/KanbanCard.svelte @@ -28,51 +28,56 @@ export let object: WithLookup export let dragged: boolean - function showCandidate () { + function showCandidate() { showPanel(view.component.EditDoc, object.attachedTo, object.attachedToClass, 'full') } $: todoItems = (object.$lookup?.todoItems as TodoItem[]) ?? [] $: doneTasks = todoItems.filter((it) => it.done) + -
-
- -
-
- {formatName(object.$lookup?.attachedTo?.name ?? '')} +
+
+
+ +
+
+ {formatName(object.$lookup?.attachedTo?.name ?? '')} +
+
{object.$lookup?.attachedTo?.title ?? ''}
-
{object.$lookup?.attachedTo?.title ?? ''}
-
-
- {#if !dragged} -
- -
- - {/if} -
-
-
-
-
- - {#if todoItems.length > 0} - -
- ( {doneTasks?.length}/ {todoItems.length} ) -
-
+
+ {#if !dragged} +
+ +
+ {/if}
- {#if (object.attachments ?? 0) > 0} -
- {/if} - {#if (object.comments ?? 0) > 0} -
- {/if}
- +
+
+
+ + {#if todoItems.length > 0} + +
( {doneTasks?.length}/ {todoItems.length} )
+
+ {/if} +
+ {#if (object.attachments ?? 0) > 0} +
+ +
+ {/if} + {#if (object.comments ?? 0) > 0} +
+ +
+ {/if} +
+ +
diff --git a/plugins/task-resources/src/components/KanbanCard.svelte b/plugins/task-resources/src/components/KanbanCard.svelte index 49eb181ce2..9d62f55134 100644 --- a/plugins/task-resources/src/components/KanbanCard.svelte +++ b/plugins/task-resources/src/components/KanbanCard.svelte @@ -32,43 +32,47 @@ $: todoItems = (object.$lookup?.todoItems as TodoItem[]) ?? [] $: doneTasks = todoItems.filter((it) => it.done) + -
-
- - {#if todoItems.length > 0} - -
- ( {doneTasks?.length}/ {todoItems.length} ) -
-
- {/if} -
-
-
- +
+
+
+ + {#if todoItems.length > 0} + +
( {doneTasks?.length}/ {todoItems.length} )
+
+ {/if}
- { - showMenu(evt) - }} - icon={IconMoreH} - size={'small'} - /> +
+
+ +
+ { + showMenu(evt) + }} + icon={IconMoreH} + size={'small'} /> +
+
+
{object.name}
+ +
+
+ {#if (object.attachments ?? 0) > 0} +
+ +
+ {/if} + {#if (object.comments ?? 0) > 0} +
+ +
+ {/if} +
+
-
{object.name}
- -
-
- {#if (object.attachments ?? 0) > 0} -
- {/if} - {#if (object.comments ?? 0) > 0} -
- {/if} -
- -
diff --git a/plugins/tracker-resources/src/components/issues/Board.svelte b/plugins/tracker-resources/src/components/issues/Board.svelte index d6e8ad4525..4ac9c310a2 100644 --- a/plugins/tracker-resources/src/components/issues/Board.svelte +++ b/plugins/tracker-resources/src/components/issues/Board.svelte @@ -107,7 +107,7 @@ {@const issue = toIssue(object)} -
+
{#if issue.$lookup?.assignee} From 76619163c3e8a4e5c5d2d16623743d53c4a93722 Mon Sep 17 00:00:00 2001 From: Anna No Date: Wed, 13 Apr 2022 11:16:16 +0700 Subject: [PATCH 04/16] Remove paddings from card-container Signed-off-by: Anna No --- packages/kanban/src/components/Kanban.svelte | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/kanban/src/components/Kanban.svelte b/packages/kanban/src/components/Kanban.svelte index 2fbd3e9c26..2a40506a48 100644 --- a/packages/kanban/src/components/Kanban.svelte +++ b/packages/kanban/src/components/Kanban.svelte @@ -257,7 +257,6 @@ cursor: grab; } &.dragged { - padding: 1rem; background-color: var(--board-bg-color); } } From afa335ba3011c44b5161ead586303bc051c64442 Mon Sep 17 00:00:00 2001 From: Anna No Date: Wed, 13 Apr 2022 11:52:36 +0700 Subject: [PATCH 05/16] fix lint formatting Signed-off-by: Anna No --- plugins/board-resources/src/components/KanbanCard.svelte | 4 ++-- plugins/lead-resources/src/components/KanbanCard.svelte | 8 ++++---- .../recruit-resources/src/components/KanbanCard.svelte | 3 +-- plugins/task-resources/src/components/KanbanCard.svelte | 4 ++-- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/plugins/board-resources/src/components/KanbanCard.svelte b/plugins/board-resources/src/components/KanbanCard.svelte index 911c174f23..e59efa3376 100644 --- a/plugins/board-resources/src/components/KanbanCard.svelte +++ b/plugins/board-resources/src/components/KanbanCard.svelte @@ -33,7 +33,6 @@ function showLead() { showPanel(board.component.EditCard, object._id, object._class, 'middle') } -
@@ -51,7 +50,8 @@ showMenu(evt) }} icon={IconMoreH} - size={'small'} /> + size={'small'} + />
diff --git a/plugins/lead-resources/src/components/KanbanCard.svelte b/plugins/lead-resources/src/components/KanbanCard.svelte index 312d7fa279..1e74d3b043 100644 --- a/plugins/lead-resources/src/components/KanbanCard.svelte +++ b/plugins/lead-resources/src/components/KanbanCard.svelte @@ -28,14 +28,13 @@ export let object: WithLookup export let dragged: boolean - function showMenu(ev?: Event): void { + function showMenu (ev?: Event): void { showPopup(ContextMenu, { object }, (ev as MouseEvent).target as HTMLElement) } - function showLead() { + function showLead () { showPanel(view.component.EditDoc, object._id, object._class, 'full') } -
@@ -53,7 +52,8 @@ showMenu(evt) }} icon={IconMoreH} - size={'small'} /> + size={'small'} + />
diff --git a/plugins/recruit-resources/src/components/KanbanCard.svelte b/plugins/recruit-resources/src/components/KanbanCard.svelte index aebeb060f5..9319644864 100644 --- a/plugins/recruit-resources/src/components/KanbanCard.svelte +++ b/plugins/recruit-resources/src/components/KanbanCard.svelte @@ -28,13 +28,12 @@ export let object: WithLookup export let dragged: boolean - function showCandidate() { + function showCandidate () { showPanel(view.component.EditDoc, object.attachedTo, object.attachedToClass, 'full') } $: todoItems = (object.$lookup?.todoItems as TodoItem[]) ?? [] $: doneTasks = todoItems.filter((it) => it.done) -
diff --git a/plugins/task-resources/src/components/KanbanCard.svelte b/plugins/task-resources/src/components/KanbanCard.svelte index 9d62f55134..f4c702ddab 100644 --- a/plugins/task-resources/src/components/KanbanCard.svelte +++ b/plugins/task-resources/src/components/KanbanCard.svelte @@ -32,7 +32,6 @@ $: todoItems = (object.$lookup?.todoItems as TodoItem[]) ?? [] $: doneTasks = todoItems.filter((it) => it.done) -
@@ -55,7 +54,8 @@ showMenu(evt) }} icon={IconMoreH} - size={'small'} /> + size={'small'} + />
{object.name}
From b8722527461cdf466af0dad33aeb27106cc1c6ed Mon Sep 17 00:00:00 2001 From: Anna No Date: Wed, 13 Apr 2022 16:18:44 +0700 Subject: [PATCH 06/16] Fix AttachmentDroppable Signed-off-by: Anna No --- packages/theme/styles/_layouts.scss | 1 + .../src/components/AttachmentDroppable.svelte | 8 ++++-- .../src/components/Attachments.svelte | 4 +-- plugins/board-assets/lang/en.json | 1 + plugins/board-assets/lang/ru.json | 1 + .../src/components/KanbanCard.svelte | 28 ++++++++++++++----- plugins/board-resources/src/plugin.ts | 1 + 7 files changed, 33 insertions(+), 11 deletions(-) diff --git a/packages/theme/styles/_layouts.scss b/packages/theme/styles/_layouts.scss index 4d96da5c59..c2a73818e2 100644 --- a/packages/theme/styles/_layouts.scss +++ b/packages/theme/styles/_layouts.scss @@ -541,6 +541,7 @@ a.no-line { } /* Backgrounds & Colors */ +.background-theme-content-accent { background-color: var(--theme-content-accent-color);} .background-theme-bg-color { background-color: var(--theme-bg-color); } .background-highlight-red { background-color: var(--highlight-red); } .background-button-bg-color { background-color: var(--button-bg-color); } diff --git a/plugins/attachment-resources/src/components/AttachmentDroppable.svelte b/plugins/attachment-resources/src/components/AttachmentDroppable.svelte index 94701dea5a..d808d41c0d 100644 --- a/plugins/attachment-resources/src/components/AttachmentDroppable.svelte +++ b/plugins/attachment-resources/src/components/AttachmentDroppable.svelte @@ -23,12 +23,14 @@ export let objectClass: Ref> export let objectId: Ref export let space: Ref + export let canDrop: ((e: DragEvent) => boolean) | undefined = undefined export let dragover = false const client = getClient() function fileDrop(e: DragEvent) { + dragover = false const list = e.dataTransfer?.files if (list === undefined || list.length === 0) return for (let index = 0; index < list.length; index++) { @@ -40,8 +42,10 @@
{ - dragover = true + on:dragover|preventDefault={(e) => { + if (canDrop?.(e) ?? true) { + dragover = true + } }} on:dragleave={() => { dragover = false diff --git a/plugins/attachment-resources/src/components/Attachments.svelte b/plugins/attachment-resources/src/components/Attachments.svelte index 7047f03933..f6a06ffeb9 100644 --- a/plugins/attachment-resources/src/components/Attachments.svelte +++ b/plugins/attachment-resources/src/components/Attachments.svelte @@ -47,10 +47,10 @@
-
+
-
+
inputFile.click()}>
diff --git a/plugins/board-assets/lang/en.json b/plugins/board-assets/lang/en.json index c137c3714c..75e01c6ec3 100644 --- a/plugins/board-assets/lang/en.json +++ b/plugins/board-assets/lang/en.json @@ -34,6 +34,7 @@ "Dates": "Dates", "Attachments": "Attachments", "AddAttachment": "Add an attachment", + "DropFileToUpload": "Drop files to upload.", "CustomFields": "Custom Fields", "Automation": "Automation", "AddButton": "Add Button", diff --git a/plugins/board-assets/lang/ru.json b/plugins/board-assets/lang/ru.json index a8dcf5f91a..3fd205ab48 100644 --- a/plugins/board-assets/lang/ru.json +++ b/plugins/board-assets/lang/ru.json @@ -34,6 +34,7 @@ "Dates": "Дата", "Attachments": "Прикрепленное", "AddAttachment": "Прикрепить", + "DropFileToUpload": "Добавьте файлы.", "CustomFields": "Дополнительно", "Automation": "Автоматизация", "AddButton": "Добавить", diff --git a/plugins/board-resources/src/components/KanbanCard.svelte b/plugins/board-resources/src/components/KanbanCard.svelte index bb06302732..0ad570c2e1 100644 --- a/plugins/board-resources/src/components/KanbanCard.svelte +++ b/plugins/board-resources/src/components/KanbanCard.svelte @@ -19,7 +19,7 @@ import { CommentsPresenter } from '@anticrm/chunter-resources' import type { WithLookup } from '@anticrm/core' import notification from '@anticrm/notification' - import { ActionIcon, Component, IconMoreH, showPanel, showPopup } from '@anticrm/ui' + import { ActionIcon, Component, IconMoreH, Label, showPanel, showPopup } from '@anticrm/ui' import { ContextMenu } from '@anticrm/view-resources' import board from '../plugin' @@ -29,14 +29,18 @@ let loadingAttachment = 0 let dragoverAttachment = false - function showMenu(ev?: Event): void { + function showMenu (ev?: Event): void { showPopup(ContextMenu, { object }, (ev as MouseEvent).target as HTMLElement) } - function showCard() { + function showCard () { showPanel(board.component.EditCard, object._id, object._class, 'middle') } + function canDropAttachment (e: DragEvent): boolean { + return !!e.dataTransfer?.items && e.dataTransfer?.items.length > 0; + } + -
-
+ space={object.space} + canDrop={canDropAttachment}> +
+ {#if dragoverAttachment} +
+
+
+ {/if} +
{object.title}
@@ -63,7 +77,7 @@ size="small" />
-
+
{#if (object.attachments ?? 0) > 0}
diff --git a/plugins/board-resources/src/plugin.ts b/plugins/board-resources/src/plugin.ts index 9b4a749076..5742a886e3 100644 --- a/plugins/board-resources/src/plugin.ts +++ b/plugins/board-resources/src/plugin.ts @@ -55,6 +55,7 @@ export default mergeIds(boardId, board, { Dates: '' as IntlString, Attachments: '' as IntlString, AddAttachment: '' as IntlString, + DropFileToUpload: '' as IntlString, CustomFields: '' as IntlString, Automation: '' as IntlString, AddButton: '' as IntlString, From 1d5bebcd4c9ef73a43f3baefbd129060d0b77640 Mon Sep 17 00:00:00 2001 From: Anna No Date: Wed, 13 Apr 2022 16:33:22 +0700 Subject: [PATCH 07/16] Fix Attachments spinner Signed-off-by: Anna No --- .../src/components/Attachments.svelte | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/plugins/attachment-resources/src/components/Attachments.svelte b/plugins/attachment-resources/src/components/Attachments.svelte index f6a06ffeb9..5665e10368 100644 --- a/plugins/attachment-resources/src/components/Attachments.svelte +++ b/plugins/attachment-resources/src/components/Attachments.svelte @@ -39,11 +39,14 @@
- + {#if loading} + + {:else} + + {/if}
- {#if loading} - - {:else if attachments === 0} + + {#if attachments === 0 && !loading}
From d7bbf86b9734571fe990bfa6e1635940ace710a2 Mon Sep 17 00:00:00 2001 From: Anna No Date: Wed, 13 Apr 2022 17:46:19 +0700 Subject: [PATCH 08/16] Fix Attachments spinner Signed-off-by: Anna No --- .../src/components/AddAttachment.svelte | 22 ++++--- .../src/components/AttachmentDroppable.svelte | 17 +++--- plugins/attachment-resources/src/utils.ts | 58 +++++++++++-------- 3 files changed, 54 insertions(+), 43 deletions(-) diff --git a/plugins/attachment-resources/src/components/AddAttachment.svelte b/plugins/attachment-resources/src/components/AddAttachment.svelte index 979b1e70fa..34495a9adf 100644 --- a/plugins/attachment-resources/src/components/AddAttachment.svelte +++ b/plugins/attachment-resources/src/components/AddAttachment.svelte @@ -2,7 +2,7 @@ import { Class, Doc, Ref, Space } from '@anticrm/core' import { getClient } from '@anticrm/presentation' import { CircleButton, IconAdd } from '@anticrm/ui' - import { createAttachment } from '../utils' + import { createAttachments } from '../utils' export let loading: number = 0 export let inputFile: HTMLInputElement @@ -10,16 +10,18 @@ export let objectClass: Ref> export let objectId: Ref export let space: Ref - const client = getClient() - function fileSelected() { + async function fileSelected() { const list = inputFile.files if (list === null || list.length === 0) return - for (let index = 0; index < list.length; index++) { - const file = list.item(index) - if (file !== null) createAttachment(client, file, loading, { objectClass, objectId, space }) + + loading++ + try { + await createAttachments(client, list, {objectClass, objectId, space}) + } finally { + loading-- } } @@ -31,13 +33,9 @@
{#if $$slots.control} - + {:else} - + {/if} > export let objectId: Ref export let space: Ref export let canDrop: ((e: DragEvent) => boolean) | undefined = undefined - + export let dragover = false const client = getClient() - - function fileDrop(e: DragEvent) { + + async function fileDrop(e: DragEvent) { dragover = false const list = e.dataTransfer?.files if (list === undefined || list.length === 0) return - for (let index = 0; index < list.length; index++) { - const file = list.item(index) - if (file !== null) createAttachment(client, file, loading, { objectClass, objectId, space }) + + loading++ + try { + await createAttachments(client, list, {objectClass, objectId, space}) + } finally { + loading-- } } diff --git a/plugins/attachment-resources/src/utils.ts b/plugins/attachment-resources/src/utils.ts index 5019e1f8e7..bcc700d847 100644 --- a/plugins/attachment-resources/src/utils.ts +++ b/plugins/attachment-resources/src/utils.ts @@ -14,13 +14,13 @@ // limitations under the License. // -import type { Class, Doc, Ref, Space, TxOperations as Client } from '@anticrm/core' +import type { Class, Doc, Ref, Space, TxOperations as Client } from '@anticrm/core' import login from '@anticrm/login' import { getMetadata, setPlatformStatus, unknownError } from '@anticrm/platform' import attachment from './plugin' -export async function uploadFile (file: File, opts?: { space: Ref, attachedTo: Ref }): Promise { +export async function uploadFile(file: File, opts?: { space: Ref; attachedTo: Ref }): Promise { const uploadUrl = getMetadata(login.metadata.UploadUrl) if (uploadUrl === undefined) { @@ -30,12 +30,16 @@ export async function uploadFile (file: File, opts?: { space: Ref, attach const data = new FormData() data.append('file', file) - const params = opts !== undefined - ? [['space', opts.space], ['attachedTo', opts.attachedTo]] - .filter((x): x is [string, Ref] => x[1] !== undefined) - .map(([name, value]) => `${name}=${value}`) - .join('&') - : '' + const params = + opts !== undefined + ? [ + ['space', opts.space], + ['attachedTo', opts.attachedTo] + ] + .filter((x): x is [string, Ref] => x[1] !== undefined) + .map(([name, value]) => `${name}=${value}`) + .join('&') + : '' const suffix = params === '' ? params : `?${params}` const url = `${uploadUrl}${suffix}` @@ -54,7 +58,7 @@ export async function uploadFile (file: File, opts?: { space: Ref, attach return await resp.text() } -export async function deleteFile (id: string): Promise { +export async function deleteFile(id: string): Promise { const uploadUrl = getMetadata(login.metadata.UploadUrl) const url = `${uploadUrl as string}?file=${id}` @@ -70,27 +74,33 @@ export async function deleteFile (id: string): Promise { } } -export async function createAttachment (client: Client, file: File, loading: number, attachTo: {objectClass: Ref>, space: Ref, objectId: Ref}) { - loading++ - const {objectClass, objectId, space} = attachTo +export async function createAttachments( + client: Client, + list: FileList, + attachTo: { objectClass: Ref>; space: Ref; objectId: Ref } +) { + const { objectClass, objectId, space } = attachTo try { - const uuid = await uploadFile(file, { space, attachedTo: objectId }) - console.log('uploaded file uuid', uuid) - client.addCollection(attachment.class.Attachment, space, objectId, objectClass, 'attachments', { - name: file.name, - file: uuid, - type: file.type, - size: file.size, - lastModified: file.lastModified - }) + for (let index = 0; index < list.length; index++) { + const file = list.item(index) + if (file !== null) { + const uuid = await uploadFile(file, { space, attachedTo: objectId }) + console.log('uploaded file uuid', uuid) + client.addCollection(attachment.class.Attachment, space, objectId, objectClass, 'attachments', { + name: file.name, + file: uuid, + type: file.type, + size: file.size, + lastModified: file.lastModified + }) + } + } } catch (err: any) { setPlatformStatus(unknownError(err)) - } finally { - loading-- } } -export function getType (type: string): 'image' | 'video' | 'audio' | 'pdf' | 'other' { +export function getType(type: string): 'image' | 'video' | 'audio' | 'pdf' | 'other' { if (type.startsWith('image/')) { return 'image' } From 53873c03fc37ec26a423d49fdc6fbbd8b2d99657 Mon Sep 17 00:00:00 2001 From: Anna No Date: Wed, 13 Apr 2022 17:50:46 +0700 Subject: [PATCH 09/16] Fix lint issues Signed-off-by: Anna No --- .../src/components/AddAttachment.svelte | 6 +++--- .../src/components/AttachmentDroppable.svelte | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/attachment-resources/src/components/AddAttachment.svelte b/plugins/attachment-resources/src/components/AddAttachment.svelte index 34495a9adf..b70170e29a 100644 --- a/plugins/attachment-resources/src/components/AddAttachment.svelte +++ b/plugins/attachment-resources/src/components/AddAttachment.svelte @@ -19,7 +19,7 @@ loading++ try { - await createAttachments(client, list, {objectClass, objectId, space}) + await createAttachments(client, list, { objectClass, objectId, space }) } finally { loading-- } @@ -28,7 +28,6 @@ function openFile() { inputFile.click() } -
@@ -44,5 +43,6 @@ name="file" id="file" style="display: none" - on:change={fileSelected} /> + on:change={fileSelected} + />
diff --git a/plugins/attachment-resources/src/components/AttachmentDroppable.svelte b/plugins/attachment-resources/src/components/AttachmentDroppable.svelte index 4ac435dfc8..5209455200 100644 --- a/plugins/attachment-resources/src/components/AttachmentDroppable.svelte +++ b/plugins/attachment-resources/src/components/AttachmentDroppable.svelte @@ -36,12 +36,11 @@ loading++ try { - await createAttachments(client, list, {objectClass, objectId, space}) + await createAttachments(client, list, { objectClass, objectId, space }) } finally { loading-- } } -
{ dragover = false }} - on:drop|preventDefault|stopPropagation={fileDrop}> + on:drop|preventDefault|stopPropagation={fileDrop} +>
From b7842e0c4cfbbc1b2c12fe8767a8c0a82ca0c257 Mon Sep 17 00:00:00 2001 From: Anna No Date: Wed, 13 Apr 2022 20:59:15 +0700 Subject: [PATCH 10/16] Fix lint issues Signed-off-by: Anna No --- plugins/board-resources/src/components/EditCard.svelte | 5 ----- plugins/board-resources/src/components/KanbanCard.svelte | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/plugins/board-resources/src/components/EditCard.svelte b/plugins/board-resources/src/components/EditCard.svelte index 59d59e0aa9..eb967acc64 100644 --- a/plugins/board-resources/src/components/EditCard.svelte +++ b/plugins/board-resources/src/components/EditCard.svelte @@ -139,11 +139,6 @@ {/if}