cancel
Showing results for 
Search instead for 
Did you mean: 

Dashlet Creation

riktaminaars
Champ on-the-rise
Champ on-the-rise
Hi

I have a folder where a new document is placed in every day, how can I automatically show this one most recent document in a dashlet ?

It only needs to show 1 document, so dashlets recent documents / my documents etc. not really useful. I tried creating my own dashlet myself but there is no tutorial around to learn this… The Hello-World dashlet on share-extras helped me understand the file&folder structure a bit more but I just can not find out how to display the most recent document from a simple folder
21 REPLIES 21

jpotts
World-Class Innovator
World-Class Innovator
I have it on my to-do list to download and review this code. I think it would make a good blog post or wiki page because it encapsulates a lot of techniques fundamental to Share customizations. We need all of the examples we can get.

Regarding the refresh, here's a high-level tip. A technique that is common across Share is to use YUI bubbling events. Components throw events and then other components subscribe to those events. So in this case, setting the config should throw an event and the dashlet's client-side code can listen for that event and then refresh itself when it captures the event.

I haven't yet looked at your revisions, but the original version of the dashlet did everything in the Share-tier web script controller. To make this refresh work, it might be better to refactor the dashlet a bit. Instead of doing the work in the controller, the work can be done in client-side JavaScript that posts an AJAX call to the Share proxy that invokes the existing repository web script. That way, you can refresh the data in the dashlet without refreshing the entire page.

Jeff

wabson
Star Contributor
Star Contributor
Related to the refresh question, the Alfresco.component.Base class (which your dashlet client-side code will likely extend) now (as of Alfresco 4) has a refresh() method that can be used to re-draw the contents of a component on-screen. I'm not sure how practical it is for dashlets, since you need to provide the URL of the web script as a parameter to the method, and that URL would need to include the htmlid of the dashlet div as a URL parameter, but it could simplify your code if it works for you.

http://sharextras.org/jsdoc/share/community-4.0.d/symbols/Alfresco.component.Base.html

Thanks,
Will.

jpotts
World-Class Innovator
World-Class Innovator
RikTaminaars,

I took your code and did a little bit of refactoring. The result lives here.

The biggest change was to get everything out of the Alfresco namespace. So now all web scripts (folder structure and URL) and client-side JavaScript objects are in a "SomeCo" example namespace.

I also was seeing a problem with the validation on the config dialog that wasn't properly detecting when the file path was set. I just disabled the validation for that particular field for now.

Also the "clear" button was clearing out the dashlet title, which didn't seem optimal, so I tweaked that.

I think there are a few places where this could still be trimmed down/cleaned up, and it still has the refresh issue, but it is a decent example of the simple pattern of retrieving data from the repo as well as working with configuration.

I used Will's Share Extras build script. So the whole thing is an Eclipse project with an Ant build that can deploy using AMPs, JARs, or zip.

Jeff

angello0571
Champ on-the-rise
Champ on-the-rise
Hi guys,

I have been looking for information about dashlet creation, and of course this post has been very useful for me. I understand that there is a javascript API, with many objects that we have to use to retrieve data.

But I wonder how can I show in a dashlet, data from a table that I created by my self (for example GLOSARY_TABLE) ?

Is it necesary to extend JavaScript API, in order to have my own JavaScript objects that connects with my own table in DB ?

How can I program something like that ?

I am not very well with english, but I hope you can understand me.

Thank you for your support and your time.

jpotts
World-Class Innovator
World-Class Innovator
If you would like to access your own custom database table from JavaScript, you might find it easier to access the table from Java, then expose that Java bean as a JavaScript root scoped object. This would allow your web scripts to get to the data.

This is documented in various places, but one place you might want to start is with my colleague, Nathan McMinn. He has a blog post on the subject.

Jeff

angello0571
Champ on-the-rise
Champ on-the-rise
Thanks a lot Jeff,

I just have a few weeks working with Alfresco, and that is exactly I was looking for, right now I have my own webscript with an AMP as service for retrieve data of my custom table!

I feel deeply in debt with you Smiley Happy thank you man !

jpotts
World-Class Innovator
World-Class Innovator
Sure, no problem. Glad it helped.

If anyone else is interested, there are two blog posts that go along with this example. They live here and here. The source code has been checked into a Google Code project if anyone needs it.

Jeff

