Changes for page Nice Display

Last modified by Benjamin Fischer on 2025/03/26 13:19

From version 44.12
edited by Benjamin Fischer
on 2025/03/25 17:47
Change comment: There is no comment for this version
To version 44.2
edited by Benjamin Fischer
on 2025/03/25 17:06
Change comment: Update document after refactoring.

Summary

Details

XWiki.JavaScriptExtension[0]
Code
... ... @@ -1,92 +1,87 @@
1 -/*!
2 -#if ( $ntrg_tagCols == $null )
3 -#set( $ntrg_tagCols = [["Tags", true]] )
4 -#end
5 -#if ( $ntrg_tabName == $null )
6 -#set( $ntrg_tabName = "research_groups" )
7 -#end
8 -#[[*/
9 -((tagCols = [["Tags", true]], tabName = "research_groups") => {
1 +const tabName = "research_groups";
2 +const tagCols = [
3 + ["Tags", true],
4 +]
10 10  
11 - document.observe('xwiki:livetable:loading', () => {
12 - const mats = document.getElementById(tabName);
13 - if (!mats) return;
6 +document.observe('xwiki:livetable:loading', () => {
7 + const mats = document.getElementById(tabName);
14 14  
15 - // coulmn data sources
16 - const conf = JSON.parse(mats.dataset.settings);
17 - tagCols.forEach(([name], i) => {
18 - const cn = `tags-${i}`;
19 - conf.columns.splice(conf.columns.indexOf("tags"), 1, cn);
20 - conf.columnDescriptors[cn] = {
21 - displayName: name,
22 - headerClass: "tagsCol",
23 - html: true,
24 - sortable: false,
25 - };
26 - });
27 - mats.dataset.settings = JSON.stringify(conf);
9 + // coulmn data sources
10 + const conf = JSON.parse(mats.dataset.settings);
11 + tagCols.forEach(([name], i) => {
12 + const cn = `tags-${i}`;
13 + conf.columns.splice(conf.columns.indexOf("tags"), 1, cn);
14 + conf.columnDescriptors[cn] = {
15 + displayName: name,
16 + headerClass: "tagsCol",
17 + html: true,
18 + sortable: false,
19 + };
20 + });
21 + mats.dataset.settings = JSON.stringify(conf);
28 28  
29 - // column headers
30 - mats.querySelectorAll(".xwiki-livetable-display-header .tagsCol").forEach(
31 - (v, i) => v.textContent = tagCols[i][0]
32 - );
23 + // column headers
24 + mats.querySelectorAll(".xwiki-livetable-display-header .tagsCol").forEach(
25 + (v, i) => v.textContent = tagCols[i][0]
26 + );
33 33  
34 - // handle clicks for tags
35 - document.getElementById(`${tabName}-display`).addEventListener("click", ev => {
36 - if (ev.button) return; // only left click
37 - if (ev.target.nodeName !== "SPAN") return;
38 - if (!ev.target.classList.contains("ltTag")) return;
39 - const tag = ev.target.textContent;
40 - ev.preventDefault();
41 - const lt = mats.__liveTable;
42 - const st = lt.tagCloud.selectedTags;
43 - if (tag in st) delete st[tag];
44 - else st[tag] = {};
45 - lt.tags = Object.keys(st);
46 - lt.clearCache();
47 - lt.showRows(1, lt.limit);
48 - })
49 - });
28 + // handle clicks for tags
29 + document.getElementById(`${tabName}-display`).addEventListener("click", ev => {
30 + if (ev.button) return; // only left click
31 + if (ev.target.nodeName !== "SPAN") return;
32 + if (!ev.target.classList.contains("ltTag")) return;
33 + const tag = ev.target.textContent;
34 + ev.preventDefault();
35 + const lt = mats.__liveTable;
36 + const st = lt.tagCloud.selectedTags;
37 + if (tag in st) delete st[tag];
38 + else st[tag] = {};
39 + lt.tags = Object.keys(st);
40 + lt.clearCache();
41 + lt.showRows(1, lt.limit);
42 + })
43 +});
50 50  
51 - document.observe(`xwiki:livetable:${tabName}:receivedEntries`, ({memo: {data}}) => {
52 - for (const row of data.rows) {
53 - const a = new Element("a", { href: row.URL });
54 - a.innerHTML = row.affiliation_value.split("\n").map((a, i) => i ? a : `<b class="wikiexternallink">${a}</b>`).join("<br/>");
55 - a.title = row.doc_title;
56 - if (row.content !== "-") {
57 - a.dataset.content = row.content;
58 - a.dataset.toggle = "popover";
59 - }
45 +document.observe(`xwiki:livetable:${tabName}:receivedEntries`, ({memo: {data}}) => {
46 + for (const row of data.rows) {
47 + const a = new Element("a", { href: row.URL });
48 + a.innerHTML = row.affiliation_value.split("\n").map((a, i) => i ? a : `<b class="wikiexternallink">${a}</b>`).join("<br/>");
49 + a.title = row.doc_title;
50 + if (row.content !== "-") {
51 + a.dataset.content = row.content;
52 + a.dataset.toggle = "popover";
53 + }
60 60  
61 - row.affiliation = a.outerHTML;
55 + row.affiliation = a.outerHTML;
62 62  
63 - row.doc_date = row.doc_date.split(" ")[0].split("/").slice(0, 2).join("/");
57 + row.doc_date = row.doc_date.split(" ")[0].split("/").slice(0, 2).join("/");
64 64  
65 - // tags
66 - const tags = new Set(row.tags_value.slice(1, -1).split(", "));
67 - tagCols.forEach(([name, ...want], i) =>
68 - row[`tags-${i}`] = (
69 - want[0] === true
70 - ? Array.from(tags)
71 - : want.filter(tag => tags.delete(tag))
72 - ).sort().map(tag => `<span class="ltTag" style="cursor:pointer;">${tag}</span>`).join(", ")
73 - );
74 - }
75 - });
59 + // tags
60 + const tags = new Set(row.tags_value.slice(1, -1).split(", "));
61 + tagCols.forEach(([name, ...want], i) =>
62 + row[`tags-${i}`] = (
63 + want[0] === true
64 + ? Array.from(tags)
65 + : want.filter(tag => tags.delete(tag))
66 + ).sort().map(tag => `<span class="ltTag" style="cursor:pointer;">${tag}</span>`).join(", ")
67 + );
68 + }
69 +});
76 76  
77 - require(['jquery', 'bootstrap'], function($) {
78 - document.styleSheets[0].insertRule(`#mainContentArea .popover {max-width: 50%;}`);
71 +require(['jquery', 'bootstrap'], function($) {
72 + document.styleSheets[0].insertRule(`#mainContentArea .popover {max-width: 50%;}`)
79 79  
80 - const ttApply = () => {
81 - $(`#${tabName} [data-toggle="popover"]`).popover({
82 - html: true,
83 - container: `#mainContentArea`,
84 - trigger: "hover",
85 - });
86 - };
74 + const ttApply = () => {
75 + $(`#${tabName} [data-toggle="popover"]`).popover({
76 + html: true,
77 + container: `#mainContentArea`,
78 + trigger: "hover",
79 + });
80 + };
87 87  
88 - document.observe(`xwiki:livetable:${tabName}:displayComplete`, ttApply);
89 - ttApply();
90 - });
91 -/* ]]# */
92 -})($jsontool.serialize($ntrg_tagCols), $jsontool.serialize($ntrg_tabName));
82 + document.observe(`xwiki:livetable:${tabName}:displayComplete`, ttApply);
83 + ttApply();
84 +});
85 +
86 +
87 +
Name
... ... @@ -1,1 +1,1 @@
1 -Nice Table - Research Groups
1 +Live Table - Research Groups
Parse content
... ... @@ -1,1 +1,1 @@
1 -Yes
1 +No