2021-11-30 15:39:08 +00:00
|
|
|
<!--
|
2021-12-17 09:04:49 +00:00
|
|
|
// Copyright © 2020, 2021 Anticrm Platform Contributors.
|
|
|
|
// Copyright © 2021 Hardcore Engineering Inc.
|
|
|
|
//
|
2021-11-30 15:39:08 +00:00
|
|
|
// 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
|
2021-12-17 09:04:49 +00:00
|
|
|
//
|
2021-11-30 15:39:08 +00:00
|
|
|
// 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.
|
2021-12-17 09:04:49 +00:00
|
|
|
//
|
2021-11-30 15:39:08 +00:00
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
-->
|
|
|
|
<script lang="ts">
|
2022-12-02 18:10:53 +00:00
|
|
|
import { Attachment } from '@hcengineering/attachment'
|
|
|
|
import { Class, Data, Doc, DocumentQuery, Ref, Space } from '@hcengineering/core'
|
2023-04-03 09:17:45 +00:00
|
|
|
import { IntlString } from '@hcengineering/platform'
|
2023-05-19 02:22:38 +00:00
|
|
|
import { Icon, Label, resizeObserver, Scroller, Spinner, Button, IconAdd } from '@hcengineering/ui'
|
2022-12-02 18:10:53 +00:00
|
|
|
import view, { BuildModelKey } from '@hcengineering/view'
|
2022-09-21 08:08:25 +00:00
|
|
|
import { Table } from '@hcengineering/view-resources'
|
2023-05-19 02:22:38 +00:00
|
|
|
import { getClient } from '@hcengineering/presentation'
|
2022-01-11 09:07:29 +00:00
|
|
|
import attachment from '../plugin'
|
2023-05-19 02:22:38 +00:00
|
|
|
import { createAttachments } from '../utils'
|
|
|
|
import { createEventDispatcher } from 'svelte'
|
2022-04-12 17:28:46 +00:00
|
|
|
import AttachmentDroppable from './AttachmentDroppable.svelte'
|
2023-03-21 02:18:08 +00:00
|
|
|
import IconAttachments from './icons/Attachments.svelte'
|
2021-11-30 15:39:08 +00:00
|
|
|
import UploadDuo from './icons/UploadDuo.svelte'
|
|
|
|
|
|
|
|
export let objectId: Ref<Doc>
|
|
|
|
export let space: Ref<Space>
|
|
|
|
export let _class: Ref<Class<Doc>>
|
2022-11-22 18:13:26 +00:00
|
|
|
export let query: DocumentQuery<Doc> = {}
|
2022-12-02 18:10:53 +00:00
|
|
|
export let attachmentClass: Ref<Class<Attachment>> = attachment.class.Attachment
|
|
|
|
export let attachmentClassOptions: Partial<Data<Attachment>> = {}
|
|
|
|
export let extraConfig: (BuildModelKey | string)[] = []
|
|
|
|
export let readonly = false
|
|
|
|
export let showHeader = true
|
2023-04-03 09:17:45 +00:00
|
|
|
export let label: IntlString = attachment.string.Attachments
|
2022-01-12 09:18:50 +00:00
|
|
|
export let attachments: number | undefined = undefined
|
2021-11-30 15:39:08 +00:00
|
|
|
|
|
|
|
let inputFile: HTMLInputElement
|
|
|
|
let loading = 0
|
|
|
|
let dragover = false
|
2022-11-30 05:53:49 +00:00
|
|
|
let wSection: number
|
2023-05-19 02:22:38 +00:00
|
|
|
|
|
|
|
const client = getClient()
|
|
|
|
const dispatch = createEventDispatcher()
|
|
|
|
|
|
|
|
async function fileSelected () {
|
|
|
|
const list = inputFile.files
|
|
|
|
if (list === null || list.length === 0) return
|
|
|
|
|
|
|
|
loading++
|
|
|
|
try {
|
|
|
|
await createAttachments(
|
|
|
|
client,
|
|
|
|
list,
|
|
|
|
{ objectClass: _class, objectId, space },
|
|
|
|
attachmentClass,
|
|
|
|
attachmentClassOptions
|
|
|
|
)
|
|
|
|
} finally {
|
|
|
|
loading--
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inputFile) {
|
|
|
|
inputFile.value = ''
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch('attached')
|
|
|
|
}
|
|
|
|
|
|
|
|
function openFile () {
|
|
|
|
inputFile.click()
|
|
|
|
}
|
2023-08-11 07:22:56 +00:00
|
|
|
|
|
|
|
function updateContent (evt: CustomEvent) {
|
|
|
|
attachments = evt.detail.length
|
|
|
|
dispatch('attachments', evt.detail)
|
|
|
|
}
|
2021-11-30 15:39:08 +00:00
|
|
|
</script>
|
|
|
|
|
2022-11-30 05:53:49 +00:00
|
|
|
<div class="antiSection" use:resizeObserver={(element) => (wSection = element.clientWidth)}>
|
2023-05-19 02:22:38 +00:00
|
|
|
{#if showHeader}
|
|
|
|
<div class="antiSection-header">
|
|
|
|
<div class="antiSection-header__icon">
|
2023-03-21 02:18:08 +00:00
|
|
|
<Icon icon={IconAttachments} size={'small'} />
|
2023-05-19 02:22:38 +00:00
|
|
|
</div>
|
|
|
|
<span class="antiSection-header__title">
|
2023-04-03 09:17:45 +00:00
|
|
|
<Label {label} />
|
2023-05-19 02:22:38 +00:00
|
|
|
</span>
|
|
|
|
<div class="buttons-group small-gap">
|
|
|
|
{#if loading}
|
|
|
|
<Spinner />
|
|
|
|
{:else if !readonly}
|
2023-07-06 07:01:27 +00:00
|
|
|
<Button icon={IconAdd} kind={'ghost'} on:click={openFile} />
|
2023-05-19 02:22:38 +00:00
|
|
|
{/if}
|
|
|
|
</div>
|
2022-06-28 06:50:39 +00:00
|
|
|
</div>
|
2023-05-19 02:22:38 +00:00
|
|
|
{/if}
|
2022-04-13 09:33:22 +00:00
|
|
|
|
2023-05-19 02:22:38 +00:00
|
|
|
<input
|
|
|
|
bind:this={inputFile}
|
|
|
|
multiple
|
|
|
|
type="file"
|
|
|
|
name="file"
|
|
|
|
id="file"
|
|
|
|
style="display: none"
|
|
|
|
on:change={fileSelected}
|
|
|
|
/>
|
2022-12-02 18:10:53 +00:00
|
|
|
{#if !loading && (attachments === null || attachments === 0) && !readonly}
|
2023-02-27 06:20:18 +00:00
|
|
|
<AttachmentDroppable
|
|
|
|
bind:loading
|
|
|
|
bind:dragover
|
|
|
|
objectClass={_class}
|
|
|
|
{objectId}
|
|
|
|
{space}
|
|
|
|
{attachmentClass}
|
|
|
|
{attachmentClassOptions}
|
|
|
|
>
|
2023-05-19 02:22:38 +00:00
|
|
|
<div class="antiSection-empty attachments flex-col" class:mt-3={showHeader} class:solid={dragover}>
|
2023-05-05 05:21:40 +00:00
|
|
|
<div class="flex-center caption-color">
|
2022-06-28 06:50:39 +00:00
|
|
|
<UploadDuo size={'large'} />
|
|
|
|
</div>
|
2023-05-05 05:21:40 +00:00
|
|
|
<div class="text-sm content-dark-color" style:pointer-events="none">
|
2022-04-12 17:28:46 +00:00
|
|
|
<Label label={attachment.string.NoAttachments} />
|
|
|
|
</div>
|
2022-11-22 18:13:26 +00:00
|
|
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
2022-06-28 06:50:39 +00:00
|
|
|
<div
|
2023-05-05 05:21:40 +00:00
|
|
|
class="over-underline text-sm caption-color"
|
2022-06-28 06:50:39 +00:00
|
|
|
style:pointer-events={dragover ? 'none' : 'all'}
|
|
|
|
on:click={() => inputFile.click()}
|
|
|
|
>
|
|
|
|
<Label label={attachment.string.UploadDropFilesHere} />
|
2022-04-12 17:28:46 +00:00
|
|
|
</div>
|
2021-11-30 15:39:08 +00:00
|
|
|
</div>
|
2022-04-12 17:28:46 +00:00
|
|
|
</AttachmentDroppable>
|
2022-11-30 05:53:49 +00:00
|
|
|
{:else if wSection < 640}
|
|
|
|
<Scroller horizontal>
|
|
|
|
<Table
|
2022-12-02 18:10:53 +00:00
|
|
|
_class={attachmentClass}
|
2022-11-30 05:53:49 +00:00
|
|
|
config={[
|
|
|
|
'',
|
|
|
|
'description',
|
|
|
|
{
|
|
|
|
key: 'pinned',
|
|
|
|
presenter: view.component.BooleanTruePresenter,
|
|
|
|
label: attachment.string.Pinned,
|
|
|
|
sortingKey: 'pinned'
|
|
|
|
},
|
2022-12-02 18:10:53 +00:00
|
|
|
...extraConfig,
|
2022-11-30 05:53:49 +00:00
|
|
|
'lastModified'
|
|
|
|
]}
|
|
|
|
options={{ sort: { pinned: -1 } }}
|
|
|
|
query={{ ...query, attachedTo: objectId }}
|
|
|
|
loadingProps={{ length: attachments ?? 0 }}
|
2023-08-11 07:22:56 +00:00
|
|
|
on:content={updateContent}
|
2022-12-02 18:10:53 +00:00
|
|
|
{readonly}
|
2022-11-30 05:53:49 +00:00
|
|
|
/>
|
|
|
|
</Scroller>
|
2021-11-30 15:39:08 +00:00
|
|
|
{:else}
|
2021-12-02 13:12:16 +00:00
|
|
|
<Table
|
2022-12-02 18:10:53 +00:00
|
|
|
_class={attachmentClass}
|
2022-05-28 07:33:11 +00:00
|
|
|
config={[
|
|
|
|
'',
|
|
|
|
'description',
|
|
|
|
{
|
|
|
|
key: 'pinned',
|
|
|
|
presenter: view.component.BooleanTruePresenter,
|
|
|
|
label: attachment.string.Pinned,
|
|
|
|
sortingKey: 'pinned'
|
|
|
|
},
|
2022-12-02 18:10:53 +00:00
|
|
|
...extraConfig,
|
2022-05-28 07:33:11 +00:00
|
|
|
'lastModified'
|
|
|
|
]}
|
|
|
|
options={{ sort: { pinned: -1 } }}
|
2022-11-22 18:13:26 +00:00
|
|
|
query={{ ...query, attachedTo: objectId }}
|
2022-04-23 02:40:38 +00:00
|
|
|
loadingProps={{ length: attachments ?? 0 }}
|
2023-08-11 07:22:56 +00:00
|
|
|
on:content={updateContent}
|
2022-12-02 18:10:53 +00:00
|
|
|
{readonly}
|
2022-04-23 02:40:38 +00:00
|
|
|
/>
|
2021-11-30 15:39:08 +00:00
|
|
|
{/if}
|
|
|
|
</div>
|