(function() {
/**
* this backend connector is able to handle UR content
* @augments Help4.widget.help.project._Special
*/
Help4.widget.help.project.UR = class extends Help4.widget.help.project._Special {
static NAME = 'UR';
static data = /** @type {Help4.widget.help.ProjectTile[]} */ [];
static lastUpdate = 0;
static #moveUpdate = false;
/**
* @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} [isStructuralUpdate = true] - added or removed tiles
* @returns {Promise<void>}
*/
static async clearData(isStructuralUpdate = true) {
if (!this.hasData()) return;
this.data = [];
// only if structural update:
// - refresh widget
// - update timestamp
if (isStructuralUpdate) {
this.lastUpdate = Date.now();
await super._refreshWidget()
}
}
/**
* @param {Help4.widget.help.ProjectTile[]} data
* @param {boolean} [isStructuralUpdate = true] - added or removed tiles
* @param {boolean} [isMoveUpdate = false] - hotspots have moved
* @returns {Promise<void>}
*/
static async setData(data, isStructuralUpdate = true, isMoveUpdate = false) {
await this.clearData(false);
await this.addData(data, isStructuralUpdate, isMoveUpdate);
}
/**
* @param {Help4.widget.help.ProjectTile[]} data
* @param {boolean} [isStructuralUpdate = true] - added or removed tiles
* @param {boolean} [isMoveUpdate = false] - hotspots have moved
* @returns {Promise<void>}
*/
static async addData(data, isStructuralUpdate = true, isMoveUpdate = false) {
const {[this.NAME]: catalogue} = Help4.widget.help.catalogues;
const {ID: _projectId, CATALOGUE_TYPE: _catalogueType} = catalogue;
const _dataType = catalogue.getDataType();
this.#moveUpdate ||= isMoveUpdate;
data = /** @type {Help4.widget.help.ProjectTile[]} */ data.map(tile => ({
...tile,
_dataType,
_catalogueType,
_projectId,
}));
this.data.push(...data);
// only if structural update:
// - refresh widget
// - update timestamp
if (isStructuralUpdate) {
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;
}
/** @returns {boolean} */
static consumeMoveStatus() {
const move = this.#moveUpdate;
this.#moveUpdate = false;
return move;
}
}
})();