Skip to content

Commit f4e0825

Browse files
authored
Merge pull request #1433 from MatthewHana/v3.2-devel
WEB UI: Show collection size [SMALL]
2 parents e76011e + b945749 commit f4e0825

File tree

1 file changed

+31
-4
lines changed
  • radicale/web/internal_data

1 file changed

+31
-4
lines changed

radicale/web/internal_data/fn.js

+31-4
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,15 @@ const CollectionType = {
130130
* @param {string} description
131131
* @param {string} color
132132
*/
133-
function Collection(href, type, displayname, description, color, contentcount, source) {
133+
function Collection(href, type, displayname, description, color, contentcount, size, source) {
134134
this.href = href;
135135
this.type = type;
136136
this.displayname = displayname;
137137
this.color = color;
138138
this.description = description;
139139
this.source = source;
140140
this.contentcount = contentcount;
141+
this.size = size;
141142
}
142143

143144
/**
@@ -215,6 +216,7 @@ function get_collections(user, password, collection, callback) {
215216
let calendardesc_element = response.querySelector(response_query + " > *|propstat > *|prop > *|calendar-description");
216217
let addressbookdesc_element = response.querySelector(response_query + " > *|propstat > *|prop > *|addressbook-description");
217218
let contentcount_element = response.querySelector(response_query + " > *|propstat > *|prop > *|getcontentcount");
219+
let contentlength_element = response.querySelector(response_query + " > *|propstat > *|prop > *|getcontentlength");
218220
let webcalsource_element = response.querySelector(response_query + " > *|propstat > *|prop > *|source");
219221
let components_query = response_query + " > *|propstat > *|prop > *|supported-calendar-component-set";
220222
let components_element = response.querySelector(components_query);
@@ -225,12 +227,14 @@ function get_collections(user, password, collection, callback) {
225227
let description = "";
226228
let source = "";
227229
let count = 0;
230+
let size = 0;
228231
if (resourcetype_element) {
229232
if (resourcetype_element.querySelector(resourcetype_query + " > *|addressbook")) {
230233
type = CollectionType.ADDRESSBOOK;
231234
color = addressbookcolor_element ? addressbookcolor_element.textContent : "";
232235
description = addressbookdesc_element ? addressbookdesc_element.textContent : "";
233236
count = contentcount_element ? parseInt(contentcount_element.textContent) : 0;
237+
size = contentlength_element ? parseInt(contentlength_element.textContent) : 0;
234238
} else if (resourcetype_element.querySelector(resourcetype_query + " > *|subscribed")) {
235239
type = CollectionType.WEBCAL;
236240
source = webcalsource_element ? webcalsource_element.textContent : "";
@@ -251,6 +255,7 @@ function get_collections(user, password, collection, callback) {
251255
color = calendarcolor_element ? calendarcolor_element.textContent : "";
252256
description = calendardesc_element ? calendardesc_element.textContent : "";
253257
count = contentcount_element ? parseInt(contentcount_element.textContent) : 0;
258+
size = contentlength_element ? parseInt(contentlength_element.textContent) : 0;
254259
}
255260
}
256261
let sane_color = color.trim();
@@ -263,7 +268,7 @@ function get_collections(user, password, collection, callback) {
263268
}
264269
}
265270
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));
267272
}
268273
}
269274
collections.sort(function(a, b) {
@@ -296,6 +301,7 @@ function get_collections(user, password, collection, callback) {
296301
'<CR:addressbook-description />' +
297302
'<CS:source />' +
298303
'<RADICALE:getcontentcount />' +
304+
'<getcontentlength />' +
299305
'</prop>' +
300306
'</propfind>');
301307
return request;
@@ -772,7 +778,11 @@ function CollectionsScene(user, password, collection, onerror) {
772778
description_form.classList.add("smalltext");
773779
}
774780
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;
776786
}
777787
let href = SERVER + collection.href;
778788
url_form.value = href;
@@ -1183,7 +1193,7 @@ function CreateEditCollectionScene(user, password, collection) {
11831193
}
11841194
let loading_scene = new LoadingScene();
11851195
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);
11871197
let callback = function(error1) {
11881198
if (scene_index === null) {
11891199
return;
@@ -1279,6 +1289,23 @@ function CreateEditCollectionScene(user, password, collection) {
12791289
};
12801290
}
12811291

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+
12821309
function main() {
12831310
// Hide startup loading message
12841311
document.getElementById("loadingscene").classList.add("hidden");

0 commit comments

Comments
 (0)