From 057580b7937c2cef3ce632fe3550fafca9ae2cc4 Mon Sep 17 00:00:00 2001 From: Delgermurun Date: Sat, 28 Mar 2015 18:30:26 +0900 Subject: [PATCH] Settings package --- .meteor/packages | 1 + .meteor/versions | 1 + client/helpers/handlebars.js | 5 -- client/main.js | 4 +- client/views/admin/settings_form.html | 7 -- client/views/common/css.js | 14 ++-- client/views/common/footer.js | 6 +- client/views/common/layout.js | 8 +- client/views/errors/no_account.js | 4 +- client/views/errors/no_invite.js | 4 +- client/views/nav/logo.js | 6 +- client/views/nav/nav.js | 6 +- client/views/nav/user_menu.js | 2 +- client/views/posts/modules/post_admin.js | 6 +- client/views/posts/post_list/posts_list.js | 4 +- client/views/posts/post_view_nav.js | 6 +- collections/comments.js | 2 +- collections/posts.js | 6 +- lib/analytics.js | 20 ++--- lib/config/at_config.js | 6 +- lib/debug.js | 4 +- lib/helpers.js | 2 +- lib/router/admin.js | 21 +---- lib/router/filters.js | 2 +- lib/router/posts.js | 18 ++--- lib/router/server.js | 6 +- lib/router/users.js | 6 +- lib/vote.js | 6 +- packages/telescope-base/lib/base.js | 29 ++++--- packages/telescope-base/package.js | 19 +++-- packages/telescope-blank/lib/settings.js | 2 +- packages/telescope-blank/package.js | 5 +- packages/telescope-daily/lib/routes.js | 8 +- packages/telescope-daily/package.js | 9 ++- packages/telescope-email/lib/server/email.js | 38 ++++----- packages/telescope-email/package.js | 7 +- .../lib/client/autoform-postthumbnail.js | 4 +- packages/telescope-embedly/lib/embedly.js | 10 +-- .../lib/server/get_embedly_data.js | 12 +-- packages/telescope-embedly/package.js | 1 + packages/telescope-i18n/i18n.js | 8 +- packages/telescope-invites/lib/invites.js | 6 +- .../telescope-invites/lib/server/invites.js | 4 +- packages/telescope-invites/package.js | 1 + .../telescope-kadira/lib/kadira-settings.js | 8 +- .../telescope-kadira/lib/server/kadira.js | 6 +- packages/telescope-kadira/package.js | 5 +- packages/telescope-lib/lib/lib.js | 32 ++------ packages/telescope-lib/lib/permissions.js | 6 +- packages/telescope-lib/package.js | 13 ++- .../lib/client/post_share.js | 4 +- packages/telescope-module-share/package.js | 11 ++- .../lib/client/templates/newsletter_banner.js | 4 +- .../telescope-newsletter/lib/newsletter.js | 18 ++--- .../lib/server/campaign.js | 10 +-- .../telescope-newsletter/lib/server/cron.js | 8 +- .../lib/server/mailchimp.js | 24 +++--- .../telescope-newsletter/lib/server/routes.js | 4 +- packages/telescope-newsletter/package.js | 1 + .../client/templates/notifications_menu.js | 8 +- .../telescope-notifications/lib/herald.js | 6 +- .../lib/notifications.js | 20 ++--- packages/telescope-notifications/package.js | 3 +- packages/telescope-rss/lib/server/rss.js | 6 +- packages/telescope-rss/package.js | 10 ++- .../telescope-search/lib/client/routes.js | 4 +- packages/telescope-search/package.js | 9 ++- packages/telescope-seo/lib/routes.js | 2 +- packages/telescope-seo/lib/seo.js | 4 +- packages/telescope-seo/lib/server/sitemaps.js | 2 +- packages/telescope-seo/package.js | 1 + .../telescope-settings/lib/client/helpers.js | 6 ++ .../lib/client/language_changer.js | 12 +++ .../lib/client/templates/settings_form.html | 7 ++ .../lib/client/templates}/settings_form.js | 33 +++----- packages/telescope-settings/lib/router.js | 18 +++++ .../lib/server/publications.js | 9 ++- .../telescope-settings/lib}/settings.js | 79 +++++++++++-------- packages/telescope-settings/package.js | 38 +++++++++ .../lib/client/templates/single_day.js | 8 +- packages/telescope-singleday/lib/routes.js | 6 +- .../lib/client/templates/tagline_banner.js | 2 +- .../telescope-tagline-banner/lib/tagline.js | 4 +- packages/telescope-tagline-banner/package.js | 3 +- .../lib/client/templates/categories_menu.js | 4 +- .../lib/server/phone_home.js | 6 +- server/migrations.js | 4 +- server/publications/users.js | 2 +- server/scoring.js | 2 +- server/start.js | 6 +- tests/jasmine/client/unit/navSpec.js | 6 +- 91 files changed, 445 insertions(+), 385 deletions(-) delete mode 100644 client/views/admin/settings_form.html create mode 100644 packages/telescope-settings/lib/client/helpers.js create mode 100644 packages/telescope-settings/lib/client/language_changer.js create mode 100644 packages/telescope-settings/lib/client/templates/settings_form.html rename {client/views/admin => packages/telescope-settings/lib/client/templates}/settings_form.js (70%) create mode 100644 packages/telescope-settings/lib/router.js rename server/publications/settings.js => packages/telescope-settings/lib/server/publications.js (60%) rename {collections => packages/telescope-settings/lib}/settings.js (85%) create mode 100644 packages/telescope-settings/package.js diff --git a/.meteor/packages b/.meteor/packages index 23d01ae48..a499c8817 100644 --- a/.meteor/packages +++ b/.meteor/packages @@ -94,3 +94,4 @@ telescope-tagline-banner # Custom Packages telescope-seo telescope-messages +telescope-settings diff --git a/.meteor/versions b/.meteor/versions index bed7a09b2..317e6e56f 100644 --- a/.meteor/versions +++ b/.meteor/versions @@ -134,6 +134,7 @@ telescope-releases@0.1.0 telescope-rss@0.0.0 telescope-search@0.0.0 telescope-seo@0.0.5 +telescope-settings@0.0.0 telescope-singleday@0.1.0 telescope-subscribe-to-posts@0.1.0 telescope-tagline-banner@0.1.0 diff --git a/client/helpers/handlebars.js b/client/helpers/handlebars.js index 0d3a02367..8a599c116 100644 --- a/client/helpers/handlebars.js +++ b/client/helpers/handlebars.js @@ -13,11 +13,6 @@ UI.registerHelper('eachWithRank', function(items, options) { }); return out; }); - -UI.registerHelper('getSetting', function(setting, defaultArgument){ - setting = getSetting(setting, defaultArgument); - return setting; -}); UI.registerHelper('isLoggedIn', function() { return !!Meteor.user(); }); diff --git a/client/main.js b/client/main.js index 3c807bd7a..9d8f037ec 100644 --- a/client/main.js +++ b/client/main.js @@ -1,5 +1,5 @@ // Session variables -Session.set('postsLimit', getSetting('postsPerPage', 10)); +Session.set('postsLimit', Settings.get('postsPerPage', 10)); // Sort postModules array position using modulePositions as index postModules = _.sortBy(postModules, 'order'); @@ -12,4 +12,4 @@ Meteor.startup(function () { $('#rss-link').attr('title', i18n.t('new_posts')); }); -// AutoForm.debug(); \ No newline at end of file +// AutoForm.debug(); diff --git a/client/views/admin/settings_form.html b/client/views/admin/settings_form.html deleted file mode 100644 index b01ada090..000000000 --- a/client/views/admin/settings_form.html +++ /dev/null @@ -1,7 +0,0 @@ - \ No newline at end of file diff --git a/client/views/common/css.js b/client/views/common/css.js index 39287b387..e3c97d35f 100644 --- a/client/views/common/css.js +++ b/client/views/common/css.js @@ -15,21 +15,21 @@ Template[getTemplate('css')].helpers({ // loop over all properties, and add the relevant selectors _.each(properties, function (selector, property) { - css += selector + "{\n " + property + ": " + getSetting(color) + ";\n}\n"; + css += selector + "{\n " + property + ": " + Settings.get(color) + ";\n}\n"; }); }); return css; }, headerTextColorHalfOpacity: function () { - return tinycolor(getSetting("headerTextColor")).setAlpha(0.5); + return tinycolor(Settings.get("headerTextColor")).setAlpha(0.5); }, buttonColorHalfOpacity: function () { - return tinycolor(getSetting("buttonColor")).setAlpha(0.5); + return tinycolor(Settings.get("buttonColor")).setAlpha(0.5); }, hideAuthClass: function () { - + var authClass = ''; - var authMethods = getSetting('authMethods', ["email"]); + var authMethods = Settings.get('authMethods', ["email"]); var selectors = [ {name: 'email', selector: ".at-pwd-form"}, {name: 'twitter', selector: "#at-twitter"}, @@ -50,5 +50,5 @@ Template[getTemplate('css')].helpers({ return authClass.slice(0, - 2) + "{display:none !important}"; - } -}); \ No newline at end of file + } +}); diff --git a/client/views/common/footer.js b/client/views/common/footer.js index 62eb3e900..90e0eb613 100644 --- a/client/views/common/footer.js +++ b/client/views/common/footer.js @@ -1,7 +1,7 @@ Template[getTemplate('footer')].helpers({ footerCode: function(){ - return getSetting('footerCode'); - }, + return Settings.get('footerCode'); + }, footerClass: function(){ return Session.get('isPostsList') ? 'absolute' : 'static'; }, @@ -11,4 +11,4 @@ Template[getTemplate('footer')].helpers({ getTemplate: function () { return getTemplate(this.template); } -}); \ No newline at end of file +}); diff --git a/client/views/common/layout.js b/client/views/common/layout.js index 57b0d38c7..2e1305046 100644 --- a/client/views/common/layout.js +++ b/client/views/common/layout.js @@ -6,7 +6,7 @@ Template[getTemplate('layout')].helpers({ return getTemplate('nav'); }, navLayout: function () { - return getSetting('navLayout', 'top-nav'); + return Settings.get('navLayout', 'top-nav'); }, messages: function () { return getTemplate('messages'); @@ -24,7 +24,7 @@ Template[getTemplate('layout')].helpers({ return getTemplate('css'); }, extraCode: function() { - return getSetting('extraCode'); + return Settings.get('extraCode'); }, heroModules: function () { return _.sortBy(heroModules, 'order'); @@ -48,7 +48,7 @@ Template[getTemplate('layout')].rendered = function(){ var link = document.createElement('link'); link.type = 'image/x-icon'; link.rel = 'shortcut icon'; - link.href = getSetting('faviconUrl', '/img/favicon.ico'); + link.href = Settings.get('faviconUrl', '/img/favicon.ico'); document.getElementsByTagName('head')[0].appendChild(link); }; @@ -60,4 +60,4 @@ Template[getTemplate('layout')].events({ $('body').removeClass('mobile-nav-open'); } } -}); \ No newline at end of file +}); diff --git a/client/views/errors/no_account.js b/client/views/errors/no_account.js index 9ffe7dbff..8ae8be649 100644 --- a/client/views/errors/no_account.js +++ b/client/views/errors/no_account.js @@ -1,6 +1,6 @@ Template[getTemplate('no_account')].helpers({ landingPageText: function(){ - return getSetting("landingPageText"); + return Settings.get("landingPageText"); } }); Template[getTemplate('no_account')].events({ @@ -9,4 +9,4 @@ Template[getTemplate('no_account')].events({ Router.go('/'); }); } -}); \ No newline at end of file +}); diff --git a/client/views/errors/no_invite.js b/client/views/errors/no_invite.js index 83d5f98d7..02174e462 100644 --- a/client/views/errors/no_invite.js +++ b/client/views/errors/no_invite.js @@ -1,5 +1,5 @@ Template[getTemplate('no_invite')].helpers({ afterSignupText: function(){ - return getSetting("afterSignupText"); + return Settings.get("afterSignupText"); } -}); \ No newline at end of file +}); diff --git a/client/views/nav/logo.js b/client/views/nav/logo.js index 2a7724c2a..0bf1b9377 100644 --- a/client/views/nav/logo.js +++ b/client/views/nav/logo.js @@ -1,8 +1,8 @@ Template[getTemplate('logo')].helpers({ site_title: function(){ - return getSetting('title', "Telescope"); + return Settings.get('title', "Telescope"); }, logo_url: function(){ - return getSetting('logoUrl'); + return Settings.get('logoUrl'); } -}); \ No newline at end of file +}); diff --git a/client/views/nav/nav.js b/client/views/nav/nav.js index 409a3ff40..4ad37b863 100644 --- a/client/views/nav/nav.js +++ b/client/views/nav/nav.js @@ -1,7 +1,7 @@ Template[getTemplate('nav')].helpers({ headerClass: function () { var headerClass = ""; - var bgBrightness = tinycolor(getSetting('headerColor')).getBrightness(); + var bgBrightness = tinycolor(Settings.get('headerColor')).getBrightness(); if (bgBrightness < 50) { headerClass += " dark-bg"; } else if (bgBrightness < 130) { @@ -33,7 +33,7 @@ Template[getTemplate('nav')].helpers({ if (this.length > 3) { dropdownClass += "long-dropdown"; } - if (getSetting('navLayout', 'top-nav') == 'top-nav' && getThemeSetting('useDropdowns', true)) { + if (Settings.get('navLayout', 'top-nav') == 'top-nav' && getThemeSetting('useDropdowns', true)) { dropdownClass += "has-dropdown"; } else { dropdownClass += "no-dropdown"; @@ -61,4 +61,4 @@ Template[getTemplate('nav')].events({ e.stopPropagation(); // Make sure we don't immediately close the mobile nav again. See layout.js event handler. $('body').toggleClass('mobile-nav-open'); } -}); \ No newline at end of file +}); diff --git a/client/views/nav/user_menu.js b/client/views/nav/user_menu.js index a5de45b4b..eb1c0308b 100644 --- a/client/views/nav/user_menu.js +++ b/client/views/nav/user_menu.js @@ -8,7 +8,7 @@ Template[getTemplate('userMenu')].helpers({ menuMode: function () { if (!!this.mobile) { return 'list'; - } else if (getSetting('navLayout', 'top-nav') === 'top-nav') { + } else if (Settings.get('navLayout', 'top-nav') === 'top-nav') { return 'dropdown'; } else { return 'accordion'; diff --git a/client/views/posts/modules/post_admin.js b/client/views/posts/modules/post_admin.js index 53decc4ca..95fe0daec 100644 --- a/client/views/posts/modules/post_admin.js +++ b/client/views/posts/modules/post_admin.js @@ -3,7 +3,7 @@ Template[getTemplate('postAdmin')].helpers({ return this.status == STATUS_PENDING; }, showUnapprove: function(){ - return !!getSetting('requirePostsApproval') && this.status == STATUS_APPROVED; + return !!Settings.get('requirePostsApproval') && this.status == STATUS_APPROVED; }, shortScore: function(){ return Math.floor(this.score*1000)/1000; @@ -14,9 +14,9 @@ Template[getTemplate('postAdmin')].events({ 'click .approve-link': function(e, instance){ Meteor.call('approvePost', this); e.preventDefault(); - }, + }, 'click .unapprove-link': function(e, instance){ Meteor.call('unapprovePost', this); e.preventDefault(); } -}); \ No newline at end of file +}); diff --git a/client/views/posts/post_list/posts_list.js b/client/views/posts/post_list/posts_list.js index ae12fb9dd..2d057042d 100644 --- a/client/views/posts/post_list/posts_list.js +++ b/client/views/posts/post_list/posts_list.js @@ -4,7 +4,7 @@ Template[getTemplate('posts_list')].created = function() { Template[getTemplate('posts_list')].helpers({ postsLayout: function () { - return getSetting('postsLayout', 'posts-list'); + return Settings.get('postsLayout', 'posts-list'); }, description: function () { var controller = Iron.controller(); @@ -40,4 +40,4 @@ Template[getTemplate('posts_list')].helpers({ postsListSort: function () { return getTemplate('postsListSort'); } -}); \ No newline at end of file +}); diff --git a/client/views/posts/post_view_nav.js b/client/views/posts/post_view_nav.js index 964568acd..a85bf7cfd 100644 --- a/client/views/posts/post_view_nav.js +++ b/client/views/posts/post_view_nav.js @@ -1,13 +1,13 @@ Template[getTemplate('postViewsNav')].helpers({ showNav: function () { - var navElements = getSetting('postViews', _.pluck(viewsMenu, 'route')); + var navElements = Settings.get('postViews', _.pluck(viewsMenu, 'route')); var navCount = (typeof navElements === "array") ? navElements.length : _.keys(navElements).length; return navCount > 1; }, menuItems: function () { var defaultViews = _.pluck(viewsMenu, 'route'); var menuItems = _.filter(viewsMenu, function (item) { - if (!_.contains(getSetting('postViews', defaultViews), item.route) || (item.adminOnly && !isAdmin(Meteor.user()))) { + if (!_.contains(Settings.get('postViews', defaultViews), item.route) || (item.adminOnly && !isAdmin(Meteor.user()))) { // don't show the item return false; } @@ -15,4 +15,4 @@ Template[getTemplate('postViewsNav')].helpers({ }); return menuItems; } -}); \ No newline at end of file +}); diff --git a/collections/comments.js b/collections/comments.js index 5aaa9c954..a251b194e 100644 --- a/collections/comments.js +++ b/collections/comments.js @@ -226,7 +226,7 @@ Meteor.methods({ if (!hasAdminRights) { var timeSinceLastComment = timeSinceLast(user, Comments), - commentInterval = Math.abs(parseInt(getSetting('commentInterval',15))); + commentInterval = Math.abs(parseInt(Settings.get('commentInterval',15))); // check that user waits more than 15 seconds between comments if((timeSinceLastComment < commentInterval)) diff --git a/collections/posts.js b/collections/posts.js index 82cc948f6..cc7202b6a 100644 --- a/collections/posts.js +++ b/collections/posts.js @@ -231,7 +231,7 @@ getPostProperties = function (post) { // default status for new posts getDefaultPostStatus = function (user) { var hasAdminRights = typeof user === 'undefined' ? false : isAdmin(user); - if (hasAdminRights || !getSetting('requirePostsApproval', false)) { + if (hasAdminRights || !Settings.get('requirePostsApproval', false)) { // if user is admin, or else post approval is not required return STATUS_APPROVED } else { @@ -408,8 +408,8 @@ Meteor.methods({ var timeSinceLastPost=timeSinceLast(user, Posts), numberOfPostsInPast24Hours=numberOfItemsInPast24Hours(user, Posts), - postInterval = Math.abs(parseInt(getSetting('postInterval', 30))), - maxPostsPer24Hours = Math.abs(parseInt(getSetting('maxPostsPerDay', 30))); + postInterval = Math.abs(parseInt(Settings.get('postInterval', 30))), + maxPostsPer24Hours = Math.abs(parseInt(Settings.get('maxPostsPerDay', 30))); // check that user waits more than X seconds between posts if(timeSinceLastPost < postInterval) diff --git a/lib/analytics.js b/lib/analytics.js index b7b49a874..ebd27d52f 100644 --- a/lib/analytics.js +++ b/lib/analytics.js @@ -1,7 +1,7 @@ analyticsInit = _.once(function() { // Mixpanel - if (mixpanelId=getSetting("mixpanelId")){ + if (mixpanelId=Settings.get("mixpanelId")){ (function (c, a) { window.mixpanel = a; var b, d, h, e; @@ -33,7 +33,7 @@ analyticsInit = _.once(function() { } // GoSquared - if (goSquaredId = getSetting("goSquaredId")) { + if (goSquaredId = Settings.get("goSquaredId")) { window.GoSquared = {}; GoSquared.acct = goSquaredId; window._gstc_lt = +new Date(); @@ -45,7 +45,7 @@ analyticsInit = _.once(function() { } // Clicky - if ((clickyId = getSetting("clickyId"))){ + if ((clickyId = Settings.get("clickyId"))){ clicky_site_ids = []; clicky_site_ids.push(clickyId); (function() { @@ -58,7 +58,7 @@ analyticsInit = _.once(function() { } // Google Analytics - if (googleAnalyticsId = getSetting("googleAnalyticsId")){ + if (googleAnalyticsId = Settings.get("googleAnalyticsId")){ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), @@ -67,18 +67,18 @@ analyticsInit = _.once(function() { ga('create', googleAnalyticsId, 'auto'); - } + } }); analyticsRequest = function() { - + // Google Analytics if (typeof window.ga !== 'undefined'){ ga('send', 'pageview', { 'page': window.location.pathname - }); - } + }); + } // Mixpanel if(typeof mixpanel !== 'undefined' && typeof mixpanel.people !== 'undefined'){ @@ -87,7 +87,7 @@ analyticsRequest = function() { mixpanel.people.identify(currentUserEmail); mixpanel.people.set({ 'username': getDisplayName(Meteor.user()), - '$last_login': new Date(), + '$last_login': new Date(), '$created': moment(Meteor.user().createdAt)._d, '$email': currentUserEmail }); @@ -110,4 +110,4 @@ analyticsRequest = function() { clicky.log(encodeURIComponent(window.location.pathname), getCurrentTemplate(), "pageview"); } -}; \ No newline at end of file +}; diff --git a/lib/config/at_config.js b/lib/config/at_config.js index c6140df35..197f708ba 100644 --- a/lib/config/at_config.js +++ b/lib/config/at_config.js @@ -1,6 +1,6 @@ /* global AccountsTemplates: false, - getSetting: false + Settings: false */ ////////////////////////////////// @@ -9,8 +9,8 @@ if (Meteor.isServer) { Meteor.startup(function () { - Accounts.emailTemplates.siteName = getSetting('title'); - Accounts.emailTemplates.from = getSetting('defaultEmail'); + Accounts.emailTemplates.siteName = Settings.get('title'); + Accounts.emailTemplates.from = Settings.get('defaultEmail'); }); } diff --git a/lib/debug.js b/lib/debug.js index 9e4f3457a..016b14809 100644 --- a/lib/debug.js +++ b/lib/debug.js @@ -1,4 +1,4 @@ clog = function (s) { - if(getSetting('debug', false)) + if(Settings.get('debug', false)) console.log(s); -} \ No newline at end of file +}; diff --git a/lib/helpers.js b/lib/helpers.js index e57f508f8..ba398080c 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -102,7 +102,7 @@ getDomain = function(url){ return urlObject.parse(url).hostname.replace('www.', ''); }; invitesEnabled = function () { - return getSetting("requireViewInvite") || getSetting("requirePostInvite"); + return Settings.get("requireViewInvite") || Settings.get("requirePostInvite"); }; getOutgoingUrl = function(url){ return getRouteUrl('out', {}, {query: {url: url}}); diff --git a/lib/router/admin.js b/lib/router/admin.js index 0aed01334..9f9349aee 100644 --- a/lib/router/admin.js +++ b/lib/router/admin.js @@ -3,24 +3,9 @@ AdminController = RouteController.extend({ template: "adminWrapper" }); - + Meteor.startup(function (){ - // Settings - - Router.route('/settings', { - controller: AdminController, - name: 'settings', - // layoutTemplate: getTemplate('adminLayout'), - data: function () { - // we only have one set of settings for now - return { - hasSettings: !!Settings.find().count(), - settings: Settings.findOne() - } - } - }); - // Loading (for testing purposes) Router.route('/loading', { @@ -34,5 +19,5 @@ Meteor.startup(function (){ name: 'toolbox', template: getTemplate('toolbox') }); - -}); \ No newline at end of file + +}); diff --git a/lib/router/filters.js b/lib/router/filters.js index 382591c0a..fcc4a5113 100644 --- a/lib/router/filters.js +++ b/lib/router/filters.js @@ -133,7 +133,7 @@ Router._filters = { setTitle: function () { // if getTitle is set, use it. Otherwise default to site title. - var title = (typeof this.getTitle === 'function') ? this.getTitle() : getSetting("title", "Telescope"); + var title = (typeof this.getTitle === 'function') ? this.getTitle() : Settings.get("title", "Telescope"); document.title = title; } diff --git a/lib/router/posts.js b/lib/router/posts.js index b7451398b..81fce328a 100644 --- a/lib/router/posts.js +++ b/lib/router/posts.js @@ -18,7 +18,7 @@ PostsListController = RouteController.extend({ // note: most of the time this.params.slug will be empty this._terms = { view: this.view, - limit: this.params.limit || getSetting('postsPerPage', 10), + limit: this.params.limit || Settings.get('postsPerPage', 10), category: this.params.slug }; @@ -57,7 +57,7 @@ PostsListController = RouteController.extend({ hasMorePosts: this._terms.limit == postsCount, loadMoreHandler: function () { - var count = parseInt(Session.get('postsLimit')) + parseInt(getSetting('postsPerPage', 10)); + var count = parseInt(Session.get('postsLimit')) + parseInt(Settings.get('postsPerPage', 10)); var categorySegment = Session.get('categorySlug') ? Session.get('categorySlug') + '/' : ''; // TODO: use Router.path here? @@ -67,12 +67,12 @@ PostsListController = RouteController.extend({ }, getTitle: function () { - return i18n.t(this.view) + ' - ' + getSetting('title', "Telescope"); + return i18n.t(this.view) + ' - ' + Settings.get('title', "Telescope"); }, getDescription: function () { if (Router.current().route.getName() == 'posts_default') { // return site description on root path - return getSetting('description'); + return Settings.get('description'); } else { return i18n.t(_.findWhere(viewsMenu, {label: this.view}).description); } @@ -86,7 +86,7 @@ PostsListController = RouteController.extend({ }); var getDefaultViewController = function () { - var defaultView = getSetting('defaultView', 'top'); + var defaultView = Settings.get('defaultView', 'top'); defaultView = defaultView.charAt(0).toUpperCase() + defaultView.slice(1); return eval("Posts"+defaultView+"Controller"); }; @@ -96,8 +96,8 @@ Meteor.startup(function () { PostsDefaultController = getDefaultViewController().extend({ getTitle: function () { - var title = getSetting('title', 'Telescope'); - var tagline = getSetting('tagline'); + var title = Settings.get('title', 'Telescope'); + var tagline = Settings.get('tagline'); var fullTitle = !!tagline ? title + ' – ' + tagline : title ; return fullTitle; } @@ -143,7 +143,7 @@ PostPageController = RouteController.extend({ getTitle: function () { if (!!this.post()) - return this.post().title + ' - ' + getSetting('title', "Telescope"); + return this.post().title + ' - ' + Settings.get('title', "Telescope"); }, onBeforeAction: function() { @@ -255,4 +255,4 @@ Meteor.startup(function () { } }); -}); \ No newline at end of file +}); diff --git a/lib/router/server.js b/lib/router/server.js index 537f7acc5..ffb2948c2 100644 --- a/lib/router/server.js +++ b/lib/router/server.js @@ -1,6 +1,6 @@ var increasePostClicks = function(postId, ip){ - + var clickEvent = { name: 'click', properties: { @@ -53,7 +53,7 @@ Meteor.startup(function (){ var emailProperties = { profileUrl: getProfileUrl(user), username: getUserName(user), - siteTitle: getSetting('title'), + siteTitle: Settings.get('title'), siteUrl: getSiteUrl() }; html = Handlebars.templates[getTemplate('emailAccountApproved')](emailProperties); @@ -62,4 +62,4 @@ Meteor.startup(function (){ } }); -}); \ No newline at end of file +}); diff --git a/lib/router/users.js b/lib/router/users.js index ecffa7486..fe17e0e0b 100644 --- a/lib/router/users.js +++ b/lib/router/users.js @@ -7,7 +7,7 @@ UserPageController = RouteController.extend({ coreSubscriptions.subscribe('singleUser', this.params._idOrSlug) ] }, - + getUser: function () { return Meteor.users.findOne({slug: this.params._idOrSlug}); }, @@ -26,7 +26,7 @@ UserPageController = RouteController.extend({ }, getTitle: function () { - return getDisplayName(this.getUser()) + ' - ' + getSetting('title', "Telescope"); + return getDisplayName(this.getUser()) + ' - ' + Settings.get('title', "Telescope"); }, getDescription: function () { @@ -122,4 +122,4 @@ Meteor.startup(function () { } }); -}); \ No newline at end of file +}); diff --git a/lib/vote.js b/lib/vote.js index 3d118d798..3f8cad091 100644 --- a/lib/vote.js +++ b/lib/vote.js @@ -82,7 +82,7 @@ upvoteItem = function (collection, item, user) { // if karma redistribution is enabled, give karma to all previous upvoters of the post // (but not to the person doing the upvoting) - if (getSetting('redistributeKarma', false)) { + if (Settings.get('redistributeKarma', false)) { _.each(item.upvoters, function (upvoterId) { // share the karma equally among all upvoters, but cap the value at 0.1 var karmaIncrease = Math.min(0.1, votePower/item.upvoters.length); @@ -122,7 +122,7 @@ downvoteItem = function (collection, item, user) { item = downvoteMethodCallbacks.reduce(function(result, currentFunction) { return currentFunction(collection, result, user); }, item); - + // ----------------------------------------------------------------------- // votePower = getVotePower(user); @@ -239,7 +239,7 @@ cancelDownvote = function (collection, item, user) { item = cancelDownvoteMethodCallbacks.reduce(function(result, currentFunction) { return currentFunction(collection, result, user); }, item); - + // ----------------------------------------------------------------------- // votePower = getVotePower(user); diff --git a/packages/telescope-base/lib/base.js b/packages/telescope-base/lib/base.js index ae4c0b039..2699386af 100644 --- a/packages/telescope-base/lib/base.js +++ b/packages/telescope-base/lib/base.js @@ -3,7 +3,6 @@ // array containing properties to be added to the post/settings/comments schema on startup. addToPostSchema = []; addToCommentsSchema = []; -addToSettingsSchema = []; addToUserSchema = []; SimpleSchema.extendOptions({ @@ -25,7 +24,7 @@ postStatuses = [ value: 3, label: 'Rejected' } -] +]; STATUS_PENDING=1; STATUS_APPROVED=2; @@ -96,7 +95,7 @@ viewsMenu = [ label: 'scheduled', description: 'future_scheduled_posts', adminOnly: true - }, + }, ]; // array containing items in the admin menu @@ -139,7 +138,7 @@ userMenu = [ label: 'sign_out', description: 'sign_out' } -] +]; // ------------------------------------- Views -------------------------------- // @@ -160,19 +159,19 @@ viewParameters.top = function (terms) { return { options: {sort: {sticky: -1, score: -1}} }; -} +}; viewParameters.new = function (terms) { return { options: {sort: {sticky: -1, postedAt: -1}} }; -} +}; viewParameters.best = function (terms) { return { options: {sort: {sticky: -1, baseScore: -1}} }; -} +}; viewParameters.pending = function (terms) { return { @@ -182,21 +181,21 @@ viewParameters.pending = function (terms) { options: {sort: {createdAt: -1}}, showFuture: true }; -} +}; viewParameters.scheduled = function (terms) { return { find: {postedAt: {$gte: new Date()}}, options: {sort: {postedAt: -1}} }; -} +}; viewParameters.userPosts = function (terms) { return { find: {userId: terms.userId}, options: {limit: 5, sort: {postedAt: -1}} }; -} +}; viewParameters.userUpvotedPosts = function (terms) { var user = Meteor.users.findOne(terms.userId); @@ -205,7 +204,7 @@ viewParameters.userUpvotedPosts = function (terms) { find: {_id: {$in: postsIds}, userId: {$ne: terms.userId}}, // exclude own posts options: {limit: 5, sort: {postedAt: -1}} }; -} +}; viewParameters.userDownvotedPosts = function (terms) { var user = Meteor.users.findOne(terms.userId); @@ -215,7 +214,7 @@ viewParameters.userDownvotedPosts = function (terms) { find: {_id: {$in: postsIds}}, options: {limit: 5, sort: {postedAt: -1}} }; -} +}; heroModules = []; @@ -287,7 +286,7 @@ postMeta = [ template: 'postAdmin', order: 50 } -] +]; // ------------------------------ Callbacks ------------------------------ // postClassCallbacks = []; @@ -358,7 +357,7 @@ userProfileEdit = [ template: 'userAccount', order: 1 } -] +]; userProfileCompleteChecks.push( function(user) { @@ -373,7 +372,7 @@ templates = {} getTemplate = function (name) { // if template has been overwritten, return this; else return template name return !!templates[name] ? templates[name] : name; -} +}; // ------------------------------ Theme Settings ------------------------------ // diff --git a/packages/telescope-base/package.js b/packages/telescope-base/package.js index e69900554..b5b7ea447 100644 --- a/packages/telescope-base/package.js +++ b/packages/telescope-base/package.js @@ -14,17 +14,16 @@ Package.onUse(function (api) { 'STATUS_PENDING', 'STATUS_APPROVED', 'STATUS_REJECTED', - + 'adminMenu', 'viewsMenu', 'userMenu', - 'addToPostSchema', - 'addToCommentsSchema', - 'addToSettingsSchema', + 'addToPostSchema', + 'addToCommentsSchema', 'addToUserSchema', - 'preloadSubscriptions', - 'primaryNav', - 'secondaryNav', + 'preloadSubscriptions', + 'primaryNav', + 'secondaryNav', 'mobileNav', 'viewParameters', @@ -45,7 +44,7 @@ Package.onUse(function (api) { 'postAfterSubmitMethodCallbacks', 'postApproveCallbacks', - + 'postEditRenderedCallbacks', 'postEditClientCallbacks', 'postEditMethodCallbacks', @@ -71,14 +70,14 @@ Package.onUse(function (api) { 'downvoteMethodCallbacks', 'cancelUpvoteMethodCallbacks', 'cancelDownvoteMethodCallbacks', - + 'userEditRenderedCallbacks', 'userEditClientCallbacks', 'userProfileCompleteChecks', 'userProfileDisplay', 'userProfileEdit', 'userCreatedCallbacks', - + 'getTemplate', 'templates', diff --git a/packages/telescope-blank/lib/settings.js b/packages/telescope-blank/lib/settings.js index 4cc5ae2c2..b939c703d 100644 --- a/packages/telescope-blank/lib/settings.js +++ b/packages/telescope-blank/lib/settings.js @@ -11,4 +11,4 @@ var customSetting = { } } } -addToSettingsSchema.push(customSetting); \ No newline at end of file +Settings.addToSchema(customSetting); diff --git a/packages/telescope-blank/package.js b/packages/telescope-blank/package.js index 65600c66e..44787291c 100644 --- a/packages/telescope-blank/package.js +++ b/packages/telescope-blank/package.js @@ -19,6 +19,7 @@ Package.onUse(function (api) { 'iron:router', // routing package 'telescope-base', // basic Telescope hooks and objects 'telescope-lib', // useful functions + 'telescope-settings', 'telescope-i18n', // internationalization wrapper 'fourseven:scss' // SCSS compilation package ]); @@ -69,7 +70,7 @@ Package.onUse(function (api) { api.add_files([ 'lib/server/publications.js' - ], ['server']); + ], ['server']); // i18n languages (must come last) @@ -83,4 +84,4 @@ Package.onUse(function (api) { 'myFunction' ]); -}); \ No newline at end of file +}); diff --git a/packages/telescope-daily/lib/routes.js b/packages/telescope-daily/lib/routes.js index 8a1980aa5..ef5d87d06 100644 --- a/packages/telescope-daily/lib/routes.js +++ b/packages/telescope-daily/lib/routes.js @@ -6,7 +6,7 @@ var coreSubscriptions = new SubsManager({ }); PostsDailyController = RouteController.extend({ - + onBeforeAction: function () { this.render(getTemplate('postListTop'), {to: 'postListTop'}); this.next(); @@ -31,7 +31,7 @@ PostsDailyController = RouteController.extend({ }, getTitle: function () { - return i18n.t('daily') + ' - ' + getSetting('title', "Telescope"); + return i18n.t('daily') + ' - ' + Settings.get('title', "Telescope"); }, getDescription: function () { @@ -42,10 +42,10 @@ PostsDailyController = RouteController.extend({ }); Meteor.startup(function () { - + Router.route('/daily/:days?', { name: 'postsDaily', controller: PostsDailyController }); -}); \ No newline at end of file +}); diff --git a/packages/telescope-daily/package.js b/packages/telescope-daily/package.js index fbe415759..4f6c8726f 100644 --- a/packages/telescope-daily/package.js +++ b/packages/telescope-daily/package.js @@ -3,10 +3,11 @@ Package.describe({summary: "Telescope daily view"}); Package.onUse(function (api) { api.use([ - 'telescope-lib', - 'telescope-base', + 'telescope-lib', + 'telescope-base', + 'telescope-settings', 'iron:router', - 'meteorhacks:fast-render', + 'meteorhacks:fast-render', 'meteorhacks:subs-manager', 'tap:i18n', 'telescope-singleday', @@ -43,4 +44,4 @@ Package.onUse(function (api) { ], ["client", "server"]); api.export(['PostsDailyController']); -}); \ No newline at end of file +}); diff --git a/packages/telescope-email/lib/server/email.js b/packages/telescope-email/lib/server/email.js index 474356219..d0ae60d81 100644 --- a/packages/telescope-email/lib/server/email.js +++ b/packages/telescope-email/lib/server/email.js @@ -15,26 +15,26 @@ getEmailTemplate = function (template) { buildEmailTemplate = function (htmlContent) { var emailProperties = { - headerColor: getSetting('headerColor', '#444444'), - buttonColor: getSetting('buttonColor', '#DD3416'), - siteName: getSetting('title'), - tagline: getSetting('tagline'), + headerColor: Settings.get('headerColor', '#444444'), + buttonColor: Settings.get('buttonColor', '#DD3416'), + siteName: Settings.get('title'), + tagline: Settings.get('tagline'), siteUrl: getSiteUrl(), body: htmlContent, unsubscribe: '', accountLink: getSiteUrl()+'account', - footer: getSetting('emailFooter'), - logoUrl: getSetting('logoUrl'), - logoHeight: getSetting('logoHeight'), - logoWidth: getSetting('logoWidth') + footer: Settings.get('emailFooter'), + logoUrl: Settings.get('logoUrl'), + logoHeight: Settings.get('logoHeight'), + logoWidth: Settings.get('logoWidth') } var emailHTML = Handlebars.templates[getTemplate('emailWrapper')](emailProperties); var inlinedHTML = juice(emailHTML); - + var doctype = '' - + return doctype+inlinedHTML; } @@ -42,13 +42,13 @@ sendEmail = function(to, subject, html, text){ // TODO: limit who can send emails // TODO: fix this error: Error: getaddrinfo ENOTFOUND - - var from = getSetting('defaultEmail', 'noreply@example.com'); - var siteName = getSetting('title', 'Telescope'); + + var from = Settings.get('defaultEmail', 'noreply@example.com'); + var siteName = Settings.get('title', 'Telescope'); var subject = '['+siteName+'] '+subject; if (typeof text == 'undefined'){ - // Auto-generate text version if it doesn't exist. Has bugs, but should be good enough. + // Auto-generate text version if it doesn't exist. Has bugs, but should be good enough. var text = htmlToText.fromString(html, { wordwrap: 130 }); @@ -62,9 +62,9 @@ sendEmail = function(to, subject, html, text){ // console.log('text: '+text); var email = { - from: from, - to: to, - subject: subject, + from: from, + to: to, + subject: subject, text: text, html: html } @@ -82,7 +82,7 @@ buildAndSendEmail = function (to, subject, template, properties) { Meteor.methods({ testEmail: function () { if(isAdminById(this.userId)){ - var email = buildAndSendEmail (getSetting('defaultEmail'), 'Telescope email test', 'emailTest', {date: new Date()}); + var email = buildAndSendEmail (Settings.get('defaultEmail'), 'Telescope email test', 'emailTest', {date: new Date()}); } } }) @@ -102,4 +102,4 @@ function adminUserCreationNotification (user) { }); return user; } -userCreatedCallbacks.push(adminUserCreationNotification); \ No newline at end of file +userCreatedCallbacks.push(adminUserCreationNotification); diff --git a/packages/telescope-email/package.js b/packages/telescope-email/package.js index 821e73908..f962c4e8a 100644 --- a/packages/telescope-email/package.js +++ b/packages/telescope-email/package.js @@ -13,6 +13,7 @@ Package.onUse(function (api) { api.use([ 'iron:router', 'telescope-base', + 'telescope-settings', 'telescope-lib', 'telescope-i18n', 'tap:i18n' @@ -41,7 +42,7 @@ Package.onUse(function (api) { 'lib/server/templates/emailTest.handlebars', 'lib/server/templates/emailWrapper.handlebars', ], ['server']); - + api.add_files([ "i18n/de.i18n.json", "i18n/en.i18n.json", @@ -52,9 +53,9 @@ Package.onUse(function (api) { ], ["client", "server"]); api.export([ - 'buildEmailTemplate', + 'buildEmailTemplate', 'sendEmail', 'buildAndSendEmail', 'getEmailTemplate' ]); -}); \ No newline at end of file +}); diff --git a/packages/telescope-embedly/lib/client/autoform-postthumbnail.js b/packages/telescope-embedly/lib/client/autoform-postthumbnail.js index 0c8f5f57f..d6c5205d6 100644 --- a/packages/telescope-embedly/lib/client/autoform-postthumbnail.js +++ b/packages/telescope-embedly/lib/client/autoform-postthumbnail.js @@ -61,8 +61,8 @@ Template.afPostThumbnail.helpers({ return atts; }, style: function () { - var thumbnailWidth = getSetting('thumbnailWidth', 200); - var thumbnailHeight = getSetting('thumbnailHeight', 125); + var thumbnailWidth = Settings.get('thumbnailWidth', 200); + var thumbnailHeight = Settings.get('thumbnailHeight', 125); return "width: "+thumbnailWidth+"px; height: "+thumbnailHeight+"px;" }, embedlyKeyExists: function () { diff --git a/packages/telescope-embedly/lib/embedly.js b/packages/telescope-embedly/lib/embedly.js index 2146bc53b..28ea01c65 100644 --- a/packages/telescope-embedly/lib/embedly.js +++ b/packages/telescope-embedly/lib/embedly.js @@ -26,7 +26,7 @@ var mediaProperty = { addToPostSchema.push(mediaProperty); postThumbnail.push({ - template: 'postThumbnail', + template: 'postThumbnail', order: 15 }); @@ -41,7 +41,7 @@ var embedlyKeyProperty = { } } } -addToSettingsSchema.push(embedlyKeyProperty); +Settings.addToSchema(embedlyKeyProperty); var thumbnailWidthProperty = { propertyName: 'thumbnailWidth', @@ -53,7 +53,7 @@ var thumbnailWidthProperty = { } } } -addToSettingsSchema.push(thumbnailWidthProperty); +Settings.addToSchema(thumbnailWidthProperty); var thumbnailHeightProperty = { propertyName: 'thumbnailHeight', @@ -65,10 +65,10 @@ var thumbnailHeightProperty = { } } } -addToSettingsSchema.push(thumbnailHeightProperty); +Settings.addToSchema(thumbnailHeightProperty); // add callback that adds "has-thumbnail" or "no-thumbnail" CSS classes postClassCallbacks.push(function (post, postClass){ var thumbnailClass = !!post.thumbnailUrl ? "has-thumbnail" : "no-thumbnail"; return postClass + " " + thumbnailClass; -}); \ No newline at end of file +}); diff --git a/packages/telescope-embedly/lib/server/get_embedly_data.js b/packages/telescope-embedly/lib/server/get_embedly_data.js index a9a2c682e..14ad08abc 100644 --- a/packages/telescope-embedly/lib/server/get_embedly_data.js +++ b/packages/telescope-embedly/lib/server/get_embedly_data.js @@ -1,9 +1,9 @@ getEmbedlyData = function (url) { var data = {} var extractBase = 'http://api.embed.ly/1/extract'; - var embedlyKey = getSetting('embedlyKey'); - var thumbnailWidth = getSetting('thumbnailWidth', 200); - var thumbnailHeight = getSetting('thumbnailHeight', 125); + var embedlyKey = Settings.get('embedlyKey'); + var thumbnailWidth = Settings.get('thumbnailWidth', 200); + var thumbnailHeight = Settings.get('thumbnailHeight', 125); if(!embedlyKey) { // fail silently to still let the post be submitted as usual @@ -12,7 +12,7 @@ getEmbedlyData = function (url) { } try { - + var result = Meteor.http.get(extractBase, { params: { key: embedlyKey, @@ -106,11 +106,11 @@ Meteor.methods({ return getEmbedlyData(url); }, embedlyKeyExists: function () { - return !!getSetting('embedlyKey'); + return !!Settings.get('embedlyKey'); }, regenerateEmbedlyData: function (post) { if (can.edit(Meteor.user(), post)) { addMediaAfterSubmit(post); } } -}); \ No newline at end of file +}); diff --git a/packages/telescope-embedly/package.js b/packages/telescope-embedly/package.js index c177f3c44..3e8297c76 100644 --- a/packages/telescope-embedly/package.js +++ b/packages/telescope-embedly/package.js @@ -12,6 +12,7 @@ Package.onUse( function(api) { api.use([ 'telescope-lib', 'telescope-base', + 'telescope-settings', 'aldeed:autoform', 'tap:i18n', 'fourseven:scss', diff --git a/packages/telescope-i18n/i18n.js b/packages/telescope-i18n/i18n.js index 77b9d1fce..6fdabd4c8 100644 --- a/packages/telescope-i18n/i18n.js +++ b/packages/telescope-i18n/i18n.js @@ -33,15 +33,15 @@ setLanguage = function (language) { i18n = { t: function (str, options) { if (Meteor.isServer) { - return TAPi18n.__(str, options, getSetting('language', 'en')); + return TAPi18n.__(str, options, Settings.get('language', 'en')); } else { - return TAPi18n.__(str, options); + return TAPi18n.__(str, options); } } }; Meteor.startup(function () { - + if (Meteor.isClient) { // doesn't quite work yet @@ -56,7 +56,7 @@ Meteor.startup(function () { // } // }); - setLanguage(getSetting('language', 'en')); + setLanguage(Settings.get('language', 'en')); } }); diff --git a/packages/telescope-invites/lib/invites.js b/packages/telescope-invites/lib/invites.js index e237bb611..624175b0a 100644 --- a/packages/telescope-invites/lib/invites.js +++ b/packages/telescope-invites/lib/invites.js @@ -35,19 +35,19 @@ userProfileEdit.push({ function setStartingInvites (user) { // give new users a few invites (default to 3) - user.inviteCount = getSetting('startInvitesCount', 3); + user.inviteCount = Settings.get('startInvitesCount', 3); return user; } userCreatedCallbacks.push(setStartingInvites); function checkIfInvited (user) { - // if the new user has been invited + // if the new user has been invited // set her status accordingly and update invitation info if(invitesEnabled() && getEmail(user)){ var invite = Invites.findOne({ invitedUserEmail : getEmail(user) }); if(invite){ var invitedBy = Meteor.users.findOne({ _id : invite.invitingUserId }); - + user = _.extend(user, { isInvited: true, invitedBy: invitedBy._id, diff --git a/packages/telescope-invites/lib/server/invites.js b/packages/telescope-invites/lib/server/invites.js index 1bc4ba179..2b9412ede 100644 --- a/packages/telescope-invites/lib/server/invites.js +++ b/packages/telescope-invites/lib/server/invites.js @@ -59,7 +59,7 @@ Meteor.methods({ }}); } - var communityName = getSetting('title','Telescope'), + var communityName = Settings.get('title','Telescope'), emailSubject = 'You are invited to try '+communityName, emailProperties = { newUser : typeof user === 'undefined', @@ -79,4 +79,4 @@ Meteor.methods({ newUser : typeof user === 'undefined' }; } -}); \ No newline at end of file +}); diff --git a/packages/telescope-invites/package.js b/packages/telescope-invites/package.js index 88558ca54..f4bb9e40a 100644 --- a/packages/telescope-invites/package.js +++ b/packages/telescope-invites/package.js @@ -18,6 +18,7 @@ Package.onUse(function (api) { 'tap:i18n', 'iron:router', 'telescope-base', + 'telescope-settings', 'telescope-lib', 'telescope-i18n', 'aldeed:simple-schema', diff --git a/packages/telescope-kadira/lib/kadira-settings.js b/packages/telescope-kadira/lib/kadira-settings.js index 22e1f2d4c..2cb4c4741 100644 --- a/packages/telescope-kadira/lib/kadira-settings.js +++ b/packages/telescope-kadira/lib/kadira-settings.js @@ -8,8 +8,8 @@ var kadiraAppIdProperty = { group: 'kadira' } } -} -addToSettingsSchema.push(kadiraAppIdProperty); +}; +Settings.addToSchema(kadiraAppIdProperty); var kadiraAppSecretProperty = { propertyName: 'kadiraAppSecret', @@ -22,5 +22,5 @@ var kadiraAppSecretProperty = { private: true } } -} -addToSettingsSchema.push(kadiraAppSecretProperty); \ No newline at end of file +}; +Settings.addToSchema(kadiraAppSecretProperty); diff --git a/packages/telescope-kadira/lib/server/kadira.js b/packages/telescope-kadira/lib/server/kadira.js index 6150b74b0..22381089c 100644 --- a/packages/telescope-kadira/lib/server/kadira.js +++ b/packages/telescope-kadira/lib/server/kadira.js @@ -1,5 +1,5 @@ Meteor.startup(function() { - if(!!getSetting('kadiraAppId') && !!getSetting('kadiraAppSecret')){ - Kadira.connect(getSetting('kadiraAppId'), getSetting('kadiraAppSecret')); + if(!!Settings.get('kadiraAppId') && !!Settings.get('kadiraAppSecret')){ + Kadira.connect(Settings.get('kadiraAppId'), Settings.get('kadiraAppSecret')); } -}); \ No newline at end of file +}); diff --git a/packages/telescope-kadira/package.js b/packages/telescope-kadira/package.js index a76e491b4..10103276b 100644 --- a/packages/telescope-kadira/package.js +++ b/packages/telescope-kadira/package.js @@ -8,8 +8,9 @@ Package.onUse(function (api) { api.use([ 'templating', - 'telescope-lib', + 'telescope-lib', 'telescope-base', + 'telescope-settings', 'tap:i18n', 'meteorhacks:kadira@2.20.1' ], ['client', 'server']); @@ -27,4 +28,4 @@ Package.onUse(function (api) { "i18n/en.i18n.json" ], ["client", "server"]); -}); \ No newline at end of file +}); diff --git a/packages/telescope-lib/lib/lib.js b/packages/telescope-lib/lib/lib.js index afbc759b2..4dc6dddcf 100644 --- a/packages/telescope-lib/lib/lib.js +++ b/packages/telescope-lib/lib/lib.js @@ -1,29 +1,7 @@ getSiteUrl = function () { - return getSetting('siteUrl', Meteor.absoluteUrl()); -} - -getSetting = function(setting, defaultValue){ - var settings = Settings.find().fetch()[0]; - - if (Meteor.isServer && Meteor.settings && !!Meteor.settings[setting]) { // if on the server, look in Meteor.settings - return Meteor.settings[setting]; - - } else if (Meteor.settings && Meteor.settings.public && !!Meteor.settings.public[setting]) { // look in Meteor.settings.public - return Meteor.settings.public[setting]; - - } else if(settings && (typeof settings[setting] !== 'undefined')) { // look in Settings collection - return settings[setting]; - - } else if (typeof defaultValue !== 'undefined') { // fallback to default - return defaultValue; - - } else { // or return undefined - return undefined; - } - + return Settings.get('siteUrl', Meteor.absoluteUrl()); }; - removeSetting = function (setting) { var settings = Settings.find().fetch()[0]; console.log(settings._id) @@ -45,15 +23,15 @@ getThemeSetting = function(setting, defaultValue){ camelToDash = function (str) { return str.replace(/\W+/g, '-').replace(/([a-z\d])([A-Z])/g, '$1-$2').toLowerCase(); -} +}; camelCaseify = function(str) { return dashToCamel(str.replace(' ', '-')); -} +}; dashToCamel = function (str) { return str.replace(/(\-[a-z])/g, function($1){return $1.toUpperCase().replace('-','');}); -} +}; trimWords = function(s, numWords) { expString = s.split(/\s+/,numWords); @@ -64,4 +42,4 @@ trimWords = function(s, numWords) { capitalise = function (string) { return string.charAt(0).toUpperCase() + string.slice(1); -} \ No newline at end of file +}; diff --git a/packages/telescope-lib/lib/permissions.js b/packages/telescope-lib/lib/permissions.js index 84d5bc921..907d90241 100644 --- a/packages/telescope-lib/lib/permissions.js +++ b/packages/telescope-lib/lib/permissions.js @@ -8,7 +8,7 @@ can = {}; // // return true if all is well, false can.view = function (user) { - if (getSetting('requireViewInvite', false)) { + if (Settings.get('requireViewInvite', false)) { if (Meteor.isClient) { // on client only, default to the current user @@ -32,7 +32,7 @@ can.viewRejectedPosts = function (user) { can.viewById = function (userId) { // if an invite is required to view, run permission check, else return true - if (getSetting('requireViewInvite', false)) { + if (Settings.get('requireViewInvite', false)) { return !!userId ? can.view(Meteor.users.findOne(userId)) : false; } return true; @@ -44,7 +44,7 @@ can.post = function (user, returnError) { return returnError ? "no_account" : false; } else if (isAdmin(user)) { return true; - } else if (getSetting('requirePostInvite')) { + } else if (Settings.get('requirePostInvite')) { if (user.isInvited) { return true; } else { diff --git a/packages/telescope-lib/package.js b/packages/telescope-lib/package.js index d8cee69c1..ff2ee06c0 100644 --- a/packages/telescope-lib/package.js +++ b/packages/telescope-lib/package.js @@ -16,20 +16,19 @@ Package.onUse(function (api) { api.add_files([ 'lib/lib.js', - 'lib/deep.js', - 'lib/deep_extend.js', - 'lib/autolink.js', + 'lib/deep.js', + 'lib/deep_extend.js', + 'lib/autolink.js', 'lib/permissions.js' ], ['client', 'server']); api.add_files(['lib/client/jquery.exists.js'], ['client']); - + api.export([ - 'deepExtend', + 'deepExtend', 'camelToDash', 'dashToCamel', 'camelCaseify', - 'getSetting', 'removeSetting', 'getThemeSetting', 'getSiteUrl', @@ -38,4 +37,4 @@ Package.onUse(function (api) { '_', 'capitalise' ]); -}); \ No newline at end of file +}); diff --git a/packages/telescope-module-share/lib/client/post_share.js b/packages/telescope-module-share/lib/client/post_share.js index 55e1e766e..0236a28fd 100644 --- a/packages/telescope-module-share/lib/client/post_share.js +++ b/packages/telescope-module-share/lib/client/post_share.js @@ -4,7 +4,7 @@ Meteor.startup(function () { return !!this.url ? this.url : getSiteUrl() + "posts/"+this._id; }, viaTwitter: function () { - return !!getSetting('twitterAccount') ? 'via='+getSetting('twitterAccount') : ''; + return !!Settings.get('twitterAccount') ? 'via='+Settings.get('twitterAccount') : ''; } }); @@ -19,4 +19,4 @@ Meteor.startup(function () { $share.toggleClass("hidden"); } }); -}); \ No newline at end of file +}); diff --git a/packages/telescope-module-share/package.js b/packages/telescope-module-share/package.js index f79bf38a4..3775018ef 100644 --- a/packages/telescope-module-share/package.js +++ b/packages/telescope-module-share/package.js @@ -2,7 +2,12 @@ Package.describe({summary: "Telescope share module package"}); Package.onUse(function (api) { - api.use(['telescope-lib', 'telescope-base', 'fourseven:scss'], ['client', 'server']); + api.use([ + 'telescope-lib', + 'telescope-base', + 'telescope-settings', + 'fourseven:scss' + ], ['client', 'server']); api.use([ 'jquery', @@ -13,6 +18,6 @@ Package.onUse(function (api) { api.add_files(['lib/share.js'], ['client', 'server']); api.add_files(['lib/client/post_share.html', 'lib/client/post_share.js', 'lib/client/post_share.scss'], ['client']); - + // api.export(); -}); \ No newline at end of file +}); diff --git a/packages/telescope-newsletter/lib/client/templates/newsletter_banner.js b/packages/telescope-newsletter/lib/client/templates/newsletter_banner.js index 76c396374..77f202cd6 100644 --- a/packages/telescope-newsletter/lib/client/templates/newsletter_banner.js +++ b/packages/telescope-newsletter/lib/client/templates/newsletter_banner.js @@ -22,7 +22,7 @@ var dismissBanner = function () { Meteor.startup(function () { Template[getTemplate('newsletterBanner')].helpers({ siteName: function () { - return getSetting('title'); + return Settings.get('title'); }, isNotConnected: function () { return !Meteor.user() @@ -30,7 +30,7 @@ Meteor.startup(function () { showBanner: function () { // note: should not be reactive if( - getSetting('showBanner', false) == false + Settings.get('showBanner', false) == false || !can.view(Meteor.user()) || Router.current().location.get().path != '/' || Cookie.get('showBanner') == "no" diff --git a/packages/telescope-newsletter/lib/newsletter.js b/packages/telescope-newsletter/lib/newsletter.js index cfc8f372c..8b18f6d12 100644 --- a/packages/telescope-newsletter/lib/newsletter.js +++ b/packages/telescope-newsletter/lib/newsletter.js @@ -55,7 +55,7 @@ var enableNewsletter = { } } } -addToSettingsSchema.push(enableNewsletter); +Settings.addToSchema(enableNewsletter); var showBanner = { propertyName: 'showBanner', @@ -69,7 +69,7 @@ var showBanner = { } } } -addToSettingsSchema.push(showBanner); +Settings.addToSchema(showBanner); var mailChimpAPIKey = { propertyName: 'mailChimpAPIKey', @@ -82,7 +82,7 @@ var mailChimpAPIKey = { } } } -addToSettingsSchema.push(mailChimpAPIKey); +Settings.addToSchema(mailChimpAPIKey); var mailChimpListId = { propertyName: 'mailChimpListId', @@ -96,7 +96,7 @@ var mailChimpListId = { } } } -addToSettingsSchema.push(mailChimpListId); +Settings.addToSchema(mailChimpListId); var postsPerNewsletter = { propertyName: 'postsPerNewsletter', @@ -108,7 +108,7 @@ var postsPerNewsletter = { } } } -addToSettingsSchema.push(postsPerNewsletter); +Settings.addToSchema(postsPerNewsletter); var newsletterFrequency = { propertyName: 'newsletterFrequency', @@ -139,7 +139,7 @@ var newsletterFrequency = { } } } -addToSettingsSchema.push(newsletterFrequency); +Settings.addToSchema(newsletterFrequency); var newsletterTime = { propertyName: 'newsletterTime', @@ -154,7 +154,7 @@ var newsletterTime = { } } } -addToSettingsSchema.push(newsletterTime); +Settings.addToSchema(newsletterTime); var autoSubscribe = { propertyName: 'autoSubscribe', @@ -167,7 +167,7 @@ var autoSubscribe = { } } } -addToSettingsSchema.push(autoSubscribe); +Settings.addToSchema(autoSubscribe); // create new "campaign" lens for all posts from the past X days that haven't been scheduled yet viewParameters.campaign = function (terms) { @@ -188,7 +188,7 @@ heroModules.push({ }); function subscribeUserOnCreation (user) { - if (!!getSetting('autoSubscribe') && !!getEmail(user)) { + if (!!Settings.get('autoSubscribe') && !!getEmail(user)) { addToMailChimpList(user, false, function (error, result) { console.log(error) console.log(result) diff --git a/packages/telescope-newsletter/lib/server/campaign.js b/packages/telescope-newsletter/lib/server/campaign.js index fcf8cc826..75f5b0232 100644 --- a/packages/telescope-newsletter/lib/server/campaign.js +++ b/packages/telescope-newsletter/lib/server/campaign.js @@ -3,11 +3,11 @@ defaultPosts = 5; getCampaignPosts = function (postsCount) { - var newsletterFrequency = getSetting('newsletterFrequency', defaultFrequency); + var newsletterFrequency = Settings.get('newsletterFrequency', defaultFrequency); // look for last scheduled campaign in the database var lastCampaign = SyncedCron._collection.findOne({name: 'Schedule newsletter'}, {sort: {finishedAt: -1}, limit: 1}); - + // if there is a last campaign use its date, else default to posts from the last 7 days var lastWeek = moment().subtract(7, 'days').toDate(); var after = (typeof lastCampaign != 'undefined') ? lastCampaign.finishedAt : lastWeek @@ -43,7 +43,7 @@ buildCampaign = function (postsArray) { if (post.body) properties.body = marked(trimWords(post.body, 20)).replace('

