fix sitepages query

This commit is contained in:
Abderahman88 2021-09-22 23:37:51 +02:00
parent b40eefb535
commit 6549bedc47
4 changed files with 9 additions and 8 deletions

View File

@ -38,12 +38,14 @@ None
Solution|Author(s) Solution|Author(s)
--------|--------- --------|---------
src/react-advanced-page-properties | [Mike Homol](https://homol.work), Principal Consultant, [ThreeWill](https://threewill.com/) src/react-advanced-page-properties | [Mike Homol](https://homol.work), Principal Consultant, [ThreeWill](https://threewill.com/)
react-advanced-page-properties | Abderahman Moujahid
## Version history ## Version history
Version|Date|Comments Version|Date|Comments
-------|----|-------- -------|----|--------
1.0|March 30, 2021|Initial release 1.0.0|March 30, 2021|Initial release
1.0.1|September 22, 2021|Added support for multi-language sites
## Disclaimer ## Disclaimer

View File

@ -3,7 +3,7 @@
"solution": { "solution": {
"name": "Advanced Page Properties", "name": "Advanced Page Properties",
"id": "daae06a2-8599-445c-93c0-3bd739305f56", "id": "daae06a2-8599-445c-93c0-3bd739305f56",
"version": "1.0.0.0", "version": "1.0.1.0",
"includeClientSideAssets": true, "includeClientSideAssets": true,
"isDomainIsolated": false, "isDomainIsolated": false,
"developer": { "developer": {

View File

@ -68,13 +68,13 @@ export default class AdvancedPagePropertiesWebPart extends BaseClientSideWebPart
private async getPageProperties(): Promise<void> { private async getPageProperties(): Promise<void> {
Log.Write("Getting Site Page fields..."); Log.Write("Getting Site Page fields...");
const list = sp.web.lists.getByTitle("Site Pages"); const list = await sp.web.lists.ensureSiteAssetsLibrary();
const fi = await list.fields(); const fi = await list.fields();
this.availableProperties = []; this.availableProperties = [];
Log.Write(`${fi.length.toString()} fields retrieved!`); Log.Write(`${fi.length.toString()} fields retrieved!`);
fi.forEach((f) => { fi.forEach((f) => {
if (!f.FromBaseType && !f.Hidden && !f.Sealed && f.SchemaXml.indexOf("ShowInListSettings=\"FALSE\"") === -1 if (!f.FromBaseType && !f.Hidden && f.SchemaXml.indexOf("ShowInListSettings=\"FALSE\"") === -1
&& f.TypeAsString !== "Boolean" && f.TypeAsString !== "Note" && f.TypeAsString !== "User") { && f.TypeAsString !== "Boolean" && f.TypeAsString !== "Note" && f.TypeAsString !== "User") {
this.availableProperties.push({ key: f.InternalName, text: f.Title }); this.availableProperties.push({ key: f.InternalName, text: f.Title });
Log.Write(f.TypeAsString); Log.Write(f.TypeAsString);

View File

@ -42,9 +42,9 @@ const AdvancedPageProperties: React.FunctionComponent<IAdvancedPagePropertiesPro
// Get the value(s) for the field from the list item itself // Get the value(s) for the field from the list item itself
var allValues: any = {}; var allValues: any = {};
const siteAssetsList = await sp.web.lists.ensureSitePagesLibrary();
if (props.context.pageContext.listItem !== undefined && props.context.pageContext.listItem !== null) { if (props.context.pageContext.listItem !== undefined && props.context.pageContext.listItem !== null) {
allValues = await sp.web.lists.getByTitle("Site Pages").items.getById(props.context.pageContext.listItem.id).select(...props.selectedProperties).get(); allValues = await siteAssetsList.items.getById(props.context.pageContext.listItem.id).select(...props.selectedProperties).get();
console.log(allValues);
} }
for (let i = 0; i < props.selectedProperties.length; i++) { for (let i = 0; i < props.selectedProperties.length; i++) {
@ -53,7 +53,7 @@ const AdvancedPageProperties: React.FunctionComponent<IAdvancedPagePropertiesPro
Log.Write(`Selected Property: ${prop}`); Log.Write(`Selected Property: ${prop}`);
// Get field information, in case anything is needed in conjunction with value types // Get field information, in case anything is needed in conjunction with value types
const field = await sp.web.lists.getByTitle("Site Pages").fields.getByInternalNameOrTitle(prop)(); const field = await siteAssetsList.fields.getByInternalNameOrTitle(prop)();
// Establish the values array // Establish the values array
var values: any[] = []; var values: any[] = [];
@ -123,7 +123,6 @@ const AdvancedPageProperties: React.FunctionComponent<IAdvancedPagePropertiesPro
* @returns * @returns
*/ */
const RenderPagePropValue = (prop: PageProperty) => { const RenderPagePropValue = (prop: PageProperty) => {
console.log(prop);
var retVal = _.map(prop.values, (val) => { var retVal = _.map(prop.values, (val) => {
if (val !== null) { if (val !== null) {
switch (prop.info.TypeAsString) { switch (prop.info.TypeAsString) {