Änderungen von Dokument View File Macro

Zuletzt geändert von xwikiadmin am 2025/12/11 07:44

Von Version 6.1
bearbeitet von xwikiadmin
am 2024/06/24 15:04
Änderungskommentar: Install extension [com.xwiki.pro:xwiki-pro-macros-ui/1.19.4]
Auf Version 9.1
bearbeitet von xwikiadmin
am 2025/05/21 10:03
Änderungskommentar: Install extension [com.xwiki.pro:xwiki-pro-macros-ui/1.26.19]

Zusammenfassung

Details

Seiteneigenschaften
Inhalt
... ... @@ -6,10 +6,11 @@
6 6  
7 7  |=Parameter|=Description|=Required|=Default
8 8  |display|Kind of display. "button" for a button, "thumbnail" for a thumbnail, "full" to render the document in place|no|thumbnail (button in inline mode)
9 -|name|The attachment reference to display|if att-filename is not given|
9 +|name|The attachment reference to display|if att--filename is not given|
10 +|page|The page from where you want the attachments to be displayed. Modifying this parameter will reset the selected file value|no|
10 10  |width|The width of the view in % or px (e.g. 100%, 100px)|no|100% for the full view or 100px for the thumbnail
11 11  |height|The height of the view in % or px (e.g. 100%, 100px)|no|1000px for the full view or 100px for the thumbnail
12 -|att-filename|Alias of name|If name is not given|
13 +|att--filename|Alias of name|If name is not given|
13 13  
14 14  = Example Usage =
15 15  
XWiki.JavaScriptExtension[0]
Code
... ... @@ -1,3 +1,68 @@
1 +require.config({
2 + paths: {
3 + 'xwiki-suggestAttachments': "$xwiki.getSkinFile('uicomponents/suggest/suggestAttachments.js', true)" +
4 + "?v=$escapetool.url($xwiki.version)"
5 + }
6 +});
7 +
8 +// As there is no platform implementation to allow the user to dynamically select the page from where the attachments
9 +// are shown, a custom implementation was made to dynamically update the displyed attachments in corelation to the
10 +// selected page parameter. This can be removed after the implementation of https://jira.xwiki.org/browse/XWIKI-22850.
11 +require(['jquery', 'xwiki-meta', 'xwiki-suggestAttachments'], function($, xm) {
12 + const acceptedExtensions = '.ppt,.pptx,.odp,.doc,.docx,.odt,.xls,.xlsx,.ods,.pdf';
13 + const styleObserver = new MutationObserver(function(mutations) {
14 + for (const mutation of mutations) {
15 + if (mutation.target.style.display === 'none') {
16 + styleObserver.disconnect();
17 + pageObserver.observe(document.body, { childList: true, subtree: true });
18 + return;
19 + }
20 + }
21 + });
22 +
23 + const initializeAttachments = function(selectElement) {
24 + let scope = "document:";
25 + if (selectElement.val() != null) {
26 + scope += selectElement.val();
27 + }
28 + var inputElement = $('input[name="name"]');
29 + if (inputElement.length) {
30 + let selectize = inputElement.siblings('.selectize-control');
31 + if (selectize.length) {
32 + selectize.remove();
33 + inputElement.removeAttr("class tabindex style").val('');
34 + const clone = inputElement.clone().appendTo(inputElement.parent());
35 + inputElement.remove();
36 + inputElement = clone;
37 + }
38 + const allowUpload = selectElement.val() == xm.document || !selectElement.val();
39 + inputElement.suggestAttachments({
40 + maxItems: 1,
41 + accept: acceptedExtensions,
42 + searchScope: scope,
43 + uploadAllowed: allowUpload
44 + });
45 + }
46 + }
47 +
48 + const pageObserver = new MutationObserver(function(mutationsList, observer) {
49 + const selectElement = $('select[name="page"]');
50 + if (selectElement.length) {
51 + const modal = selectElement.closest(".macro-editor-modal")[0];
52 + if (modal.style.display !== 'none') {
53 + observer.disconnect();
54 + styleObserver.observe(modal, { attributes: true, attributeFilter: ['style'] });
55 + $(selectElement).change(function() {
56 + initializeAttachments($(this))
57 + });
58 + initializeAttachments(selectElement)
59 + }
60 + }
61 + });
62 +
63 + pageObserver.observe(document.body, { childList: true, subtree: true });
64 +});
65 +
1 1  window.addEventListener("DOMContentLoaded", function () {
2 2   "use strict";
3 3   document.addEventListener("click", async function (e) {
Inhalt parsen
... ... @@ -1,1 +1,1 @@
1 -Nein
1 +Ja
XWiki.StyleSheetExtension[0]
Code
... ... @@ -42,8 +42,15 @@
42 42  
43 43  .viewFileThumbnailCard, .viewFileFull {
44 44   position: relative;
45 + margin-bottom: 1rem !important;
45 45  }
46 46  
48 +.viewFileThumbnailCard {
49 + width: 10rem !important;
50 + height: fit-content !important;
51 + min-height: 10rem !important;
52 +}
53 +
47 47  span.viewFileThumbnailCard {
48 48   display: inline-block;
49 49  }
... ... @@ -54,7 +54,7 @@
54 54   flex-direction: column;
55 55   text-align: center;
56 56   width: 100%;
57 - height: 100%;
64 + min-height: inherit;
58 58  }
59 59  
60 60  .viewFileThumbnailCard a .attachmentMimeType {
... ... @@ -67,8 +67,13 @@
67 67   width: 100%;
68 68   border: 1px solid;
69 69   border-radius: 1rem;
77 + min-height: 5em;
70 70  }
71 71  
72 72  .viewFileModal-downloadLink {
73 73   margin-left: 2px;
74 74  }
83 +
84 +.viewFileName {
85 + overflow-wrap: break-word;
86 +}
XWiki.WikiMacroClass[0]
Cached
... ... @@ -1,1 +1,0 @@
1 -Nein
Asynchrones Rendern
... ... @@ -1,1 +1,0 @@
1 -Nein
Makro-Code
... ... @@ -1,155 +1,0 @@
1 -{{velocity output="false"}}
2 -#template('attachment_macros.vm')
3 -
4 -#set ($officeExtensions = [ 'ppt', 'pptx', 'odp', 'doc', 'docx', 'odt', 'xls', 'xlsx', 'ods' ])
5 -#set ($presentationExtensions = [ 'ppt', 'pptx', 'odp' ])
6 -#set ($hasPDFViewer = $xwiki.exists("XWiki.PDFViewerMacro"))
7 -
8 -#macro (renderThumbnailButton $attachmentRef $previewSupported $width $height $forceCard)
9 - #set ($style = "")
10 - #if ("$!width" != "")
11 - #set ($style = $style + " width: $width")
12 - #end
13 - #if ("$!height" != "")
14 - #set ($style = $style + " height: $height")
15 - #end
16 - #if ("$!style" != "")
17 - #set ($style = "style='$style.trim()'")
18 - #set ($thumbnailStyle = "Card")
19 - #elseif ($forceCard)
20 - #set ($style = "style='width: 100px; height: 100px;'")
21 - #set ($height = "100px")
22 - #set ($thumbnailStyle = "Card")
23 - #else
24 - #set ($thumbnailStyle = "Button")
25 - #end
26 - #if ($wikimacro.context.isInline() || $thumbnailStyle == "Button")
27 - #set ($elem = "span")
28 - #else
29 - #set ($elem = "div")
30 - #end
31 - #set ($attachment = $xwiki.getDocument($attachmentRef.getParent()).getAttachment($attachmentRef.getName()))
32 - #set ($thumbnail = "#displayAttachmentMimeType($attachment)")
33 - #if ($thumbnail.charAt(0) == '#')
34 - ## #displayAttachmentMimeType is not supported (before July 2022)
35 - #set ($thumbnail = '<div class="attachmentMimeType"><span><span class="fa fa-paperclip" aria-hidden="true"></span></span></div>')
36 - #end
37 - #if ($elem == "span")
38 - #set ($thumbnail = $thumbnail.replace('</div>', '</span>').replace('<div ', '<span '))
39 - #end
40 -
41 - {{html clean=false}}
42 - <$elem class="viewFileThumbnail viewFileThumbnail$thumbnailStyle" $style data-preview="$previewSupported" data-ref="$escapetool.xml($services.model.serialize($attachmentRef, 'default'))">
43 - <a href="$escapetool.xml($xwiki.getURL($attachmentRef))"
44 - download="download"
45 - #if ($thumbnailStyle == "Button") class="button button-primary" #end
46 - title="$escapetool.xml($services.localization.render('rendering.macro.viewFile.thumbnail.button.title'))"
47 - >
48 - $thumbnail
49 - <span class="viewFileName">$escapetool.xml($attachmentRef.getName())</span>
50 - </a>
51 - </$elem>
52 - {{/html}}
53 -
54 -#end
55 -
56 -#macro (renderFull $extension $attachmentRef $width $height)
57 - #set ($escapedAttachmentReference = $services.rendering.escape($attachmentRef, $xwiki.currentContentSyntaxId))
58 - #if ($officeExtensions.contains($extension))
59 -
60 - {{html clean=false}}
61 - <div class="viewFileFull#if (!$presentationExtensions.contains($extension)) box#end"
62 - style="width: $width; height: $height; overflow: auto">
63 - {{/html}}
64 -
65 - {{office reference="$escapedAttachmentReference" /}}
66 -
67 - {{html clean=false}}
68 - </div>
69 - {{/html}}
70 -
71 - #elseif ($extension == 'pdf' && $hasPDFViewer)
72 - #if ($height.endsWith("px"))
73 - #set ($height = $stringtool.removeEnd($height, "px"))
74 - #end
75 - #if ($width.endsWith("px"))
76 - #set ($width = $stringtool.removeEnd($width, "px"))
77 - #end
78 -
79 - {{pdfviewer file="$escapedAttachmentReference" height="$height" width="$width"/}}
80 -
81 - #else
82 - #renderThumbnailButton($attachmentRef false $width $height)
83 - #end
84 -#end
85 -
86 -#macro (executeMacro)
87 - #set($unescapedFilename = $xcontext.macro.params.get('att--filename'))
88 - #if(!$unescapedFilename)
89 - #set($unescapedFilename = $xcontext.macro.params.get('name'))
90 - #end
91 - #if(!$unescapedFilename)
92 -
93 - {{error}}
94 - $escapetool.xml($services.localization.render('rendering.macro.viewFile.namerequired'))"
95 - {{/error}}
96 - #end
97 - #continueExecutingMacro##
98 -#end
99 -
100 -#macro (continueExecutingMacro)
101 - #set ($attachmentRef = $services.model.resolveAttachment($unescapedFilename))
102 - #set ($discard = $xwiki.ssx.use('Confluence.Macros.ViewFile'))
103 - #set ($extension = $unescapedFilename.substring($unescapedFilename.lastIndexOf('.') + 1).toLowerCase())
104 - #set ($width = $xcontext.macro.params.get('width'))
105 - #set ($height = $xcontext.macro.params.get('height'))
106 - #set ($display = $xcontext.macro.params.get('display'))
107 - #if ("$!width" != "")
108 - #set ($width = $escapetool.xml($width))
109 - #if (!$width.endsWith("%") && !$width.endsWith("px"))
110 - #set($width = $width + "px")
111 - #end
112 - #end
113 - #if ("$!height" != "")
114 - #set ($height = $escapetool.xml($height))
115 - #if (!$height.endsWith("%") && !$height.endsWith("px"))
116 - #set($height = $height + "px")
117 - #end
118 - #end
119 - #if (($display == 'FULL' || $display == 'full') && ($wikimacro.context.isInline() || ($xcontext.action == "edit" || $request.outputSyntax == "annotatedhtml")))
120 - #set ($display = "thumbnail")
121 - #end
122 - #if ($display == 'FULL' || $display == 'full')
123 - #if ("$!width" == "")
124 - #set ($width = "100%")
125 - #end
126 - #if ("$!height" == "")
127 - #set ($height = "1000px")
128 - #end
129 - #renderFull($extension $attachmentRef $width $height)
130 - #else
131 - ## thumbnail or fallback
132 - #set ($hasPreview = ($extension == 'pdf' && $hasPDFViewer) || $officeExtensions.contains($extension))
133 - #if ($hasPreview)
134 - #set ($discard = $xwiki.jsx.use('Confluence.Macros.ViewFile'))
135 - #end
136 - #set ($forceCard = ($display == 'THUMBNAIL' || $display == 'thumbnail' || ("$!display" == "" && !$wikimacro.context.isInline())))
137 - #if ($presentationExtensions.contains($extension))
138 - #set ($discard = $xwiki.jsfx.use("uicomponents/widgets/gallery/gallery.js", {"forceSkinAction": true}))
139 - #set ($discard = $xwiki.ssfx.use("uicomponents/widgets/gallery/gallery.css"))
140 - #end
141 - #renderThumbnailButton($attachmentRef $hasPreview $width $height $forceCard)
142 - #end
143 -#end
144 -{{/velocity}}
145 -
146 -{{velocity}}
147 -## We need to check if there is a valid license because the macro is registered even if the user doesn't have view right
148 -## on the macro definition page. See XWIKI-14828: Rendering macros defined in wiki pages are available to users that
149 -## don't have view right on those pages.
150 -#if ($services.promacrolicensing.hasLicensureForEntity($xcontext.macro.doc.documentReference))##
151 - #executeMacro##
152 -#else
153 - {{missingLicenseMessage extensionName="proMacros.extension.name"/}}
154 -#end
155 -{{/velocity}}
Verfügbarkeit von Makroinhalten
... ... @@ -1,1 +1,0 @@
1 -No content
Makrobeschreibung
... ... @@ -1,1 +1,0 @@
1 -Show files using PDF Viewer Macro or Office Viewer
Makro id
... ... @@ -1,1 +1,0 @@
1 -view-file
Makroname
... ... @@ -1,1 +1,0 @@
1 -View Files
Unterstützt Inline-Modus
... ... @@ -1,1 +1,0 @@
1 -Ja
Makro-Sichtbarkeit
... ... @@ -1,1 +1,0 @@
1 -Current Wiki
XWiki.WikiMacroParameterClass[0]
Parameter-Beschreibung
... ... @@ -1,1 +1,0 @@
1 -Alias of name (here for compatibility reasons)
Parameter verpflichtend
... ... @@ -1,1 +1,0 @@
1 -Nein
Parameter-Name
... ... @@ -1,1 +1,0 @@
1 -att--filename
Parameter-Typ
... ... @@ -1,1 +1,0 @@
1 -org.xwiki.model.reference.AttachmentReference
XWiki.WikiMacroParameterClass[1]
Parameter-Beschreibung
... ... @@ -1,1 +1,0 @@
1 -The width of the view in % or px (e.g. 100%, 100px)
Parameter verpflichtend
... ... @@ -1,1 +1,0 @@
1 -Nein
Parameter-Name
... ... @@ -1,1 +1,0 @@
1 -width
XWiki.WikiMacroParameterClass[2]
Parameter-Beschreibung
... ... @@ -1,1 +1,0 @@
1 -The height of the view in % or px (e.g. 100%, 100px)
Parameter verpflichtend
... ... @@ -1,1 +1,0 @@
1 -Nein
Parameter-Name
... ... @@ -1,1 +1,0 @@
1 -height
XWiki.WikiMacroParameterClass[3]
Parameter-Beschreibung
... ... @@ -1,1 +1,0 @@
1 -Kind of display. "button" for a button, "thumbnail" for a thumbnail, "full" to render the document in place
Parameter verpflichtend
... ... @@ -1,1 +1,0 @@
1 -Nein
Parameter-Name
... ... @@ -1,1 +1,0 @@
1 -display
Parameter-Typ
... ... @@ -1,1 +1,0 @@
1 -com.xwiki.macros.internal.ViewFileDisplay
XWiki.WikiMacroParameterClass[4]
Parameter-Beschreibung
... ... @@ -1,1 +1,0 @@
1 -The attachment reference to display
Parameter verpflichtend
... ... @@ -1,1 +1,0 @@
1 -Nein
Parameter-Name
... ... @@ -1,1 +1,0 @@
1 -name
Parameter-Typ
... ... @@ -1,1 +1,0 @@
1 -org.xwiki.model.reference.AttachmentReference