(function() {
/**
* this module is able to handle UACP catalogue content for a RO model configuration
* it will always use screen id "_GLOBAL_HELP_
* @augments Help4.widget.help.catalogues.UACP
*/
Help4.widget.help.catalogues.GlobalHelp = class extends Help4.widget.help.catalogues.UACP {
static ID = '_GLOBAL_HELP_';
static CATALOGUE_TYPE = 'GlobalHelp';
/**
* @param {Help4.typedef.SystemConfiguration} config - the system configuration
* @returns {Promise<Help4.widget.help.catalogues.UACP.CatalogueProjects|null>}
*/
static async load(config) {
const {
core: {screenId},
help: {roModel, serviceUrl, useGlobalHelp}
} = config;
if (!serviceUrl || roModel !== Help4.SERVICE_LAYER.uacp) return null;
if (!useGlobalHelp || !Help4.getShell().getFioriApplication()) return null;
const {UACP} = Help4.widget.companionCore;
const url = this._getUrl(config, [this.ID]);
const response = /** @type {?Help4.widget.companionCore.UACP.CatalogueResponse} */ await UACP.doGetRequest(url);
// map "_GLOBAL_HELP_" screen id to the real one
const {status, data} = response || {};
if (status === 'OK' && Help4.isArray(data) && data.length) {
data.map(catalogueProject => catalogueProject.appUrl = screenId)
}
const pub = /** @type {Help4.widget.help.catalogues.UACP.CatalogueProject[]} */ this._parse(response, this.CATALOGUE_TYPE);
return {pub};
}
/**
* @param {Help4.widget.help.CatalogueProject[]} projects - the projects to select from
* @param {Help4.typedef.SystemConfiguration} config - the system configuration
* @returns {Object}
*/
static selectHelp(projects, config) {
// simply select the first project
for (const {contextType, screen, id} of projects) {
if (contextType === 'HELP') return {[screen]: id};
}
return {};
}
}
})();