Top Banner
Cross Site Collection Navigation SharePoint Saturday Bend Oregon October 4, 2014
59

Cross Site Collection Navigation

Jan 04, 2016

Download

Documents

bran

Cross Site Collection Navigation. SharePoint Saturday Bend Oregon October 4, 2014. Kyle Petersen [email protected]. SharePoint Architect - Petersen Consulting LLC SharePoint Consulting 2004 – 2014 2012 – Microsoft Certified Solutions Master for SharePoint - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Cross Site Collection Navigation

Cross Site Collection Navigation

SharePoint Saturday Bend Oregon

October 4, 2014

Page 2: Cross Site Collection Navigation

Kyle [email protected] SharePoint Architect - Petersen Consulting LLC

SharePoint Consulting2004 – 2014

2012 – Microsoft Certified Solutions Master for SharePoint

Microsoft based application development since 1987

Page 3: Cross Site Collection Navigation

What’s the issue? SharePoint has navigation• SharePoint has lots of navigation • Top level navigation bar • Quick launch • Managed Navigation • Custom Sitemap providers • Site Directory • Search

• All work fine within the scope of a single site collection• Sometimes our architecture is not under our control

Page 4: Cross Site Collection Navigation

Organizational Structures

Page 5: Cross Site Collection Navigation

Reasons for multiple site collections

• Separation for security • Separation to reduce size of content database • Separate Web applications • Separate Farms • Merging Farms • “It’s always been that way”

Page 6: Cross Site Collection Navigation

Tackle two issues today

Part I How can I have a global menu for ALL my sites • Across Sub Sites • Across Site Collections • Across Web Applications

Part II (Time permitting) How can I have a directory of all my sites• Automatic registration in the directory • Security trimmed

Page 7: Cross Site Collection Navigation

Cross Site Navigation

• Lots of solutions available • Business Process Managed

• Every site collection specifies the same top level navigation items • Changes need to be made at every site collection

• Custom Sitemap Provider • XML site map was my favorite • Manage XML file on each WFE server (_layouts/…)

• Managed Navigation • Pin / Link navigation items • Nightmare to maintain

Page 8: Cross Site Collection Navigation

A new solution

Global Navigation Menu

Use the Managed Metadata to configure the navigation structure

Can create any structure needed Strongly suggest you limit to 2 levels Users get frustrated trying to navigate to tertiary menus

Page 9: Cross Site Collection Navigation

Our Demo Model

Page 10: Cross Site Collection Navigation
Page 11: Cross Site Collection Navigation

Implementation Details

• This is not going to replace the top level navigation menu • It could, but in this example this is a NEW global navigation menu • Want to allow Site Collection owners to maintain their own navigation within

the site collections • Define Top level navigation • Control Inheritance of sub sites

• New Global Navigation will be placed on the SharePoint Bar • SharePoint online requires special consideration

Page 12: Cross Site Collection Navigation

Managed Metadata Benefits

• Single location to maintain our menus • Don’t need to manually edit sitemap files on servers • Don’t need to write custom providers • Can edit navigation using a browser

• Controlled access so site owners cannot mess up or navigation • Configure who has rights to edit the term set

• Leverages the capabilities of Managed Navigation • Configure and test links • Control Display Order • Nested levels of navigation

Page 13: Cross Site Collection Navigation

Implementation

There are 4 Components to the solution

1. Define the menu structure in the Managed Metadata 2. Create client side JavaScript to render the menu 3. Use jQuery & CSS to style the menu 4. Package and deploy

Page 14: Cross Site Collection Navigation

1. Managed Navigation

Page 15: Cross Site Collection Navigation

Sort Order

Page 16: Cross Site Collection Navigation

2. Script to generate the menu

• Use client side JSOM code to access the managed metadata

• Couple of hacks: • Manually configure the name of the Managed Metadata provider • Manually configure the GUID of the Term Set

Page 17: Cross Site Collection Navigation
Page 18: Cross Site Collection Navigation

Simplified Example

• Access Term Store • Iterate through the terms • Build menu structure in browser DOM • Reposition element in the DOM • Wire up the event handlers

Page 19: Cross Site Collection Navigation

