|
|
|
@ -26,12 +26,9 @@ export class ConfigState { |
|
|
|
} |
|
|
|
|
|
|
|
static getOne(key: string) { |
|
|
|
const selector = createSelector( |
|
|
|
[ConfigState], |
|
|
|
(state: Config.State) => { |
|
|
|
return state[key]; |
|
|
|
}, |
|
|
|
); |
|
|
|
const selector = createSelector([ConfigState], (state: Config.State) => { |
|
|
|
return state[key]; |
|
|
|
}); |
|
|
|
|
|
|
|
return selector; |
|
|
|
} |
|
|
|
@ -45,87 +42,71 @@ export class ConfigState { |
|
|
|
throw new Error('The argument must be a dot string or an string array.'); |
|
|
|
} |
|
|
|
|
|
|
|
const selector = createSelector( |
|
|
|
[ConfigState], |
|
|
|
(state: Config.State) => { |
|
|
|
return (keys as string[]).reduce((acc, val) => { |
|
|
|
if (acc) { |
|
|
|
return acc[val]; |
|
|
|
} |
|
|
|
|
|
|
|
return undefined; |
|
|
|
}, state); |
|
|
|
}, |
|
|
|
); |
|
|
|
const selector = createSelector([ConfigState], (state: Config.State) => { |
|
|
|
return (keys as string[]).reduce((acc, val) => { |
|
|
|
if (acc) { |
|
|
|
return acc[val]; |
|
|
|
} |
|
|
|
|
|
|
|
return undefined; |
|
|
|
}, state); |
|
|
|
}); |
|
|
|
|
|
|
|
return selector; |
|
|
|
} |
|
|
|
|
|
|
|
static getRoute(path?: string, name?: string) { |
|
|
|
const selector = createSelector( |
|
|
|
[ConfigState], |
|
|
|
(state: Config.State) => { |
|
|
|
const { flattedRoutes } = state; |
|
|
|
return (flattedRoutes as ABP.FullRoute[]).find(route => { |
|
|
|
if (path && route.path === path) { |
|
|
|
return route; |
|
|
|
} else if (name && route.name === name) { |
|
|
|
return route; |
|
|
|
} |
|
|
|
}); |
|
|
|
}, |
|
|
|
); |
|
|
|
static getRoute(path?: string, name?: string, url?: string) { |
|
|
|
const selector = createSelector([ConfigState], (state: Config.State) => { |
|
|
|
const { flattedRoutes } = state; |
|
|
|
return (flattedRoutes as ABP.FullRoute[]).find(route => { |
|
|
|
if (path && route.path === path) { |
|
|
|
return route; |
|
|
|
} else if (name && route.name === name) { |
|
|
|
return route; |
|
|
|
} else if (url && route.url === url) { |
|
|
|
return route; |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
return selector; |
|
|
|
} |
|
|
|
|
|
|
|
static getApiUrl(key?: string) { |
|
|
|
const selector = createSelector( |
|
|
|
[ConfigState], |
|
|
|
(state: Config.State): string => { |
|
|
|
return state.environment.apis[key || 'default'].url; |
|
|
|
}, |
|
|
|
); |
|
|
|
const selector = createSelector([ConfigState], (state: Config.State): string => { |
|
|
|
return state.environment.apis[key || 'default'].url; |
|
|
|
}); |
|
|
|
|
|
|
|
return selector; |
|
|
|
} |
|
|
|
|
|
|
|
static getSetting(key: string) { |
|
|
|
const selector = createSelector( |
|
|
|
[ConfigState], |
|
|
|
(state: Config.State) => { |
|
|
|
return snq(() => state.setting.values[key]); |
|
|
|
}, |
|
|
|
); |
|
|
|
const selector = createSelector([ConfigState], (state: Config.State) => { |
|
|
|
return snq(() => state.setting.values[key]); |
|
|
|
}); |
|
|
|
return selector; |
|
|
|
} |
|
|
|
|
|
|
|
static getSettings(keyword?: string) { |
|
|
|
const selector = createSelector( |
|
|
|
[ConfigState], |
|
|
|
(state: Config.State) => { |
|
|
|
if (keyword) { |
|
|
|
const keys = snq(() => Object.keys(state.setting.values).filter(key => key.indexOf(keyword) > -1), []); |
|
|
|
|
|
|
|
if (keys.length) { |
|
|
|
return keys.reduce((acc, key) => ({ ...acc, [key]: state.setting.values[key] }), {}); |
|
|
|
} |
|
|
|
const selector = createSelector([ConfigState], (state: Config.State) => { |
|
|
|
if (keyword) { |
|
|
|
const keys = snq(() => Object.keys(state.setting.values).filter(key => key.indexOf(keyword) > -1), []); |
|
|
|
|
|
|
|
if (keys.length) { |
|
|
|
return keys.reduce((acc, key) => ({ ...acc, [key]: state.setting.values[key] }), {}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return snq(() => state.setting.values, {}); |
|
|
|
}, |
|
|
|
); |
|
|
|
return snq(() => state.setting.values, {}); |
|
|
|
}); |
|
|
|
return selector; |
|
|
|
} |
|
|
|
|
|
|
|
static getGrantedPolicy(key: string) { |
|
|
|
const selector = createSelector( |
|
|
|
[ConfigState], |
|
|
|
(state: Config.State): boolean => { |
|
|
|
if (!key) return true; |
|
|
|
return snq(() => state.auth.grantedPolicies[key], false); |
|
|
|
}, |
|
|
|
); |
|
|
|
const selector = createSelector([ConfigState], (state: Config.State): boolean => { |
|
|
|
if (!key) return true; |
|
|
|
return snq(() => state.auth.grantedPolicies[key], false); |
|
|
|
}); |
|
|
|
|
|
|
|
return selector; |
|
|
|
} |
|
|
|
@ -141,47 +122,44 @@ export class ConfigState { |
|
|
|
if (!key) key = ''; |
|
|
|
|
|
|
|
const keys = key.split('::') as string[]; |
|
|
|
const selector = createSelector( |
|
|
|
[ConfigState], |
|
|
|
(state: Config.State) => { |
|
|
|
if (!state.localization) return defaultValue || key; |
|
|
|
|
|
|
|
const { defaultResourceName } = state.environment.localization; |
|
|
|
if (keys[0] === '') { |
|
|
|
if (!defaultResourceName) { |
|
|
|
throw new Error( |
|
|
|
`Please check your environment. May you forget set defaultResourceName?
|
|
|
|
const selector = createSelector([ConfigState], (state: Config.State) => { |
|
|
|
if (!state.localization) return defaultValue || key; |
|
|
|
|
|
|
|
const { defaultResourceName } = state.environment.localization; |
|
|
|
if (keys[0] === '') { |
|
|
|
if (!defaultResourceName) { |
|
|
|
throw new Error( |
|
|
|
`Please check your environment. May you forget set defaultResourceName?
|
|
|
|
Here is the example: |
|
|
|
{ production: false, |
|
|
|
localization: { |
|
|
|
defaultResourceName: 'MyProjectName' |
|
|
|
} |
|
|
|
}`,
|
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
keys[0] = snq(() => defaultResourceName); |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
let localization = (keys as any).reduce((acc, val) => { |
|
|
|
if (acc) { |
|
|
|
return acc[val]; |
|
|
|
} |
|
|
|
|
|
|
|
return undefined; |
|
|
|
}, state.localization.values); |
|
|
|
keys[0] = snq(() => defaultResourceName); |
|
|
|
} |
|
|
|
|
|
|
|
interpolateParams = interpolateParams.filter(params => params != null); |
|
|
|
if (localization && interpolateParams && interpolateParams.length) { |
|
|
|
interpolateParams.forEach(param => { |
|
|
|
localization = localization.replace(/[\'\"]?\{[\d]+\}[\'\"]?/, param); |
|
|
|
}); |
|
|
|
let localization = (keys as any).reduce((acc, val) => { |
|
|
|
if (acc) { |
|
|
|
return acc[val]; |
|
|
|
} |
|
|
|
|
|
|
|
if (typeof localization !== 'string') localization = ''; |
|
|
|
return localization || defaultValue || key; |
|
|
|
}, |
|
|
|
); |
|
|
|
return undefined; |
|
|
|
}, state.localization.values); |
|
|
|
|
|
|
|
interpolateParams = interpolateParams.filter(params => params != null); |
|
|
|
if (localization && interpolateParams && interpolateParams.length) { |
|
|
|
interpolateParams.forEach(param => { |
|
|
|
localization = localization.replace(/[\'\"]?\{[\d]+\}[\'\"]?/, param); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
if (typeof localization !== 'string') localization = ''; |
|
|
|
return localization || defaultValue || key; |
|
|
|
}); |
|
|
|
|
|
|
|
return selector; |
|
|
|
} |
|
|
|
|