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