(function() {
/**
* this backend connector is able to handle API content
* @augments Help4.widget.help.project._Special
*/
Help4.widget.help.project.API = class extends Help4.widget.help.project._Special {
static NAME = 'API';
static data = /** @type {Help4.widget.help.ProjectTile[]} */ [];
static lastUpdate = 0;
/**
* @param {Help4.widget.help.ProjectTile[]} output
* @param {string} catalogueKey
*/
static getTiles(output, catalogueKey) {
const tiles = /** @type {Help4.widget.help.ProjectTile[]} */ this.getData()
.map(data => ({...data, _catalogueKey: catalogueKey}));
output.push(...tiles);
}
/**
* @param {boolean} [doRefresh = true]
* @returns {Promise<void>}
*/
static async clearData(doRefresh = true) {
if (!this.hasData()) return;
this.data = [];
this.lastUpdate = Date.now();
doRefresh && await super._refreshWidget();
}
/**
* @param {Array<*>} data
* @returns {Promise<void>}
*/
static async setData(data) {
this.data = [];
await this.addData(data);
}
/**
* @param {Help4.widget.help.ProjectTile[]} data
* @returns {Promise<void>}
*/
static async addData(data) {
const {[this.NAME]: catalogue} = Help4.widget.help.catalogues;
const {ID: _projectId, CATALOGUE_TYPE: _catalogueType} = catalogue;
const _dataType = catalogue.getDataType();
data = /** @type {Help4.widget.help.ProjectTile[]} */ data.map(tile => ({
...tile,
_dataType,
_catalogueType,
_projectId
}));
this.data.push(...data);
this.lastUpdate = Date.now();
await super._refreshWidget();
}
/** @returns {Help4.widget.help.ProjectTile[]} */
static getData() {
return this.data;
}
/** @returns {boolean} */
static hasData() {
return this.data.length > 0;
}
}
})();