angello0571
Champ on-the-rise
Champ on-the-rise
This is me again Smiley Happy

As I told you, I could buid my data webscript with the functionallity that I need, of course, the component lives into Alfresco app. But now I have a question:

1) The URI for my webscript is next one:

    /alfresco/service/com/webscripts/dataservice/glossary-definitions?keyWord={keyWordValue}&ramo={ramoValue}

2) When I set a value for twice variables I get perfectly the JSON String with my data:

{"definition":"Indica el número de años de antigüedad que la póliza tenía al momento de ocurrir el siniestro. ","concept_name":"Año Póliza Siniestro","technical_ref":"Se identificará a cada registro con el número de años de antigüedad que la póliza tenía al momento de ocurrir el siniestro, debido a que hay siniestros que ocurrieron en ejercicios anteriores al que se reporta, cuyas pólizas pueden o no estar en vigor. Este valor se reportará en números enteros, considerándose como año póliza al periodo que comprende su aniversario. Dicho número deberá guardar consistencia con el archivo actual y futuro de emisión.","clasification":"Siniestro"}

3) The next step is to build my dashlet for consuming the webscript I created before. When I add the dashlet to my dashbord I hope to see all those information but I'm getting an error. The error message is:

Error Message: 04150001 Failed to execute script 'classpath*:alfresco/site-webscripts/org/alfresco/components/dashlets/glossary-definitions-dashlet.get.js': 04150000 Invalid uri 'http://localhost:9001/alfresco/s/com/webscripts/dataservice/glossary-definitions?keyWord=ANIO POLIZA SINIESTRO&ramo=ap&alf_ticket=TICKET_727cf1379f21d1552152e449c94b519aadf3555b': Invalid query

A snippet of the full stack trace is :
Exception: java.lang.IllegalArgumentException - Invalid uri 'http://localhost:9001/alfresco/s/com/webscripts/dataservice/glossary-definitions?keyWord=ANIO POLIZA SINIESTRO&ramo=ap&alf_ticket=TICKET_727cf1379f21d1552152e449c94b519aadf3555b': Invalid query
org.springframework.extensions.webscripts.WebScriptException - 04150000 Invalid uri 'http://localhost:9001/alfresco/s/com/webscripts/dataservice/glossary-definitions?keyWord=ANIO POLIZA SINIESTRO&ramo=ap&alf_ticket=TICKET_727cf1379f21d1552152e449c94b519aadf3555b': Invalid query
org.springframework.extensions.webscripts.processor.JSScriptProcessor.executeScriptImpl(JSScriptProcessor.java:324)

4) This is the way I call the webscript to retrive data from my Java Script file dashlet:

var connector = remote.connect("alfresco");
var json = connector.get("/com/webscripts/dataservice/glossary-definitions?keyWord=ANIO POLIZA SINIESTRO&ramo=ap");

I noticed that, there is a "extra parameter" that I never specify called "alf_ticket". My webscripts are set with no authentication ( <authentication>none</authentication> ) and I have no clear why this parameter is present.

Of course, any link or explanation for help me to solve this, is welcome.

Thanks,

Angel.

angello0571
Champ on-the-rise
Champ on-the-rise
I found the problem haha Smiley Happy

the  spaces as value for my params caused the issue, i guess that i should use scape characters for this.

thanks in advance .

riktaminaars
Champ on-the-rise
Champ on-the-rise
Hi

I updated the dashlet again Smiley Happy

I've used jpotts his latest version of the dashlet as starting point… as it's better than my initial version

I've added/tweaked a couple of things, first off, it wasn't possible to configure the dashlet when it was added to the user dashboard, changes were made in dashlet's controller, get-latest-doc.get.js (along userIsSiteManager…)

Thanks to jpotts his tip about using an AJAX call in the client side js, I've managed to implement refreshing the dashlets' metadata without refreshing the whole page. (changes in function onConfigGetLatestDocClick)

Some bugs as well: the dashlet template would throw an exception and not display itself at all if the folder "/test" (or whatever is set in the get.config.xml) does not exist or if the folder does exist but has no files in it. This is fixed by adding default values for the template if the file/folder can't be found.

Also added a simple javascript 'alert' if the user tries to add a folder that has no files in it, so it won't throw an error.

Code here:

https://code.google.com/p/alfresco-get-latest-document/