0

I have recently started developing with aikau in alfresco share. I want to achieve a functionality wherein I can export search results to a CSV file.

For that, I can change the back-end repository web script to return csv data. Now, At alfresco share end - I was successfully able to show the export link by adding a new widget to FCTSRCH_TOP_MENU_BAR. I used alfresco/renderers/PropertyLink to display this link. Now, the missing part for me is - how can I invoke the search web script passing additional param format=csv and alongwith that pass all the query parameters used to retrieve the results.

I am stuck with that. If I use the publishTopic as ALF_CRUD_GET_ALL and provide the URL there then it invokes the sample web script (I created to return sample csv response) and returns the response. However, the csv doesn't come as downloadable response. I am stuck here in order to how to achieve export csv functionality for search results.

It would be great if any of you can help me here and provide your guidance/suggestions.

SpiXel
  • 4,338
  • 1
  • 29
  • 45
Ramesh C
  • 1
  • 2

2 Answers2

0

This blog post provides an example on how you can custom the search page in Share. Although it specifically addresses changing the search queries the basic extension approach is more or less that same in that you will want to change the data that is used to send an XHR request. I think that the major difference here is that you may need to do more in-depth updates to the service - in particular with regards to the switch statement that is used to build the advanced search query object.

If you have extended or replaced the default search REST API then I would expect that you will need to call the same URL, but if you have provided an entirely new REST API to return the CSV data then you'll also need to change the URL that is used by the service.

In terms of providing a link for downloading the content we have previously implemented something in the DragAndDropModelCreationService (see the generateDownload function) but this only works with Chrome due to security limitations and the generation of files to download.

Your best bet may be temporarily store the CSV content on the repository in a hidden location and then use the standard download links to allow it to be downloaded - this would be more complex but would provide better cross browser support. Something similar is done for the "Download as ZIP" action.

Dave Draper
  • 1,837
  • 11
  • 25
  • Thank you for the response Dave. There are still few things unclear to me and kindly excuse my ignorance. I could not 100% follow what you have mentioned above. I am rendering an export link using `alfresco/renderers/PropertyLink`. I am not sure how to send XHR request to search web script passing format=csv parameter. If I simply use the publish topic as `ALF_CRUD_GET_ALL`, i am not sure how to pass the search parameters to it again when the export link is clicked. If you have code snippet/example please help me understand. – Ramesh C Sep 19 '16 at 09:49
  • I think that maybe your question needs some clarification... where are you rendering the PropertyLink? Is this shown on the search results? From your question it sounds like you're updating the Repository REST API to return CSV data? Have your provided a new API? Perhaps you can provide a walk through of the use case. If you're updating the existing search page then you definitely don't want to be using `ALF_CRUD_GET_ALL` - you need to be doing what the `SearchService` is doing which is more search specific. Again, more information in the questino will help provide a better answer. – Dave Draper Sep 19 '16 at 10:24
  • Sure. Let me try to provide you what exactly I am trying to achieve. I am customizing faceted-search page wherein I am trying to add a link where the search results are displayed (mostly just beside X results found text). For showing the link, I have used `alfresco/renderers/PropertyLink`. I've customized the OOTB repo web script to return csv format as a response. Now, the one part that I am missing is from the link on search page, how can I invoke the search web script passing format=csv and also all the search criteria, which were used to get the results originally. Hope this clarifies. – Ramesh C Sep 19 '16 at 10:43
  • Ok, thanks for the update, I'll add an additional answer – Dave Draper Sep 19 '16 at 12:05
0

OK, with the extra information provided I would do the following...

The information on the process of adding widgets to the search page are quite well detailed here (although you're not adding a view, you can follow the approach to add a new PropertyLink after the widget with the id "FCTSRCH_RESULTS_COUNT_LABEL").

The approach I would take would be to include an additional custom service on the page that subscribes to the "ALF_RETRIEVE_DOCUMENTS_REQUEST_SUCCESS" topic (which is published on a completed search). It should save the the search response in a variable in preparation for users clicking on the PropertyLink.

This custom service should also subscribe to a topic that is published by the PropertyLink (called say "DOWNLOAD_CSV"). This custom service could then generate a file download using the approach described in my previous answer using the CSV data that will have been provided in the payload. As I said though, this may only work with some browsers due to security reasons.

If your custom search WebScript were able to store the CSV data as a node on the Repository then you could just provide a the NodeRef of the CSV data in the search response and the PropertyLink could just publish the "ALF_DOWNLOAD" topic for the DocumentService to handle the download.

Trying to generate a file to download on the client side is going to be an issue for most browsers I think.

Dave Draper
  • 1,837
  • 11
  • 25