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,CAAC;oBAC1D,EAAE,EAAE,QAAQ,CAAC,yBAAW,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;oBAC7D,IAAI,EAAE,yBAAW,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC;oBACrD,QAAQ,EAAE,aAAK,CAAC,eAAe,CAAC,yBAAW,CAAC,mBAAmB,CAAC,WAAW,EAAE,KAAK,CAAC,EAAE,OAAO,CAAC;iBAC9F,CAAC,CAAC;YACL,CAAC,EAAE,UAAC,KAAU;gBACZ,MAAM,CAAC,KAAK,CAAC,CAAC;YAChB,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACL,CAAC;IACH,wBAAC;AAAD,CAhMA,AAgMC,CAhM8C,KAAK,CAAC,SAAS,GAgM7D","file":"webparts/myRecentDocuments/components/MyRecentDocuments.js","sourcesContent":["import * as React from 'react';\nimport {\n css,\n DocumentCard,\n DocumentCardPreview,\n DocumentCardTitle,\n DocumentCardActivity,\n Spinner\n} from 'office-ui-fabric-react';\n\nimport styles from '../MyRecentDocuments.module.scss';\nimport { IMyRecentDocumentsWebPartProps } from '../IMyRecentDocumentsWebPartProps';\nimport { SPHttpClient, SPHttpClientConfiguration, SPHttpClientResponse, ODataVersion, ISPHttpClientConfiguration } from '@microsoft/sp-http';\nimport { ITrendingDocument } from '../../ITrendingDocument';\nimport { IActorInformation } from '../../IActorInformation';\nimport { SearchUtils, ISearchQueryResponse, IRow, ICell, IEdge } from '../../SearchUtils';\nimport { Utils } from '../../Utils';\n\nexport interface IMyRecentDocumentsProps extends IMyRecentDocumentsWebPartProps {\n httpClient: SPHttpClient;\n siteUrl: string;\n}\n\nexport interface IMyRecentDocumentsState {\n myDocuments: ITrendingDocument[];\n loading: boolean;\n error: string;\n}\n\nexport default class MyRecentDocuments extends React.Component {\n constructor(props: IMyRecentDocumentsProps, state: IMyRecentDocumentsState) {\n super(props);\n\n this.state = {\n myDocuments: [] as ITrendingDocument[],\n loading: true,\n error: null\n };\n }\n\n public componentDidMount(): void {\n this.loadMyDocuments(this.props.siteUrl, this.props.numberOfDocuments);\n }\n\n public componentDidUpdate(prevProps: IMyRecentDocumentsProps, prevState: IMyRecentDocumentsState, prevContext: any): void {\n if (this.props.numberOfDocuments !== prevProps.numberOfDocuments ||\n this.props.siteUrl !== prevProps.siteUrl && (\n this.props.numberOfDocuments && this.props.siteUrl\n )) {\n this.loadMyDocuments(this.props.siteUrl, this.props.numberOfDocuments);\n }\n }\n\n public render(): JSX.Element {\n const loading: JSX.Element = this.state.loading ?
:
;\n const error: JSX.Element = this.state.error ?
Error: {this.state.error}
:
;\n const documents: JSX.Element[] = this.state.myDocuments.map((doc: ITrendingDocument, i: number) => {\n const iconUrl: string = `https://spoprod-a.akamaihd.net/files/odsp-next-prod_ship-2016-08-15_20160815.002/odsp-media/images/filetypes/32/${doc.extension}.png`;\n return (\n \n \n \n \n \n );\n });\n return (\n
\n
{this.props.title}
\n {loading}\n {error}\n {documents}\n
\n
\n );\n }\n\n private loadMyDocuments(siteUrl: string, numberOfDocuments: number): void {\n const myDocuments: ITrendingDocument[] = [];\n this.props.httpClient.get(`${siteUrl}/_api/search/query?querytext='*'&properties='GraphQuery:actor(me\\\\,or(action\\\\:1001\\\\,action\\\\:1003)),GraphRankingModel:{\"features\"\\\\:[{\"function\"\\\\:\"EdgeTime\"}]}'&selectproperties='Author,AuthorOwsUser,DocId,DocumentPreviewMetadata,Edges,EditorOwsUser,FileExtension,FileType,HitHighlightedProperties,HitHighlightedSummary,LastModifiedTime,LikeCountLifetime,ListID,ListItemID,OriginalPath,Path,Rank,SPWebUrl,SecondaryFileExtension,ServerRedirectedURL,SiteTitle,Title,ViewCountLifetime,siteID,uniqueID,webID'&rowlimit=${numberOfDocuments}&ClientType='MyRecentDocuments'&RankingModelId='0c77ded8-c3ef-466d-929d-905670ea1d72'`, SPHttpClient.configurations.v1, {\n headers: {\n 'Accept': 'application/json;odata=nometadata',\n 'odata-version': ''\n }\n })\n .then((response: SPHttpClientResponse): Promise => {\n return response.json();\n })\n .then((response: ISearchQueryResponse): Promise => {\n if (!response ||\n !response.PrimaryQueryResult ||\n !response.PrimaryQueryResult.RelevantResults ||\n response.PrimaryQueryResult.RelevantResults.RowCount === 0) {\n return Promise.resolve();\n }\n\n let actorId: number = undefined;\n for (let i: number = 0; i < response.PrimaryQueryResult.RelevantResults.Table.Rows.length; i++) {\n const row: IRow = response.PrimaryQueryResult.RelevantResults.Table.Rows[i];\n const edges: IEdge[] = JSON.parse(SearchUtils.getValueFromResults('Edges', row.Cells));\n if (edges.length < 1) {\n continue;\n }\n\n // we can get multiple edges back so let's show the information from the latest one\n let latestEdge: IEdge = edges[0];\n if (edges.length > 1) {\n let latestEdgeDate: Date = new Date(latestEdge.Properties.Time);\n for (let i: number = 1; i < edges.length; i++) {\n const edgeDate: Date = new Date(edges[i].Properties.Time);\n if (edgeDate > latestEdgeDate) {\n latestEdge = edges[i];\n latestEdgeDate = edgeDate;\n }\n }\n }\n\n if (!actorId) {\n // since all edges that we're retrieving are personal (I viewed, I modified)\n // we only need to get the actor ID once because it's the same on all edges (me)\n actorId = latestEdge.ActorId;\n }\n\n const cells: ICell[] = row.Cells;\n const date: Date = new Date(latestEdge.Properties.Time);\n const dateString: string = (date.getMonth() + 1) + '/' + date.getDate() + '/' + date.getFullYear();\n myDocuments.push({\n id: SearchUtils.getValueFromResults('DocId', cells),\n url: SearchUtils.getValueFromResults('ServerRedirectedURL', cells),\n title: SearchUtils.getValueFromResults('Title', cells),\n previewImageUrl: SearchUtils.getPreviewImageUrl(cells, siteUrl),\n extension: SearchUtils.getValueFromResults('FileType', cells),\n activity: {\n actorId: latestEdge.ActorId,\n date: dateString,\n name: SearchUtils.getActionName(latestEdge.Properties.Action)\n }\n });\n }\n\n return this.getActorsInfo(actorId, siteUrl);\n }).\n then((actorInformation: IActorInformation): void => {\n if (actorInformation) {\n for (let i: number = 0; i < myDocuments.length; i++) {\n if (myDocuments[i].activity.actorId !== actorInformation.id) {\n continue;\n }\n\n myDocuments[i].activity.actorName = actorInformation.name;\n myDocuments[i].activity.actorPhotoUrl = actorInformation.photoUrl;\n }\n }\n\n this.setState({\n loading: false,\n error: null,\n myDocuments: myDocuments\n });\n }, (error: any): void => {\n this.setState({\n loading: false,\n error: error,\n myDocuments: []\n });\n });\n }\n\n private getActorsInfo(actorId: number, siteUrl: string): Promise {\n if (!actorId) {\n return Promise.resolve();\n }\n\n return new Promise((resolve: (actorInformation: IActorInformation) => void, reject: (error: any) => void): void => {\n this.props.httpClient.get(`${siteUrl}/_api/search/query?querytext='WorkId:${actorId}'&selectproperties='DocId,Title,WorkEmail'&ClientType='MyRecentDocuments'&SourceId='b09a7990-05ea-4af9-81ef-edfab16c4e31'`, SPHttpClient.configurations.v1 , {\n headers: {\n 'Accept': 'application/json;odata=nometadata',\n 'odata-version': ''\n }\n })\n .then((response: SPHttpClientResponse): Promise => {\n return response.json();\n })\n .then((response: ISearchQueryResponse): Promise => {\n if (!response ||\n !response.PrimaryQueryResult ||\n !response.PrimaryQueryResult.RelevantResults ||\n response.PrimaryQueryResult.RelevantResults.RowCount === 0) {\n return Promise.resolve();\n }\n\n const cells: ICell[] = response.PrimaryQueryResult.RelevantResults.Table.Rows[0].Cells;\n\n resolve({\n email: SearchUtils.getValueFromResults('WorkEmail', cells),\n id: parseInt(SearchUtils.getValueFromResults('DocId', cells)),\n name: SearchUtils.getValueFromResults('Title', cells),\n photoUrl: Utils.getUserPhotoUrl(SearchUtils.getValueFromResults('WorkEmail', cells), siteUrl)\n });\n }, (error: any): void => {\n reject(error);\n });\n });\n }\n}\n"],"sourceRoot":"..\\..\\..\\..\\src"}