Every shared file server administrator has this problem: "who
is taking most of the space?". This question is also a valid one for
Alfresco administrators, but they do not have any easy tool to answer
it. Adding this feature to Alfresco isn't very hard but for those who
prefer reusing the others work, I will present a piece of Freemarker
template doing it. This template will be also a good way to introduce
interesting Alfresco Freemarker use.

First, here is a preview of the final result.

I will present the template file in two steps:

Showing a table with the current space children and their total size

Showing the same information as a pie chart

STEP 1: Showing the table

First of all, having a function returning the total size of a space is
necessary. This function will have to recurse over the whole hierarchy
to compute the real size of the space. The following piece of Freemarker
code defines this function and can be called either on a container or on
a leaf of the tree.

Now that the function computing a node's real size is written, the
template showing the table is easy to do. Here is a way to do it like
the screenshot. The only noticeable point in this code could be the way
to alternate the CSS class for the data rows.

To show a chart, an existing library for charts creation will be
necessary. I have chosen to use PlotKit Javascript library. This
library depends on the MochiKit Javascript library. There is an
example of chart with labels among the PlotKit examples to know how to
create the pie chart with the children names as labels. The problem is
that the JavaScript function used to create the chart will need the data
and these ones can't be computed another time for obvious performance
reasons.

The previously written function will have to be reused to produce the
JavaScript function. In order to reuse the data for both the chart and
the table, the data have to be put in a Freemarker sequence. But as
creating an empty Freemarker sequence and fill it in a loop doesn't seem
to be possible, the only solution is to create the Freemarker definition
of the sequence and evaluate it. Here is how to do it:

After this Freemarker code, the values variable will contain the data
as a sequence of sequences. The JavaScript function to add in the
template and the HTML tag for the chart rendering are done in the
following way. For it to work, the files provided in the lib/MochiKit
directory of the MochiKit distribution and the files found in the
PlotKit directory of the MochiKit distribution have to be placed in
/scripts/mochikit and /scripts/plotkit in the alfresco WAR.

Social

Links

Browse content by

Copyright notice

Disclaimer

All opinions expressed in this site are my own personal opinions and are not endorsed by, nor do they represent the opinions of my previous, current and future employers or any of its affiliates, partners or customers.