1/* global combo */ 2// noinspection JSUnresolvedVariable 3 4window.addEventListener("DOMContentLoaded", function () { 5 6 7 document.querySelectorAll(".combo-cache-item").forEach((metadataControlItem) => { 8 9 metadataControlItem.addEventListener("click", async function (event) { 10 event.preventDefault(); 11 12 let pageId = JSINFO.id; 13 let modalBacklinkId = combo.toHtmlId(`combo-cache-${pageId}`); 14 let cacheModal = combo.getOrCreateModal(modalBacklinkId) 15 .resetIfBuild() 16 .addDialogClass("modal-fullscreen-md-down"); 17 18 /** 19 * Creating the form 20 */ 21 22 let html = `<p>List of <a href="https://combostrap.com/page/cache">cache information</a> for the slots of the page (${pageId}).</p>`; 23 24 /** 25 * Add the page runtime cache metadata field 26 */ 27 let cachePageInfo = document.querySelector('script[type="application/combo+cache+json"]'); 28 if (cachePageInfo !== null) { 29 let cachePageJsonString = cachePageInfo 30 .innerText 31 .trim() 32 .slice("/*<![CDATA[*/".length) 33 .slice(0, -("/*!]]>*/".length)); 34 35 html += `<table class="table table-striped table-hover text-nowrap overflow-auto"><thead><th>Slot</th><th>Output</th><th>Cache <br/>Hit</th><th title="Modification time of the cache file">Modification <br/>Time</th><th>Cache Deps</th><th>Cache File</th></thead>`; 36 let cachePageJson = JSON.parse(cachePageJsonString); 37 for (let slot in cachePageJson) { 38 if (!cachePageJson.hasOwnProperty(slot)) { 39 continue; 40 } 41 42 let formatResults = cachePageJson[slot]; 43 let outputCounterBySlot = 0; 44 let slotUrl = combo.DokuUrl.createEdit(slot).toString() 45 let slotLabel = `<a href="${slotUrl}" title="Edit the slot ${slot}">${slot}</a>`; 46 for (let formatResult in formatResults) { 47 if (!formatResults.hasOwnProperty(formatResult)) { 48 continue; 49 } 50 outputCounterBySlot++; 51 if (outputCounterBySlot > 1) { 52 slotLabel = ""; 53 } 54 let result = formatResults[formatResult]; 55 // Mode 56 let styledFormatResult; 57 if (formatResult === "i") { 58 styledFormatResult = "Parse Instructions" 59 } else { 60 styledFormatResult = formatResult.charAt(0).toUpperCase() + formatResult.slice(1); 61 } 62 let hit = result["result"]; 63 let checkedBox = ""; 64 if (hit === true) { 65 checkedBox = "checked"; 66 } 67 let hitHtml = ` <input type="checkbox" class="form-check-input" disabled ${checkedBox}>` 68 let mtime = combo.comboDate.createFromIso(result["mtime"]).toSqlTimestampString(); 69 let file = result["file"]; 70 let fileLabel = file.substr(file.indexOf(':') + 1, file.lastIndexOf('.') - 2); 71 let fileUrl = combo.DokuUrl 72 .createFetch(file,'cache') 73 .toString(); 74 let fileAnchor = `<a href="${fileUrl}" target="_blank">${fileLabel}</a>`; 75 76 let dependencies = ""; 77 let dependency = result["dependency"]; 78 if (typeof dependency !== 'undefined') { 79 dependencies = dependency.join(", "); 80 } 81 html += `<tr><td>${slotLabel}</td><td>${styledFormatResult}</td><td>${hitHtml}</td><td>${mtime}</td><td>${dependencies}</td><td>${fileAnchor}</td></tr>`; 82 } 83 } 84 html += '</table><hr/>'; 85 } 86 87 /** 88 * The modal 89 */ 90 cacheModal 91 .setHeader(`Cache Info for the page (${pageId})`) 92 .addBody(html) 93 .addFooterCloseButton() 94 .show(); 95 }); 96 97 }); 98 } 99); 100 101