2017-05-26 14:48:04 +09:00
|
|
|
export const getSetting = (setting, defaultValue) => {
|
|
|
|
|
|
|
|
if (Meteor.isServer) {
|
|
|
|
// look in public, private, and root
|
|
|
|
const rootSetting = Meteor.settings && Meteor.settings[setting];
|
|
|
|
const privateSetting = Meteor.settings && Meteor.settings.private && Meteor.settings.private[setting];
|
|
|
|
const publicSetting = Meteor.settings && Meteor.settings.public && Meteor.settings.public[setting];
|
|
|
|
|
|
|
|
// if setting is an object, "collect" properties from all three places
|
|
|
|
if (typeof rootSetting === 'object' || typeof privateSetting === 'object' || typeof publicSetting === 'object') {
|
|
|
|
return {
|
2017-08-09 19:20:21 +09:00
|
|
|
...defaultValue,
|
2017-05-26 14:48:04 +09:00
|
|
|
...rootSetting,
|
|
|
|
...privateSetting,
|
|
|
|
...publicSetting,
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return rootSetting || privateSetting || publicSetting || defaultValue;
|
|
|
|
}
|
|
|
|
|
2016-04-15 15:42:14 +09:00
|
|
|
} else {
|
2017-05-26 14:48:04 +09:00
|
|
|
// look only in public
|
|
|
|
const publicSetting = Meteor.settings && Meteor.settings.public && Meteor.settings.public[setting];
|
|
|
|
return publicSetting || defaultValue;
|
2016-04-15 15:42:14 +09:00
|
|
|
}
|
|
|
|
|
2017-05-26 14:48:04 +09:00
|
|
|
}
|
2016-04-15 15:42:14 +09:00
|
|
|
|
2016-12-12 15:00:56 +09:00
|
|
|
// Settings collection is deprecated
|
|
|
|
// getSetting = function (setting, defaultValue) {
|
2016-04-15 15:42:14 +09:00
|
|
|
|
2016-12-12 15:00:56 +09:00
|
|
|
// const collection = Telescope.settings.collection;
|
2016-04-15 15:42:14 +09:00
|
|
|
|
2016-12-12 15:00:56 +09:00
|
|
|
// if (typeof getSettingFromJSON(setting) !== "undefined") { // if on the server, look in Meteor.settings
|
2016-02-16 15:08:30 +09:00
|
|
|
|
2016-12-12 15:00:56 +09:00
|
|
|
// return getSettingFromJSON(setting);
|
2016-04-11 10:23:23 +09:00
|
|
|
|
2016-12-12 15:00:56 +09:00
|
|
|
// } else if (collection && collection.findOne() && typeof collection.findOne()[setting] !== "undefined") { // look in collection
|
2016-04-11 10:23:23 +09:00
|
|
|
|
2016-12-12 15:00:56 +09:00
|
|
|
// return Telescope.settings.collection.findOne()[setting];
|
2016-02-16 15:08:30 +09:00
|
|
|
|
2016-12-12 15:00:56 +09:00
|
|
|
// } else if (typeof defaultValue !== 'undefined') { // fallback to default
|
2016-02-16 15:08:30 +09:00
|
|
|
|
2016-12-12 15:00:56 +09:00
|
|
|
// return defaultValue;
|
2016-02-16 15:08:30 +09:00
|
|
|
|
2016-12-12 15:00:56 +09:00
|
|
|
// } else { // or return undefined
|
2016-02-16 15:08:30 +09:00
|
|
|
|
2016-12-12 15:00:56 +09:00
|
|
|
// return undefined;
|
|
|
|
|
|
|
|
// }
|
|
|
|
// };
|