02-15-2018 11:01 AM
##Dear All,
I need to add a new button on Share Search result page that allow users to export search metadata results as Excel file.
So, I made the repo webscript to make the Excel outputstream based on user search data (i.e: terms, query, etc..) and I'm looking to bind to the Share Aikau Search Result page.
I added to Share search page a new button linke this:
var searchResultsMenuBar = widgetUtils.findObject(model.jsonModel, "id", "SEARCH_RESULTS_MENU_BAR");
searchResultsMenuBar.config.widgets.push({
id: "EXPORT_BUTTON_SEARCH",
name: "alfresco/buttons/AlfButton",
config: {additionalCssClasses:"call-to-action",label : "export.search.result"
}
})
Now how can we add the repo webscript call? Pheraps adding something like this:publishPayloadType: 'PROCESS',Could you suggest me any sample to do this?
useHash: true,
hashDataMapping: {
searchTerm: "widgetsContent.0.config.searchTerm",
siteId: "widgetsContent.0.config.siteId",
searchSort: "widgetsContent.0.config.searchSort"
},
publishPayload: {
}
Thank you.
02-20-2018 06:03 AM
Ok Guys,
we've found the solutions. I report some basic steps to solve this mess J.
1) Write your JS backend widget service and register it to the Aikau runtime; for example a servce to make XHR repository calls:
define(["dojo/_base/declare",
"alfresco/services/BaseService",
"alfresco/core/CoreXhr",
"service/constants/Default",
"alfresco/core/PathUtils",
"alfresco/enums/urlTypes",
"dojo/_base/lang",
"dojo/_base/array",
"alfresco/util/hashUtils"],
function(declare, BaseService, CoreXhr, AlfConstants, PathUtils, urlTypes, lang, array, hashUtils) {
return declare([BaseService, CoreXhr, PathUtils], {
constructor: function alfresco_services_BaseService__constructor(args) {
this.alfSubscribe("EXPORT_SEARCH_RESULTS_SERVICE", lang.hitch(this, this.onAction));
},
onAction: function facetedsearch_DocumentService_onAction(payload) {
// hashUtils.getHash() - IT CONTAINS YOUR SEARCH PARAMETERS
// query - scope - searchTerm
console.log(hashUtils.getHash());
this.serviceXhr({
url: AlfConstants.PROXY_URI + "/api/YOUR_WEBSCRIPT_AND_SEARCH_PARAMS",
method: "GET",
successCallback: this.onSuccess,
callbackScope: this
});
},
onSuccess: function facetedsearch_DocumentService_onSuccess(response, originalRequestConfig) {
Alfresco.util.PopupManager.displayMessage({ title: this.message("export.search.result"), text: this.message("export.search.result.ok")});
},
onFailure: function facetedsearch_DocumentService_onFailure(response, originalRequestConfig) {
Alfresco.util.PopupManager.displayMessage({ title: this.message("export.search.result"), text: this.message("export.search.result.no")});
}
})
}
);
2) Declare your new faceted-search widgets override, for example by adding a new button:
//PUT THE NEW SERVICE IN PREVIOUS MODEL SERVICE LIST
model.jsonModel.services.push("widgets/medica-search-export");
//ADD YOUR BUTTON AND CALL THE NEW SERVICE BY USING the publishTopic config element.
var searchResultsMenuBar = widgetUtils.findObject(model.jsonModel, "id", "SEARCH_RESULTS_MENU_BAR");
searchResultsMenuBar.config.widgets.push({
id: "EXPORT_BUTTON_SEARCH",
name: "alfresco/buttons/AlfButton",
config: {
label : "medica.export.search.result",
additionalCssClasses:"call-to-action",
publishPayloadType: 'PROCESS',
publishTopic: "EXPORT_SEARCH_RESULTS_SERVICE"
}
});
02-16-2018 04:13 AM
For doing calls to Repository-tier web scripts you either have to provide custom services that perform those Xhr calls or use the CrudService for generic Xhr handling. This platform contains a mini example for using the CrudService. Since some widgets may require very specific requests / response formats, using a CrudService is not possible in every use case, and generally I would say it is recommended to provide custom services instead to improve on the abstraction between widgets and backend calls, making your Aikau UIs simpler to upgrade when backend web scripts change.
02-16-2018 11:16 AM
Ok Faust,
I've added a new widget like this:
define(["dojo/_base/declare",
"alfresco/services/BaseService",
"alfresco/core/CoreXhr",
"service/constants/Default",
"alfresco/core/PathUtils",
"alfresco/enums/urlTypes",
"dojo/_base/lang",
"dojo/_base/array"],
function(declare, BaseService, CoreXhr, AlfConstants, PathUtils, urlTypes, lang, array) {
this.alfLog("log", "myFunction called");
return declare([BaseService, CoreXhr, PathUtils], {
constructor: function alfresco_services_BaseService__constructor(args) {
this.alfSubscribe("EXPORT_SEARCH_RESULTS_SERVICE", lang.hitch(this, this.onAction));
},
onAction: function facetedsearch_DocumentService_onAction(payload) {
this.alfLog("onAction", payload);
//TODO - CALL the serviceXhr
},
onSuccess: function facetedsearch_DocumentService_onSuccess(response, originalRequestConfig) {
var msg = "Export generated successfully";
this.alfLog("log", msg, response, originalRequestConfig);
Alfresco.util.PopupManager.displayMessage({ title: "Info", text: msg});
},
onFailure: function facetedsearch_DocumentService_onFailure(response, originalRequestConfig) {
var msg = "Something went wrong.";
this.alfLog("log", msg, response, originalRequestConfig);
Alfresco.util.PopupManager.displayMessage({ title: "Info", text: msg});
}
})
}
);
How can I use it in my AlfButton? By using the publishTopic and publishPayload?
02-16-2018 01:27 PM
Precisely...
Note: The Alfresco.util.PopupManager utility is legacy YUI. In Aikau you create notifications by triggering a publication on topics of either the DialogService (for complex/custom displays incl. data entry) or NotificationService.
02-19-2018 11:10 AM
Ok.
Could you suggest me the right way to pass search parameters in the payload? I have to get user search terms from the faceted-search widgets. I put my new button in the SEARCH_RESULTS_MENU_BAR and I was able to call my remote webscript set in publishTopic field.
Regards.
02-20-2018 06:03 AM
Ok Guys,
we've found the solutions. I report some basic steps to solve this mess J.
1) Write your JS backend widget service and register it to the Aikau runtime; for example a servce to make XHR repository calls:
define(["dojo/_base/declare",
"alfresco/services/BaseService",
"alfresco/core/CoreXhr",
"service/constants/Default",
"alfresco/core/PathUtils",
"alfresco/enums/urlTypes",
"dojo/_base/lang",
"dojo/_base/array",
"alfresco/util/hashUtils"],
function(declare, BaseService, CoreXhr, AlfConstants, PathUtils, urlTypes, lang, array, hashUtils) {
return declare([BaseService, CoreXhr, PathUtils], {
constructor: function alfresco_services_BaseService__constructor(args) {
this.alfSubscribe("EXPORT_SEARCH_RESULTS_SERVICE", lang.hitch(this, this.onAction));
},
onAction: function facetedsearch_DocumentService_onAction(payload) {
// hashUtils.getHash() - IT CONTAINS YOUR SEARCH PARAMETERS
// query - scope - searchTerm
console.log(hashUtils.getHash());
this.serviceXhr({
url: AlfConstants.PROXY_URI + "/api/YOUR_WEBSCRIPT_AND_SEARCH_PARAMS",
method: "GET",
successCallback: this.onSuccess,
callbackScope: this
});
},
onSuccess: function facetedsearch_DocumentService_onSuccess(response, originalRequestConfig) {
Alfresco.util.PopupManager.displayMessage({ title: this.message("export.search.result"), text: this.message("export.search.result.ok")});
},
onFailure: function facetedsearch_DocumentService_onFailure(response, originalRequestConfig) {
Alfresco.util.PopupManager.displayMessage({ title: this.message("export.search.result"), text: this.message("export.search.result.no")});
}
})
}
);
2) Declare your new faceted-search widgets override, for example by adding a new button:
//PUT THE NEW SERVICE IN PREVIOUS MODEL SERVICE LIST
model.jsonModel.services.push("widgets/medica-search-export");
//ADD YOUR BUTTON AND CALL THE NEW SERVICE BY USING the publishTopic config element.
var searchResultsMenuBar = widgetUtils.findObject(model.jsonModel, "id", "SEARCH_RESULTS_MENU_BAR");
searchResultsMenuBar.config.widgets.push({
id: "EXPORT_BUTTON_SEARCH",
name: "alfresco/buttons/AlfButton",
config: {
label : "medica.export.search.result",
additionalCssClasses:"call-to-action",
publishPayloadType: 'PROCESS',
publishTopic: "EXPORT_SEARCH_RESULTS_SERVICE"
}
});
Explore our Alfresco products with the links below. Use labels to filter content by product module.