@@ -130,14 +130,15 @@ const CollectionType = {
130
130
* @param {string } description
131
131
* @param {string } color
132
132
*/
133
- function Collection ( href , type , displayname , description , color , contentcount , source ) {
133
+ function Collection ( href , type , displayname , description , color , contentcount , size , source ) {
134
134
this . href = href ;
135
135
this . type = type ;
136
136
this . displayname = displayname ;
137
137
this . color = color ;
138
138
this . description = description ;
139
139
this . source = source ;
140
140
this . contentcount = contentcount ;
141
+ this . size = size ;
141
142
}
142
143
143
144
/**
@@ -215,6 +216,7 @@ function get_collections(user, password, collection, callback) {
215
216
let calendardesc_element = response . querySelector ( response_query + " > *|propstat > *|prop > *|calendar-description" ) ;
216
217
let addressbookdesc_element = response . querySelector ( response_query + " > *|propstat > *|prop > *|addressbook-description" ) ;
217
218
let contentcount_element = response . querySelector ( response_query + " > *|propstat > *|prop > *|getcontentcount" ) ;
219
+ let contentlength_element = response . querySelector ( response_query + " > *|propstat > *|prop > *|getcontentlength" ) ;
218
220
let webcalsource_element = response . querySelector ( response_query + " > *|propstat > *|prop > *|source" ) ;
219
221
let components_query = response_query + " > *|propstat > *|prop > *|supported-calendar-component-set" ;
220
222
let components_element = response . querySelector ( components_query ) ;
@@ -225,12 +227,14 @@ function get_collections(user, password, collection, callback) {
225
227
let description = "" ;
226
228
let source = "" ;
227
229
let count = 0 ;
230
+ let size = 0 ;
228
231
if ( resourcetype_element ) {
229
232
if ( resourcetype_element . querySelector ( resourcetype_query + " > *|addressbook" ) ) {
230
233
type = CollectionType . ADDRESSBOOK ;
231
234
color = addressbookcolor_element ? addressbookcolor_element . textContent : "" ;
232
235
description = addressbookdesc_element ? addressbookdesc_element . textContent : "" ;
233
236
count = contentcount_element ? parseInt ( contentcount_element . textContent ) : 0 ;
237
+ size = contentlength_element ? parseInt ( contentlength_element . textContent ) : 0 ;
234
238
} else if ( resourcetype_element . querySelector ( resourcetype_query + " > *|subscribed" ) ) {
235
239
type = CollectionType . WEBCAL ;
236
240
source = webcalsource_element ? webcalsource_element . textContent : "" ;
@@ -251,6 +255,7 @@ function get_collections(user, password, collection, callback) {
251
255
color = calendarcolor_element ? calendarcolor_element . textContent : "" ;
252
256
description = calendardesc_element ? calendardesc_element . textContent : "" ;
253
257
count = contentcount_element ? parseInt ( contentcount_element . textContent ) : 0 ;
258
+ size = contentlength_element ? parseInt ( contentlength_element . textContent ) : 0 ;
254
259
}
255
260
}
256
261
let sane_color = color . trim ( ) ;
@@ -263,7 +268,7 @@ function get_collections(user, password, collection, callback) {
263
268
}
264
269
}
265
270
if ( href . substr ( - 1 ) === "/" && href !== collection . href && type ) {
266
- collections . push ( new Collection ( href , type , displayname , description , sane_color , count , source ) ) ;
271
+ collections . push ( new Collection ( href , type , displayname , description , sane_color , count , size , source ) ) ;
267
272
}
268
273
}
269
274
collections . sort ( function ( a , b ) {
@@ -296,6 +301,7 @@ function get_collections(user, password, collection, callback) {
296
301
'<CR:addressbook-description />' +
297
302
'<CS:source />' +
298
303
'<RADICALE:getcontentcount />' +
304
+ '<getcontentlength />' +
299
305
'</prop>' +
300
306
'</propfind>' ) ;
301
307
return request ;
@@ -772,7 +778,11 @@ function CollectionsScene(user, password, collection, onerror) {
772
778
description_form . classList . add ( "smalltext" ) ;
773
779
}
774
780
if ( collection . type != CollectionType . WEBCAL ) {
775
- contentcount_form . textContent = ( collection . contentcount > 0 ? collection . contentcount : "No" ) + " item" + ( collection . contentcount == 1 ? "" : "s" ) + " in collection" ;
781
+ let contentcount_form_txt = ( collection . contentcount > 0 ? Number ( collection . contentcount ) . toLocaleString ( ) : "No" ) + " item" + ( collection . contentcount == 1 ? "" : "s" ) + " in collection" ;
782
+ if ( collection . contentcount > 0 ) {
783
+ contentcount_form_txt += " (" + bytesToHumanReadable ( collection . size ) + ")" ;
784
+ }
785
+ contentcount_form . textContent = contentcount_form_txt ;
776
786
}
777
787
let href = SERVER + collection . href ;
778
788
url_form . value = href ;
@@ -1183,7 +1193,7 @@ function CreateEditCollectionScene(user, password, collection) {
1183
1193
}
1184
1194
let loading_scene = new LoadingScene ( ) ;
1185
1195
push_scene ( loading_scene ) ;
1186
- let collection = new Collection ( href , type , displayname , description , sane_color , 0 , source ) ;
1196
+ let collection = new Collection ( href , type , displayname , description , sane_color , 0 , 0 , source ) ;
1187
1197
let callback = function ( error1 ) {
1188
1198
if ( scene_index === null ) {
1189
1199
return ;
@@ -1279,6 +1289,23 @@ function CreateEditCollectionScene(user, password, collection) {
1279
1289
} ;
1280
1290
}
1281
1291
1292
+ /**
1293
+ * Format bytes to human-readable text.
1294
+ *
1295
+ * @param bytes Number of bytes.
1296
+ *
1297
+ * @return Formatted string.
1298
+ */
1299
+ function bytesToHumanReadable ( bytes , dp = 1 ) {
1300
+ let isNumber = ! isNaN ( parseFloat ( bytes ) ) && ! isNaN ( bytes - 0 ) ;
1301
+ if ( ! isNumber ) {
1302
+ return "" ;
1303
+ }
1304
+ var i = bytes == 0 ? 0 : Math . floor ( Math . log ( bytes ) / Math . log ( 1024 ) ) ;
1305
+ return ( bytes / Math . pow ( 1024 , i ) ) . toFixed ( dp ) * 1 + ' ' + [ 'b' , 'kb' , 'mb' , 'gb' , 'tb' ] [ i ] ;
1306
+ }
1307
+
1308
+
1282
1309
function main ( ) {
1283
1310
// Hide startup loading message
1284
1311
document . getElementById ( "loadingscene" ) . classList . add ( "hidden" ) ;
0 commit comments