Here i am going to create a dashlet that will display all the spaces and content for particular site based upon site name.
(note: every time alfresco will create space or content in Company Home > Sites , which is depends upon site activities in alfresco share.)
Step1: Create a site in share, name it as chandu as follows
Step2: next go to alfresco and create webscript in alfreso for that we need two files create those two files
a)siteacts.get.desc.xml
b)siteacts.get.json.ftl
code to add in siteacts.get.desc.xml
-------------------------------------------------------------------------------------------------------
<webscript>
<shortname>Document Property</shortname>
<description>It provides documents name and date of creation and Creator property</description>
<url>/sample/siteacts.json?siteName={sitename)</url>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>
--------------------------------------------------------------------------------------------------------
code to add in siteacts.get.json.ftl
---------------------------------------------------------------------------------------------------------
{
<#assign dateformat="yyyy/MM/dd">
"siteacts" : [
<#macro recurse_macro node>
<#if node.isContainer>
{
"name" : "${node.properties.name}" ,
"creator" : "${node.properties.creator}",
"createdDate" : "${node.properties.created?string(dateformat)}"
},
<#list node.children as child>
<#if child.isContainer>
<@recurse_macro node=child/>
<#else>
{
"name" : "${child.properties.name}" ,
"creator" : "${child.properties.creator}",
"createdDate" : "${child.properties.created?string(dateformat)}"
}
,</#if>
</#list>
</#if>
</#macro>
<@recurse_macro node=companyhome.childByNamePath["Sites/${args.siteName}"] />
]
}
-----------------------------------------------------------------------------------------------------------
Step3: add these two files into
Company Home > Data Dictionary > Web Scripts > org > alfresco > sample
Refresh the webscripts , for this go to http://localhost:8080/alfresco/service/, click on Click on Refresh Web Scripts.
if is it successfully completed you will get the message like
Maintenance Completed
Reset Web Scripts Registry; registered 335 Web Scripts. Previously, there were 334.
then check the webscript using below URI
http://localhost:8080/alfresco/service/sample/siteacts.json?siteName=chandu
here add the name of the site that you need. in my case it is chandu.
you will get the output will be like this
------------------------------------------------------------------------------------------------------------------------------
{
"siteacts" : [
{
"name" : "chandu" ,
"creator" : "admin",
"createdDate" : "2010/02/23"
},
{
"name" : "documentLibrary" ,
"creator" : "admin",
"createdDate" : "2010/02/23"
},
{
"name" : "links" ,
"creator" : "admin",
"createdDate" : "2010/02/23"
},
]
}
------------------------------------------------------------------------------------------------------
Step4: next step is to create dashlet in the share. for that we need three files.
a)siteacts.get.desc.xml
b)siteacts.get.html.ftl
c)siteacts.get.js
code for siteacts.get.desc.xml
-----------------------------------------------------------------------------------------
<webscript>
<shortname>Site Activities</shortname>
<description>Dashlet to list Site Activities from Alfresco</description>
<family>site-dashlet</family>
<url>/components/dashlets/siteactivites</url>
</webscript>
-------------------------------------------------------------------------------------------
note that here i added this as site dashlet not a user dashlet. code to add in siteacts.get.js
----------------------------------------------------------------------------------------
var connector = remote.connect("alfresco");
var data = connector.get("/sample/siteacts.json?siteName=" + page.url.templateArgs.site);
// create json object from data
var result = eval('(' + data + ')');
model.siteactivites= result["siteacts"];
------------------------------------------------------------------------------------------
code to add in siteacts.get.html.ftl
------------------------------------------------------------------------------------
<table>
<tr>
<th>Name </th>
<th>Creator </th>
<th>Date of Creation </th>
</tr>
<#list siteactivites as x>
<tr>
<td>${x.name}</td>
<td>${x.creator}</td>
<td>${x.createdDate}</td>
</tr>
</#list>
</table>
------------------------------------------------------------------------------------
place all these files into
Step5: next refresh the share webscripts using this URI http://localhost:8080/share/service/
click on refresh webscripts. is it is successes you will get the message like. as follows
Maintenance Completed
Reset Web Scripts Registry; registered 176 Web Scripts. Previously, there were 175.
next go to the site http://localhost:8080/share/page/site/chandu/dashboard
click on customise dashboard ., and add dashlet in to the site .
the dashlet will be updated if any activites performed on this site.
download the entire code here download code .
I have followed all the above steps but the dashlet in not showing in the add dashlets......................Please help
ReplyDeletehi, download the code and refresh share webscripts, restart the server once.
ReplyDeleteThanks dear............
ReplyDeleteIt gave a great help.........
Thanks........
Hello, if i want to acess document library. what should i change in the code?? Thanks
ReplyDelete