@mikezimm/fps-library-v2
Version:
Library of reusable typescript/javascript functions, interfaces and constants
194 lines (193 loc) • 10.3 kB
JavaScript
/**
* CodeAnalizerComment: Updated 4 imports on 2024-09-22 14:49:52
* Update:: import { IAnySourceItem } to '@mikezimm/fps-core-v7/lib/components/molecules/AnyContent/IAnyContent;'
* Update:: import { IFPSItem } to '@mikezimm/fps-core-v7/lib/components/molecules/AnyContent/IAnyContent;'
* Update:: import { IWebpartBannerProps } to '@mikezimm/fps-core-v7/lib/banner/mainReact/IWebpartBannerProps;'
* Update:: import { IStateSource } to '@mikezimm/fps-core-v7/lib/components/molecules/state-source/IStateSource;'
*/
import { getEasyIcon } from '@mikezimm/fps-core-v7/lib/components/atoms/easy-icons/functions/getEasyIcon';
import { gulpParam1 } from "@mikezimm/fps-core-v7/lib/components/atoms/Links/CommonDevUrls";
import { DefaultSiteLogo } from '@mikezimm/fps-core-v7/lib/components/atoms/easy-icons/SystemIcons/DefaultEasyIcons';
import { checkIsAFile } from '../getFPSLinkList';
import { encodeDecodeString } from '@mikezimm/fps-core-v7/lib/logic/Strings/urlServices';
/**
*
* @param bannerProps
* @param sourceProps
* @param search
* @param WPFPSItem
* @param departmentId - if for current site, leave empty, will get from bannerProps
* @returns
*/
export function buildFPSAnyTileItems(results, bannerProps, webPartFPSItem) {
// NOTE: FILES SHOULD HAVE PREVIOUSLY RUN addSearchMetaAllV2 which includes: addSearchFileDataItemsV2 and addSearchMeta2
results.itemsY.map((item) => {
var _a, _b;
const ThisItemAny = item;
const itemSearch = (_b = (_a = item === null || item === void 0 ? void 0 : item.FPSItem) === null || _a === void 0 ? void 0 : _a.Search) === null || _b === void 0 ? void 0 : _b.searchTypes; // returns undefined if it does not exist at depth
const searchType = itemSearch && itemSearch.length > 0 ? itemSearch[0] : null;
let iconName = searchType ? searchType.icon : item.FileSystemObjectType === 1 ? 'FabricFolder' : ''; // TypicalFileItem.FileSystemObjectType === 1 ? 'FabricFolder' :
// https://github.com/fps-solutions/LinkUp/issues/58
let iconColor = searchType ? searchType.color : ``;
// https://github.com/fps-solutions/LinkUp/issues/50 << This could be solved if this was using StdFileSearchTypes but I want to keep it simple for this implimentation.
const File_x0020_Type = item.File_x0020_Type;
if (!iconName && item.File_x0020_Type) {
if (File_x0020_Type.indexOf('xls') > -1) {
iconName = `ExcelDocument`;
if (!iconColor)
iconColor = `#217346`;
}
else if (File_x0020_Type.indexOf('doc') > -1) {
iconName = `WordDocument`;
if (!iconColor)
iconColor = `#2b579a`;
}
else if (File_x0020_Type.indexOf('ppt') > -1) {
iconName = `PowerPointDocument`;
if (!iconColor)
iconColor = `#d24726`;
}
else if (File_x0020_Type === 'pdf') {
iconName = `PDF`;
if (!iconColor)
iconColor = `#B11100`;
}
else if (File_x0020_Type === 'png' || File_x0020_Type === 'jpg') {
iconName = `FileImage`;
if (!iconColor)
iconColor = `darkblue`;
}
else if (`"zip", "7z", "tar", "rar", "lzh"`.indexOf(File_x0020_Type) > -1) {
iconName = `ZipFolder`;
}
// Added these for Pivot Tiles although at this point, it might be better to leverage pfs-core-v7/lib\components\molecules\SearchPage\Interfaces\ProgrammingFileKeys.ts
else if (`"txt", "csv", "rtf",`.indexOf(File_x0020_Type) > -1) {
iconName = `TextDocument`;
}
else if (`"msg", "pst",`.indexOf(File_x0020_Type) > -1) {
iconName = `OutlookLogo`;
iconColor = 'blue';
}
else if (`"one", "onepkg",`.indexOf(File_x0020_Type) > -1) {
iconName = `OneNoteLogo`;
iconColor = 'purple';
}
else if (`"json",`.indexOf(File_x0020_Type) > -1) {
iconName = `Code`;
}
else if (`"js"`.indexOf(File_x0020_Type) > -1) {
iconName = `JS`;
}
else if (`"html"`.indexOf(File_x0020_Type) > -1) {
iconName = `FileHTML`;
iconColor = 'dimgray';
}
else if (`"css",`.indexOf(File_x0020_Type) > -1) {
iconName = `CSS`;
iconColor = 'lightblue';
}
else if (`"xml",`.indexOf(File_x0020_Type) > -1) {
iconName = `CalculatorMultiply`;
}
else if (`"exe",`.indexOf(File_x0020_Type) > -1) {
iconName = `CSharpLanguage`;
iconColor = 'red';
}
else if (`"ps1",`.indexOf(File_x0020_Type) > -1) {
iconName = `PowerShell2`;
iconColor = 'darkblue';
}
}
// Added this due to PivotTiles not seeing folder name but 'UNK' in the Title/Link
// if ( item.FileSystemObjectType === 1 ) {
// iconName = 'Folder';
// if ( item.FileLeafRef && item[ `File/Name` as 'Title' ] === 'UNK' ) item[ `File/Name` as 'Title' ] = item.FileLeafRef;
// if ( item.FileRef && item[ `File/ServerRelativeUrl`] === 'UNK' ) item[ `File/ServerRelativeUrl`] = item.FileRef;
// }
let imageUrl = ThisItemAny.SiteLogoUrl ? ThisItemAny.SiteLogoUrl : // Sometimes comes across as SiteLogoUrl
ThisItemAny.SiteLogo ? ThisItemAny.SiteLogo : // NOTE: SiteLogo seems to be used if Site is a Team
// https://github.com/fps-solutions/LinkUp/issues/27
ThisItemAny.BannerImageUrl && ThisItemAny.BannerImageUrl.Url ? ThisItemAny.BannerImageUrl.Url : // NOTE: SiteLogo seems to be used if Site is a Team
ThisItemAny.PictureThumbnailURL ? ThisItemAny.PictureThumbnailURL :
// https://github.com/mikezimm/pivottiles7/issues/402
ThisItemAny[`imageUrl`] ? ThisItemAny[`imageUrl`] : ``;
if (!imageUrl || imageUrl.indexOf(DefaultSiteLogo) > -1)
imageUrl = getEasyIcon(bannerProps.EasyIconsObject, item, undefined);
const isAFile = checkIsAFile(item);
const bestTitle = item.Title ? item.Title : item.FileLeafRef ? item.FileLeafRef : item.File && item.File.Name ? item.File.Name : 'Unknown Title';
let bestDesc = item.Description ? item.Description : item.FileRef ? item.FileRef : item.ServerRelativeUrl ? item.ServerRelativeUrl : '';
if (bestDesc === bestTitle)
bestDesc = ``;
let bestHref = item.ServerRelativeUrl ? item.ServerRelativeUrl : item.FileRef ? item.FileRef :
// https://github.com/fps-solutions/LinkUp/issues/27
// item.File && item.File.ServerRelativeUrl ? item.File.ServerRelativeUrl :
'';
if (item.EntityTypeName) {
if (item.RootFolder)
item.ServerRelativeUrl = item.RootFolder.ServerRelativeUrl;
let ParentWebUrl = results.fetchAPI.split('/_api')[0];
let EntityTypeName = encodeDecodeString(item.EntityTypeName, 'decode');
// Handle as a list/library
if (item.ServerRelativeUrl) { // Already available
bestHref = item.ServerRelativeUrl;
}
else if (item.BaseType === 1 || item.BaseTemplate === 101) {
bestHref = `${ParentWebUrl}/${''}${EntityTypeName}`;
}
else {
EntityTypeName = EntityTypeName.substring(0, EntityTypeName.length - 4);
bestHref = `${ParentWebUrl}/${'/lists/'}${EntityTypeName}`;
}
// Adding this just to make sure it's always there
if (bestHref && !item.ServerRelativeUrl)
item.ServerRelativeUrl = bestHref;
}
if (!bestHref)
bestHref = 'Unknown Link';
const metaClick = `${bestHref}?${gulpParam1}`;
item.FPSItem.Image = {
src: imageUrl,
fabric: {
imgCover: webPartFPSItem.Image.fabric.imgCover,
imgFit: webPartFPSItem.Image.fabric.imgFit,
},
css: {
height: `${webPartFPSItem.Image.css.height}`,
width: `${webPartFPSItem.Image.css.width}`,
background: webPartFPSItem.Image.css.background,
}
};
item.FPSItem.Icon = {
name: `${iconName}`,
css: {
// https://github.com/fps-solutions/LinkUp/issues/58
color: iconColor,
}
};
// https://github.com/fps-solutions/LinkUp/issues/29
// Automatically update the alt-click for cases where it is defined to be something like the SPO Display or Edit form
let altUrl = '';
if (!isAFile && webPartFPSItem && webPartFPSItem.Link && webPartFPSItem.Link.altUrl)
altUrl = webPartFPSItem.Link.altUrl.replace(`{{ID}}`, item.ID);
item.FPSItem.Link = {
href: bestHref,
altUrl: altUrl ? altUrl : bestHref,
ctrlUrl: bestHref,
shiftUrl: bestHref,
metaUrl: metaClick,
key3Url: bestHref,
// title: `${ bestTitle } ${ altUrl ? ' ~ Alt-Click to open SharePoint Item' : ''}`,
// description: `${bestDesc} ${ altUrl ? ' ~ Alt-Click to open SharePoint Item' : ''}`,
title: `${bestTitle}`,
description: `${bestDesc}`,
};
if (!item.Title && bestTitle)
item.Title = bestTitle;
if (!item.Description && bestDesc)
item.Description = bestDesc;
if (webPartFPSItem.Link.altClick)
item.FPSItem.Link.altClick = webPartFPSItem.Link.altClick;
});
return results;
}
//# sourceMappingURL=buildFPSAnyTileItems.js.map