Changes for page Material Collection

Last modified by Judith Steinfeld on 2025/06/03 11:13

From version 54.1
edited by admin
on 2024/10/21 14:36
Change comment: There is no comment for this version
To version 55.9
edited by admin
on 2024/10/23 14:57
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -21,7 +21,8 @@
21 21   'link': {"type": "hidden"},
22 22   'date': {"html": true},
23 23   'author': {},
24 - "tags": {"sortable": false, "html": true, "headerClass": "tagsCol"}
24 + "tags": {"sortable": false, "filterable": false, "html": true, "headerClass": "tagsCol"},
25 + "_actions": {"actions": ["view", "edit"]}
25 25  })
26 26  #set ($options = {
27 27   'className': 'Materials.Code.MaterialsClass',
... ... @@ -34,5 +34,8 @@
34 34   'defaultOrder': 'desc'
35 35  })
36 36  #set ($columns = ['doc.location', 'link', "tags", "tags", 'date', 'author'])
38 +#if (!$isGuest)
39 + #set($discard = $columns.add("_actions"))
40 +#end
37 37  #livetable('materials' $columns $columnsProperties $options)
38 38  {{/velocity}}
XWiki.JavaScriptExtension[0]
Code
... ... @@ -1,21 +1,68 @@
1 +const tabName = "materials";
2 +const tagCols = [
3 + ["Type", "lecture", "exercise", "hands-on", "solution", "tutorial"],
4 + ["Tags", true],
5 +]
6 +
1 1  document.observe('xwiki:livetable:loading', () => {
8 + const mats = document.getElementById(tabName);
9 +
10 + // coulmn data sources
11 + const conf = JSON.parse(mats.dataset.settings);
12 + tagCols.forEach(([name], i) => {
13 + const cn = `tags-${i}`;
14 + conf.columns.splice(conf.columns.indexOf("tags"), 1, cn);
15 + conf.columnDescriptors[cn] = {
16 + displayName: name,
17 + headerClass: "tagsCol",
18 + html: true,
19 + sortable: false,
20 + };
21 + });
22 + mats.dataset.settings = JSON.stringify(conf);
23 +
24 + // column headers
25 + mats.querySelectorAll(".xwiki-livetable-display-header .tagsCol").forEach(
26 + (v, i) => v.textContent = tagCols[i][0]
27 + );
28 +
29 + // handle clicks for tags
30 + document.getElementById(`${tabName}-display`).addEventListener("click", ev => {
31 + if (ev.button) return; // only left click
32 + if (ev.target.nodeName !== "SPAN") return;
33 + if (!ev.target.classList.contains("ltTag")) return;
34 + const tag = ev.target.textContent;
35 + ev.preventDefault();
36 + const lt = mats.__liveTable;
37 + const st = lt.tagCloud.selectedTags;
38 + if (tag in st) delete st[tag];
39 + else st[tag] = {};
40 + lt.tags = Object.keys(st);
41 + lt.clearCache();
42 + lt.showRows(1, lt.limit);
43 + })
2 2  });
3 3  
4 -document.observe("xwiki:livetable:materials:receivedEntries", ({memo: {data}}) => {
46 +document.observe(`xwiki:livetable:${tabName}:receivedEntries`, ({memo: {data}}) => {
5 5   for (const row of data.rows) {
6 6   const ol = new DOMParser().parseFromString(row.doc_location, "text/xml").documentElement;
7 7   const li = ol.children;
8 8  
9 - li[0].remove(); // remove event
51 + li[0].remove(); // remove "Event"
10 10   for (let i = 1; i < li.length - 1; i++) // intermediate
11 11   li[i].textContent = li[i].textContent; // remove link
12 12  
13 13   const a = li[li.length - 1].children[0];
56 + const b = a.ownerDocument.createElement("b");
57 + a.replaceWith(b);
58 + b.appendChild(a);
59 +
14 14   const u = new URL(row.link_value);
15 -
16 16   let icon;
62 + if (u.hostname.includes("github")) icon = "github";
63 + if (u.hostname.includes("gitlab")) icon = "gitlab";
64 + if (u.hostname.includes("google")) icon = "google";
17 17   if (u.pathname.endsWith(".pdf")) icon = "file-pdf-o";
18 -
19 19   if (icon) {
20 20   const s = a.ownerDocument.createElement("span");
21 21   s.textContent = " ";
... ... @@ -23,11 +23,22 @@
23 23   s.setAttribute("style", "padding-right: .3em;");
24 24   a.insertBefore(s, a.firstChild);
25 25   }
26 -
27 27   a.setAttribute("class", "wikiexternallink");
28 28   a.setAttribute("href", u.href);
75 +
76 + a.parentNode
29 29  
30 30   row.doc_location = ol.outerHTML;
79 +
80 + // tags
81 + const tags = new Set(row.tags_value.slice(1, -1).split(", "));
82 + tagCols.forEach(([name, ...want], i) =>
83 + row[`tags-${i}`] = (
84 + want[0] === true
85 + ? Array.from(tags)
86 + : want.filter(tag => tags.delete(tag))
87 + ).sort().map(tag => `<span class="ltTag" style="cursor:pointer;">${tag}</span>`).join(", ")
88 + );
31 31   }
32 32  });
33 33