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-11-22 18:13:26 +00:00
|
|
|
import { Class, Doc, DocumentQuery, Ref, Space } from '@hcengineering/core'
|
2022-11-30 05:53:49 +00:00
|
|
|
import { Icon, Label, Spinner, resizeObserver, Scroller } from '@hcengineering/ui'
|
2022-09-21 08:08:25 +00:00
|
|
|
import view from '@hcengineering/view'
|
|
|
|
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'
|
2022-11-22 18:13:26 +00:00
|
|
|
import IconAttachment from './icons/Attachment.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-04-12 17:28:46 +00:00
|
|
|
|
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">
|
|
|
|
<Icon icon={IconAttachment} size={'small'} />
|
|
|
|
</div>
|
|
|
|
<span class="antiSection-header__title"><Label label={attachment.string.Attachments} /></span>
|
|
|
|
<div class="buttons-group small-gap">
|
|
|
|
{#if loading}
|
|
|
|
<Spinner />
|
|
|
|
{:else}
|
|
|
|
<AddAttachment bind:loading bind:inputFile objectClass={_class} {objectId} {space} />
|
|
|
|
{/if}
|
|
|
|
</div>
|
2021-11-30 15:39:08 +00:00
|
|
|
</div>
|
2022-04-13 09:33:22 +00:00
|
|
|
|
2022-05-25 05:56:06 +00:00
|
|
|
{#if !loading && (attachments === null || attachments === 0)}
|
2022-04-12 17:28:46 +00:00
|
|
|
<AttachmentDroppable bind:loading bind:dragover objectClass={_class} {objectId} {space}>
|
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
|
|
|
|
_class={attachment.class.Attachment}
|
|
|
|
config={[
|
|
|
|
'',
|
|
|
|
'description',
|
|
|
|
{
|
|
|
|
key: 'pinned',
|
|
|
|
presenter: view.component.BooleanTruePresenter,
|
|
|
|
label: attachment.string.Pinned,
|
|
|
|
sortingKey: 'pinned'
|
|
|
|
},
|
|
|
|
'lastModified'
|
|
|
|
]}
|
|
|
|
options={{ sort: { pinned: -1 } }}
|
|
|
|
query={{ ...query, attachedTo: objectId }}
|
|
|
|
loadingProps={{ length: attachments ?? 0 }}
|
|
|
|
on:content={(evt) => {
|
|
|
|
attachments = evt.detail.length
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</Scroller>
|
2021-11-30 15:39:08 +00:00
|
|
|
{:else}
|
2021-12-02 13:12:16 +00:00
|
|
|
<Table
|
2021-12-06 10:07:08 +00:00
|
|
|
_class={attachment.class.Attachment}
|
2022-05-28 07:33:11 +00:00
|
|
|
config={[
|
|
|
|
'',
|
|
|
|
'description',
|
|
|
|
{
|
|
|
|
key: 'pinned',
|
|
|
|
presenter: view.component.BooleanTruePresenter,
|
|
|
|
label: attachment.string.Pinned,
|
|
|
|
sortingKey: 'pinned'
|
|
|
|
},
|
|
|
|
'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-04-23 02:40:38 +00:00
|
|
|
/>
|
2021-11-30 15:39:08 +00:00
|
|
|
{/if}
|
|
|
|
</div>
|