', '').replace('

', ''); // remove p tags - + if(post.url) properties.domain = getDomain(post.url) @@ -52,7 +52,7 @@ buildCampaign = function (postsArray) { // 2. Wrap posts HTML in digest template var digestHTML = getEmailTemplate('emailDigest')({ - siteName: getSetting('title'), + siteName: Settings.get('title'), date: moment().format("dddd, MMMM Do YYYY"), content: postsHTML }); @@ -71,7 +71,7 @@ buildCampaign = function (postsArray) { scheduleNextCampaign = function (isTest) { var isTest = typeof isTest === 'undefined' ? false : isTest; - var posts = getCampaignPosts(getSetting('postsPerNewsletter', defaultPosts)); + var posts = getCampaignPosts(Settings.get('postsPerNewsletter', defaultPosts)); if(!!posts.length){ return scheduleCampaign(buildCampaign(posts), isTest); }else{ diff --git a/packages/telescope-newsletter/lib/server/cron.js b/packages/telescope-newsletter/lib/server/cron.js index b438e336e..a6aa6d90f 100644 --- a/packages/telescope-newsletter/lib/server/cron.js +++ b/packages/telescope-newsletter/lib/server/cron.js @@ -9,7 +9,7 @@ defaultFrequency = 7; // once a week defaultTime = '00:00'; var getSchedule = function (parser) { - var frequency = getSetting('newsletterFrequency', defaultFrequency); + var frequency = Settings.get('newsletterFrequency', defaultFrequency); var recur = parser.recur(); var schedule; switch (frequency) { @@ -32,7 +32,7 @@ var getSchedule = function (parser) { default: // Once a week (Mondays) schedule = recur.on(2).dayOfWeek(); } - return schedule.on(getSetting('newsletterTime', defaultTime)).time(); + return schedule.on(Settings.get('newsletterTime', defaultTime)).time(); } Meteor.methods({ @@ -56,7 +56,7 @@ var addJob = function () { }); } Meteor.startup(function () { - if (getSetting('enableNewsletter', false)) { + if (Settings.get('enableNewsletter', false)) { addJob(); } -}); \ No newline at end of file +}); diff --git a/packages/telescope-newsletter/lib/server/mailchimp.js b/packages/telescope-newsletter/lib/server/mailchimp.js index 53024b3aa..afad54ef5 100644 --- a/packages/telescope-newsletter/lib/server/mailchimp.js +++ b/packages/telescope-newsletter/lib/server/mailchimp.js @@ -3,8 +3,8 @@ var htmlToText = Npm.require('html-to-text'); scheduleCampaign = function (campaign, isTest) { var isTest = typeof isTest === 'undefined' ? false : isTest; - var apiKey = getSetting('mailChimpAPIKey'); - var listId = getSetting('mailChimpListId'); + var apiKey = Settings.get('mailChimpAPIKey'); + var listId = Settings.get('mailChimpListId'); if(!!apiKey && !!listId){ @@ -14,19 +14,19 @@ scheduleCampaign = function (campaign, isTest) { subject = trimWords(subject, wordCount); wordCount--; } - + try { var api = new MailChimp(apiKey); var text = htmlToText.fromString(campaign.html, {wordwrap: 130}); - var defaultEmail = getSetting('defaultEmail'); + var defaultEmail = Settings.get('defaultEmail'); var campaignOptions = { type: 'regular', options: { list_id: listId, subject: subject, from_email: defaultEmail, - from_name: getSetting('title')+ ' Top Posts', + from_name: Settings.get('title')+ ' Top Posts', }, content: { html: campaign.html, @@ -38,7 +38,7 @@ scheduleCampaign = function (campaign, isTest) { // create campaign var mailchimpCampaign = api.call( 'campaigns', 'create', campaignOptions); - + console.log( '// Campaign created'); // console.log(campaign) @@ -51,7 +51,7 @@ scheduleCampaign = function (campaign, isTest) { // schedule campaign var schedule = api.call('campaigns', 'schedule', scheduleOptions); - + console.log('// Campaign scheduled for '+scheduledTime); // console.log(schedule) @@ -75,7 +75,7 @@ scheduleCampaign = function (campaign, isTest) { } addToMailChimpList = function(userOrEmail, confirm, done){ - + var user, email; var confirm = (typeof confirm === 'undefined') ? false : confirm // default to no confirmation @@ -91,8 +91,8 @@ addToMailChimpList = function(userOrEmail, confirm, done){ throw 'User must have an email address'; } - var apiKey = getSetting('mailChimpAPIKey'); - var listId = getSetting('mailChimpListId'); + var apiKey = Settings.get('mailChimpAPIKey'); + var listId = Settings.get('mailChimpListId'); // add a user to a MailChimp list. // called when a new user is created, or when an existing user fills in their email @@ -117,7 +117,7 @@ addToMailChimpList = function(userOrEmail, confirm, done){ setUserSetting('subscribedToNewsletter', true, user); console.log("// User subscribed"); - + return subscribe; } catch (error) { @@ -143,4 +143,4 @@ Meteor.methods({ throw new Meteor.Error(500, error.message); } } -}); \ No newline at end of file +}); diff --git a/packages/telescope-newsletter/lib/server/routes.js b/packages/telescope-newsletter/lib/server/routes.js index cafe3d8f3..05d09751c 100644 --- a/packages/telescope-newsletter/lib/server/routes.js +++ b/packages/telescope-newsletter/lib/server/routes.js @@ -4,7 +4,7 @@ Meteor.startup(function () { name: 'campaign', where: 'server', action: function() { - var campaign = buildCampaign(getCampaignPosts(getSetting('postsPerNewsletter', 5))); + var campaign = buildCampaign(getCampaignPosts(Settings.get('postsPerNewsletter', 5))); var campaignSubject = '
Subject: '+campaign.subject+' (note: contents might change)
'; var campaignSchedule = '
Scheduled for: '+ Meteor.call('getNextJob') +'
'; @@ -27,4 +27,4 @@ Meteor.startup(function () { } }); -}); \ No newline at end of file +}); diff --git a/packages/telescope-newsletter/package.js b/packages/telescope-newsletter/package.js index 1d6a7db5f..427ea86f7 100644 --- a/packages/telescope-newsletter/package.js +++ b/packages/telescope-newsletter/package.js @@ -13,6 +13,7 @@ Package.onUse(function (api) { api.use([ 'telescope-lib', 'telescope-base', + 'telescope-settings', 'aldeed:simple-schema', 'iron:router', 'miro:mailchimp', diff --git a/packages/telescope-notifications/lib/client/templates/notifications_menu.js b/packages/telescope-notifications/lib/client/templates/notifications_menu.js index 9c91dc937..eda7e692b 100644 --- a/packages/telescope-notifications/lib/client/templates/notifications_menu.js +++ b/packages/telescope-notifications/lib/client/templates/notifications_menu.js @@ -2,7 +2,7 @@ Template[getTemplate('notificationsMenu')].helpers({ menuLabel: function () { var notificationsCount; var notifications=Herald.collection.find({userId: Meteor.userId(), read: false}, {sort: {timestamp: -1}}).fetch(); - + if(notifications.length==0){ notificationsCount = __('no_notifications'); }else if(notifications.length==1){ @@ -33,10 +33,10 @@ Template[getTemplate('notificationsMenu')].helpers({ menuMode: function () { if (!!this.mobile) { return 'list'; - } else if (getSetting('navLayout', 'top-nav') === 'top-nav') { + } else if (Settings.get('navLayout', 'top-nav') === 'top-nav') { return 'dropdown'; } else { return 'accordion'; - } + } } -}); \ No newline at end of file +}); diff --git a/packages/telescope-notifications/lib/herald.js b/packages/telescope-notifications/lib/herald.js index d88dc1edc..2992e5cb3 100644 --- a/packages/telescope-notifications/lib/herald.js +++ b/packages/telescope-notifications/lib/herald.js @@ -2,7 +2,7 @@ // send emails every second when in dev environment if (Meteor.absoluteUrl().indexOf('localhost') !== -1) Herald.settings.queueTimer = 1000; - + Meteor.startup(function () { Herald.collection.deny({ @@ -11,7 +11,7 @@ Meteor.startup(function () { }); // disable all email notifications when "emailNotifications" is set to false - Herald.settings.overrides.email = !getSetting('emailNotifications', true); + Herald.settings.overrides.email = !Settings.get('emailNotifications', true); }); @@ -176,4 +176,4 @@ Herald.addCourier('newCommentSubscribed', { } }, transform: commentCourierTransform -}); \ No newline at end of file +}); diff --git a/packages/telescope-notifications/lib/notifications.js b/packages/telescope-notifications/lib/notifications.js index 4d4d1ef24..1cb0f2087 100644 --- a/packages/telescope-notifications/lib/notifications.js +++ b/packages/telescope-notifications/lib/notifications.js @@ -8,10 +8,10 @@ postAfterSubmitMethodCallbacks.push(function (post) { var adminIds = _.without(adminIds, post.userId); var notifiedUserIds = _.without(notifiedUserIds, post.userId); - if (post.status === STATUS_PENDING && !!adminIds.length) { + if (post.status === STATUS_PENDING && !!adminIds.length) { // if post is pending, only notify admins Herald.createNotification(adminIds, {courier: 'newPendingPost', data: post}); - } else if (!!notifiedUserIds.length) { + } else if (!!notifiedUserIds.length) { // if post is approved, notify everybody Herald.createNotification(notifiedUserIds, {courier: 'newPost', data: post}); } @@ -47,24 +47,24 @@ commentAfterSubmitMethodCallbacks.push(function (comment) { // 2. Notify author of comment being replied to if (!!comment.parentCommentId) { - + var parentComment = Comments.findOne(comment.parentCommentId); - + // do not notify author of parent comment if they're also post author or comment author // (someone could be replying to their own comment) if (parentComment.userId !== post.userId && parentComment.userId !== comment.userId) { - + // add parent comment to notification data notificationData.parentComment = _.pick(parentComment, '_id', 'userId', 'author'); - + Herald.createNotification(parentComment.userId, {courier: 'newReply', data: notificationData}); userIdsNotified.push(parentComment.userId); - + } } - // 3. Notify users subscribed to the thread + // 3. Notify users subscribed to the thread // TODO: ideally this would be injected from the telescope-subscribe-to-posts package if (!!post.subscribers) { @@ -74,7 +74,7 @@ commentAfterSubmitMethodCallbacks.push(function (comment) { Herald.createNotification(subscriberIdsToNotify, {courier: 'newCommentSubscribed', data: notificationData}); userIdsNotified = userIdsNotified.concat(subscriberIdsToNotify); - + } } @@ -95,7 +95,7 @@ var emailNotifications = { } } }; -addToSettingsSchema.push(emailNotifications); +Settings.addToSchema(emailNotifications); // make it possible to disable notifications on a per-comment basis addToCommentsSchema.push( diff --git a/packages/telescope-notifications/package.js b/packages/telescope-notifications/package.js index ab7cfa15d..98c4666c9 100644 --- a/packages/telescope-notifications/package.js +++ b/packages/telescope-notifications/package.js @@ -9,6 +9,7 @@ Package.onUse(function (api) { api.use([ 'telescope-lib', 'telescope-base', + 'telescope-settings', 'telescope-email', 'iron:router', 'kestanous:herald@1.3.0', @@ -51,7 +52,7 @@ Package.onUse(function (api) { 'lib/server/notifications-server.js', 'lib/server/routes.js' ], ['server']); - + api.add_files([ "i18n/de.i18n.json", "i18n/en.i18n.json", diff --git a/packages/telescope-rss/lib/server/rss.js b/packages/telescope-rss/lib/server/rss.js index 7dd9d53dd..2abff8299 100644 --- a/packages/telescope-rss/lib/server/rss.js +++ b/packages/telescope-rss/lib/server/rss.js @@ -1,10 +1,10 @@ var RSS = Npm.require('rss'); var getMeta = function(url) { - var siteUrl = getSetting('siteUrl', Meteor.absoluteUrl()); + var siteUrl = Settings.get('siteUrl', Meteor.absoluteUrl()); return { - title: getSetting('title'), - description: getSetting('tagline'), + title: Settings.get('title'), + description: Settings.get('tagline'), feed_url: siteUrl+url, site_url: siteUrl, image_url: siteUrl+'img/favicon.png', diff --git a/packages/telescope-rss/package.js b/packages/telescope-rss/package.js index 1ad864510..97c0ec472 100644 --- a/packages/telescope-rss/package.js +++ b/packages/telescope-rss/package.js @@ -4,9 +4,13 @@ Npm.depends({rss: "0.3.2"}); Package.onUse(function (api) { - api.use(['telescope-base', 'telescope-lib'], ['server']); + api.use([ + 'telescope-base', + 'telescope-lib', + 'telescope-settings' + ], ['server']); api.add_files(['lib/server/rss.js', 'lib/server/routes.js'], ['server']); - + api.export(['serveRSS']); -}); \ No newline at end of file +}); diff --git a/packages/telescope-search/lib/client/routes.js b/packages/telescope-search/lib/client/routes.js index aa768462b..c6a390a61 100644 --- a/packages/telescope-search/lib/client/routes.js +++ b/packages/telescope-search/lib/client/routes.js @@ -4,10 +4,10 @@ Meteor.startup(function () { view: 'search', showViewsNav: false, getTitle: function() { - return i18n.t("Search") + ' - ' + getSetting('title', "Telescope"); + return i18n.t("Search") + ' - ' + Settings.get('title', "Telescope"); }, getDescription: function() { - return getSetting('description'); + return Settings.get('description'); }, onBeforeAction: function() { var query = this.params.query; diff --git a/packages/telescope-search/package.js b/packages/telescope-search/package.js index b3b701b7f..3825ff97b 100644 --- a/packages/telescope-search/package.js +++ b/packages/telescope-search/package.js @@ -2,7 +2,12 @@ Package.describe({summary: "Telescope search package"}); Package.onUse(function (api) { - api.use(['telescope-lib', 'telescope-base', 'aldeed:simple-schema'], ['client', 'server']); + api.use([ + 'telescope-lib', + 'telescope-base', + 'telescope-settings', + 'aldeed:simple-schema' + ], ['client', 'server']); api.use([ 'jquery', @@ -42,4 +47,4 @@ Package.onUse(function (api) { ], ["client", "server"]); api.export(['adminMenu', 'viewParameters']); -}); \ No newline at end of file +}); diff --git a/packages/telescope-seo/lib/routes.js b/packages/telescope-seo/lib/routes.js index 106f4e8a0..30a3943b3 100644 --- a/packages/telescope-seo/lib/routes.js +++ b/packages/telescope-seo/lib/routes.js @@ -4,7 +4,7 @@ Meteor.startup(function() { var props = {meta: {}, og: {}}; var title = this.getTitle && this.getTitle(); var description = this.getDescription && this.getDescription(); - var image = getSetting("siteImage"); + var image = Settings.get("siteImage"); if (title) { props.og.title = title; } diff --git a/packages/telescope-seo/lib/seo.js b/packages/telescope-seo/lib/seo.js index e12df02a0..e2b4932ab 100644 --- a/packages/telescope-seo/lib/seo.js +++ b/packages/telescope-seo/lib/seo.js @@ -1,5 +1,5 @@ // Add SEO settings. -addToSettingsSchema.push({ +Settings.addToSchema({ propertyName: "siteImage", propertySchema: { type: String, @@ -10,4 +10,4 @@ addToSettingsSchema.push({ instructions: "URL to an image for the open graph image tag for all pages" } } -}); \ No newline at end of file +}); diff --git a/packages/telescope-seo/lib/server/sitemaps.js b/packages/telescope-seo/lib/server/sitemaps.js index f39abd043..24396ae21 100644 --- a/packages/telescope-seo/lib/server/sitemaps.js +++ b/packages/telescope-seo/lib/server/sitemaps.js @@ -16,7 +16,7 @@ Meteor.startup(function() { // Posts list pages var paths = [ - {page: "/", lastmod: _getLatest(getSetting("defaultView", "top")), changefreq: "hourly"}, + {page: "/", lastmod: _getLatest(Settings.get("defaultView", "top")), changefreq: "hourly"}, {page: "/top", lastmod: _getLatest("top"), changefreq: "hourly"}, {page: "/new", lastmod: _getLatest("new"), changefreq: "hourly"}, {page: "/best", lastmod: _getLatest("best"), changefreq: "daily"}, diff --git a/packages/telescope-seo/package.js b/packages/telescope-seo/package.js index 56e66f02e..c3fce6734 100644 --- a/packages/telescope-seo/package.js +++ b/packages/telescope-seo/package.js @@ -13,6 +13,7 @@ Package.onUse(function(api) { "iron:router", "telescope-lib", "telescope-base", + "telescope-settings", "telescope-i18n", "manuelschoebel:ms-seo@0.4.1", "gadicohen:sitemaps@0.0.20" diff --git a/packages/telescope-settings/lib/client/helpers.js b/packages/telescope-settings/lib/client/helpers.js new file mode 100644 index 000000000..c2c4a41a1 --- /dev/null +++ b/packages/telescope-settings/lib/client/helpers.js @@ -0,0 +1,6 @@ +/* global Settings: false */ + +Template.registerHelper('getSetting', function(setting, defaultArgument){ + setting = Settings.get(setting, defaultArgument); + return setting; +}); diff --git a/packages/telescope-settings/lib/client/language_changer.js b/packages/telescope-settings/lib/client/language_changer.js new file mode 100644 index 000000000..57e379d8f --- /dev/null +++ b/packages/telescope-settings/lib/client/language_changer.js @@ -0,0 +1,12 @@ +var query = Settings.collection.find(); + +query.observeChanges({ + added: function (id, fields) { + if (fields.language) + setLanguage(fields.language); + }, + changed: function (id, fields) { + if (fields.language) + setLanguage(fields.language); + } +}); diff --git a/packages/telescope-settings/lib/client/templates/settings_form.html b/packages/telescope-settings/lib/client/templates/settings_form.html new file mode 100644 index 000000000..9ccf7d195 --- /dev/null +++ b/packages/telescope-settings/lib/client/templates/settings_form.html @@ -0,0 +1,7 @@ + diff --git a/client/views/admin/settings_form.js b/packages/telescope-settings/lib/client/templates/settings_form.js similarity index 70% rename from client/views/admin/settings_form.js rename to packages/telescope-settings/lib/client/templates/settings_form.js index 46e530aa9..cfbfc10ba 100644 --- a/client/views/admin/settings_form.js +++ b/packages/telescope-settings/lib/client/templates/settings_form.js @@ -1,13 +1,4 @@ -AutoForm.hooks({ - updateSettingsForm: { - - before: { - update: function(modifier) { - this.template.$('button[type=submit]').addClass('loading'); - return modifier; - } - }, - +AutoForm.addHooks(['updateSettingsForm', 'insertSettingsForm'], { onSuccess: function(operation, result) { this.template.$('button[type=submit]').removeClass('loading'); }, @@ -15,24 +6,24 @@ AutoForm.hooks({ onError: function(operation, result, template) { this.template.$('button[type=submit]').removeClass('loading'); } +}); + +AutoForm.hooks({ + updateSettingsForm: { + before: { + update: function(modifier) { + this.template.$('button[type=submit]').addClass('loading'); + return modifier; + } + } }, insertSettingsForm: { - before: { insert: function(doc) { this.template.$('button[type=submit]').addClass('loading'); return doc; } - }, - - onSuccess: function(operation, result) { - this.template.$('button[type=submit]').removeClass('loading'); - }, - - onError: function(operation, result) { - this.template.$('button[type=submit]').removeClass('loading'); } - } -}); \ No newline at end of file +}); diff --git a/packages/telescope-settings/lib/router.js b/packages/telescope-settings/lib/router.js new file mode 100644 index 000000000..8167d3f07 --- /dev/null +++ b/packages/telescope-settings/lib/router.js @@ -0,0 +1,18 @@ +Meteor.startup(function () { + // Settings + + Router.route('/settings', { + controller: AdminController, + name: 'settings', + // layoutTemplate: getTemplate('adminLayout'), + data: function () { + // we only have one set of settings for now + + var settings = Settings.collection.findOne(); + return { + hasSettings: !!settings, + settings: settings + }; + } + }); +}); diff --git a/server/publications/settings.js b/packages/telescope-settings/lib/server/publications.js similarity index 60% rename from server/publications/settings.js rename to packages/telescope-settings/lib/server/publications.js index 74742d91b..3ca7c6a78 100644 --- a/server/publications/settings.js +++ b/packages/telescope-settings/lib/server/publications.js @@ -2,8 +2,8 @@ Meteor.publish('settings', function() { var options = {}; var privateFields = {}; - // look at SettingsSchema to see which fields should be kept private - _.each(SettingsSchema._schema, function( val, key ) { + // look at Settings.schema to see which fields should be kept private + _.each(Settings.schema._schema, function( val, key ) { if (val.autoform && !!val.autoform.private) privateFields[key] = false; }); @@ -13,5 +13,6 @@ Meteor.publish('settings', function() { fields: privateFields }); } - return Settings.find({}, options); -}); \ No newline at end of file + + return Settings.collection.find({}, options); +}); diff --git a/collections/settings.js b/packages/telescope-settings/lib/settings.js similarity index 85% rename from collections/settings.js rename to packages/telescope-settings/lib/settings.js index 947eaa881..d675e6d81 100644 --- a/collections/settings.js +++ b/packages/telescope-settings/lib/settings.js @@ -1,4 +1,8 @@ -settingsSchemaObject = { +Settings = { + collection: new Meteor.Collection("settings") +}; + +Settings.schema = new SimpleSchema({ title: { type: String, optional: true, @@ -84,7 +88,7 @@ settingsSchemaObject = { instructions: 'MAIL_URL environment variable (requires restart).', private: true } - }, + }, scoreUpdateInterval: { type: Number, optional: true, @@ -136,7 +140,7 @@ settingsSchemaObject = { } }) } - }, + }, postInterval: { type: Number, optional: true, @@ -379,46 +383,55 @@ settingsSchemaObject = { } ], instructions: 'Authentication methods (default to email only)' - } + } } -}; - -// add any extra properties to settingsSchemaObject (provided by packages for example) -_.each(addToSettingsSchema, function(item){ - settingsSchemaObject[item.propertyName] = item.propertySchema; }); -Settings = new Meteor.Collection("settings"); -SettingsSchema = new SimpleSchema(settingsSchemaObject); -Settings.attachSchema(SettingsSchema); +Settings.collection.attachSchema(Settings.schema); + +Settings.addToSchema = function(item) { + var itemSchema = {}; + itemSchema[item.propertyName] = item.propertySchema; + + Settings.collection.attachSchema(itemSchema); + Settings.schema = new SimpleSchema(Settings.schema, itemSchema); +}; + +Settings.get = function(setting, defaultValue) { + var settings = Settings.collection.find().fetch()[0]; + + if (Meteor.isServer && Meteor.settings && !!Meteor.settings[setting]) { // if on the server, look in Meteor.settings + return Meteor.settings[setting]; + + } else if (Meteor.settings && Meteor.settings.public && !!Meteor.settings.public[setting]) { // look in Meteor.settings.public + return Meteor.settings.public[setting]; + + } else if(settings && (typeof settings[setting] !== 'undefined')) { // look in Settings collection + return settings[setting]; + + } else if (typeof defaultValue !== 'undefined') { // fallback to default + return defaultValue; + + } else { // or return undefined + return undefined; + } +}; // use custom template for checkboxes - not working yet // if(Meteor.isClient){ // AutoForm.setDefaultTemplateForType('afCheckbox', 'settings'); // } -Settings.allow({ - insert: isAdminById, - update: isAdminById, - remove: isAdminById -}); - -if (Meteor.isClient){ - var query = Settings.find(); - var handle = query.observeChanges({ - added: function (id, fields) { - if (fields.language) - setLanguage(fields.language) - }, - changed: function (id, fields) { - if (fields.language) - setLanguage(fields.language) - } +Meteor.startup(function () { + Settings.collection.allow({ + insert: isAdminById, + update: isAdminById, + remove: isAdminById }); -} +}); Meteor.startup(function () { // override Meteor.absoluteUrl() with URL provided in settings - Meteor.absoluteUrl.defaultOptions.rootUrl = getSetting('siteUrl', Meteor.absoluteUrl()); - debug = getSetting('debug', false); -}); \ No newline at end of file + Meteor.absoluteUrl.defaultOptions.rootUrl = Settings.get('siteUrl', Meteor.absoluteUrl()); + debug = Settings.get('debug', false); +}); diff --git a/packages/telescope-settings/package.js b/packages/telescope-settings/package.js new file mode 100644 index 000000000..f983bb74b --- /dev/null +++ b/packages/telescope-settings/package.js @@ -0,0 +1,38 @@ +Package.describe({summary: "Telescope settings package"}); + +Package.onUse(function(api) { + var both = ['server', 'client']; + + api.use([ + 'mongo', + 'underscore', + + 'aldeed:simple-schema', + + 'telescope-base', + 'telescope-lib' + ], both); + + api.use([ + 'templating', + 'aldeed:autoform' + ], 'client'); + + api.addFiles([ + 'lib/settings.js', + 'lib/router.js' + ], both); + + api.addFiles([ + 'lib/server/publications.js', + ], 'server'); + + api.addFiles([ + 'lib/client/language_changer.js', + 'lib/client/helpers.js', + 'lib/client/templates/settings_form.html', + 'lib/client/templates/settings_form.js' + ], 'client'); + + api.export('Settings', both); +}); diff --git a/packages/telescope-singleday/lib/client/templates/single_day.js b/packages/telescope-singleday/lib/client/templates/single_day.js index 9ec6fae22..7c1610113 100644 --- a/packages/telescope-singleday/lib/client/templates/single_day.js +++ b/packages/telescope-singleday/lib/client/templates/single_day.js @@ -11,7 +11,7 @@ Template[getTemplate('singleDay')].created = function () { // initialize the reactive variables instance.postsLoaded = new ReactiveVar(0); - instance.postsLimit = new ReactiveVar(getSetting('postsPerPage', 10)); + instance.postsLimit = new ReactiveVar(Settings.get('postsPerPage', 10)); instance.postsReady = new ReactiveVar(false); instance.getTerms = function () { @@ -31,7 +31,7 @@ Template[getTemplate('singleDay')].created = function () { instance.autorun(function () { // just by including this session variable in the autorun, we automatically make it depend on it var currentDate = Session.get('currentDate'); - instance.postsLimit.set(getSetting('postsPerPage', 10)); + instance.postsLimit.set(Settings.get('postsPerPage', 10)); }); // will re-run when postsLimit or currentDate change @@ -107,7 +107,7 @@ Template[getTemplate('singleDay')].helpers({ // get current value for limit, i.e. how many posts are currently displayed var limit = instance.postsLimit.get(); // increase limit by 5 and update it - limit += getSetting('postsPerPage', 10); + limit += Settings.get('postsPerPage', 10); instance.postsLimit.set(limit); }, @@ -118,4 +118,4 @@ Template[getTemplate('singleDay')].helpers({ return context; } -}); \ No newline at end of file +}); diff --git a/packages/telescope-singleday/lib/routes.js b/packages/telescope-singleday/lib/routes.js index f1980bddc..b67b7e749 100644 --- a/packages/telescope-singleday/lib/routes.js +++ b/packages/telescope-singleday/lib/routes.js @@ -8,14 +8,14 @@ PostsSingledayController = RouteController.extend({ this.render(getTemplate('postListTop'), {to: 'postListTop'}); this.next(); }, - + data: function() { var currentDate = this.params.day ? new Date(this.params.year, this.params.month-1, this.params.day) : Session.get('today'); Session.set('currentDate', currentDate); }, getTitle: function () { - return i18n.t('single_day') + ' - ' + getSetting('title', 'Telescope'); + return i18n.t('single_day') + ' - ' + Settings.get('title', 'Telescope'); }, getDescription: function () { @@ -40,4 +40,4 @@ Meteor.startup(function () { controller: PostsSingledayController }); -}); \ No newline at end of file +}); diff --git a/packages/telescope-tagline-banner/lib/client/templates/tagline_banner.js b/packages/telescope-tagline-banner/lib/client/templates/tagline_banner.js index f0ee2d435..adf4ee7d8 100644 --- a/packages/telescope-tagline-banner/lib/client/templates/tagline_banner.js +++ b/packages/telescope-tagline-banner/lib/client/templates/tagline_banner.js @@ -1,6 +1,6 @@ Template[getTemplate('taglineBanner')].helpers({ showTaglineBanner: function () { - return !!getSetting('tagline') && !!getSetting('showTaglineBanner'); + return !!Settings.get('tagline') && !!Settings.get('showTaglineBanner'); } }); diff --git a/packages/telescope-tagline-banner/lib/tagline.js b/packages/telescope-tagline-banner/lib/tagline.js index ee7b63929..c61590f85 100644 --- a/packages/telescope-tagline-banner/lib/tagline.js +++ b/packages/telescope-tagline-banner/lib/tagline.js @@ -14,5 +14,5 @@ var showTaglineBanner = { instructions: 'Show tagline on homepage.' } } -} -addToSettingsSchema.push(showTaglineBanner); \ No newline at end of file +}; +Settings.addToSchema(showTaglineBanner); diff --git a/packages/telescope-tagline-banner/package.js b/packages/telescope-tagline-banner/package.js index cdd0927db..3b932d1a6 100644 --- a/packages/telescope-tagline-banner/package.js +++ b/packages/telescope-tagline-banner/package.js @@ -13,6 +13,7 @@ Package.onUse(function (api) { api.use([ 'telescope-base', // basic Telescope hooks and objects 'telescope-lib', // useful functions + 'telescope-settings', 'fourseven:scss', // SCSS compilation package 'tap:i18n' ]); @@ -45,4 +46,4 @@ Package.onUse(function (api) { "i18n/en.i18n.json" ], ["client", "server"]); -}); \ No newline at end of file +}); diff --git a/packages/telescope-tags/lib/client/templates/categories_menu.js b/packages/telescope-tags/lib/client/templates/categories_menu.js index 9ce66c54f..ac9aff451 100644 --- a/packages/telescope-tags/lib/client/templates/categories_menu.js +++ b/packages/telescope-tags/lib/client/templates/categories_menu.js @@ -19,11 +19,11 @@ Meteor.startup(function () { menuMode: function () { if (!!this.mobile) { return 'list'; - } else if (getSetting('navLayout', 'top-nav') === 'top-nav') { + } else if (Settings.get('navLayout', 'top-nav') === 'top-nav') { return 'dropdown'; } else { return 'accordion'; } } }); -}); \ No newline at end of file +}); diff --git a/packages/telescope-update-prompt/lib/server/phone_home.js b/packages/telescope-update-prompt/lib/server/phone_home.js index 2c074b2da..2d1524cb2 100644 --- a/packages/telescope-update-prompt/lib/server/phone_home.js +++ b/packages/telescope-update-prompt/lib/server/phone_home.js @@ -1,11 +1,11 @@ Meteor.methods({ phoneHome: function () { - + var url = 'http://version.telescopeapp.org/'; var params = { currentVersion: telescopeVersion, - siteTitle: getSetting('title'), + siteTitle: Settings.get('title'), siteUrl: getSiteUrl(), users: Meteor.users.find().count(), posts: Posts.find().count(), @@ -26,4 +26,4 @@ Meteor.methods({ } } } -}) \ No newline at end of file +}) diff --git a/server/migrations.js b/server/migrations.js index 270ae9855..b681494ab 100644 --- a/server/migrations.js +++ b/server/migrations.js @@ -497,7 +497,7 @@ var migrationsList = { }, changeColorNames: function () { var i = 0; - var settings = Settings.findOne(); + var settings = Settings.collection.findOne(); var set = {}; if (!!settings) { @@ -513,7 +513,7 @@ var migrationsList = { if (!!settings.buttonColor) set.secondaryContrastColor = settings.headerTextColor; - + if (!_.isEmpty(set)) { Settings.update(settings._id, {$set: set}, {validate: false}); } diff --git a/server/publications/users.js b/server/publications/users.js index 63f750e0f..79709a6b9 100644 --- a/server/publications/users.js +++ b/server/publications/users.js @@ -9,7 +9,7 @@ Meteor.publish('currentUser', function() { // TODO: find a better way Meteor.publish('allUsersAdmin', function() { - var selector = getSetting('requirePostInvite') ? {isInvited: true} : {}; // only users that can post + var selector = Settings.get('requirePostInvite') ? {isInvited: true} : {}; // only users that can post if (isAdminById(this.userId)) { return Meteor.users.find(selector, {fields: { _id: true, diff --git a/server/scoring.js b/server/scoring.js index b0f0c45f7..626601676 100644 --- a/server/scoring.js +++ b/server/scoring.js @@ -1,5 +1,5 @@ Meteor.startup(function () { - var scoreInterval = getSetting("scoreUpdateInterval") || 30; + var scoreInterval = Settings.get("scoreUpdateInterval") || 30; if (scoreInterval > 0) { // active items get updated every N seconds diff --git a/server/start.js b/server/start.js index c1dcdebd5..0abc3b23c 100644 --- a/server/start.js +++ b/server/start.js @@ -1,10 +1,10 @@ Meteor.startup(function () { logEvent({ name: "firstRun", - unique: true, // will only get logged a single time + unique: true, // will only get logged a single time important: true }) }); -if (getSetting('mailUrl')) - process.env.MAIL_URL = getSetting('mailUrl'); +if (Settings.get('mailUrl')) + process.env.MAIL_URL = Settings.get('mailUrl'); diff --git a/tests/jasmine/client/unit/navSpec.js b/tests/jasmine/client/unit/navSpec.js index 8c456d6df..1bb77beac 100644 --- a/tests/jasmine/client/unit/navSpec.js +++ b/tests/jasmine/client/unit/navSpec.js @@ -27,7 +27,7 @@ describe('test nav template', function() { }); it('should render the logo from the setting', function () { - spyOn(window, 'getSetting').and.callFake(function (settingName) { + spyOn(window, 'Settings.get').and.callFake(function (settingName) { return settingName; }); @@ -44,7 +44,7 @@ describe('test nav template', function() { }); it('should render the site title if logo_url setting is empty', function () { - spyOn(window, 'getSetting').and.callFake(function (settingName) { + spyOn(window, 'Settings.get').and.callFake(function (settingName) { if (settingName === 'logoUrl') { return null; } @@ -231,4 +231,4 @@ describe('test nav template', function() { expect(renderedSecondaryNav.length).toEqual(1); }); }); -}); \ No newline at end of file +});