Skip to main content

XWiki Panel Navigation: scripts

Neuer Ansatz

Die Default Navigation befindets sich unter /Panels/Navigation. Folgende Objekte einsetzen/ergänzen:

Objekt vom Typ Panels.PanelClass

{{velocity}}
#panelheader($services.localization.render('xe.panels.navigation'))
## Escape special characters in macro parameter values.
#set ($openToDoc = $doc.documentReference.toString().replaceAll('([~"])', '~$1'))
## Apply the configured page exclusions.
#set ($config = $xwiki.getDocument('PanelsCode.NavigationConfiguration'))
#set ($exclusions = $collectiontool.set)
#set ($defaultDocumentName = $services.model.getEntityReference('DOCUMENT', 'default').name)
## Exclude top level extension pages.
#if ($config.getValue('excludeTopLevelExtensionPages') == 1)
  #set ($query = $services.query.hql('select space.name from XWikiSpace space where space.parent is null'))
  #set ($discard = $query.addFilter('hidden/space'))
  #foreach ($result in $query.execute())
    #set ($documentReference = $services.model.createDocumentReference($NULL, $result, $defaultDocumentName))
    #set ($installedExtensions = $services.extension.xar.getInstalledExtensions($documentReference))
    #if ($installedExtensions && $installedExtensions.size() > 0
        && !$services.extension.xar.isEditAllowed($documentReference))
      #set ($discard = $exclusions.add("document:$documentReference"))
    #end
  #end
#end
## Exclude top level application pages.
#if ($config.getValue('excludeTopLevelApplicationPages') == 1)
  #set ($statement = 'select space.name '
    + 'from XWikiSpace as space, Document as doc, doc.object(AppWithinMinutes.LiveTableClass) as app '
    + 'where space.parent is null and doc.space = space.reference')
  #set ($query = $services.query.xwql($statement).addFilter('hidden/space'))
  #foreach ($result in $query.execute())
    #set ($documentReference = $services.model.createDocumentReference($NULL, $result, $defaultDocumentName))
    #set ($discard = $exclusions.add("document:$documentReference"))
  #end
#end
## Inclusions are treated as exceptions to the dynamic exclusion filters.
#if ($config.getValue('excludeTopLevelExtensionPages') == 1 || $config.getValue('excludeTopLevelApplicationPages') == 1)
  ## FIXME: This panel is cached and the cache is not invalidated by default when an extension is installed or
  ## uninstalled and neither when an application is created, deleted or renamed. Ideally we should invalidate the cache
  ## whenever a top level page is created or modified but we can't do this ATM so the next best thing is to invalidate
  ## the cache whenever a page (anywhere in the page hierarchy) is modified.
  #set ($discard = $services.async.useEntity("wiki:$xcontext.database"))
  #foreach ($inclusion in $config.getValue('inclusions'))
    #set ($documentReference = $services.model.resolveDocument($inclusion))
    #set ($discard = $exclusions.remove("document:$documentReference"))
  #end
#end
## Other page exclusions.
#foreach ($exclusion in $config.getValue('exclusions'))
  #set ($documentReference = $services.model.resolveDocument($exclusion))
  #set ($discard = $exclusions.add("document:$documentReference"))
#end
#set ($exclusions = $stringtool.join($exclusions, ','))

{{html wiki="true"}}
<div id="custom-navigation-panel">

{{documentTree limit="9999" showTranslations="false" showAttachments="false" compact="true" openTo="document:$openToDoc"
  exclusions="$exclusions" /}}

</div>
{{/html}}

#panelfooter()
{{/velocity}}

Objekt vom Typ XWiki.StyleSheetExtension

#header-article-navigation{
  overflow-y: auto;
  overflow-x: clip;
  border-bottom: 1px solid #e8e8e8;
  overscroll-behavior: none;
}

Objekt vom Typ XWiki.JavaScriptExtension

Object.defineProperty(Element.prototype, 'outerHeight', {
    'get': function(){
        var height = this.clientHeight;
        var computedStyle = window.getComputedStyle(this);
        height += parseInt(computedStyle.marginTop, 10);
        height += parseInt(computedStyle.marginBottom, 10);
        height += parseInt(computedStyle.borderTopWidth, 10);
        height += parseInt(computedStyle.borderBottomWidth, 10);
        return height;
    }
});