<ul class="ldd_menu" id="ldd_menu"> <li> <span style="width: 127px; height: 25px;">Contoso</span> <div class="ldd_submenu" style="display: none;"> <ul> <li class="ldd_heading">Corporate</li> <li><a href="http://firefly.pdx.local/contoso/board">Board</a></li> <li><a href="http://firefly.pdx.local/contoso/corp/finance">Finance</a></li> <li><a href="http://firefly.pdx.local/contoso/corp/hr">HR</a></li> <li><a href="http://firefly.pdx.local/contoso/corp/investor">Investor</a></li> <li><a href="http://firefly.pdx.local/contoso/corp/it">IT</a></li> </ul> <ul> <li class="ldd_heading">Los Angeles</li> <li><a href="http://firefly.pdx.local/contoso/la/hr">HR</a></li> <li><a href="http://firefly.pdx.local/contoso/la/it">IT</a></li> <li><a href="http://firefly.pdx.local/contoso/la/ops">Ops</a></li> <li><a href="http://firefly.pdx.local/contoso/la/sales">Sales</a></li> </ul> <ul> <li class="ldd_heading">Portland</li> <li><a href="http://firefly.pdx.local/contoso/portland/hr">HR</a></li> <li><a href="http://firefly.pdx.local/contoso/portland/it">IT</a></li> <li><a href="http://firefly.pdx.local/contoso/portland/mfg">Mfg</a></li> <li><a href="http://firefly.pdx.local/contoso/portland/ops">Ops</a></li> </ul> <ul> <li class="ldd_heading">San Francisco</li> <li><a href="http://firefly.pdx.local/contoso/sf/hr">HR</a></li> <li><a href="http://firefly.pdx.local/contoso/sf/it">IT</a></li> <li><a href="http://firefly.pdx.local/contoso/sf/ops">Ops</a></li> <li><a href="http://firefly.pdx.local/contoso/sf/sales">Sales</a></li> </ul> <ul> <li class="ldd_heading">Seattle</li> <li><a href="http://firefly.pdx.local/contoso/seattle/hr">HR</a></li> <li><a href="http://firefly.pdx.local/contoso/seattle/it">IT</a></li> <li><a href="http://firefly.pdx.local/contoso/seattle/mfg">Mfg</a></li> <li><a href="http://firefly.pdx.local/contoso/seattle/ops">Ops</a></li> </ul> </div> </li> </ul>

Page 20: Cross Site Collection Navigation

$(document).ready(InitSPSGlobalNav); // document.ready

