-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'a1mery-ChartCard-FilesByContentType_Improvements' into …
…'main'
- Loading branch information
Showing
7 changed files
with
116 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 47 additions & 47 deletions
94
samples/ChartCard-FilesByContentType/src/adaptiveCardExtensions/FileService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,48 @@ | ||
import { MSGraphClientV3 } from "@microsoft/sp-http"; | ||
import { AdaptiveCardExtensionContext } from '@microsoft/sp-adaptive-card-extension-base'; | ||
import { GraphFiles } from './types'; | ||
|
||
|
||
export interface IFileService { | ||
_getFiles(siteAddress: string, listTitle: string): Promise<GraphFiles>; | ||
} | ||
|
||
export class FileService implements IFileService { | ||
public context: AdaptiveCardExtensionContext; | ||
private MSGraphClient: MSGraphClientV3; | ||
|
||
constructor(context: AdaptiveCardExtensionContext) { | ||
this.context = context; | ||
} | ||
|
||
public async _getFiles(siteAddress: string, listTitle: string): Promise<GraphFiles> { | ||
let files: GraphFiles; | ||
try{ | ||
const client = await this._getClient(); | ||
const siteId = await this._getSiteId(client, siteAddress); | ||
const listId = await this._getListId(client, siteId, listTitle); | ||
files = await client.api("sites/"+siteId+"/lists/"+listId+"/items").select("contentType").version('beta').get(); | ||
} catch{ | ||
files = {value:[]}; | ||
} | ||
return files; | ||
} | ||
|
||
private async _getSiteId (client:MSGraphClientV3, siteAddress: string): Promise<string> { | ||
const hostname = siteAddress.split('/')[2]; | ||
const serverRelativeUrl = siteAddress.split(hostname)[1]; | ||
const siteId = await client.api("sites/"+hostname+":"+serverRelativeUrl).version('beta').get(); | ||
return siteId.id; | ||
} | ||
|
||
private async _getListId (client:MSGraphClientV3, siteId: string, listTitle: string): Promise<string> { | ||
const list = await client.api("sites/"+siteId+"/lists").version('beta').filter("displayName eq '"+listTitle+"'").get(); | ||
return list.value[0].id; | ||
} | ||
|
||
private async _getClient(): Promise<MSGraphClientV3> { | ||
if (this.MSGraphClient === undefined) | ||
this.MSGraphClient = await this.context.msGraphClientFactory.getClient("3"); | ||
return this.MSGraphClient; | ||
} | ||
import { MSGraphClientV3 } from "@microsoft/sp-http"; | ||
import { AdaptiveCardExtensionContext } from '@microsoft/sp-adaptive-card-extension-base'; | ||
import { GraphFiles } from './types'; | ||
|
||
|
||
export interface IFileService { | ||
_getFiles(siteAddress: string, listTitle: string): Promise<GraphFiles>; | ||
} | ||
|
||
export class FileService implements IFileService { | ||
public context: AdaptiveCardExtensionContext; | ||
private MSGraphClient: MSGraphClientV3; | ||
|
||
constructor(context: AdaptiveCardExtensionContext) { | ||
this.context = context; | ||
} | ||
|
||
public async _getFiles(siteAddress: string, listTitle: string): Promise<GraphFiles> { | ||
let files: GraphFiles; | ||
try{ | ||
const client = await this._getClient(); | ||
const siteId = await this._getSiteId(client, siteAddress); | ||
const listId = await this._getListId(client, siteId, listTitle); | ||
files = await client.api("sites/"+siteId+"/lists/"+listId+"/items").select("contentType").version('beta').get(); | ||
} catch{ | ||
files = {value:[]}; | ||
} | ||
return files; | ||
} | ||
|
||
private async _getSiteId (client:MSGraphClientV3, siteAddress: string): Promise<string> { | ||
const hostname = siteAddress.split('/')[2]; | ||
const serverRelativeUrl = siteAddress.split(hostname)[1]; | ||
const siteId = await client.api("sites/"+hostname+":"+serverRelativeUrl).version('beta').get(); | ||
return siteId.id; | ||
} | ||
|
||
private async _getListId (client:MSGraphClientV3, siteId: string, listTitle: string): Promise<string> { | ||
const list = await client.api("sites/"+siteId+"/lists").version('beta').filter("displayName eq '"+listTitle+"'").get(); | ||
return list.value[0].id; | ||
} | ||
|
||
private async _getClient(): Promise<MSGraphClientV3> { | ||
if (this.MSGraphClient === undefined) | ||
this.MSGraphClient = await this.context.msGraphClientFactory.getClient("3"); | ||
return this.MSGraphClient; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 13 additions & 18 deletions
31
samples/ChartCard-FilesByContentType/src/adaptiveCardExtensions/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,13 @@ | ||
export type File = { | ||
"@odata.etag"?: string; | ||
contentType: { | ||
id: string; | ||
name: string; | ||
} | ||
}; | ||
|
||
|
||
export type GraphFiles = { | ||
"@odata.context"?: string; | ||
value: File[]; | ||
}; | ||
|
||
export type PieFileData ={ | ||
name: string; | ||
total: number; | ||
} | ||
export type File = { | ||
"@odata.etag"?: string; | ||
contentType: { | ||
id: string; | ||
name: string; | ||
} | ||
}; | ||
|
||
|
||
export type GraphFiles = { | ||
"@odata.context"?: string; | ||
value: File[]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters