UNPKG

@mikezimm/fps-core-v7

Version:

Library of reusable core interfaces, types and constants migrated from fps-library-v2

207 lines (205 loc) 12 kB
import { MinFileObjectSelects, MinFileSelects } from "../../AnyContent/IFPSFileObject"; import { ItemIsADocSet, ItemIsADraft, ItemIsAFile, ItemIsAFileObject, ItemIsAMajor, ItemIsANewsLink, ItemIsANewsPost, ItemIsAPage, ItemIsCheckedOut, ItemIsCodeContent, ItemIsFolderContent, ItemIsPublished, ItemIsUnPublished } from "../../AnyContent/IsA/IFPSItemIsA"; import { ALLProgrammingFileKeys } from "../../SearchPage/Interfaces/ProgrammingFileKeys"; import { addItemIsA } from "./addItemIsA"; export function addSearchFileDataItemsV2(items, sourceProps, SearchTypes) { items.map((item) => { item = addSearchFileDataV2(item, sourceProps, SearchTypes); }); return items; } export function check4MissingSelects(item, selects, consoleLog = true) { const missing = []; const hasFileObject = item.File ? true : false; selects.map(select => { if (!item[select] && item[select] !== 0) { // If it's not on the item level and not on the File level, then push missing if (!item.File || !item.File[select]) missing.push(select); } }); // https://github.com/mikezimm/pivottiles7/issues/434 - clean up console.logs for PivotTiles SitePages which do not really use full file selects if (missing.length > 0 && consoleLog === true) console.log(`check4MissingSelects:`, missing, item); return missing.length > 0 ? true : false; } export function addSearchFileDataV2(item, sourceProps, SearchTypes) { /** * 2024-11-30: Refactoring this since adding standardizeFileProps */ const { FileLeafRef, FileRef, OData__UIVersionString, DocIcon, FileSizeDisplay, ServerRelativeUrl } = item; // if ( item.File || item.FileSizeDisplay || FileLeafRef || item.FileRef || item.File_x0020_Type || item.DocIcon || item.FirstPublishedDate ) { // removed item.FirstPublishedDate because Hubs data had item.FirstPublishedDate which caused issues. if (item.File || FileSizeDisplay || FileLeafRef || FileRef || item.File_x0020_Type || DocIcon) { // Item is a file item = addItemIsA(item, ItemIsAFileObject); } else { return item; } const consoleMissing = sourceProps.listTitle === 'Site Pages' ? false : true; // https://github.com/mikezimm/pivottiles7/issues/434 - clean up console.logs for PivotTiles SitePages which do not really use full file selects if (check4MissingSelects(item, MinFileObjectSelects, consoleMissing) === false) { } item.FPSItem.File.fileDisplayName = ''; //Basically the file name but without extension // Added this in case File is not expanded but there is a FileRef // if ( !item.File && ( FileRef || ServerRelativeUrl ) ) { This can be refactroed wtih new standardizeFileProps // if ( !item.File && ( FileRef || ServerRelativeUrl ) ) { // item.File = { // ServerRelativeUrl: ServerRelativeUrl ? ServerRelativeUrl : FileRef, // } // } // This loop was originally in addDateTimeFileInfoSearch // Added this to flatten file url for easier use if (item.File && FileLeafRef) { // item[ 'File/ServerRelativeUrl' as 'ServerRelativeUrl' ] = item.File.ServerRelativeUrl ; // https://github.com/mikezimm/pivottiles7/issues/314 // const FileLeafRef = item.File.FileLeafRef ? item.File.FileLeafRef : item.File.ServerRelativeUrl.substring(item.File.ServerRelativeUrl.lastIndexOf('/') + 1); // if ( !item.File.FileRef ) item.File.FileRef = item.File.ServerRelativeUrl; // if ( !item.File.Name ) item.File.Name = FileLeafRef; // if ( !item.File.FileLeafRef ) item.File.FileLeafRef = FileLeafRef; item.FPSItem.File ? item.FPSItem.File.valid = true : item.FPSItem.File = { valid: true, fileDisplayName: FileLeafRef, }; } //https://github.com/mikezimm/Compliance/issues/121 if (item.FileSizeDisplay) item.FPSItem.File.fileSizeNumber = parseInt(item.FileSizeDisplay); let { searchTitle, searchDesc, } = item.FPSItem.Search; let searchType = item.FPSItem.Search.type; if (item.FileSystemObjectType === 1) { /** * THIS IS A FOLDER */ item = addItemIsA(item, ItemIsFolderContent); const thisContentType = item[`ContentType/Name`] ? item[`ContentType/Name`] : 'Unknown'; if (thisContentType.indexOf(`Document Set`) > -1) { searchType = 'docset'; item[`File_x0020_Type`] = 'docset'; searchTitle = FileLeafRef ? FileLeafRef : ''; searchDesc = item.Description ? item.Description : ''; item = addItemIsA(item, ItemIsADocSet); } else { searchType = 'folder'; // item[`File_x0020_Type`] = 'folder'; // MOVED TO standardizeFileProps searchTitle = FileLeafRef ? FileLeafRef : ''; //webRelativeLink const webLink = `${sourceProps.webUrl}${sourceProps.webRelativeLink ? sourceProps.webRelativeLink : ''}`; const fileRelativeLink = item.FileRef && item.FileRef.indexOf(webLink) === 0 ? item.FileRef.substring(webLink.length) : item.FileRef ? item.FileRef : ''; searchDesc = item.Description ? item.Description : !FileLeafRef ? '' : fileRelativeLink.substring(0, fileRelativeLink.lastIndexOf(FileLeafRef) - 1); item = addItemIsA(item, ItemIsFolderContent); } } else if (item.FileSystemObjectType === 0) { /** * THIS IS A FILE */ if (check4MissingSelects(item, MinFileSelects, consoleMissing) === false) { } item = addItemIsA(item, ItemIsAFile); /** * OData__OriginalSourceUrl is a hidden column in SharePoint Online that is used to store the original URL of a document that was uploaded to SharePoint. * This column is used by the SharePoint Online search engine to crawl and index documents. * It is not recommended to modify or delete this column as it can cause issues with search results and other SharePoint Online features¹. I hope this helps! Let me know if you have any other questions. Source: Conversation with Bing, 7/6/2023 (1) Use OData query operations in SharePoint REST requests. https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/use-odata-query-operations-in-sharepoint-rest-requests. (2) OData Source for SharePoint Online - social.msdn.microsoft.com. https://social.msdn.microsoft.com/Forums/en-US/58807617-90aa-48e3-a06f-9582b683d8de/odata-source-for-sharepoint-online?forum=sharepointadmin. (3) Working with SharePoint Online through OData v4 Endpoint - KingswaySoft. http://www.kingswaysoft.com/blog/2021/06/29/Working-with-SharePoint-Online-through-OData-v4-Endpoint. (4) Using OData sources with Business Connectivity Services in SharePoint .... https://learn.microsoft.com/en-us/sharepoint/dev/general-development/using-odata-sources-with-business-connectivity-services-in-sharepoint. */ let isAPage = sourceProps.listTitle && sourceProps.listTitle === 'Site Pages' ? true : false; if (isAPage === false) { if (item.DocIcon === 'aspx' || item.File_x0020_Type === 'aspx') { isAPage = true; } else if (FileLeafRef && FileLeafRef.indexOf('.aspx') > -1) { isAPage = true; // } else if ( item[ `File/ServerRelativeUrl` ] && item[ `File/ServerRelativeUrl` ].indexOf( '.aspx' ) > -1 ) { // 2024-11-30: No longer needed with standardizeFileProps // isAPage = true; // } else if ( item.ServerRelativeUrl && item.ServerRelativeUrl.indexOf( '.aspx' ) > -1 ) { // 2024-11-30: No longer needed with standardizeFileProps // isAPage = true; } else if (sourceProps.webRelativeLink && sourceProps.webRelativeLink.toLowerCase().indexOf('sitepages') > -1) { isAPage = true; } } if (isAPage === true) { /** * THIS IS A PAGE */ searchDesc = item.Description; searchType = 'page'; item.FPSItem.File.fileDisplayName = FileLeafRef ? FileLeafRef.replace(`.aspx`, '') : ''; // eslint-disable-line dot-notation searchTitle = item.Title ? item.Title : item.FPSItem.File.fileDisplayName; if (item.OData__OriginalSourceUrl !== null) { item = addItemIsA(item, ItemIsANewsLink); } else if (item.PromotedState === 1 || item.PromotedState === 2) { item = addItemIsA(item, ItemIsANewsPost); } else { item = addItemIsA(item, ItemIsAPage); } } else { // This is a normal file /** * THIS IS A NORMAL FILE */ searchType = item.DocIcon ? item.DocIcon : item.File_x0020_Type ? item.File_x0020_Type : ``; item.FPSItem.File.fileDisplayName = FileLeafRef ? FileLeafRef.replace(`.${item.DocIcon}`, '') : ''; // eslint-disable-line dot-notation searchTitle = FileLeafRef ? FileLeafRef : 'No Filename to show'; // eslint-disable-line dot-notation searchDesc = item.Description ? item.Description : ``; if (!searchType) { const extIdx = FileRef ? FileRef.lastIndexOf('.') : -1; searchType = FileRef ? FileRef.substring(extIdx + 1) : ''; } } const libUrl = `${sourceProps.webUrl}${sourceProps.webRelativeLink ? sourceProps.webRelativeLink : ''}`; const folderString = FileRef && libUrl ? FileRef.replace(libUrl, '').replace(`/${FileLeafRef}`, '') : ''; const folderTree = folderString ? folderString.indexOf('/') === 0 ? folderString.substring(1).split('/') : folderString.split('/') : []; item.FPSItem.File.folderString = folderString; item.FPSItem.File.folderTree = folderTree; } else { // Need to fix select statements console.log('addSearchFileDataV2: You need to update select statements to include FileSystemObjectType ~ 171', item); } if (!searchType) searchType = sourceProps.defType; if (!searchTitle) searchTitle = item.Title ? item.Title : ``; if (!searchDesc) searchDesc = 'Other Type Search Desc'; let searchTypeIdx = SearchTypes.keys.indexOf(item.FPSItem.Search.type); item.FPSItem.Search.searchTitle = searchTitle; item.FPSItem.Search.searchDesc = searchDesc; // 2023-02-13: This is needed because sometimes the type is not found and this will prevent crashes if (searchTypeIdx > -1 && SearchTypes.objs[searchTypeIdx]) { item.FPSItem.Search.searchTypes.push(SearchTypes.objs[searchTypeIdx]); item.FPSItem.Search.searchTypeIdx = searchTypeIdx; } item.FPSItem.Search.type = searchType; const minorVersion = OData__UIVersionString && OData__UIVersionString.split('.')[1] !== '0' ? true : false; if (minorVersion === true) { item = addItemIsA(item, ItemIsADraft); } else if (OData__UIVersionString) { item = addItemIsA(item, ItemIsAMajor); } ; if (item.PromotedState === 1) { item = addItemIsA(item, ItemIsUnPublished); } else if (item.PromotedState === 2) { item = addItemIsA(item, ItemIsPublished); } if (item['File_x0020_Type'] && ALLProgrammingFileKeys.indexOf(item['File_x0020_Type']) > -1) { item = addItemIsA(item, ItemIsCodeContent); } if (item.CheckoutUserId) { item = addItemIsA(item, ItemIsCheckedOut); } return item; } //# sourceMappingURL=addSearchFileV2.js.map