Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
303 changes: 299 additions & 4 deletions src/sdk/PnP.Core/Model/SharePoint/Branding/Internal/BrandingManager.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ internal ChromeOptions(PnPContext pnpContext)

public IFooterOptions Footer { get; internal set; }

public IFontOptions Font { get; internal set; }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ internal enum SiteLogoType
/// <summary>
/// Global navigation logo
/// </summary>
GlobalNavLogo = 3
GlobalNavLogo = 3,

/// <summary>
/// Footer background image
/// </summary>
FooterBackground = 4
}
}
23 changes: 23 additions & 0 deletions src/sdk/PnP.Core/Model/SharePoint/Branding/Internal/FontOption.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Text.Json.Serialization;

namespace PnP.Core.Model.SharePoint
{
internal sealed class FontOption : IFontOption
{
/// <summary>
/// fontFamilyKey
/// </summary>
[JsonPropertyName("fontFamilyKey")]
public string FamilyKey { get; set; }
/// <summary>
/// fontFace
/// </summary>
[JsonPropertyName("fontFace")]
public string Face { get; set; }
/// <summary>
/// fontVariantWeight
/// </summary>
[JsonPropertyName("fontVariantWeight")]
public string VariantWeight { get; set; }
}
}
10 changes: 10 additions & 0 deletions src/sdk/PnP.Core/Model/SharePoint/Branding/Internal/FontOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace PnP.Core.Model.SharePoint
{
internal sealed class FontOptions : IFontOptions
{
public IFontOption SiteTitle { get; set; } = null;
public IFontOption SiteNav { get; set; } = null;
public IFontOption SiteFooterTitle { get; set; } = null;
public IFontOption SiteFooterNav { get; set; } = null;
}
}
12 changes: 12 additions & 0 deletions src/sdk/PnP.Core/Model/SharePoint/Branding/Internal/FontPackage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace PnP.Core.Model.SharePoint
{
internal sealed class FontPackage : IFontPackage
{
public string ID { get; set; }
public bool IsHidden { get; set; }
public bool IsValid { get; set; }
public string PackageJson { get; set; }
public int Store { get; set; }
public string Title { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;

namespace PnP.Core.Model.SharePoint
Expand All @@ -25,6 +26,13 @@ internal FooterOptions(PnPContext pnpContext)

public string DisplayName { get; set; }

public FooterLinkAlignment LinkAlignment { get; set; }
public OverlayColorType OverlayColor { get; set; }
public int OverlayOpacity { get; set; }
public OverlayGradientDirectionType OverlayGradientDirection { get; set; }
public int ColorIndexInLightMode { get; set; }
public int ColorIndexInDarkMode { get; set; }

public async Task SetLogoAsync(string fileName, Stream content, bool overwrite = false)
{
// Upload the image
Expand Down Expand Up @@ -99,5 +107,53 @@ internal MenuStateWrapper GetMenuStateToPersist(string serverRelativeUrl)
return menuStateWrapper;
}

public async Task SetFooterBackgroundImageAsync(string fileName, Stream content, double focalX = 0, double focalY = 0, bool overwrite = false)
{
// Upload the image
IFile siteLogo = await UploadImageToSiteAssetsAsync(fileName, content, overwrite).ConfigureAwait(false);
// Set the uploaded file as header background
await (PnPContext.Web as Web).RawRequestAsync(BuildSetSiteLogoApiCall(siteLogo.ServerRelativeUrl, SiteLogoType.FooterBackground, SiteLogoAspect.Square, focalX, focalY), HttpMethod.Post, "SetSiteLogo").ConfigureAwait(false);
}

public void SetFooterBackgroundImage(string fileName, Stream content, double focalX = 0, double focalY = 0, bool overwrite = false)
{
SetFooterBackgroundImageAsync(fileName, content, focalX, focalY, overwrite).GetAwaiter().GetResult();
}

public async Task ClearFooterBackgroundImageAsync()
{
await (PnPContext.Web as Web).RawRequestAsync(BuildSetSiteLogoApiCall("", SiteLogoType.FooterBackground, SiteLogoAspect.Square, 0, 0), HttpMethod.Post, "SetSiteLogo").ConfigureAwait(false);
}

public void ClearFooterBackgroundImage()
{
ClearFooterBackgroundImageAsync().GetAwaiter().GetResult();
}

private static ApiCall BuildSetSiteLogoApiCall(string serverRelativeUrl, SiteLogoType type, SiteLogoAspect aspect, double focalX = 0, double focalY = 0)
{
string jsonBody;
if (type == SiteLogoType.FooterBackground)
{
jsonBody = JsonSerializer.Serialize(new
{
relativeLogoUrl = serverRelativeUrl,
type = (int)type,
aspect = (int)aspect,
focalx = focalX,
focaly = focalY
});
}
else
{
jsonBody = JsonSerializer.Serialize(new
{
relativeLogoUrl = serverRelativeUrl,
type = (int)type,
aspect = (int)aspect
});
}
return new ApiCall("_api/siteiconmanager/setsitelogo", ApiType.SPORest, jsonBody);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ internal HeaderOptions(PnPContext pnpContext)
public bool HideTitle { get; set; }

public LogoAlignment LogoAlignment { get; set; }
public OverlayColorType OverlayColor { get; set; } = OverlayColorType.None;
public int OverlayOpacity { get; set; } = 0;
public OverlayGradientDirectionType OverlayGradientDirection { get; set; } = OverlayGradientDirectionType.TopToBottom;
public int ColorIndexInLightMode { get; set; } = -1;
public int ColorIndexInDarkMode { get; set; } = -1;

public async Task SetSiteLogoAsync(string fileName, Stream content, bool overwrite = false)
{
Expand Down Expand Up @@ -145,10 +150,11 @@ public void ResetSiteLogoThumbnail()

public async Task SetHeaderBackgroundImageAsync(string fileName, Stream content, double focalX = 0, double focalY = 0, bool overwrite = false)
{
if (Layout != HeaderLayoutType.Extended)
{
throw new ClientException(ErrorType.Unsupported, PnPCoreResources.Exception_Unsupported_BackgroundImageHeaderIsNotOfTypeExtended);
}
// => modern Header does allow background images for all layouts
//if (Layout != HeaderLayoutType.Extended)
//{
// throw new ClientException(ErrorType.Unsupported, PnPCoreResources.Exception_Unsupported_BackgroundImageHeaderIsNotOfTypeExtended);
//}

// Upload the image
IFile siteLogo = await UploadImageToSiteAssetsAsync(fileName, content, overwrite).ConfigureAwait(false);
Expand Down
137 changes: 137 additions & 0 deletions src/sdk/PnP.Core/Model/SharePoint/Branding/Public/IBrandingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,5 +223,142 @@ public interface IBrandingManager
/// <returns></returns>
void SetChromeOptionsBatch(IChromeOptions chromeOptions);
#endregion

#region OutOfBoxFontPackages

/// <summary>
/// Gets the out of the box fonts available
/// </summary>
/// <returns>Site's <see cref="IFontPackage"/></returns>
Task<List<IFontPackage>> GetOutOfBoxFontPackagesAsync();

/// <summary>
/// Gets the out of the box fonts available
/// </summary>
/// <returns>Site's <see cref="IFontPackage"/></returns>
List<IFontPackage> GetOutOfBoxFontPackages();

/// <summary>
/// Gets the out of the box fonts available
/// </summary>
/// <param name="batch"></param>
/// <returns>Site's <see cref="IFontPackage"/></returns>
Task<IBatchSingleResult<List<IFontPackage>>> GetOutOfBoxFontPackagesBatchAsync(Batch batch);

/// <summary>
/// Gets the out of the box fonts available
/// </summary>
/// <returns>Site's <see cref="System.Collections.Generic.List{IFontPackage}"/></returns>
IBatchSingleResult<List<IFontPackage>> GetOutOfBoxFontPackagesBatch(Batch batch);

/// <summary>
/// Sets the out of the box font with the given id on the Site
/// </summary>
/// <param name="fontId"></param>
void SetOutOfBoxFontPackage(string fontId);

/// <summary>
/// Sets the out of the box font with the given id on the Site
/// </summary>
/// <param name="fontId"></param>
Task SetOutOfBoxFontPackageAsync(string fontId);

/// <summary>
/// Sets the out of the box font with the given id on the Site
/// </summary>
/// <param name="batch"></param>
/// <param name="fontId"></param>
void SetOutOfBoxFontPackageBatch(Batch batch, string fontId);

/// <summary>
/// Sets the out of the box font with the given id on the Site
/// </summary>
/// <param name="batch"></param>
/// <param name="fontId"></param>
Task SetOutOfBoxFontPackageBatchAsync(Batch batch, string fontId);

#endregion OutOfBoxFontPackages

#region Branding Center FontPackages

/// <summary>
/// Gets the fonts available in branding center
/// </summary>
/// <returns>Site's <see cref="System.Collections.Generic.List{IFontPackage}"/></returns>
Task<List<IFontPackage>> GetFontPackagesAsync();

/// <summary>
/// Gets the fonts available in branding center
/// </summary>
/// <returns>Site's <see cref="System.Collections.Generic.List{IFontPackage}"/></returns>
List<IFontPackage> GetFontPackages();

/// <summary>
/// Gets the fonts available in branding center
/// </summary>
/// <returns>Site's <see cref="System.Collections.Generic.List{IFontPackage}"/></returns>
Task<IBatchSingleResult<List<IFontPackage>>> GetFontPackagesBatchAsync(Batch batch);

/// <summary>
/// Gets the fonts available in branding center
/// </summary>
/// <returns>Site's <see cref="System.Collections.Generic.List{IFontPackage}"/></returns>
IBatchSingleResult<List<IFontPackage>> GetFontPackagesBatch(Batch batch);

/// <summary>
/// Sets the branding center font with the given id on the Site
/// </summary>
/// <param name="fontId"></param>
void SetFontPackage(string fontId);

/// <summary>
/// Sets the branding center font with the given id on the Site
/// </summary>
/// <param name="fontId"></param>
Task SetFontPackageAsync(string fontId);

/// <summary>
/// Sets the branding center font with the given id on the Site
/// </summary>
/// <param name="batch"></param>
/// <param name="fontId"></param>
void SetFontPackageBatch(Batch batch, string fontId);

/// <summary>
/// Sets the branding center font with the given id on the Site
/// </summary>
/// <param name="batch"></param>
/// <param name="fontId"></param>
Task SetPackageBatchAsync(Batch batch, string fontId);

#endregion Branding Center FontPackages

#region SiteFontPackages

/// <summary>
/// Gets the fonts installed on the site
/// </summary>
/// <returns>Site's <see cref="System.Collections.Generic.List{IFontPackage}"/></returns>
Task<List<IFontPackage>> GetSiteFontPackagesAsync();

/// <summary>
/// Gets the fonts installed on the site
/// </summary>
/// <returns>Site's <see cref="System.Collections.Generic.List{IFontPackage}"/></returns>
List<IFontPackage> GetSiteFontPackages();

/// <summary>
/// Gets the fonts installed on the site
/// </summary>
/// <returns>Site's <see cref="System.Collections.Generic.List{IFontPackage}"/></returns>
Task<IBatchSingleResult<List<IFontPackage>>> GetSiteFontPackagesBatchAsync(Batch batch);

/// <summary>
/// Gets the fonts installed on the site
/// </summary>
/// <returns>Site's <see cref="System.Collections.Generic.List{IFontPackage}"/></returns>
IBatchSingleResult<List<IFontPackage>> GetSiteFontPackagesBatch(Batch batch);

#endregion SiteFontPackages
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@ public interface IChromeOptions
/// </summary>
IFooterOptions Footer { get; }

/// <summary>
/// Site font chrome configuration
/// </summary>
IFontOptions Font { get; }
}
}
28 changes: 28 additions & 0 deletions src/sdk/PnP.Core/Model/SharePoint/Branding/Public/IFontOption.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Text.Json.Serialization;

namespace PnP.Core.Model.SharePoint
{
/// <summary>
/// specify font to use for header / footer
/// </summary>
public interface IFontOption
{
/// <summary>
/// fontFamilyKey
/// </summary>
[JsonPropertyName("fontFamilyKey")]
string FamilyKey { get; set; }

/// <summary>
/// fontFace
/// </summary>
[JsonPropertyName("fontFace")]
string Face { get; set; }

/// <summary>
/// fontVariantWeight
/// </summary>
[JsonPropertyName("fontVariantWeight")]
string VariantWeight { get; set; }
}
}
28 changes: 28 additions & 0 deletions src/sdk/PnP.Core/Model/SharePoint/Branding/Public/IFontOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace PnP.Core.Model.SharePoint
{
/// <summary>
/// Options to configure a the site font chrome.
/// </summary>
public interface IFontOptions
{
/// <summary>
/// fontOptionForSiteTitle
/// </summary>
IFontOption SiteTitle { get; set; }

/// <summary>
/// fontOptionForSiteNav
/// </summary>
IFontOption SiteNav { get; set; }

/// <summary>
/// fontOptionForSiteFooterTitle
/// </summary>
IFontOption SiteFooterTitle { get; set; }

/// <summary>
/// fontOptionForSiteFooterNav
/// </summary>
IFontOption SiteFooterNav { get; set; }
}
}
Loading
Loading