@mikezimm/fps-library-v2
Version:
Library of reusable typescript/javascript functions, interfaces and constants
314 lines (312 loc) • 22.6 kB
JavaScript
/**
* CodeAnalizerComment: Updated 1 imports on 2024-09-22 14:49:52
* Update:: import { IWebpartBannerProps } to '@mikezimm/fps-core-v7/lib/banner/mainReact/IWebpartBannerProps;'
*/
/**
* CodeAnalizerComment: Updated 3 imports on 2024-09-21 23:07:24
* Update:: import { PivotLinkFormat } to '@mikezimm/fps-core-v7/lib/types/@fluentUI/@7.199.1/Pivot;'
* Update:: import { PivotLinkSize } to '@mikezimm/fps-core-v7/lib/types/@fluentUI/@7.199.1/Pivot;'
* Update:: import { defaultBannerCommandStyles } to '@mikezimm/fps-core-v7/lib/common/commandStyles/defaults;'
*/
import * as React from "react";
// For SPPermission: let addAndCustomizePages = pageContext.web.permissions.hasPermission( SPPermission.addAndCustomizePages );
// import { SPPermission } from '@microsoft/sp-page-context';
import { PivotLinkFormat, PivotLinkSize } from '@fluentui/react/lib/Pivot';
import { Pivot, PivotItem, } from '@fluentui/react/lib/Pivot';
import { Icon } from '@fluentui/react/lib/Icon';
import { defaultBannerCommandStyles } from "@mikezimm/fps-core-v7/lib/common/commandStyles/defaults";
import { CurrentHostName, CurrentOrigin } from "@mikezimm/fps-core-v7/lib/components/molecules/source-props/WindowLocationConstants";
require('@mikezimm/fps-styles/dist/bannerSettings.css');
export function standardSettingsLink(title, iconName, iconStyles, href, color = null) {
let styleName = 'grayHover';
let titleProp = '';
if (color === 'red') {
styleName = 'red';
titleProp = 'You are not on your z-Account!!!';
}
else if (color === 'green') {
styleName = 'green';
titleProp = 'You are on your z-Account :)';
}
else if (color === 'yellow') {
styleName = 'yellow';
titleProp = 'Azure DevOps - you have an account?';
}
return React.createElement("li", { title: titleProp, className: styleName, onClick: () => { window.open(href, '_none'); } },
iconName && iconName.length > 0 ? React.createElement(Icon, { iconName: iconName, style: iconStyles }) : null,
React.createElement("span", null, title));
}
function getTenantAdminUrl() {
let tenant = CurrentHostName.split('.');
return `https://${tenant[0]}-admin.sharepoint.com`;
}
export function Settings(siteUrl, showIcon, iconStyles) {
return standardSettingsLink('Settings', showIcon === true ? 'Settings' : '', iconStyles, `${siteUrl}/_layouts/15/settings.aspx`);
}
export function Contents(siteUrl, showIcon, iconStyles) {
return standardSettingsLink('Site Contents', showIcon === true ? 'BulletedList2' : '', iconStyles, `${siteUrl}/_layouts/15/viewlsts.aspx?view=14`);
}
export function SitePages(siteUrl, showIcon, iconStyles) {
return standardSettingsLink('Site Pages', showIcon === true ? 'KnowledgeArticle' : '', iconStyles, `${siteUrl}/SitePages`);
}
export function SiteAssets(siteUrl, showIcon, iconStyles) {
return standardSettingsLink('Site Assets', showIcon === true ? 'AssetLibrary' : '', iconStyles, `${siteUrl}/SiteAssets`);
}
export function Permissions(siteUrl, showIcon, iconStyles) {
return standardSettingsLink('Permissions', showIcon === true ? 'Permissions' : '', iconStyles, `${siteUrl}/_layouts/15/user.aspx`);
}
export function AdminRecycleBin(siteUrl, showIcon, iconStyles, webLevel) {
let title = `${webLevel === true ? 'Web' : 'Site'} Recycle Bin`;
return standardSettingsLink(title, showIcon === true ? 'RecycleBin' : '', iconStyles, `${siteUrl}/_layouts/15/AdminRecycleBin.aspx${webLevel === true ? '?view=5' : '?view=13'}`);
}
export function GroupsLink(siteUrl, showIcon, iconStyles) {
return standardSettingsLink('Groups', showIcon === true ? 'Group' : '', iconStyles, `${siteUrl}/_layouts/15/groups.aspx`);
}
export function StorageMetrics(siteUrl, showIcon, iconStyles) {
return standardSettingsLink('Storage Metrics', showIcon === true ? 'OfflineStorage' : '', iconStyles, `${siteUrl}/_layouts/15/storman.aspx`);
}
export function NavigationLinks(siteUrl, showIcon, iconStyles) {
return standardSettingsLink('Navigation', showIcon === true ? 'CompassNW' : '', iconStyles, `${siteUrl}/_layouts/15/AreaNavigationSettings.aspx`);
}
export function ReIndex(siteUrl, showIcon, iconStyles) {
return standardSettingsLink('ReIndex', showIcon === true ? 'SearchData' : '', iconStyles, `${siteUrl}/_layouts/15/srchvis.aspx`);
}
export function TermStore(siteUrl, showIcon, iconStyles) {
return standardSettingsLink('TermStore', showIcon === true ? 'eDiscovery' : '', iconStyles, `${siteUrl}/_layouts/15/termstoremanager.aspx?RedirectToModernExperience=true`);
}
export function NavigationElements(siteUrl, showIcon, iconStyles) {
return standardSettingsLink('Navigation Elements', showIcon === true ? 'CompassNW' : '', iconStyles, `${siteUrl}/_layouts/15/navoptions.aspx`);
}
//https://tenant-admin.sharepoint.com/_layouts/15/online/AdminHome.aspx#/siteManagement/view/SITES%20WITHOUT%20A%20GROUP
export function TenantSites(siteUrl, showIcon, iconStyles, tenantColor) {
return standardSettingsLink('Sites', showIcon === true ? 'SharepointLogo' : '', iconStyles, `${getTenantAdminUrl()}/_layouts/15/online/AdminHome.aspx#/siteManagement/view/SITES%20WITHOUT%20A%20GROUP`, tenantColor);
}
export function TenantHubs(siteUrl, showIcon, iconStyles, tenantColor) {
return standardSettingsLink('Hubs', showIcon === true ? 'TFVCLogo' : '', iconStyles, `${getTenantAdminUrl()}/_layouts/15/online/AdminHome.aspx#/siteManagement/view/ALL%20SITES`, tenantColor);
}
//https://tenant-admin.sharepoint.com/_layouts/15/online/AdminHome.aspx#/siteManagement/view/TEAMS%20CONNECTED%20SITES
export function TenantTeams(siteUrl, showIcon, iconStyles, tenantColor) {
return standardSettingsLink('Teams', showIcon === true ? 'TeamsLogo' : '', iconStyles, `${getTenantAdminUrl()}/_layouts/15/online/AdminHome.aspx#/siteManagement/view/TEAMS%20CONNECTED%20SITES`, tenantColor);
}
//https://tenant-admin.sharepoint.com/_layouts/15/online/AdminHome.aspx#/siteManagement/view/TEAMS%20CONNECTED%20SITES
export function TenantApps(siteUrl, showIcon, iconStyles, tenantColor) {
return standardSettingsLink('Tenant Apps', showIcon === true ? 'WebAppBuilderFragment' : '', iconStyles, `${getTenantAdminUrl()}/_layouts/15/online/TenantAdminApps.aspx`, tenantColor);
}
export function TenantSearch(siteUrl, showIcon, iconStyles, tenantColor) {
return standardSettingsLink('Search', showIcon === true ? 'SearchAndApps' : '', iconStyles, `${getTenantAdminUrl()}`, tenantColor);
}
export function AzureDevOps(siteUrl, showIcon, iconStyles, tenantColor) {
return standardSettingsLink('Azure Devops', showIcon === true ? 'ReleaseDefinition' : '', iconStyles, `https://go.microsoft.com/fwlink/?LinkId=2014676&githubsi=true`, 'yellow');
}
//https://tenant-admin.sharepoint.com/_layouts/15/online/AdminHome.aspx#/contentTypes
export function TenantContentCenter(siteUrl, showIcon, iconStyles, tenantColor) {
return standardSettingsLink('Content Types', showIcon === true ? 'Archive' : '', iconStyles, `${getTenantAdminUrl()}/_layouts/15/online/AdminHome.aspx#/contentTypes`, tenantColor);
}
//https://tenant-admin.sharepoint.com/_layouts/15/TenantProfileAdmin/ManageUserProfileServiceApplication.aspx https://github.com/mikezimm/fps-library-v2/issues/181
export function TenantProfileService(siteUrl, showIcon, iconStyles, tenantColor) {
return standardSettingsLink('User Profiles', showIcon === true ? 'CRMServices' : '', iconStyles, `${getTenantAdminUrl()}/_layouts/15/TenantProfileAdmin/ManageUserProfileServiceApplication.aspx`, tenantColor);
}
// TenantProfileService TenantSearchAdmin TenantTermStore
//https://tenant-admin.sharepoint.com/_layouts/15/searchadmin/TA_SearchAdministration.aspx https://github.com/mikezimm/fps-library-v2/issues/181
export function TenantSearchAdmin(siteUrl, showIcon, iconStyles, tenantColor) {
return standardSettingsLink('Tenant Search', showIcon === true ? 'SearchData' : '', iconStyles, `${getTenantAdminUrl()}/_layouts/15/searchadmin/TA_SearchAdministration.aspx`, tenantColor);
}
//https://tenant-admin.sharepoint.com/_layouts/15/online/AdminHome.aspx#/termStoreAdminCenter https://github.com/mikezimm/fps-library-v2/issues/181
export function TenantTermStore(siteUrl, showIcon, iconStyles, tenantColor) {
return standardSettingsLink('Term Store', showIcon === true ? 'ShoppingCart' : '', iconStyles, `${getTenantAdminUrl()}/_layouts/15/online/AdminHome.aspx#/termStoreAdminCenter`, tenantColor);
}
//https://tenant-admin.sharepoint.com/_layouts/15/online/AdminHome.aspx#/contentTypes
// export function TenantContentCenter( siteUrl: string, showIcon: boolean, iconStyles: any, tenantColor: hoverColor ) {
// return standardSettingsLink( 'Content Types', showIcon === true ? 'Archive' : '', iconStyles, `${getTenantAdminUrl()}/_layouts/15/online/AdminHome.aspx#/contentTypes`, tenantColor );
// }
//https://tenant.sharepoint.com/sites/contentTypeHub/_layouts/15/mngfield.aspx
export function TenantSiteColumns(siteUrl, showIcon, iconStyles, tenantColor) {
return standardSettingsLink('Site Columns', showIcon === true ? 'ReportAdd' : '', iconStyles, `${siteUrl}/_layouts/15/mngfield.aspx`, tenantColor);
}
// forceNarrowStyles?: boolean; //If true (like when web part is pinned or in vertical section, force Gear settings to narrow mode )
// export function bannerSettingsContent( showTricks: boolean, pageContext: PageContext, keySiteProps: IKeySiteProps, bannerCommandStylesX: React.CSSProperties, bannerWidth: number, forceNarrowStyles: boolean | null | undefined ) {
export function bannerSettingsContent(bannerProps, forceNarrowStyles) {
const { context, keySiteProps, bannerWidth, bannerPillShape, FPSUser } = bannerProps;
const pageContext = context.pageContext;
const legacyPageContext = pageContext.legacyPageContext;
const LPC = `pageContext.legacyPageContext.`;
const bannerCommandStylesX = defaultBannerCommandStyles;
//Admin links
let bannerCommandStyles = JSON.parse(JSON.stringify(bannerCommandStylesX));
if (bannerCommandStyles && bannerCommandStyles.background) {
bannerCommandStyles.background = 'transparent';
}
if (bannerCommandStyles && bannerCommandStyles.backgroundColor) {
bannerCommandStyles.backgroundColor = 'transparent';
}
let bannerCommandStylesSCA = { ...bannerCommandStyles, ...{ padding: '6px 7px' } };
// Commenting out since it only seems to add to console. https://github.com/mikezimm/fps-library-v2/issues/39
// let addAndCustomizePages = pageContext.web.permissions.hasPermission( SPPermission.addAndCustomizePages );
// console.log('Current user can addAndCustomizePages', addAndCustomizePages );
let showAdmin = FPSUser ? FPSUser.isSiteAdmin : legacyPageContext.isSiteAdmin === true ? true : false;
let siteUrl = pageContext.site.absoluteUrl;
let contentTypeHub = `${CurrentOrigin}/sites/contentTypeHub`;
let isFraudTenant = legacyPageContext.isFraudTenant;
let allowInfectedDownload = legacyPageContext.allowInfectedDownload;
let isNoScriptEnabled = pageContext.site.isNoScriptEnabled;
let noScriptStyle = isNoScriptEnabled !== true ? 'redLabel' : 'justLabel';
let blockDownloads = legacyPageContext.blockDownloadsExperienceEnabled;
let blockDownloadStyle = blockDownloads !== true ? 'redLabel' : 'justLabel';
let disableFlows = legacyPageContext.disableFlows;
let isWebWelcomePage = legacyPageContext.isWebWelcomePage;
let hasManageWebPermissions = FPSUser ? FPSUser.managePermissions : legacyPageContext.hasManageWebPermissions;
let guestsEnabled = legacyPageContext.guestsEnabled;
let guestStyle = guestsEnabled === true ? 'redLabel' : 'justLabel';
let isSiteOwner = showAdmin === true ? true : FPSUser ? FPSUser.isSiteOwner : legacyPageContext.isSiteOwner;
let isArchived = legacyPageContext.isArchived;
let liIsNoScriptEnabled = React.createElement("li", { className: noScriptStyle, title: 'pageContext.site.isNoScriptEnabled' }, `Scripts Disabled: ${isNoScriptEnabled}`);
let liGuestsEnabled = React.createElement("li", { className: guestStyle, title: `${LPC}guestsEnabled` }, `Guests Enabled: ${guestsEnabled}`);
let liBlockDownloads = React.createElement("li", { className: blockDownloadStyle, title: `${LPC}blockDownloadsExperienceEnabled` }, `Block Downloads: ${blockDownloads}`);
let flowStyle = disableFlows === true ? 'redLabel' : 'justLabel';
let liDisableFlows = React.createElement("li", { className: flowStyle, title: `${LPC}disableFlows` }, `Disable Flows: ${disableFlows}`);
let licGuestsEnabled = React.createElement("li", { className: 'compressedLabel', title: `${LPC}guestsEnabled` }, `Guests Enabled: ${guestsEnabled}`);
let licBlockDownloads = React.createElement("li", { className: 'compressedLabel', title: `${LPC}blockDownloadsExperienceEnabled` }, `Block Downloads: ${blockDownloads}`);
// Highlight red color if you are NOT on z-Account
const loginName = FPSUser ? FPSUser.name : pageContext.user.loginName;
let tenantColor = loginName.indexOf('z-') === 0 ? 'green' : 'red';
let scaContent = showAdmin !== true ? null : React.createElement("div", { className: 'tileBox' },
React.createElement("h2", { style: { marginBlockStart: '0.5em', marginBlockEnd: '0.3em' } }, "Site - SCAs"),
React.createElement("ul", { className: 'boxLinks' },
Settings(siteUrl, true, bannerCommandStylesSCA),
Contents(siteUrl, true, bannerCommandStylesSCA),
SitePages(siteUrl, true, bannerCommandStylesSCA),
SiteAssets(siteUrl, true, bannerCommandStylesSCA),
Permissions(siteUrl, true, bannerCommandStylesSCA),
GroupsLink(siteUrl, true, bannerCommandStylesSCA),
AdminRecycleBin(siteUrl, true, bannerCommandStylesSCA, false),
StorageMetrics(siteUrl, true, bannerCommandStylesSCA),
NavigationLinks(siteUrl, true, bannerCommandStylesSCA),
ReIndex(siteUrl, true, bannerCommandStylesSCA),
TermStore(siteUrl, true, bannerCommandStylesSCA),
React.createElement("div", { style: { height: '10px' } }),
liIsNoScriptEnabled,
liGuestsEnabled,
liBlockDownloads));
//Admin links
let showOwner = showAdmin === true || isSiteOwner === true ? true : false;
let webUrl = pageContext.web.absoluteUrl;
if (siteUrl === webUrl && showAdmin === true) {
showOwner = false;
}
let ownerContent = showOwner !== true ? null : React.createElement("div", { className: 'tileBox' },
React.createElement("h2", null, "Web - Owners"),
React.createElement("ul", { className: 'boxLinks' },
Settings(webUrl, true, bannerCommandStyles),
Contents(webUrl, true, bannerCommandStyles),
SitePages(webUrl, true, bannerCommandStyles),
SiteAssets(webUrl, true, bannerCommandStyles),
Permissions(webUrl, true, bannerCommandStyles),
GroupsLink(webUrl, true, bannerCommandStyles),
AdminRecycleBin(webUrl, true, bannerCommandStyles, true),
StorageMetrics(siteUrl, true, bannerCommandStyles),
NavigationElements(webUrl, true, bannerCommandStyles),
ReIndex(webUrl, true, bannerCommandStyles),
TermStore(siteUrl, true, bannerCommandStyles)));
//Tenant links
let trickyContent = bannerProps.showTricks !== true ? null : React.createElement("div", { className: 'tileBox' },
React.createElement("h2", { style: { marginBlockStart: '0.5em', marginBlockEnd: '0.3em' } }, "Tenant Links"),
React.createElement("ul", { className: 'boxLinks' },
TenantSites(webUrl, true, bannerCommandStylesSCA, tenantColor),
TenantHubs(webUrl, true, bannerCommandStylesSCA, tenantColor),
TenantTeams(webUrl, true, bannerCommandStylesSCA, tenantColor),
TenantApps(webUrl, true, bannerCommandStylesSCA, tenantColor),
TenantContentCenter(webUrl, true, bannerCommandStylesSCA, tenantColor),
TenantSiteColumns(contentTypeHub, true, bannerCommandStylesSCA, tenantColor),
TenantProfileService(webUrl, true, bannerCommandStylesSCA, tenantColor),
TenantSearchAdmin(webUrl, true, bannerCommandStylesSCA, tenantColor),
TenantTermStore(webUrl, true, bannerCommandStylesSCA, tenantColor),
AzureDevOps(webUrl, true, bannerCommandStylesSCA, tenantColor),
React.createElement("div", { style: { height: '20px' } }),
liIsNoScriptEnabled,
liGuestsEnabled,
liBlockDownloads,
React.createElement("li", { className: 'justLabel', title: `${LPC}isFraudTenant` }, `FraudTenant: ${isFraudTenant}`),
React.createElement("li", { className: 'justLabel', title: `${LPC}allowInfectedDownload` }, `Inf Download: ${allowInfectedDownload}`)));
let timePrefTitle = keySiteProps.UserTimePref === true ? `You will see timestamps based on your time zone` : `YOU will see timestamps based on ???`;
let timesAreSame = keySiteProps.WebTimezone === keySiteProps.UserTimezone ? true : false;
let userTimeZoneTitle = timesAreSame === true ? `User Timezone: (same)` : React.createElement("span", { style: { color: 'red' } }, `User Timezone: ( Different )`);
//Tenant links
// _layouts/15/regionalsetng.aspx
let webTime24 = legacyPageContext.webTime24;
let WebTimeTitle = `Web Timezone: ( ${webTime24 === true ? 24 : 12} hour )`;
let webRegionalSettings = webUrl + '/_layouts/15/regionalsetng.aspx';
const nowDate = new Date();
const localNow = `${nowDate}`;
let settingsContent = React.createElement("div", { className: ['tileBox', 'summaryBox'].join(' ') },
React.createElement("h2", null, "Summary"),
React.createElement("ul", { className: 'boxLinks' },
React.createElement("li", { className: 'heading', title: keySiteProps.WebTimezone, onClick: () => { window.open(webRegionalSettings, '_none'); } },
React.createElement("div", null, WebTimeTitle),
`${keySiteProps.WebTimezone}`),
React.createElement("li", { className: 'heading', title: keySiteProps.UserTimezone, style: { cursor: 'default' } },
React.createElement("div", null, userTimeZoneTitle),
`${keySiteProps.UserTimezone}`),
React.createElement("li", { className: 'heading', title: timePrefTitle, style: { cursor: 'default' } },
React.createElement("div", null, "User Time Pref:"),
`${keySiteProps.UserTimePref}`),
React.createElement("li", { className: 'heading', style: { cursor: 'default' } },
React.createElement("div", null, "Web Language:"),
`${keySiteProps.WebLanguage}`),
licBlockDownloads,
licGuestsEnabled,
liDisableFlows,
React.createElement("li", { className: 'compressedLabel', title: 'pageContext.site.isArchived' }, `Is archived: ${isArchived}`),
React.createElement("li", { className: 'compressedLabel', title: `${LPC}isWebWelcomePage` }, `Is Welcome Page: ${isWebWelcomePage}`),
React.createElement("li", { className: 'compressedLabel', title: `${LPC}hasManageWebPermissions` }, `Can Manage Web: ${hasManageWebPermissions}`),
React.createElement("li", { className: 'compressedLabel', title: `${LPC}isSiteOwner` }, `Is Site Owner: ${isSiteOwner}`),
React.createElement("li", null, `Members can edit: ${keySiteProps.BrokenPermissions === null ? 'TBD' : keySiteProps.LimitedDownload}`),
React.createElement("li", null, `Broken permissions: ${keySiteProps.BrokenPermissions === null ? 'TBD' : keySiteProps.BrokenPermissions}`),
React.createElement("div", { style: { height: '10px' } }),
React.createElement("li", { className: 'compressedLabel', title: localNow }, `Loaded: ${localNow}`)));
let approxWidth = 0;
if (scaContent !== null) {
approxWidth += 169 + 90;
}
if (ownerContent !== null) {
approxWidth += 206 + 90;
}
if (trickyContent !== null) {
approxWidth += 206 + 90;
}
approxWidth += 237 + 90; //For Summary
let content = null;
let showSettingsAsPivot = forceNarrowStyles === true || approxWidth > bannerWidth ? true : false;
// https://github.com/mikezimm/fps-library-v2/issues/53
const bannerSettingsCompClass = ['banner-settings-component', bannerPillShape === true ? 'bannerPillShapeSetting' : null].join(' ');
if (showSettingsAsPivot === true) {
let pivotItems = [];
if (ownerContent !== null) {
pivotItems.push(React.createElement(PivotItem, { headerText: 'Web', ariaLabel: 'Web', title: 'Web' }, ownerContent));
}
if (scaContent !== null) {
pivotItems.push(React.createElement(PivotItem, { headerText: 'Site', ariaLabel: 'Site', title: 'Site' }, scaContent));
}
if (trickyContent !== null) {
pivotItems.push(React.createElement(PivotItem, { headerText: 'Tenant', ariaLabel: 'Tenant', title: 'Tenant' }, trickyContent));
}
if (settingsContent !== null) {
pivotItems.push(React.createElement(PivotItem, { headerText: 'Key Settings', ariaLabel: 'Key Settings', title: 'Key Settings' }, settingsContent));
}
content = React.createElement("div", { className: bannerSettingsCompClass },
React.createElement(Pivot
// styles={ pivotStyles }
, {
// styles={ pivotStyles }
linkFormat: PivotLinkFormat.links, linkSize: PivotLinkSize.large }, pivotItems));
}
else {
content = React.createElement("div", { className: bannerSettingsCompClass },
React.createElement("div", { className: 'flexBoxes', style: { paddingBottom: '100px' } },
ownerContent,
scaContent,
trickyContent,
settingsContent));
}
return { content: content, approxWidth: approxWidth, showSettingsAsPivot: showSettingsAsPivot };
}
//# sourceMappingURL=bannerGearFunctions.js.map