Updated RoutingItem,Route,RoutingNode classes

This commit is contained in:
Atomos821 2020-11-26 10:07:00 +01:00
parent 5b0c3ac913
commit bf2603c891

View File

@ -28,7 +28,7 @@ class Docs {
} }
/** /**
* Called on instanciation by the constructor. * Called on initialization by the constructor.
*/ */
async onExec() { async onExec() {
this.routesData = await this.fetchRoutes(); this.routesData = await this.fetchRoutes();
@ -223,12 +223,24 @@ class RoutingItem {
this.hidden = hidden; this.hidden = hidden;
} }
buildSelf() { /**
* @param {*} force Wether to force generation or not despite the hidden property.
* @returns {HTMLElement} The RoutingItem as an HTML element (div).
*/
buildSelf(force = false) {
if (this.hidden === false || typeof this.hidden === 'undefined') {
force = true;
}
if (force) {
const element = document.createElement('div'); const element = document.createElement('div');
element.innerText = this.name; element.innerText = this.name;
return element; return element;
} }
} }
}
class Route extends RoutingItem { class Route extends RoutingItem {
/** /**
@ -249,7 +261,7 @@ class Route extends RoutingItem {
*/ */
buildSelf(force = false) { buildSelf(force = false) {
if (this.hidden === false || typeof this.hidden === 'undefined') { if (this.hidden === false || typeof this.hidden === 'undefined') {
force = true force = true;
} }
if (force) { if (force) {
@ -259,12 +271,13 @@ class Route extends RoutingItem {
element.innerText = this.name; element.innerText = this.name;
return element; return element;
} else {
return;
} }
} }
/** /**
* Loads the Route content and returns it as text.
* @param {string} prefix (optional) An url prefix to add *(i.e: different location)*.
* @param {string} suffix (optional) An url suffix to add *(i.e: file extension)*.
* @returns {string} The document content to load as a string. * @returns {string} The document content to load as a string.
*/ */
async loadSelf(prefix, suffix) { async loadSelf(prefix, suffix) {
@ -276,8 +289,6 @@ class Route extends RoutingItem {
if (typeof suffix === 'undefined') { if (typeof suffix === 'undefined') {
suffix = ''; suffix = '';
} else {
suffix += '/';
} }
const response = await fetch(`${prefix}${this.filepath}${suffix}`); const response = await fetch(`${prefix}${this.filepath}${suffix}`);
@ -305,6 +316,9 @@ class RoutingNode extends RoutingItem {
this.onExec(); this.onExec();
} }
/**
* Called on initialization by the constructor.
*/
onExec() { onExec() {
this.routesData.forEach(routeData => { this.routesData.forEach(routeData => {
if ('routes' in routeData) { if ('routes' in routeData) {
@ -316,7 +330,8 @@ class RoutingNode extends RoutingItem {
} }
/** /**
* @returns {HTMLUListElement} The RoutingNode as an HTML unordered list. * Builds the HTML representation of the RoutingNode as an HTML unorded list.
* @returns {HTMLUListElement} The RoutingNode as an HTML list.
*/ */
buildSelf(force = false) { buildSelf(force = false) {
if (this.hidden === false || typeof this.hidden === 'undefined') { if (this.hidden === false || typeof this.hidden === 'undefined') {
@ -339,6 +354,11 @@ class RoutingNode extends RoutingItem {
} }
} }
/**
* @private
* @param {string} text
* @param {Function} onClickCallback (optional)
*/
buildSelf_Heading(text, onClickCallback) { buildSelf_Heading(text, onClickCallback) {
const wrapper = document.createElement('div'); const wrapper = document.createElement('div');
const headingText = document.createElement('span'); const headingText = document.createElement('span');
@ -359,6 +379,7 @@ class RoutingNode extends RoutingItem {
} }
/** /**
* @private
* @param {Array.<(Route,RoutingNode)>} entries * @param {Array.<(Route,RoutingNode)>} entries
*/ */
buildSelf_List(entries) { buildSelf_List(entries) {