1

I have some difficulties customizing the Aikau faceted search page on Alfresco, which may be more a matter of lack of my knowledge about dojo/AMD.

What I want to do is to replace the document details page URL by a download URL.

I extended the Search Results Widget to include my own custom module :

var searchResultWidget = widgetUtils.findObject(model.jsonModel, "id", "FCTSRCH_SEARCH_RESULT");

if(searchResultWidget) {
    searchResultWidget.name = "mynamespace/search/CustomAlfSearchResult";
}

I understand search results URLs are rendered this way : AlfSearchResult module => uses SearchResultPropertyLink module => mixins _SearchResultLinkMixin renderer => bring the "generateSearchLinkPayload" function => renders URLs depending on the result type

I want to override this "generateSearchLinkPayload" function but I can't figure out what is the best way to do that.

Thanks in advance for the help !

Younes Regaieg
  • 4,156
  • 2
  • 21
  • 37
Tony Rivet
  • 11
  • 1

2 Answers2

4

This answer assumes you're able to use the latest version of Aikau (at the time of writing this is 1.0.61). Older versions might require slightly different overriding...

In order to do this you're going to need to override the createDisplayNameRenderer function of AlfSearchResult in your CustomAlfSearchResult widget. This will allow you to create an extension of alfresco/search/SearchResultPropertyLink.

If you want to take advantage of the the download capabilities provided by the alfresco/services/DocumentService for downloading both documents and folders (as a zip) then you're going to want to change both the publishTopic and publishPayload of the SearchResultPropertyLink.

You should extend the getPublishTopic and generateSearchLinkPayload functions. For the getPublishTopic function you'll want to change the return value to be "ALF_SMART_DOWNLOAD" (there are constants available for these strings in the alfresco/core/topics module). This topic can be used to tell the DocumentService to take care of figuring out if the node is a folder or document and will make an XHR request for the full node metadata (in order to get the contentUrl attribute that is not included in the data returned by the Search API.

You should extend the generateSearchLinkPayload function so that for document or folder types the payload contains the attribute nodes that is a single array where the object is the search result object that you wish to download.

I would recommend that you call this.inherited first to get the default payload and only update it for documents and folders.

Hopefully that all makes sense - if not, add a comment and I'll try to provide further assistance!

Dave Draper
  • 1,837
  • 11
  • 25
  • Thanks for your help Dave ! I should have specified that I use Alfresco 5.1.2.5, which is packaged with Aikau 1.0.25. Unfortunately, the createDisplayNameRenderer function is not available in this version... Is there another "clean" way to extend SearchResultPropertyLink in older versions ? – Tony Rivet Apr 05 '16 at 08:45
  • OK... I'll take another look at this later today and see what the options are. The smart download definitely won't be available and as you say the AlfSearchResult won't be quite so neatly broken up. It is possible to pull later versions of Aikau in (obviously there is a small element of risk here as they wont' have been through the full integrated QA process). But later service packs (for 5.0 and 5.1) typically take the latest version of Aikau anyway. – Dave Draper Apr 05 '16 at 09:04
3

This is the answer for 1.0.25.2 - unfortunately it's not quite so straightforward...

You still need to extend the alfresco/search/AlfSearchResult widget, however this time you need to extend the postCreate function (remembering to call this.inherited(arguments)). It's not possible to stop the original alfresco/search/SearchResultPropertyLink widget from being created... so it will be necessary to find it and destroy it.

The widget is not assigned to a variable, so it will be necessary to find it using dijit/registry. Use the byNode function from dijit/registry to find the widget assigned to this.nameNode and then call destroy on it (be sure to pass the argument true to preserve the DOM). However, you will then need to empty the DOM node so that you can start again...

Now you need to add in your extension to alfresco/search/SearchResultPropertyLink. Unfortunately, because the smart download capability is not available you'll need to do more work. The difference here is that you'll need to make an XHR request to retrieve the full node metadata in order to obtain the contentURL. It's possible to publish a request to the DocumentService(via the "ALF_RETRIEVE_SINGLE_DOCUMENT_REQUEST" topic). However, you need to be aware that having the XHR step will not allow you to then proceed with the download as is. Instead you'll need to use an iframe download solution, I'd suggest you take a look at the changes in the pull request we recently made to solve this problem and backport them into your own solution.

Dave Draper
  • 1,837
  • 11
  • 25
  • I realised that the answer was only partially correct - so I've edited to describe how to implement the custom SearchResultPropertyLink - this was previously missing from the original answer. – Dave Draper Apr 06 '16 at 07:16