Feng Forum

Other Topics => Development => Community Contributions => : Henry December 30, 2010, 06:26:21 PM

: Mod: column filesize in list view
: Henry December 30, 2010, 06:26:21 PM
Hi,
i created a mod that added the column size in the documents list view.


created with FO version: 1.7.3.1

Have fun.

Henry

: Re: Mod: column filesize in list view
: Robert1724 January 01, 2011, 12:44:57 PM
Hi:

Can you describe how to turn modify the code to display the size of documents ?
: Re: Mod: column filesize in list view
: Henry January 01, 2011, 03:56:44 PM
you change the code of this two files.

\public\assets\javascript\og\FileManager.js
\public\assets\javascript\og\og.js

the file "FileManager.js" contains the code to generate the documents list.

line 11 define the fields or attributes of the files.
the field list must extend with the attribute "size".
:
this.fields =
['name', 'object_id', 'type', 'tags', 'createdBy', 'createdById',
 ...
'isMP3','size'];

Now we need a render function. This function generate the formated size information. I have create the function between the other render functions.

:
function renderSize(value, p, r) {
if (!value) {
return "";
}
return userString = String.format('{0}',og.filesizeFormat(r.data.size));

}

The 3. step is necessary to create the new column in the document list.
at the end (after action) of the column declarations you can add the new size column.
:
},{
id: 'actions',
header: lang("actions"),
width: 50,
renderer: renderActions,
sortable: false
},{
id: 'size',
header: lang("size"),
dataIndex: 'size',
width: 50,   
renderer: renderSize,    // call the renderSize function
sortable: true           // i don't no why, but this column is not sortable
        }]);


This are all changes in the FileManager.js
Now it works but  the size is showing like 2.2.6 MB.

To change this you must change the og.filesizeFormat function in  og.js file.

:
/* original entry
og.filesizeFormat = function(fs) {
if (fs > 1024 * 1024) {
var total = Math.round(fs / 1024 / 1024 * 10);
return total / 10 + "." + total % 10 + " MB";
} else {
var total = Math.round(fs / 1024 * 10);
return total / 10 + "." + total % 10 + " KB";
}
};
*/
// new function to calulate the filesize
og.filesizeFormat = function(fs) {
var units = new Array(' B',' KiB',' MiB',' GiB',' TiB'); // More informations http://en.wikipedia.org/wiki/Byte
var i = 0;
while (i<units.length && fs > 1024){
fs = fs / 1024;
i++;
}
if (i!=0){
fs = Math.round(fs * 100)/100;
}
return fs + units[i];
};

My english is terrible but i hope you can understand me.



: Re: Mod: column filesize in list view
: franponce87 January 03, 2011, 08:56:37 AM
Once again, thanks for the contribution Henry!
Your English is more than great, so do not worry about it!


Keep up the good work!

Best regards,
Francisco
: Re: Mod: column filesize in list view
: filriyadh January 11, 2011, 10:47:06 AM
nice write up. Thanks