0 Votes

Changes for page IncidentGallery

Last modified by Ryan C on 2025/07/17 06:41

From version 2.15
edited by Ryan C
on 2025/07/17 05:05
Change comment: There is no comment for this version
To version 2.13
edited by Ryan C
on 2025/07/17 05:04
Change comment: There is no comment for this version

Summary

Details

XWiki.WikiMacroClass[0]
Macro code
... ... @@ -1,80 +1,74 @@
1 -{{groovy}}
2 -def binding = binding
3 -def tags = binding.getVariable('tags')
4 -def max = binding.getVariable('max')
1 +{{groovy bindings="tags,max"}}
2 +def includeTags = (context.macro.params.tags ?: "").split(',')*.trim()*.toLowerCase().findAll { it } // removes blanks
3 +def maxCount = context.macro.params.max?.toInteger() ?: 999
5 5  
6 -def includeTags = tags?.split(',')*.trim()*.toLowerCase().findAll { it }
7 -def maxCount = max?.toInteger() ?: 999
8 8  
6 +def hql = """
7 + select doc.fullName
8 + from XWikiDocument doc, BaseObject obj
9 + where obj.name = doc.fullName
10 + and obj.className = 'Main Categories.Anti White Incidents.Code.MoviesClass'
11 + order by doc.date desc
12 +"""
9 9  
10 - def hql = """
11 - select doc.fullName
12 - from XWikiDocument doc, BaseObject obj
13 - where obj.name = doc.fullName
14 - and obj.className = 'Main Categories.Anti White Incidents.Code.MoviesClass'
15 - order by doc.date desc
16 - """
14 +def docs = xwiki.search(hql, maxCount, 0)
15 +def results = []
17 17  
18 - def docs = xwiki.search(hql, maxCount, 0)
19 - def results = []
17 +docs.each { docName ->
18 + if (results.size() >= maxCount) return
20 20  
21 - docs.each { docName ->
22 - if (results.size() >= maxCount) return
20 + def doc = xwiki.getDocument(docName)
21 + def obj = doc.getObject("Main Categories.Anti White Incidents.Code.MoviesClass")
22 + if (!obj) return
23 23  
24 - def doc = xwiki.getDocument(docName)
25 - def obj = doc.getObject("Main Categories.Anti White Incidents.Code.MoviesClass")
26 - if (!obj) return
24 + // extract fields
25 + def title = obj.getProperty("shortText1")?.value?.toString()?.trim()
26 + def summary = obj.getProperty("shortText2")?.value?.toString()?.trim() ?: obj.getProperty("longText1")?.value?.toString()?.trim()
27 + def externalURL = obj.getProperty("longText2")?.value?.toString()?.trim()
28 + def tagList = obj.getProperty("tags")?.value
27 27  
28 - def title = obj.getProperty("shortText1")?.value?.toString()?.trim()
29 - def summary = obj.getProperty("shortText2")?.value?.toString()?.trim() ?: obj.getProperty("longText1")?.value?.toString()?.trim()
30 - def externalURL = obj.getProperty("longText2")?.value?.toString()?.trim()
31 - def tagList = obj.getProperty("tags")?.value
30 + if (!title || !summary) return
32 32  
33 - if (!title || !summary) return
32 + // tag filtering
33 + if (includeTags && tagList) {
34 + def tagNames = tagList.collect { it.toString().toLowerCase() }
35 + if (!tagNames.any { includeTags.contains(it) }) return
36 + }
34 34  
35 - if (includeTags && tagList) {
36 - def tagNames = tagList.collect { it.toString().toLowerCase() }
37 - if (!tagNames.any { includeTags.contains(it) }) return
38 - }
38 + def isValidURL = externalURL?.startsWith("http://") || externalURL?.startsWith("https://")
39 + def linkTarget = isValidURL ? externalURL : "doc:${docName}"
40 + def safeTitle = title.replaceAll(/[\[\]\|]/, '').replaceAll(/\>\>/, '>>\u200B')
39 39  
40 - def isValidURL = externalURL?.startsWith("http://") || externalURL?.startsWith("https://")
41 - def linkTarget = isValidURL ? externalURL : "doc:${docName}"
42 - def safeTitle = title.replaceAll(/[\[\]\|]/, '').replaceAll(/\>\>/, '>>\u200B')
42 + def imageFile = doc.getAttachmentList()?.find {
43 + it.filename.toLowerCase().matches(".*\\.(png|jpg|jpeg|gif)")
44 + }?.filename
43 43  
44 - def imageFile = doc.getAttachmentList()?.find {
45 - it.filename.toLowerCase().matches(".*\\.(png|jpg|jpeg|gif)")
46 - }?.filename
46 + def imageMarkup = ""
47 + if (imageFile) {
48 + imageMarkup = "[[image:${doc.fullName}@${imageFile}||alt=\"Image\" data-xwiki-image-style=\"thumbnail-clickable\" style=\"border:1px solid #ccc\" width=\"200\"]]"
49 + }
47 47  
48 - def imageMarkup = ""
49 - if (imageFile) {
50 - imageMarkup = "[[image:${doc.fullName}@${imageFile}||alt=\"Image\" data-xwiki-image-style=\"thumbnail-clickable\" style=\"border:1px solid #ccc\" width=\"200\"]]"
51 - }
51 + def block = """
52 + (% style="margin-bottom:20px; width:100%" %)
53 + |${imageMarkup}|
52 52  
53 - def block = """
54 - (% style="margin-bottom:20px; width:100%" %)
55 - |${imageMarkup}|
55 + === [[${safeTitle}>>${linkTarget}]] ===
56 56  
57 - === [[${safeTitle}>>${linkTarget}]] ===
57 + ${summary}
58 + [[Read More>>${linkTarget}]]
59 + """.trim()
58 58  
59 - ${summary}
60 - [[Read More>>${linkTarget}]]
61 - """.trim()
61 + results << block
62 +}
62 62  
63 - results << block
64 - }
65 -
66 - if (results.isEmpty()) {
67 - if (includeTags) {
68 - println "⚠️ No incidents found for tags: ${tags}"
69 - } else {
70 - println "⚠️ No incidents to display."
71 - }
64 +if (results.isEmpty()) {
65 + if (includeTags) {
66 + println "⚠️ No incidents found for tags: ${parameters.tags}"
72 72   } else {
73 - println results.join("\n\n")
68 + println "⚠️ No incidents to display."
74 74   }
70 +} else {
71 + println results.join("\n\n")
75 75  }
76 -
77 -// ✅ This is the actual macro parameter call
78 -render(tags, max)
79 79  {{/groovy}}
80 80