function InitSPSGlobalNav() { var scriptbase = _spPageContextInfo.webServerRelativeUrl + "/_layouts/15/";

// Load the Taxonomy Functions we will need to call $.getScript(scriptbase + "SP.Taxonomy.js")..done(function () { var context = SP.ClientContext.get_current(); var taxonomySession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);

// HACK #1 var termStore = taxonomySession.get_termStores().getByName('Managed Metadata Service');

// HACK #2 var termSet = termStore.getTermSet('e093ba58-ba8a-480b-8f4c-0b722b5e0d62');

var terms = termSet.getAllTerms(); context.load(terms, 'Include(IsRoot,Labels,TermsCount, CustomSortOrder,Id, Name, PathOfTerm,Parent,

LocalCustomProperties, TermSet.Name)');

navOut = '<ul class="ldd_menu" id="ldd_menu"><li><span style="width:127px;height:25px;">Contoso</span>'; navOut += '<div class="ldd_submenu" style="display:none">';

Page 21: Cross Site Collection Navigation

context.executeQueryAsync(Function.createDelegate(this, function (sender, args) { var termsEnumerator = terms.getEnumerator();

// Create an array for the parent nodes var parents = [];

// populate the parents while (termsEnumerator.moveNext()) { var currentTerm = termsEnumerator.get_current(); var children = currentTerm.get_termsCount();

// Save a reference to the parent if (children > 0) { // Save our Parent menu items parents.push(currentTerm); var parent = currentTerm.get_name(); } }

Page 22: Cross Site Collection Navigation

for (var i = 0; i < parents.length; i++) { var parent = parents[i]; var parentID = parent.get_id();

// Write out the Parent entry var item = '<ul><li class="ldd_heading">' + parent.get_name() + '</li>'; navOut += item;

termsEnumerator.reset(); while (termsEnumerator.moveNext()) { var currentTerm = termsEnumerator.get_current(); var children = currentTerm.get_termsCount();

// Find the children of this parent var myParentTerm = currentTerm.get_parent();

var myParentID = myParentTerm.get_id();

if (myParentID.equals(parentID)) { // Child Term -- write out a LI var item = '<li><a href="' + currentTerm.get_localCustomProperties()['_Sys_Nav_SimpleLinkUrl'] + '">' + currentTerm.get_name() + '</a></li>'; navOut += item; } }

// Close out the parent list navOut += '</ul>' }

Page 23: Cross Site Collection Navigation

public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPWebApplication webApp = (SPWebApplication)properties.Feature.Parent; if (webApp != null) { var placeholder = "<div class='ms-core-brandingText'

id='GlobalMenu'>Contoso1</div>"; webApp.SuiteBarBrandingElementHtml = placeholder; webApp.Update(); } }

Create the Placeholder on the SuiteBar

Page 24: Cross Site Collection Navigation

var interval = setInterval(function () {

// Check if our element is rendered yet if ($('#GlobalMenu').length)

{ // Inject into page

$("#GlobalMenu").html(navOut);

//Apply Formatting InitMenu();

// all done so stop the timer loopclearInterval(interval);

} }, 100);

Need to wait for the placeholder to be rendered

Page 25: Cross Site Collection Navigation

3. Custom Rendering

• Simple jQuery to handle the hide / show scripting • Create onMouse and onClick handlers to hide / show the menu • Create onMouse to highlight the selected value • Move the menu to where we want it

• Simple CSS to handle the styling • Styles for the background color • Styles for the heading • Styles for the menu items • Styles for the footer

Page 26: Cross Site Collection Navigation

function InitMenu() { var $menu = $('#ldd_menu');

$menu.children('li').each(function () { var $this = $(this); var $span = $this.children('span'); $span.data('width', $span.width());

$this.bind('mouseenter', function () { $menu.find('.ldd_submenu').stop(true, true).hide(); $span.stop().animate({ 'width': '850px' }, 300, function () { $this.find('.ldd_submenu').slideDown(300); });

}).bind('mouseleave', function () { $this.find('.ldd_submenu').stop(true, true).hide(); $span.stop().animate({ 'width': $span.data('width') + 'px' }, 300); }); });}

Page 27: Cross Site Collection Navigation

ul.ldd_menu{margin:0px;padding:0;display:block;background-color:#0072C6;list-style:none;font-family:"Trebuchet MS", sans-serif;border-top:1px solid #0072C6;border-bottom:1px solid #0072C6;border-left:10px solid #0072C6;-moz-box-shadow:0px 3px 4px #0072C6;-webkit-box-shadow:0px 3px 4px #0072C6;-box-shadow:0px 3px 4px #591E12;z-index:100;}

ul.ldd_menu a{text-decoration:none;}

ul.ldd_menu > li{float:left;position:relative;}

ul.ldd_menu > li > span{float:left;color:#fff;background-color:#0072C6;height:30px;line-height:30px;cursor:default;padding:0px 20px;text-shadow:0px 0px 1px #fff;border-right:1px solid #0072C6;border-left:1px solid #0072C6;z-index:100;}

ul.ldd_menu ul{list-style:none;float:left;border-left:1px solid #0072C6;margin:20px 0px 10px 30px;padding:10px;}

li.ldd_heading{font-family: Georgia, serif;font-size: 14px;font-style: italic; font-weight:bold;color:#ffffff;text-shadow:0px 0px 1px #000000;padding:0px 0px 10px 0px;}

ul.ldd_menu ul li a{font-family: Arial, serif;font-size:10px;line-height:20px;color:#fff;padding:1px 3px;}

ul.ldd_menu ul li a:hover{-moz-box-shadow:0px 0px 2px #333;-webkit-box-shadow:0px 0px 2px #333;box-shadow:0px 0px 2px #333;background:#0072C6;}

ul.ldd_menu .ldd_submenu{position:absolute;top:25px;width:550px;display:none;opacity:0.95;left:0px;font-size:10px;background: #0072C6;border-top:1px solid #0072C6;-moz-box-shadow:0px 3px 4px #0072C6 inset;-webkit-box-shadow:0px 3px 4px #0072C6 inset;-box-shadow:0px 3px 4px #0072C6 inset;z-index:100;}

a.ldd_subfoot{background-color:#f0f0f0;color:#444;display:block;clear:both;padding:15px 20px;text-transform:uppercase;font-family: Arial, serif;font-size:12px;text-shadow:0px 0px 1px #fff;-moz-box-shadow:0px 0px 2px #777 inset;-webkit-box-shadow:0px 0px 2px #777 inset;-box-shadow:0px 0px 2px #777 inset;z-index:100;}

Page 28: Cross Site Collection Navigation

4. Packaging (on-premise)

1. Deploy the files to the servers (_layouts folder) 2. Inject our rendering script onto every page • Farm, Web Application or Site Collection scoped feature • Feature adds scriptlinks to every page

3. Add our placeholder into the suite bar 4. Call the rendering process at the right time

Page 29: Cross Site Collection Navigation

Packaging

<?xml version="1.0" encoding="utf-8"?><Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <CustomAction ScriptSrc="~SiteCollection/_layouts/15/GlobalNavigation/jquery-1.11.1.min.js" Location="ScriptLink" Sequence="90" /> <CustomAction ScriptSrc="~SiteCollection/_layouts/15/GlobalNavigation/globalnavigation.js" Location="ScriptLink" Sequence="10000" /> <CustomAction Id="MegaCSS" Location="ScriptLink" ScriptBlock="document.write('&lt;link rel=&quot;stylesheet&quot; After=&quot;Corev15.css&quot; type=&quot;text/css&quot; href=&quot;_layouts/15/GlobalNavigation/GlobalNavigation.css&quot;&gt;&lt;/' + 'link&gt;');" Sequence="203" /></Elements>

Page 30: Cross Site Collection Navigation

Enhancements

• Support for Minimal Download Strategy (MDS)

• Performance Optimizations • Batch process to generate HTML structure • Cache HTML in memory

Page 31: Cross Site Collection Navigation

SharePoint Online Considerations

• Scripting • Lookup the name of the managed metadata provider

• Deployment • Can only deploy to a Site Collection (Sandbox Solution) • Separate deployment feature on just the root site collection

• Single place to maintain scripts / CSS

• Placement • Cannot use SuiteBarBrandingElement technique (no web app in O365) • SharePoint bar has different CSS ID’s and Classes • MS Changes these frequently

• Rendering • Need to let Office 365 complete the SharePoint bar rendering

Page 32: Cross Site Collection Navigation

References

Global Navigation• http://blog.mastykarz.nl/building-global-navigation-sharepoint-2013/

• http://blog.mastykarz.nl/global-navigation-sharepoint-2013-revisited/

MDS• http://www.wictorwilen.se/the-correct-way-to-execute-javascript-functions-in-sharepoint-2013-mds-enable

d-sites

Mega menus • http://jaspreetchahal.org/5-best-jquery-css3-navigational-mega-menus

Page 33: Cross Site Collection Navigation

Site Directory

Page 34: Cross Site Collection Navigation

Warning!!!

• Entering 400 Level topic • Requires custom application development

Page 35: Cross Site Collection Navigation

Site Directory Issues

• Have hundreds or thousands of sites • How do I find them all without just clicking through sites • Don’t want to maintain a manual site directory • Custom SharePoint list with every site listed

• Site directory should be security trimmed. You should not see sites you do not have access to. • This is controversial. Sometimes you want to let users discover sites they

don’t have access to so they can request access. • Multiple ways to solve this issue.

Page 36: Cross Site Collection Navigation

Need

• Need a Directory for all the sites • Need a way to “categorize” sites so we can organize our phone book• Must be security trimmed so we do not know about sites we don’t

have access to.

Page 37: Cross Site Collection Navigation

Site Directory Solution

• Define metadata on each site to categorize them • Location (Portland, Seattle, LA, …) • Type of site (Intranet, Project, Document Archive, …) • Status of site (Active, Archived, …)

• Uses Search Index to find sites • Global Site Directory shows all sites • “Mall Directory” • Search Refiners • Search Term

Page 38: Cross Site Collection Navigation

Site Directory

Page 39: Cross Site Collection Navigation

Site Directory Solution

3 Components to our solution

1. Add Metadata to the siteUse web Property bagDescribes ways we would want to categorize our sites

2. Add the Metadata to the Search Index Create Search Managed Properties mapped to our Property Bag Values. 3. Custom Search Display Create custom Search Display templates to render our results

Page 40: Cross Site Collection Navigation

Site Metadata

• Lots of options • Regions

• Portland – Bend – Salem • Oregon – Washington – California - … • North America – Asia – Europe - …

• Departments • Sales – HR – Marketing – IT - …

• Site Usage • Intranet – Collaboration – Communities – Applications - …

• Site Status • Active – Archived – Top Secret (do not list in any directory)

• Product / Services • Contoso Electronics – Tailspin Toys – Northwind Bikes - …

• Business Units • Contoso - Tailspin - Northwind

Page 41: Cross Site Collection Navigation

Site Level Metadata

• Simple for this demo

• Location • Portland• Seattle• San Francisco• Los Angeles • Corporate

• Site Usage• Intranet - Permanent Sites that are part• Project - Linked to a specific project or initiative • Social – Temporary sites

Page 42: Cross Site Collection Navigation

Metadata

• Setting Property Bag Values $web = get-spweb “http://firefly.pdx.local”

$web.Properties[“property_name"]= “property_value”

$web.Properties.Update()

• Secret Sauce (new in 2013) • Adding Property to Indexed Properties

$web.IndexedPropertyKeys.Add(“property_value")

$web.Update()

See PowerShell Script SetSiteProperties.ps1

Page 43: Cross Site Collection Navigation

Property Bag in SharePoint Designer

Page 44: Cross Site Collection Navigation

Search Index

• Create Managed Properties in Search Schema

• Metadata becomes Searchable • siteLocation:Seattle• siteUsage:Social

Page 45: Cross Site Collection Navigation

Managed Properties

• Key Concepts • Create new Managed Properties (siteLocation & siteUsge) • Must be queryable • So we can use siteLocation:Portland

• Refinable • So we can include in refinement panels

Page 46: Cross Site Collection Navigation
Page 47: Cross Site Collection Navigation
Page 48: Cross Site Collection Navigation
Page 49: Cross Site Collection Navigation
Page 50: Cross Site Collection Navigation

Search Display

• Create a custom Search Display Template

• Use the Search Web Parts • Search Results• Search Refiners

Page 51: Cross Site Collection Navigation

Search Directory

Page 52: Cross Site Collection Navigation

Search Display Template <html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"> <head><title>PDX Site Item</title>

<!--[if gte mso 9]><xml><mso:CustomDocumentProperties><mso:TemplateHidden msdt:dt="string">0</mso:TemplateHidden><mso:MasterPageDescription msdt:dt="string">Displays a result tailored for a SharePoint site.</mso:MasterPageDescription><mso:ContentTypeId msdt:dt="string">0x0101002039C03B61C64EC4A04F5361F385106603</mso:ContentTypeId><mso:TargetControlType msdt:dt="string">;#SearchResults;#</mso:TargetControlType><mso:HtmlDesignAssociated msdt:dt="string">1</mso:HtmlDesignAssociated><mso:ManagedPropertyMapping msdt:dt="string">'Title':'Title','Path':'Path','SiteLogo':'SiteLogo','SiteDescription':'SiteDescription','CollapsingStatus':'CollapsingStatus','DocId':'DocId','HitHighlightedProperties':'HitHighlightedProperties','FileExtension':'FileExtension','ViewsLifeTime':'ViewsLifeTime','deeplinks':'deeplinks','importance':'importance','FileType':'FileType','SiteLocation':'SiteLocation','SiteUsage':'SiteUsage'</mso:ManagedPropertyMapping></mso:CustomDocumentProperties></xml><![endif]--></head>

Page 53: Cross Site Collection Navigation

Search Display Template

<body> <div id="Item_Site"> <!--#_ if(!$isNull(ctx.CurrentItem) && !$isNull(ctx.ClientControl)){ var id = ctx.ClientControl.get_nextUniqueId(); var itemId = id + Srch.U.Ids.item; $setResultItem(itemId, ctx.CurrentItem); _#--> <div id="_#= $htmlEncode(itemId) =#_" name="Item" data-displaytemplate="SiteItem" class="ms-srch-item" > _#=ctx.RenderBody(ctx)=#_ </div> <!--#_ } _#--> </div></body></html>

Page 54: Cross Site Collection Navigation

<html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"> <head><title>PDX Site Item</title>

<!--[if gte mso 9]><xml><mso:CustomDocumentProperties><mso:TemplateHidden msdt:dt="string">0</mso:TemplateHidden><mso:MasterPageDescription msdt:dt="string">Displays a result tailored for a SharePoint site.</mso:MasterPageDescription><mso:ContentTypeId msdt:dt="string">0x0101002039C03B61C64EC4A04F5361F385106603</mso:ContentTypeId><mso:TargetControlType msdt:dt="string">;#SearchResults;#</mso:TargetControlType><mso:HtmlDesignAssociated msdt:dt="string">1</mso:HtmlDesignAssociated><mso:ManagedPropertyMapping msdt:dt="string">'Title':'Title','Path':'Path','SiteLogo':'SiteLogo','SiteDescription':'SiteDescription','CollapsingStatus':'CollapsingStatus','DocId':'DocId','HitHighlightedProperties':'HitHighlightedProperties','FileExtension':'FileExtension','ViewsLifeTime':'ViewsLifeTime','deeplinks':'deeplinks','importance':'importance','FileType':'FileType','SiteLocation':'SiteLocation','SiteUsage':'SiteUsage'</mso:ManagedPropertyMapping></mso:CustomDocumentProperties></xml><![endif]--></head><body> <div id="Item_Site"><!--#_ if(!$isNull(ctx.CurrentItem) && !$isNull(ctx.ClientControl)){ var id = ctx.ClientControl.get_nextUniqueId(); var itemId = id + Srch.U.Ids.item;$setResultItem(itemId, ctx.CurrentItem);

// Get a value from the search results var location = $getItemValue(ctx, "SiteLocation"); _#-->

<div id="_#= $htmlEncode(itemId) =#_" name="Item" data-displaytemplate="SiteItem" class="ms-srch-item" >

<div>Title: _#=ctx.CurrentItem.Title=#_</div> <div>Path: _#=ctx.CurrentItem.Path=#_</div> <div>SiteDescription: _#=ctx.CurrentItem.SiteDescription=#_</div> <div>SiteLocation: _#=ctx.CurrentItem.SiteLocation=#_</div> <div>SiteUsage: _#=ctx.CurrentItem.SiteUsage=#_</div> <div>variable: _#=location=#_</div>

</div><!--#_ } _#--> </div></body></html>

Page 55: Cross Site Collection Navigation

Multiple Uses

• Global Site Directory • Find any site

• Region / Department Directory • Hosted on Web Page • Show all child sites within the parent (region or department for example)

Page 56: Cross Site Collection Navigation

Enhancements

• Create Application page to manage the site properties • Use Dropdown lists to set properties

• Event Receiver (Web Provisioned) • Propagate site properties from parent site

Page 57: Cross Site Collection Navigation

SharePoint online Considerations

• PowerShell is more complicated • Invoke CSOM through PowerShell or write command line utility

• Can’t control full crawls • How to request a site crawl

• Can’t define a managed property to be refinable • Have to use the predefined RefinableString00-99 values • Map to our crawled term and create alias

Page 58: Cross Site Collection Navigation

Re-index a site in O365

Page 59: Cross Site Collection Navigation

Site Directory Summary

• Configure Property Bag Values on Sites • Add Properties to the Site index • Full Crawl • Map Crawled Property to Managed Property

• Define property name (used in search) • Set correct attributes (queryable, Refinable)

• Full Crawl• Customize the Search Results

• Search Results • Result Type • Search Display Template