if (window.innerWidth > 991) {
  let stateCheck = setInterval(() => {
    if (document.readyState === 'complete') {
      clearInterval(stateCheck);
      // document ready
      var menuTop = document.querySelector('#menuview');
      var menuTopHeight = menuTop.outerHeight;
      var menuBottom = document.querySelector('#menu-horizontal-Menu-Test-WebHome');
      var menuBottomHeight = menuBottom.outerHeight;
      var navHeader = document.querySelector("#leftPanels > div > h1");
      var navHeaderHeight = navHeader.outerHeight;
      var footerGlobal = document.querySelector("#footerglobal");
      var footerGlobalHeight = footerGlobal.outerHeight;
      var article = document.querySelector("#contentcolumn > div");
      var articleHeight = article.outerHeight;
      console.log(articleHeight);

      var navBody = document.querySelector("#header-article-navigation");
      var navBodyHeight = articleHeight - (navHeaderHeight + 15);
      if (window.innerHeight < (articleHeight + menuBottomHeight + menuTopHeight)) {
        navBody.style.height = navBodyHeight + "px";
      } else {
        // 15px + 15px for #leftPanels padding top and bottom; 20px for #leftPanels > div margin bottom; 1px for safety to avoid a scroll bar
        navBody.style.height = window.innerHeight - (navHeaderHeight + menuBottomHeight + menuTopHeight + footerGlobalHeight + 15 + 15 + 20 + 1) + "px";
      }
    }
  }, 100);
}

Panel-Eintrag

Das Panel muss dann noch im Adminbereich > Menüleisten-Assistent bekannt gemacht werden.

wiki/ndr/admin/XWiki/XWikiPreferences?editor=globaladmin&section=Panels.PanelWizard&forceLeftPanels=1&forceRightPanels=1&section=Panels.PanelWizard

Alter Ansatz

Hauptbereiche

{{velocity}}
#panelheader('Hauptbereiche')
##* [[Abteilungen>>doc:Abteilungen.WebHome]]
##* [[Anwendungen>>doc:Anwendungen.WebHome]]
##* [[ARD-aktuell>>doc:ARD-aktuell.WebHome]]
##* [[Formate>>doc:Formate.WebHome]]
##* [[Glossar>>doc:Glossar.WebHome]]
##* [[Infrastruktur>>doc:Infrastruktur.WebHome]]
##* [[Organisatorisches>>doc:Organisatorisches.WebHome]]
##* [[Produktion>>doc:Produktion.WebHome]]
##* [[Projekte>>doc:Projekte.WebHome]]
##* [[Richtlinien und Prozesse>>doc:Richtlinien und Prozesse.WebHome]]

{{html wiki="true"}}
<div id="rootPanel" style="max-height: 19em;overflow-y: auto;overflow-x: clip;border-bottom: 1px solid #e8e8e8;overscroll-behavior: none">

{{documentTree showTranslations="false" showAttachments="false" compact="true" exclusions="document:ndr:Help.WebHome,document:ndr:Menu.WebHome,document:ndr:Sandbox.WebHome,document:ndr:Main.WebHome,document:ndr:URLNormalizer.WebHome,document:ndr:XWiki.WebHome" limit="1000" /}}

</div>
{{/html}}

#panelfooter()
{{/velocity}}

Unterseiten

{{velocity}}
#panelheader("Unterseiten")
## Escape special characters in macro parameter values.
#set ($openTo = $services.model.serialize($doc.documentReference, 'default').replaceAll('([~"])', '~$1'))

{{html wiki="true"}}
<div id="childrenPanel" style="max-height: 19em;overflow-y: auto;overflow-x: clip;border-bottom: 1px solid #e8e8e8;overscroll-behavior: none">

{{documentTree showTranslations="false" showAttachments="false" compact="true" root="document:$openTo" limit="1000" /}}

</div>
{{/html}}

#panelfooter()
{{/velocity}}

Geschwisterseiten

