rename variables
This commit is contained in:
parent
07a667c664
commit
39795c78e2
|
@ -24,23 +24,22 @@ export class GraphService implements IGraphService {
|
||||||
public async GetWebParts(siteId: string, pageId: string): Promise<GraphWebPartCollection> {
|
public async GetWebParts(siteId: string, pageId: string): Promise<GraphWebPartCollection> {
|
||||||
try {
|
try {
|
||||||
const client = await this.Get_Client();
|
const client = await this.Get_Client();
|
||||||
const rawWebParts: GraphWebPartCollection = await client.api("sites/" + siteId + "/pages/" + pageId + "/webparts").version('beta').get();
|
const retrievedWebParts: GraphWebPartCollection = await client.api("sites/" + siteId + "/pages/" + pageId + "/webparts").version('beta').get();
|
||||||
return rawWebParts;
|
return retrievedWebParts;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async GetSitePages(siteId: string): Promise<GraphSitePage[]> {
|
public async GetSitePages(siteId: string): Promise<GraphSitePage[]> {
|
||||||
|
|
||||||
const pages: GraphSitePage[] = [];
|
const pages: GraphSitePage[] = [];
|
||||||
const client = await this.Get_Client();
|
const client = await this.Get_Client();
|
||||||
const rawPages: GraphSitePageCollection = await client.api("sites/" + siteId + "/pages").select("id,title").version('beta').get();
|
const retrievedPages: GraphSitePageCollection = await client.api("sites/" + siteId + "/pages").select("id,title").version('beta').get();
|
||||||
rawPages.value.forEach(rawPage => {
|
retrievedPages.value.forEach(page => {
|
||||||
pages.push(
|
pages.push(
|
||||||
{
|
{
|
||||||
id: rawPage.id,
|
id: page.id,
|
||||||
title: rawPage.title
|
title: page.title
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
|
@ -28,8 +28,8 @@ export type GraphWebPartData = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AggredatedWebParts = {
|
export type AggredatedWebParts = {
|
||||||
titles: string[];
|
WPTitles: string[];
|
||||||
count: number[];
|
WPCount: number[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type GraphSitePageCollection = {
|
export type GraphSitePageCollection = {
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { AggredatedWebParts, WebPart } from "../../types";
|
||||||
|
|
||||||
export interface IWebPartReportWebPartState {
|
export interface IWebPartReportWebPartState {
|
||||||
webPartList: WebPart[];
|
webPartList: WebPart[];
|
||||||
aggregatedWebPartList: AggredatedWebParts;
|
chartWebPartList: AggredatedWebParts;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
page: number;
|
page: number;
|
||||||
}
|
}
|
|
@ -49,9 +49,6 @@ const options: any = {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let webPartsCounts: number[] = [];
|
|
||||||
let webPartsTitles: string[] = [];
|
|
||||||
const aggregatedWebPartData = new Map<string, number>();
|
|
||||||
|
|
||||||
export default class WebPartReport extends React.Component<IWebPartReportProps, IWebPartReportWebPartState> {
|
export default class WebPartReport extends React.Component<IWebPartReportProps, IWebPartReportWebPartState> {
|
||||||
|
|
||||||
|
@ -60,57 +57,56 @@ export default class WebPartReport extends React.Component<IWebPartReportProps,
|
||||||
this.state = {
|
this.state = {
|
||||||
loading: true,
|
loading: true,
|
||||||
webPartList: [],
|
webPartList: [],
|
||||||
aggregatedWebPartList: { titles: [], count: [] },
|
chartWebPartList: { WPTitles: [], WPCount: [] },
|
||||||
page: 1
|
page: 1
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public async componentDidMount(): Promise<void> {
|
public async componentDidMount(): Promise<void> {
|
||||||
await this._setChartData();
|
await this._getWebParts();
|
||||||
}
|
}
|
||||||
|
|
||||||
private loadingData(): Promise<ChartData> {
|
private loadingData(): Promise<ChartData> {
|
||||||
|
|
||||||
return new Promise<ChartData>((resolve, _reject) => {
|
return new Promise<ChartData>((resolve, _reject) => {
|
||||||
|
|
||||||
let countWP: number[] = [];
|
|
||||||
countWP = this.state.aggregatedWebPartList.count
|
|
||||||
const data: ChartData =
|
const data: ChartData =
|
||||||
{
|
{
|
||||||
labels: this.state.aggregatedWebPartList.titles.length > 0 ? this.state.aggregatedWebPartList.titles : [],
|
labels: this.state.chartWebPartList.WPTitles.length > 0 ? this.state.chartWebPartList.WPTitles : [],
|
||||||
datasets: [{ label: "WebParts", data: countWP.length > 0 ? countWP : [] }]
|
datasets: [{
|
||||||
|
label: "WebParts",
|
||||||
|
data: this.state.chartWebPartList.WPCount.length > 0 ? this.state.chartWebPartList.WPCount : []
|
||||||
|
}]
|
||||||
};
|
};
|
||||||
resolve(data);
|
resolve(data);
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async _setChartData(): Promise<void> {
|
public async _getWebParts(): Promise<void> {
|
||||||
webPartsCounts = [];
|
|
||||||
webPartsTitles = [];
|
const webPartsCounts: number[] = [];
|
||||||
aggregatedWebPartData.clear();
|
const webPartsTitles: string[] = [];
|
||||||
|
const webPartMap = new Map<string, number>();
|
||||||
|
|
||||||
|
webPartMap.clear();
|
||||||
|
|
||||||
const siteWebParts = await _getSiteWebParts(this.props.GraphService, this.props.siteId.toString());
|
const siteWebParts = await _getSiteWebParts(this.props.GraphService, this.props.siteId.toString());
|
||||||
siteWebParts.forEach(e => {
|
siteWebParts.forEach(e => {
|
||||||
if (!aggregatedWebPartData.has(e.title)) {
|
if (!webPartMap.has(e.title)) {
|
||||||
aggregatedWebPartData.set(e.title, 1);
|
webPartMap.set(e.title, 1);
|
||||||
} else {
|
} else {
|
||||||
aggregatedWebPartData.set(e.title, aggregatedWebPartData.get(e.title) + 1)
|
webPartMap.set(e.title, webPartMap.get(e.title) + 1)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
aggregatedWebPartData.forEach(a => {
|
|
||||||
webPartsCounts.push(a);
|
|
||||||
});
|
|
||||||
|
|
||||||
aggregatedWebPartData.forEach((value, key) => {
|
webPartMap.forEach((value, key) => {
|
||||||
|
webPartsCounts.push(value);
|
||||||
webPartsTitles.push(key);
|
webPartsTitles.push(key);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
webPartList: siteWebParts,
|
webPartList: siteWebParts,
|
||||||
aggregatedWebPartList: {
|
chartWebPartList: {
|
||||||
titles: webPartsTitles,
|
WPTitles: webPartsTitles,
|
||||||
count: webPartsCounts
|
WPCount: webPartsCounts
|
||||||
},
|
},
|
||||||
loading: false
|
loading: false
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue