// Вкладка «Файлы»: передача файлов через сервер команды и архивы проектов.import{Fragment}from'preact';import{ useEffect, useMemo, useRef, useState }from'preact/hooks';import{
html, rpc, act, toast, useRes, invalidate, mutateRes, humanError, svc, roleAtLeast, relTime, fmtDateTime,
humanBytes, plural, saveUi,}from'./core.js';import{Icon, fileIconFor }from'./icons.js';import{Avatar confirmDialog
uploadSeq
xhr
qs kind teamId
recipientId qs recipientId
note qs note
projectName qs projectName
promise
xhr qs
xhr svc
xhr file
xhr file
xhr e e e
xhr
body
body xhr
xhr xhr body
bodyerror xhr xhr
xhr
xhr
xhrfile
xhr promise
items setItems
list x id x p x
id uploadSeq
xhr promise file opts s id p
list id file xhr opts
promise
id
opts
list x id
e list x id
id e e e
it items x id itxhr
it items x id
it
list x id
it it
list x id
items start cancel retry dismiss
pct it
html
r err method s params
err r
html r
mine fid myId
toMe fid myId
keyFors list x f
err s f
err
expiresSoon f f
html
archives keyFors s
limits keyFors s
project setProject
input
keyFors list x a
err s a
err
f files uploadsf project f
list archives
htmldiv
role s
canEdit role
canDel role
user s
uploads s
recipient setRecipient
note setNote
view setView svcuifilesView
hot setHot
input
root
depth
members boardmembers m userid
canEdit
list
f list uploadsf recipient note
pane root
pane
etypes
e e depth
e e e
e depth depth depth
e e depth e
pane enter
pane over
pane leave
pane drop
pane enter pane over pane leave pane drop
all files
list all
mine fid userid
view mine f f userid
view mine
ba all view userid
inCount all fid userid f f userid
outCount all fid userid
html
section
div
$ value$view onChange$ v v label
options$
div
$files html
list html
html
section
$ s$s uploads$uploads canEdit$canEdit canDel$canDel
div`
`<sectionclass="stack-s"><divclass="row"><divclass="sec-title"><${Icon}name="archive"size=${14}/>Архивы проектов</div><spanclass="grow"></span>${limits.data? html`<spanclass="faint xs">до ${humanBytes(limits.data.archiveMaxBytes)} · хранятся ${limits.data.archiveTtlDays}${plural(limits.data.archiveTtlDays,'день','дня','дней')}</span>`:null</div>${canEdit ? html`<divclass="row"><inputclass="inp sm grow"value=${project}placeholder="Проект (необязательно)"aria-label="Название проекта"onInput=${(e)=>setProject(e.currentTarget.value)}/>
Загрузить архив
${!archives.data? html`<${SkelList}rows=${2}/>`:!list.length? html`<divclass="card"><${Empty}icon="archive"title="Архивов нет
html`div $list html`div key$a style$ i
span $ name size$ span
div div style$adiv
div $a · $aname a · $a$a a divdiv
button type onClick$ s a svcworkspace a$ name size$ Скачатьbutton
$canDel html </div>`
)
}
<
/
>
`}
</section>`
;
}
export
function
FilesTab
(
{ s, files, board, active }
)
{
const
=
myRole
(
)
;
const
=
roleAtLeast
(
,
'dev'
)
;
const
=
roleAtLeast
(
,
'maintainer'
)
;
const
=
me
(
)
;
const
=
useUploads
(
)
;
const
[
,
]
=
useState
(
''
)
;
const
[
,
]
=
useState
(
''
)
;
const
[
,
]
=
useState
(
.
state
?.
?.
||
'in'
)
;
const
[
,
]
=
useState
(
false
)
;
const
=
useRef
(
null
)
;
const
=
useRef
(
null
)
;
const
=
useRef
(
0
)
;
const
=
(
.
data
?.
??
[
]
)
.
filter
(
(
m
)
=>
.
id
!==
?.
)
;
const
send
=
(
list
)
=>
{
if
(
!
)
{
toast
(
'Наблюдатель не может отправлять файлы'
,
{
kind
:
'err'
}
)
;
return
;
}
if
(
!
.
length
)
return
;
for
(
const
of
)
.
start
(
,
{
kind
:
'file'
,
recipientId
:
||
undefined
,
note
:
.
trim
(
)
||
undefined
}
)
;
setNote
(
''
)
;
}
;
// Перетаскивание файлов в любую точку вкладки.
useEffect
(
(
)
=>
{
const
=
.
current
?.
closest
(
'.pane'
)
;
if
(
!
)
return
;
const
hasFiles
=
(
e
)
=>
[
...
(
.
dataTransfer
?.
||
[
]
)
]
.
includes
(
'Files'
)
;
const
enter
=
(
e
)
=>
{
if
(
!
hasFiles
(
)
)
return
;
.
preventDefault
(
)
;
.
current
++
;
setHot
(
true
)
;
}
;
const
over
=
(
e
)
=>
{
if
(
!
hasFiles
(
)
)
return
;
.
preventDefault
(
)
;
.
dataTransfer
.
dropEffect
=
'copy'
;
}
;
const
leave
=
(
e
)
=>
{
if
(
!
hasFiles
(
)
)
return
;
.
current
=
Math
.
max
(
0
,
.
current
-
1
)
;
if
(
!
.
current
)
setHot
(
false
)
;
}
;
const
drop
=
(
e
)
=>
{
if
(
!
hasFiles
(
)
)
return
;
.
preventDefault
(
)
;
.
current
=
0
;
setHot
(
false
)
;
send
(
[
...
.
dataTransfer
.
files
]
)
;
}
;
.
addEventListener
(
'dragenter'
,
)
;
.
addEventListener
(
'dragover'
,
)
;
.
addEventListener
(
'dragleave'
,
)
;
.
addEventListener
(
'drop'
,
)
;
return
(
)
=>
{
.
removeEventListener
(
'dragenter'
,
)
;
.
removeEventListener
(
'dragover'
,
)
;
.
removeEventListener
(
'dragleave'
,
)
;
.
removeEventListener
(
'drop'
,
)
;
}
;
}
)
;
const
=
.
data
??
[
]
;
const
=
useMemo
(
(
)
=>
.
filter
(
(
f
)
=>
{
const
=
.
createdBy
?.
===
?.
;
if
(
===
'in'
)
return
!
&&
(
!
.
recipient
||
.
recipient
.
id
===
?.
)
;
if
(
===
'out'
)
return
;
return
true
;
}
)
.
sort
(
(
a, b
)
=>
String
(
.
createdAt
)
.
localeCompare
(
String
(
.
createdAt
)
)
)
,
[
,
,
?.
]
)
;
const
=
.
filter
(
(
f
)
=>
.
createdBy
?.
!==
?.
&&
(
!
.
recipient
||
.
recipient
.
id
===
?.
)
)
.
length
;
const
=
.
filter
(
(
f
)
=>
.
createdBy
?.
===
?.
)
.
length
;
return
`<divclass="pad stack"ref=${root}style="gap:18px">${hot ? html`<divclass="drop-overlay"><divclass="inner"><${Icon}name="upload"size=${28}/>Отпустите, чтобы отправить${recipient ?' — '+(members.find((m)=> m.id=== recipient)?.displayName ||''):' всей команде'}</div></div>`:null}${canEdit ? html`<section class="stack-s"><div class="sec-title"><${Icon} name="send" size=${14}/>Отправить файлы</div><div class="card pad stack-s"><div class=${'dropzone'+(hot ?' hot':'')}><${Icon} name="upload" size=${22}/>
divspan styleПеретащите файлы сюдаspan илиdiv
button type onClick$ inputВыбрать файлыbutton
input ref$input type multiple hidden datakind onChange$ e e
div
div
span styleКомуspan
$ sm value$recipient label onChange$setRecipient
options$ members m m
div
input value$note maxlength placeholder arialabel onInput$ e
div
$uploads html </section>`
:
null
}
<
class
=
"stack-s"
>
<
class
=
"row"
>
<
{
Seg
}
=
{
}
=
{
(
v
)
=>
{
setView
(
)
;
saveUi
(
{
filesView
:
}
)
;
}
}
=
"Список файлов"
=
{
[
{
id
:
'in'
,
label
:
`Входящие${inCount ?' '+ inCount :''}`
}
,
{
id
:
'out'
,
label
:
`Отправленные${outCount ?' '+ outCount :''}`
}
,
{
id
:
'all'
,
label
:
'Все'
}
]
}
/
>
<
/
>
{
!
.
data
?
`<${SkelList}rows=${3}/>`
:
!
.
length
?
`<divclass="card"><${Empty}icon="inbox"title=${view ==='out'?'Вы ещё ничего не отправляли':'Входящих нет'}text="Файлы хранятся на сервере команды ограниченное время и удаляются автоматически."/></div>`