{{velocity}}
#panelheader("Geschwisterseiten")
## Escape special characters in macro parameter values.
##set ($homeName = $services.model.getEntityReference('DOCUMENT', 'default').name)
##set ($homeName = $doc.getParent())
##set ($homeName = $homeName.getReference())
##== $homeName ==
#set ($openTo = $services.model.serialize($doc.documentReference.getParent().getParent(), 'default').replaceAll('([~"])', '~$1'))
#set ($openTo = $openTo + ".WebHome")
##set($homeName = $homeName.replaceAll('.WebHome', ''))
##set ($spaceHome = $services.model.createEntityReference($homeName, 'DOCUMENT', $homeName))
##== $spaceHome ==
##set ($openTo = $services.model.serialize($spaceHome, 'default').replaceAll('([~"])', '~$1'))
##==== $openTo ====
{{html wiki="true"}}

<div id="siblingPanel" style="max-height: 19em;overflow-y: auto;overflow-x: clip;border-bottom: 1px solid #e8e8e8;overscroll-behavior: none">

{{documentTree showTranslations="false" showAttachments="false" compact="true" root="document:$openTo" limit="1000" /}}

</div>
{{/html}}

#panelfooter()
{{/velocity}}

Default

Die Default Navigation befindets sich unter /Panels/Navigation.

{{velocity}}
#panelheader($services.localization.render('xe.panels.navigation'))
## Escape special characters in macro parameter values.
#set ($openToDoc = $doc.documentReference.toString().replaceAll('([~"])', '~$1'))
## Apply the configured page exclusions.
#set ($config = $xwiki.getDocument('PanelsCode.NavigationConfiguration'))
#set ($exclusions = $collectiontool.set)
#set ($defaultDocumentName = $services.model.getEntityReference('DOCUMENT', 'default').name)
## Exclude top level extension pages.
#if ($config.getValue('excludeTopLevelExtensionPages') == 1)
  #set ($query = $services.query.hql('select space.name from XWikiSpace space where space.parent is null'))
  #set ($discard = $query.addFilter('hidden/space'))
  #foreach ($result in $query.execute())
    #set ($documentReference = $services.model.createDocumentReference($NULL, $result, $defaultDocumentName))
    #set ($installedExtensions = $services.extension.xar.getInstalledExtensions($documentReference))
    #if ($installedExtensions && $installedExtensions.size() > 0
        && !$services.extension.xar.isEditAllowed($documentReference))
      #set ($discard = $exclusions.add("document:$documentReference"))
    #end
  #end
#end
## Exclude top level application pages.
#if ($config.getValue('excludeTopLevelApplicationPages') == 1)
  #set ($statement = 'select space.name '
    + 'from XWikiSpace as space, Document as doc, doc.object(AppWithinMinutes.LiveTableClass) as app '
    + 'where space.parent is null and doc.space = space.reference')
  #set ($query = $services.query.xwql($statement).addFilter('hidden/space'))
  #foreach ($result in $query.execute())
    #set ($documentReference = $services.model.createDocumentReference($NULL, $result, $defaultDocumentName))
    #set ($discard = $exclusions.add("document:$documentReference"))
  #end
#end
## Inclusions are treated as exceptions to the dynamic exclusion filters.
#if ($config.getValue('excludeTopLevelExtensionPages') == 1 || $config.getValue('excludeTopLevelApplicationPages') == 1)
  ## FIXME: This panel is cached and the cache is not invalidated by default when an extension is installed or
  ## uninstalled and neither when an application is created, deleted or renamed. Ideally we should invalidate the cache
  ## whenever a top level page is created or modified but we can't do this ATM so the next best thing is to invalidate
  ## the cache whenever a page (anywhere in the page hierarchy) is modified.
  #set ($discard = $services.async.useEntity("wiki:$xcontext.database"))
  #foreach ($inclusion in $config.getValue('inclusions'))
    #set ($documentReference = $services.model.resolveDocument($inclusion))
    #set ($discard = $exclusions.remove("document:$documentReference"))
  #end
#end
## Other page exclusions.
#foreach ($exclusion in $config.getValue('exclusions'))
  #set ($documentReference = $services.model.resolveDocument($exclusion))
  #set ($discard = $exclusions.add("document:$documentReference"))
#end
#set ($exclusions = $stringtool.join($exclusions, ','))
{{documentTree limit="100" showTranslations="false" showAttachments="false" compact="true" openTo="document:$openToDoc"
  exclusions="$exclusions" /}}
#panelfooter()
{{/velocity}}