Änderungen von Dokument View File Macro
Zuletzt geändert von xwikiadmin am 2025/01/07 12:27
Von Version 3.1
bearbeitet von xwikiadmin
am 2023/04/25 11:27
am 2023/04/25 11:27
Änderungskommentar:
Install extension [com.xwiki.pro:xwiki-pro-macros/1.7.1]
Auf Version 7.1
bearbeitet von xwikiadmin
am 2025/01/07 12:27
am 2025/01/07 12:27
Änderungskommentar:
Install extension [com.xwiki.pro:xwiki-pro-macros-ui/1.25.4]
Zusammenfassung
-
Seiteneigenschaften (1 geändert, 0 hinzugefügt, 0 gelöscht)
-
Objekte (2 geändert, 6 hinzugefügt, 0 gelöscht)
Details
- Seiteneigenschaften
-
- Inhalt
-
... ... @@ -1,3 +1,34 @@ 1 - {{view-file name="Test.ppt"/}}1 +The view-file macro displays attachments in a document, in place or as thumbnail and offers a preview. 2 2 3 -{{view-file name="TestPDF.pdf" /}} 3 +Limitation: the thumbnail is actually only an icon for now. 4 + 5 += Parameters = 6 + 7 +|=Parameter|=Description|=Required|=Default 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| 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 +|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 + 14 += Example Usage = 15 + 16 +Thumbnails side by side: 17 + 18 +{{view-file display="thumbnail" name="Test.ppt"/}} {{view-file display="thumbnail" name="TestPDF.pdf"/}} 19 + 20 +Or standalone: 21 + 22 +{{view-file name="Test.ppt"/}} 23 + 24 +In a paragraph: {{view-file name="Test.ppt"/}} 25 + 26 + 27 +Full PDF: 28 + 29 +{{view-file display="full" name="TestPDF.pdf"/}} 30 + 31 +Full Presentation: 32 + 33 +{{view-file display="full" name="Test.ppt"/}} 34 +
- XWiki.WikiMacroClass[0]
-
- Makro-Code
-
... ... @@ -1,35 +1,157 @@ 1 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 + #set ($clean = false) 29 + #else 30 + #set ($elem = "div") 31 + #set ($clean = true) 32 + #end 33 + #set ($attachment = $xwiki.getDocument($attachmentRef.getParent()).getAttachment($attachmentRef.getName())) 34 + #set ($thumbnail = "#displayAttachmentMimeType($attachment)") 35 + #if ($thumbnail.charAt(0) == '#') 36 + ## #displayAttachmentMimeType is not supported (before July 2022) 37 + #set ($thumbnail = '<div class="attachmentMimeType"><span><span class="fa fa-paperclip" aria-hidden="true"></span></span></div>') 38 + #end 39 + #if ($elem == "span") 40 + #set ($thumbnail = $thumbnail.replace('</div>', '</span>').replace('<div ', '<span ')) 41 + #end 42 + 43 + {{html clean="$clean"}} 44 + <$elem class="viewFileThumbnail viewFileThumbnail$thumbnailStyle" $style data-preview="$previewSupported" data-ref="$escapetool.xml($services.model.serialize($attachmentRef, 'default'))"> 45 + <a href="$escapetool.xml($xwiki.getURL($attachmentRef))" 46 + download="download" 47 + #if ($thumbnailStyle == "Button") class="button button-primary" #end 48 + title="$escapetool.xml($services.localization.render('rendering.macro.viewFile.thumbnail.button.title'))" 49 + > 50 + $thumbnail 51 + <span class="viewFileName">$escapetool.xml($attachmentRef.getName())</span> 52 + </a> 53 + </$elem> 54 + {{/html}} 55 + 56 +#end 57 + 58 +#macro (renderFull $extension $attachmentRef $width $height) 59 + #set ($escapedAttachmentReference = $services.rendering.escape($attachmentRef, $xwiki.currentContentSyntaxId)) 60 + #if ($officeExtensions.contains($extension)) 61 + 62 + {{html clean=false}} 63 + <div class="viewFileFull#if (!$presentationExtensions.contains($extension)) box#end" 64 + style="width: $width; height: $height; overflow: auto"> 65 + {{/html}} 66 + 67 + {{office reference="$escapedAttachmentReference" /}} 68 + 69 + {{html clean=false}} 70 + </div> 71 + {{/html}} 72 + 73 + #elseif ($extension == 'pdf' && $hasPDFViewer) 74 + #if ($height.endsWith("px")) 75 + #set ($height = $stringtool.removeEnd($height, "px")) 76 + #end 77 + #if ($width.endsWith("px")) 78 + #set ($width = $stringtool.removeEnd($width, "px")) 79 + #end 80 + 81 + {{pdfviewer file="$escapedAttachmentReference" height="$height" width="$width"/}} 82 + 83 + #else 84 + #renderThumbnailButton($attachmentRef false $width $height) 85 + #end 86 +#end 87 + 2 2 #macro (executeMacro) 3 - #set($hasPDFViewer = $xwiki.exists("XWiki.PDFViewerMacro")) 4 - #set($officeExtensions = [ 'ppt', 'pptx', 'odp', 'doc', 'docx', 'odt', 'xls', 'xlsx', 'ods' ]) 5 - #set($filename = $xcontext.macro.params.get('att--filename')) 6 - #if(!$filename) 7 - #set($filename = $xcontext.macro.params.get('name')) 89 + #set($unescapedFilename = $xcontext.macro.params.get('att--filename')) 90 + #if(!$unescapedFilename) 91 + #set($unescapedFilename = $xcontext.macro.params.get('name')) 8 8 #end 9 - #set($extension = $filename.substring($mathtool.add($filename.lastIndexOf('.'), 1)).toLowerCase()) 10 - #if($extension == 'pdf' && $hasPDFViewer) 93 + #if(!$unescapedFilename) 11 11 12 - {{pdfviewer file="${filename}" /}} 13 - #elseif($officeExtensions.contains($extension)) 95 + {{error}} 96 + $escapetool.xml($services.localization.render('rendering.macro.viewFile.namerequired'))" 97 + {{/error}} 98 + #end 99 + #continueExecutingMacro## 100 +#end 14 14 15 - {{office reference="attach:${filename}" /}} 16 - #elseif($doc.getAttachment($filename)) 17 - [[attach:${filename}]] 102 +#macro (continueExecutingMacro) 103 + #set ($attachmentRef = $services.model.resolveAttachment($unescapedFilename)) 104 + #set ($discard = $xwiki.ssx.use('Confluence.Macros.ViewFile')) 105 + #set ($extension = $unescapedFilename.substring($unescapedFilename.lastIndexOf('.') + 1).toLowerCase()) 106 + #set ($width = $xcontext.macro.params.get('width')) 107 + #set ($height = $xcontext.macro.params.get('height')) 108 + #set ($display = $xcontext.macro.params.get('display')) 109 + #if ("$!width" != "") 110 + #set ($width = $escapetool.xml($width)) 111 + #if (!$width.endsWith("%") && !$width.endsWith("px")) 112 + #set($width = $width + "px") 113 + #end 18 18 #end 115 + #if ("$!height" != "") 116 + #set ($height = $escapetool.xml($height)) 117 + #if (!$height.endsWith("%") && !$height.endsWith("px")) 118 + #set($height = $height + "px") 119 + #end 120 + #end 121 + #if (($display == 'FULL' || $display == 'full') && ($wikimacro.context.isInline() || ($xcontext.action == "edit" || $request.outputSyntax == "annotatedhtml"))) 122 + #set ($display = "thumbnail") 123 + #end 124 + #if ($display == 'FULL' || $display == 'full') 125 + #if ("$!width" == "") 126 + #set ($width = "100%") 127 + #end 128 + #if ("$!height" == "") 129 + #set ($height = "1000px") 130 + #end 131 + #renderFull($extension $attachmentRef $width $height) 132 + #else 133 + ## thumbnail or fallback 134 + #set ($hasPreview = ($extension == 'pdf' && $hasPDFViewer) || $officeExtensions.contains($extension)) 135 + #if ($hasPreview) 136 + #set ($discard = $xwiki.jsx.use('Confluence.Macros.ViewFile')) 137 + #end 138 + #set ($forceCard = ($display == 'THUMBNAIL' || $display == 'thumbnail' || ("$!display" == "" && !$wikimacro.context.isInline()))) 139 + #if ($presentationExtensions.contains($extension)) 140 + #set ($discard = $xwiki.jsfx.use("uicomponents/widgets/gallery/gallery.js", {"forceSkinAction": true})) 141 + #set ($discard = $xwiki.ssfx.use("uicomponents/widgets/gallery/gallery.css")) 142 + #end 143 + #renderThumbnailButton($attachmentRef $hasPreview $width $height $forceCard) 144 + #end 19 19 #end 20 20 {{/velocity}} 21 21 22 -{{include reference="Licenses.Code.VelocityMacros"/}} 23 - 24 24 {{velocity}} 25 25 ## We need to check if there is a valid license because the macro is registered even if the user doesn't have view right 26 26 ## on the macro definition page. See XWIKI-14828: Rendering macros defined in wiki pages are available to users that 27 27 ## don't have view right on those pages. 28 -#if ($services.licensing. licensor.hasLicensureForEntity($xcontext.macro.doc.documentReference))29 - #executeMacro 152 +#if ($services.promacrolicensing.hasLicensureForEntity($xcontext.macro.doc.documentReference))## 153 + #executeMacro## 30 30 #else 31 - {{error}} 32 - #getMissingLicenseMessage('proMacros.extension.name') 33 - {{/error}} 155 + {{missingLicenseMessage extensionName="proMacros.extension.name"/}} 34 34 #end 35 35 {{/velocity}} - Standardkategorie
-
... ... @@ -1,1 +1,0 @@ 1 -content - Unterstützt Inline-Modus
-
... ... @@ -1,1 +1,1 @@ 1 - Nein1 +Ja - Verfügbarkeit von Makroinhalten
-
... ... @@ -1,1 +1,1 @@ 1 - Optional1 +No content
- XWiki.WikiMacroParameterClass[0]
-
- Parameter-Beschreibung
-
... ... @@ -1,0 +1,1 @@ 1 +Alias of name (here for compatibility reasons) - Parameter-Typ
-
... ... @@ -1,0 +1,1 @@ 1 +org.xwiki.model.reference.AttachmentReference - Parameter verpflichtend
-
... ... @@ -1,0 +1,1 @@ 1 +Nein
- XWiki.JavaScriptExtension[0]
-
- Pufferstrategie
-
... ... @@ -1,0 +1,1 @@ 1 +long - Code
-
... ... @@ -1,0 +1,33 @@ 1 +window.addEventListener("DOMContentLoaded", function () { 2 + "use strict"; 3 + document.addEventListener("click", async function (e) { 4 + if (("" + document.getElementById("xwikicontent")?.contentEditable) == "true") { 5 + return; 6 + } 7 + const viewFile = e.target?.closest(".viewFileThumbnail"); 8 + if (viewFile && viewFile.dataset.preview === 'true') { 9 + const popup = new XWiki.widgets.ModalPopup(); 10 + popup.createDialog(); 11 + popup.setContent("<span class='fa fa-spinner'></span>"); 12 + popup.dialogBox.classList.add("viewFileModal"); 13 + popup.dialogBox.style.top = "2.5vh"; 14 + popup.dialogBox.style.width = "95vw"; 15 + popup.dialogBox.style.height = "95vh"; 16 + const a = e.target.closest('a'); 17 + const downloadLink = document.createElement("a"); 18 + downloadLink.download = true; 19 + downloadLink.textContent = a.textContent; 20 + downloadLink.className = "fa fa-download button button-primary viewFileModal-downloadLink"; 21 + downloadLink.href = a.href; 22 + popup.dialogBox.insertBefore(downloadLink, popup.dialogBox.firstChild) 23 + popup.showDialog(); 24 + e.preventDefault(); 25 + const response = await fetch(XWiki.contextPath + "/wiki/" + XWiki.currentWiki + "/get/Confluence/Macros/ViewFileService?action=render&attachment=" + encodeURIComponent(viewFile.dataset.ref)); 26 + popup.setContent(await response.text()); 27 + const gallery = popup.dialogBox.querySelector(".gallery"); 28 + if (gallery) { 29 + new XWiki.Gallery(gallery); 30 + } 31 + } 32 + }); 33 +}); - Benutze diese Erweiterung
-
... ... @@ -1,0 +1,1 @@ 1 +onDemand - Inhalt parsen
-
... ... @@ -1,0 +1,1 @@ 1 +Nein
- XWiki.StyleSheetExtension[0]
-
- Pufferstrategie
-
... ... @@ -1,0 +1,1 @@ 1 +long - Code
-
... ... @@ -1,0 +1,74 @@ 1 +.viewFileModal iframe, .viewFileModal .xdialog-content { 2 + height: calc(95vh - 5em); 3 +} 4 + 5 +.viewFileModal .xGallery, .viewFileFull .xGallery { 6 + height: 100%; 7 + width: 100%; 8 +} 9 + 10 +.viewFileModal .xdialog-content:before { 11 + clear: both; 12 +} 13 + 14 +.viewFileModal .xdialog-content { 15 + overflow: auto; 16 + margin:0 0.8em 0.8em 0.8em; 17 + width: calc(100% - 1.6em); 18 +} 19 + 20 +.viewFileContentThumb .modal-dialog { 21 + max-height: 90vh; 22 + width: 80%; 23 +} 24 + 25 +.viewFileContentThumb .modal-body { 26 + max-height: 80vh; 27 + overflow: auto; 28 +} 29 + 30 +.viewFileContentThumb.viewFilePresentation .modal-dialog { 31 + height: 90%; 32 + width: 90%; 33 + display: flex; 34 + flex-direction: column; 35 + align-items: center; 36 +} 37 + 38 +.viewFileThumbnailButton { 39 + display: inline-block; 40 + padding-right: 0.5ex; 41 +} 42 + 43 +.viewFileThumbnailCard, .viewFileFull { 44 + position: relative; 45 +} 46 + 47 +span.viewFileThumbnailCard { 48 + display: inline-block; 49 +} 50 + 51 +.viewFileThumbnailCard a { 52 + display: flex; 53 + gap: 3px; 54 + flex-direction: column; 55 + text-align: center; 56 + width: 100%; 57 + height: 100%; 58 +} 59 + 60 +.viewFileThumbnailCard a .attachmentMimeType { 61 + flex: 1; 62 + display: flex; 63 + align-items: center; 64 + align-self: center; 65 + text-align: center; 66 + justify-content: center; 67 + width: 100%; 68 + border: 1px solid; 69 + border-radius: 1rem; 70 +} 71 + 72 +.viewFileModal-downloadLink { 73 + margin-left: 2px; 74 +} - Benutze diese Erweiterung
-
... ... @@ -1,0 +1,1 @@ 1 +onDemand - Name
-
... ... @@ -1,0 +1,1 @@ 1 +viewFileCSS - Inhalt parsen
-
... ... @@ -1,0 +1,1 @@ 1 +Nein - Content Type
-
... ... @@ -1,0 +1,1 @@ 1 +CSS
- XWiki.WikiMacroParameterClass[1]
-
- Parameter-Name
-
... ... @@ -1,0 +1,1 @@ 1 +width - Parameter-Beschreibung
-
... ... @@ -1,0 +1,1 @@ 1 +The width of the view in % or px (e.g. 100%, 100px) - Parameter verpflichtend
-
... ... @@ -1,0 +1,1 @@ 1 +Nein
- XWiki.WikiMacroParameterClass[2]
-
- Parameter-Name
-
... ... @@ -1,0 +1,1 @@ 1 +height - Parameter-Beschreibung
-
... ... @@ -1,0 +1,1 @@ 1 +The height of the view in % or px (e.g. 100%, 100px) - Parameter verpflichtend
-
... ... @@ -1,0 +1,1 @@ 1 +Nein
- XWiki.WikiMacroParameterClass[3]
-
- Parameter-Name
-
... ... @@ -1,0 +1,1 @@ 1 +display - Parameter-Beschreibung
-
... ... @@ -1,0 +1,1 @@ 1 +Kind of display. "button" for a button, "thumbnail" for a thumbnail, "full" to render the document in place - Parameter-Typ
-
... ... @@ -1,0 +1,1 @@ 1 +com.xwiki.macros.internal.ViewFileDisplay - Parameter verpflichtend
-
... ... @@ -1,0 +1,1 @@ 1 +Nein
- XWiki.WikiMacroParameterClass[4]
-
- Parameter-Name
-
... ... @@ -1,0 +1,1 @@ 1 +name - Parameter-Beschreibung
-
... ... @@ -1,0 +1,1 @@ 1 +The attachment reference to display - Parameter-Typ
-
... ... @@ -1,0 +1,1 @@ 1 +org.xwiki.model.reference.AttachmentReference - Parameter verpflichtend
-
... ... @@ -1,0 +1,1 @@ 1 +Nein