@mikezimm/fps-core-v7
Version:
Library of reusable core interfaces, types and constants migrated from fps-library-v2
72 lines • 4.24 kB
JavaScript
/**
* 2024-09-03: Migrated from fps-library-v2\src\common\PropPaneHelp\preconfig
*/
export function getThisSitesPreConfigProps(PreConfiguredProps, thisProps, serverRelativeUrl) {
let testServerRelativeUrl = serverRelativeUrl.lastIndexOf('/') === serverRelativeUrl.length ? serverRelativeUrl : serverRelativeUrl + '/';
testServerRelativeUrl = testServerRelativeUrl.toLowerCase();
function getConfigs(PreConfigSettings, configType, values = []) {
if (!PreConfigSettings || PreConfigSettings.length === 0)
return values;
PreConfigSettings.map(preconfigX => {
//Added preconfig.location === '*' || so that if it has * it will apply everywhere
// https://github.com/mikezimm/fps-library-v2/issues/224 - updated to location.toLowerCase()
if (preconfigX.location === '*' || testServerRelativeUrl.indexOf(preconfigX.location.toLowerCase()) > -1) {
preconfigX.triggered = true;
Object.keys(preconfigX.props).map(prop => {
// if ( !thisProps[prop] ) {
const color = configType === 'preset' ? 'yellow' : configType === 'forced' ? 'red' : configType === '_class' ? 'blue' : configType === '_webpart' ? 'green' : 'na';
let className = getPropColorClass(thisProps[prop], preconfigX.props[prop], color);
values.push({ source: preconfigX.source, location: preconfigX.location, type: configType, prop: prop, value: preconfigX.props[prop], status: 'tbd', className: className, triggered: true });
// }
});
}
});
return values;
}
// https://github.com/mikezimm/pivottiles7/issues/393
const presets = getConfigs(PreConfiguredProps.preset, 'preset');
// https://github.com/mikezimm/pivottiles7/issues/393
// PreConfiguredProps.preset.map(preconfig => {
// //Added preconfig.location === '*' || so that if it has * it will apply everywhere
// if (preconfig.location === '*' || testServerRelativeUrl.indexOf(preconfig.location) > -1) {
// preconfig.triggered = true;
// Object.keys(preconfig.props).map(prop => {
// // if ( !thisProps[prop] ) {
// let className: IPreConfigColorClassName = getPropColorClass(thisProps[prop], preconfig.props[prop], 'yellow');
// presets.push({ source: preconfig.source, location: preconfig.location, type: 'preset', prop: prop, value: preconfig.props[prop], status: 'tbd', className: className, triggered: true });
// // }
// });
// }
// });
const forces = getConfigs(PreConfiguredProps.forced, 'forced');
// https://github.com/mikezimm/pivottiles7/issues/393
// PreConfiguredProps.forced.map(preconfig => {
// //Added preconfig.location === '*' || so that if it has * it will apply everywhere
// if (preconfig.location === '*' || testServerRelativeUrl.indexOf(preconfig.location) > -1) {
// preconfig.triggered = true;
// Object.keys(preconfig.props).map(prop => {
// // if ( thisProps[prop] !== preconfig.props[ prop ] ) {
// let className: IPreConfigColorClassName = getPropColorClass(thisProps[prop], preconfig.props[prop], 'red');
// forces.push({ source: preconfig.source, location: preconfig.location, type: 'forced', prop: prop, value: preconfig.props[prop], status: 'tbd', className: className, triggered: true });
// // }
// });
// }
// });
const _class = getConfigs(PreConfiguredProps._class, '_class');
const _webpart = getConfigs(PreConfiguredProps._webpart, '_webpart');
return { presets: presets, forces: forces, _class: _class, _webpart: _webpart };
}
export function getPropColorClass(actualProp, testProp, notEqualClass, defValue = 'na') {
let className = 'na';
if (actualProp === testProp) {
className = 'green';
}
else if (actualProp && (actualProp !== testProp)) {
className = notEqualClass;
}
else {
className = defValue;
}
return className;
}
//# sourceMappingURL=getThisSitesPreConfigProps.js.map