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'
|
2022-12-02 18:10:53 +00:00
|
|
|
import { Icon, Label, resizeObserver, Scroller, Spinner } from '@hcengineering/ui'
|
|
|
|
import view, { BuildModelKey } from '@hcengineering/view'
|
2022-09-21 08:08:25 +00:00
|
|
|
import { Table } from '@hcengineering/view-resources'
|
2022-01-11 09:07:29 +00:00
|
|
|
import attachment from '../plugin'
|
2022-04-12 17:28:46 +00:00
|
|
|
import AddAttachment from './AddAttachment.svelte'
|
|
|
|
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
|
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)}>
|
2022-06-28 06:50:39 +00:00
|
|
|
<div class="antiSection-header">
|
|
|
|
<div class="antiSection-header__icon">
|
2022-12-02 18:10:53 +00:00
|
|
|
{#if showHeader}
|
2023-03-21 02:18:08 +00:00
|
|
|
<Icon icon={IconAttachments} size={'small'} />
|
2022-12-02 18:10:53 +00:00
|
|
|
{/if}
|
2022-06-28 06:50:39 +00:00
|
|
|
</div>
|
2022-12-02 18:10:53 +00:00
|
|
|
<span class="antiSection-header__title">
|
|
|
|
{#if showHeader}
|
2023-04-03 09:17:45 +00:00
|
|
|
<Label {label} />
|
2022-12-02 18:10:53 +00:00
|
|
|
{/if}
|
|
|
|
</span>
|
2022-06-28 06:50:39 +00:00
|
|
|
<div class="buttons-group small-gap">
|
|
|
|
{#if loading}
|
|
|
|
<Spinner />
|
2022-12-02 18:10:53 +00:00
|
|
|
{:else if !readonly}
|
|
|
|
<AddAttachment
|
|
|
|
bind:loading
|
|
|
|
bind:inputFile
|
|
|
|
objectClass={_class}
|
|
|
|
{objectId}
|
|
|
|
{space}
|
|
|
|
{attachmentClass}
|
|
|
|
{attachmentClassOptions}
|
|
|
|
/>
|
2022-06-28 06:50:39 +00:00
|
|
|
{/if}
|
|
|
|
</div>
|
2021-11-30 15:39:08 +00:00
|
|
|
</div>
|
2022-04-13 09:33:22 +00:00
|
|
|
|
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}
|
|
|
|
>
|
2022-06-28 06:50:39 +00:00
|
|
|
<div class="antiSection-empty attachments flex-col mt-3" class:solid={dragover}>
|
|
|
|
<div class="flex-center content-accent-color">
|
|
|
|
<UploadDuo size={'large'} />
|
|
|
|
</div>
|
|
|
|
<div class="text-sm 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
|
|
|
|
class="over-underline text-sm content-accent-color"
|
|
|
|
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 }}
|
|
|
|
on:content={(evt) => {
|
|
|
|
attachments = evt.detail.length
|
|
|
|
}}
|
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 }}
|
2022-11-22 18:13:26 +00:00
|
|
|
on:content={(evt) => {
|
|
|
|
attachments = evt.detail.length
|
|
|
|
}}
|
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>
|