-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebdav.view.ts
139 lines (106 loc) · 3.08 KB
/
webdav.view.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
namespace $.$$ {
export class $hyoo_webdav extends $.$hyoo_webdav {
render() {
// Ensure for webdav resource are created at server
$mol_http.resource( this.uri_root() ).text()
return super.render()
}
pages() {
return this.webdavs().map( ( webdav ) => ( this.webdav_type( webdav.uri() ) === 'dir' )
? this.Folder( webdav.uri() )
: this.File( webdav.uri() )
)
}
uri_root( next?: string ) {
return $mol_state_arg.value( this.state_key( 'root' ) , next ) || this.uri_root_default()
}
uri_current( next?: string ) {
return $mol_state_arg.value( this.state_key( 'current' ) , next ) || super.uri_current()
}
root() {
return $mol_webdav.item( this.uri_root() )
}
current() {
const root = this.uri_root()
const current = this.uri_current()
if( current.substring( 0 , root.length ) !== root ) return this.root()
return $mol_webdav.item( current )
}
webdav( uri : string ) {
const webdav = $mol_webdav.item( uri )
webdav.credentials = ()=> this.credentials()
return webdav
}
folder_row_current( uri : string ) {
return this.webdavs().indexOf( this.webdav( uri ) ) !== -1
}
webdavs() {
const root = this.root()
const current = this.current()
const webdavs = [ current ]
let webdav = current
while( webdav !== root) {
webdav = webdav.parent()
webdavs.unshift( webdav )
}
return webdavs
}
webdav_type( uri : string ) {
const webdav = this.webdav( uri )
if( webdav === this.root() || webdav.type() === 'dir' ) return 'dir'
return 'file'
}
webdav_title( uri : string ) {
const webdav = this.webdav( uri )
if( webdav === this.root() ) return this.title_root()
return webdav.prop( 'displayname' ) || ''
}
folder_rows( uri : string ) {
return this.webdav( uri ).sub().map( webdav => this.Folder_row( webdav.uri() ) )
}
folder_row_arg( uri : string ) {
return { 'current' : uri }
}
folder_row_icon( uri : string ) {
return this.webdav_type( uri ) === 'dir'
? this.Icon_folder( uri )
: this.Icon_file( uri )
}
folder_row_title( uri : string ) {
return this.webdav( uri )?.prop( 'displayname' ) ?? ''
}
folder_row_descr( uri : string ) {
if( this.webdav_type( uri ) !== 'file' ) return ''
const size = this.file_size( uri )
return `${ size.toLocaleString() } B`
}
file_uri( uri : string ) {
return uri
}
file_mime( uri : string ) {
return this.webdav( uri )?.prop( 'getcontenttype' ) ?? ''
}
file_size( uri : string ) {
return Number( this.webdav( uri ).prop( 'getcontentlength' ) )
}
title() {
return this.webdav_title( this.uri_current() )
}
page_tools( uri : string ) {
return uri === this.uri_root()
? this.tools_root()
: [ this.Close( uri ) ]
}
close_arg( uri : string ) {
return { 'current' : this.webdav( uri ).parent().uri() }
}
}
export class $hyoo_webdav_folder extends $.$hyoo_webdav_folder {
body() {
return [
... this.description() ? [ this.Description() ] : [] ,
this.Folder_rows() ,
]
}
}
}