You are viewing limited content. For full access, please sign in.

Discussion

Discussion

HOWTO: Convert "Total document size" bytes into a readable format in WebLink 9.x

posted on May 27, 2016 Show version history

All,

 

By default Laserfiche WebLink displays the size of an entry in the "Total document size" column in bytes. While this may be easier for a computer to understand it's not informative nor easy to understand. To help with this problem I have created a simple little JavaScript plugin that will automatically reformat the byte value found in the "Total document size" column into a easier to read format. This plugin also removes the "0" from showing on folders.

 

 

1. Open the "Browse.aspx" file into an editor and add the following code right before the ending "</body>" element:

 

<script type="text/javascript" src="<%= Page.ResolveUrl("~/script/readable_bytes.js")%>"></script>

 

2. Save and close

 

3. Copy and paste the following JavaScript into an empty text document and save it as "readable_bytes.js" in the Laserfiche WebLink "script" folder:

 

// Title: Readable Bytes for Laserfiche WebLink
// About: Converts the bytes displayed in the "Total document size" column into a more friendly format.
// Version: 1.0 (American date format)
// Date: 05/27/2016 (mm/dd/yyyy)
// Compatibility: Laserfiche WebLink 9.x
// Install: Place readable_bytes.js file in the Laserfiche WebLink script folder. Open up
//          the Browse.aspx file in an editor and add the following code before the </body> element:
//
//          <script type="text/javascript" src="<%= Page.ResolveUrl("~/script/readable_bytes.js")%>"></script>
//
//          Save Browse.aspx and refresh the page

// Class name for header title cells
var header_cell_class = ".EntrySorterCell";

// Title of header column that contains the byte information
var header_byte_title = "Total document size";
// Precision of newly formatted byte value (i.e 1 MB, 1.1 MB, 1.11 MB, etc.,)
var format_precision = 0;

$(document).ready(function () {

    //Variable used to indicate column index number
    var a = 0;
    //Obtain the header cells in the browse table and loop through them until we find the "Total document size" column
    $(header_cell_class).each(function () {
        //Increase column index number variable by 1
        a++;
        //Check to see if this column header text matches the one we want
        if ($(this).text() == header_byte_title) {
            //Now that we found the column we want go ahead and go through each cell in the column and format the bytes if found
            $(".DocumentBrowserDisplayTable .DocumentBrowserCell:nth-child(" + a + ")").each(function () {
                //Format the bytes
                var b = format_bytes($(this).text(), format_precision);
                //Clear out exsisting value. This will also remove the 0 from appearing from folders
                $(this).empty();
                //Set the newly formatted text
                $(this).text(b);
            });
        }
    });
});

/**
 * Format given byte value into a more friendly format
 * @param {Number} a : Bytes
 * @param {Number} b : Precision
 * @return {String}
 */
function format_bytes(a, b) {
    if (a != 0) {
        if (isNaN(parseFloat(a)) || !isFinite(a))
            return '-';
        if (typeof b === 'undefined')
            b = 1;

        var c = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB'];
        d = Math.floor(Math.log(a) / Math.log(1024));
        e = (a / Math.pow(1024, Math.floor(d))).toFixed(b);
        var f = (e.match(/\.0*$/) ? e.substr(0, e.indexOf('.')) : e) + ' ' + c[d];
        return f;
    }
}

 

To see it in action you will need to ensure that you have the "Total document size" column turned on.

 

 

 

Hope this helps!

2 0
replied on April 27, 2022

I would love to know if someone has a solution for Weblink version 

 

Laserfiche WebLink Version: 11.0.2111.777

 

Showing file size in bytes is extremely confusing for the general public who is used to dealing in Kb, Mb and Gb

0 0
replied on April 27, 2022 Show version history

Ingeborg,

 While not thoroughly tested, I have managed to quickly convert this over to Weblink 11.x

// Title: Readable Bytes for Laserfiche WebLink
// About: Converts the bytes displayed in the "Total document size" column into a more friendly format.
// Version: 2.0 (American date format)
// Date: 04/27/2022 (mm/dd/yyyy)
// Compatibility: Laserfiche WebLink 11.x
// Install: Place readable_bytes.js file in the Laserfiche WebLink JavaScript folder. Open up
//          the Browse.aspx file in an editor and add the following code before the </body> element:
//
//          <script type="text/javascript" src="./javascript/readable_bytes.js")"></script>
//
//          Save Browse.aspx and refresh the page

// Class name for header title cells
var header_cell_class = ".p-sortable-column";

// Title of header column that contains the byte information
var header_byte_title = "Total document size";
// Precision of newly formatted byte value (i.e 1 MB, 1.1 MB, 1.11 MB, etc.,)
var format_precision = 0;

(function() {

    var proxied = window.XMLHttpRequest.prototype.send;
	var sent = false;
    window.XMLHttpRequest.prototype.send = function() {
		sent = true;
        var pointer = this
        var intervalId = window.setInterval(function(){
                if(pointer.readyState != 4){
                        return;
                }
                clearInterval(intervalId);
				if(sent)
					transform_bytes();
				sent = false;
				

        }, 1);
        return proxied.apply(this, [].slice.call(arguments));
    };


})();

function transform_bytes() {

    //Variable used to indicate column index number
    var a = 0;
    //Obtain the header cells in the browse table and loop through them until we find the "Total document size" column
    $(header_cell_class).each(function () {
        //Increase column index number variable by 1
        a++;
        //Check to see if this column header text matches the one we want
        if ($.trim($(this).text()) == header_byte_title) {
            //Now that we found the column we want go ahead and go through each cell in the column and format the bytes if found
			var size_col = a + 1;
            $("tr.ui-widget-content td:nth-child(" + size_col + ")").each(function () {
				console.log($(this).text());
                //Format the bytes
                var b = format_bytes($(this).text(), format_precision);
                //Clear out exsisting value. This will also remove the 0 from appearing from folders
                $(this).empty();
                //Set the newly formatted text
                $(this).text(b);
            });
        }
    });
};

/**
 * Format given byte value into a more friendly format
 * @param {Number} a : Bytes
 * @param {Number} b : Precision
 * @return {String}
 */
function format_bytes(a, b) {
    if (a != 0) {
        if (isNaN(parseFloat(a)) || !isFinite(a))
            return '-';
        if (typeof b === 'undefined')
            b = 1;

        var c = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB'];
        d = Math.floor(Math.log(a) / Math.log(1024));
        e = (a / Math.pow(1024, Math.floor(d))).toFixed(b);
        var f = (e.match(/\.0*$/) ? e.substr(0, e.indexOf('.')) : e) + ' ' + c[d];
        return f;
    }
}

 

0 0
replied on April 28, 2022

Thank you. I will go try that now.

 

0 0
replied on May 5, 2022

We implemented and it works as long as we only scroll down on the page. As soon as we scroll back up on the page it returns back to the old way of displaying the size in the column.   But we are definitely a very BIG Leap in the right direction.

0 0
replied on June 14, 2019

We have weblink 10. I followed the above steps and does not seem to work in weblink 10.

0 0
replied on June 14, 2019

Do you have to restart IIS?

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.