From c1ac92ac199fbb97ef39f2fee26f90ffe813bf14 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Wed, 7 Jan 2015 13:35:49 -0500 Subject: [PATCH 1/3] popular topics will use topic creation time --- src/controllers/categories.js | 9 +++++++-- src/topics/popular.js | 9 +-------- src/topics/recent.js | 12 ++++++++---- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/controllers/categories.js b/src/controllers/categories.js index 0a06dafce1..14abb6f260 100644 --- a/src/controllers/categories.js +++ b/src/controllers/categories.js @@ -35,8 +35,13 @@ var anonCache = {}, lastUpdateTime = 0; categoriesController.popular = function(req, res, next) { var uid = req.user ? req.user.uid : 0; - - var term = req.params.term || 'daily'; + var terms = { + daily: 'day', + weekly: 'week', + monthly: 'month', + alltime: 'alltime' + }; + var term = terms[req.params.term] || 'day'; if (uid === 0) { if (anonCache[term] && (Date.now() - lastUpdateTime) < 60 * 60 * 1000) { diff --git a/src/topics/popular.js b/src/topics/popular.js index 710dc27e7c..1f8ff31bf3 100644 --- a/src/topics/popular.js +++ b/src/topics/popular.js @@ -7,11 +7,6 @@ var async = require('async'), module.exports = function(Topics) { - var terms = { - daily: 'day', - weekly: 'week', - monthly: 'month' - }; Topics.getPopular = function(term, uid, count, callback) { count = parseInt(count, 10) || 20; @@ -20,11 +15,9 @@ module.exports = function(Topics) { return getAllTimePopular(uid, count, callback); } - var since = terms[term] || 'day'; - async.waterfall([ function(next) { - Topics.getLatestTids(0, -1, since, next); + Topics.getLatestTidsFromSet('topics:tid', 0, -1, term, next); }, function(tids, next) { getTopics(tids, uid, count, next); diff --git a/src/topics/recent.js b/src/topics/recent.js index b316aa65a5..19c3debd03 100644 --- a/src/topics/recent.js +++ b/src/topics/recent.js @@ -3,10 +3,9 @@ 'use strict'; var async = require('async'), + winston = require('winston'), db = require('../database'); - - module.exports = function(Topics) { var terms = { day: 86400000, @@ -18,7 +17,7 @@ module.exports = function(Topics) { Topics.getLatestTopics = function(uid, start, end, term, callback) { async.waterfall([ function (next) { - Topics.getLatestTids(start, end, term, next); + Topics.getLatestTidsFromSet('topics:recent', start, end, term, next); }, function(tids, next) { Topics.getTopics(tids, uid, next); @@ -30,6 +29,11 @@ module.exports = function(Topics) { }; Topics.getLatestTids = function(start, end, term, callback) { + winston.warn('[deprecation warning] please use Topics.getLatestTidsFromSet("topics:recent")'); + Topics.getLatestTidsFromSet('topics:recent', start, end, term, callback); + }; + + Topics.getLatestTidsFromSet = function(set, start, end, term, callback) { var since = terms.day; if (terms[term]) { since = terms[term]; @@ -37,7 +41,7 @@ module.exports = function(Topics) { var count = parseInt(end, 10) === -1 ? end : end - start + 1; - db.getSortedSetRevRangeByScore('topics:recent', start, count, '+inf', Date.now() - since, callback); + db.getSortedSetRevRangeByScore(set, start, count, '+inf', Date.now() - since, callback); }; Topics.updateTimestamp = function(tid, timestamp, callback) { From 60f1b9679ad42731fd9782261989efb8f4717f76 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Wed, 7 Jan 2015 16:10:11 -0500 Subject: [PATCH 2/3] search filters --- public/language/en_GB/search.json | 5 +- public/src/app.js | 6 +- public/src/client/search.js | 16 +++-- public/src/modules/search.js | 11 ++-- src/controllers/index.js | 30 +-------- src/controllers/search.js | 41 ++++++++++++ src/routes/index.js | 2 +- src/search.js | 102 ++++++++++++++++++------------ src/socket.io/topics.js | 33 +--------- src/topics/tags.js | 35 ++++++++++ 10 files changed, 165 insertions(+), 116 deletions(-) create mode 100644 src/controllers/search.js diff --git a/public/language/en_GB/search.json b/public/language/en_GB/search.json index 81c404a591..945e58c852 100644 --- a/public/language/en_GB/search.json +++ b/public/language/en_GB/search.json @@ -1,4 +1,5 @@ { "results_matching": "%1 result(s) matching \"%2\", (%3 seconds)", - "no-matches": "No posts found" -} \ No newline at end of file + "no-matches": "No matches found", + "in": "In" +} diff --git a/public/src/app.js b/public/src/app.js index bf5ec32941..1664a251d5 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -435,11 +435,9 @@ app.uid = null; require(['search', 'mousetrap'], function(search, Mousetrap) { $('#search-form').on('submit', function (e) { e.preventDefault(); - var input = $(this).find('input'), - term = input.val(); + var input = $(this).find('input'); - - search.query(term, function() { + search.query(input.val(), 'posts', function() { input.val(''); }); }); diff --git a/public/src/client/search.js b/public/src/client/search.js index 861d8dd441..e08a5dc410 100644 --- a/public/src/client/search.js +++ b/public/src/client/search.js @@ -2,9 +2,17 @@ define('forum/search', ['search'], function(searchModule) { var Search = {}; Search.init = function() { - var searchQuery = $('#post-results').attr('data-search-query'); + var searchQuery = $('#results').attr('data-search-query'); var regexes = []; var searchTerms = searchQuery.split(' '); + + $('#advanced-search input').val(searchQuery); + var params = utils.params(); + if (params && params.in) { + $('#advanced-search select').val(params.in); + } + + for (var i=0; i Date: Wed, 7 Jan 2015 16:18:38 -0500 Subject: [PATCH 3/3] closed #2583 --- public/src/app.js | 5 ++- public/src/helpers.js | 35 --------------------- public/src/modules/helpers.js | 59 +++++++++++++++++++++++++++++++++++ src/meta/js.js | 1 - src/webserver.js | 5 ++- 5 files changed, 67 insertions(+), 38 deletions(-) delete mode 100644 public/src/helpers.js create mode 100644 public/src/modules/helpers.js diff --git a/public/src/app.js b/public/src/app.js index 1664a251d5..d894551064 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -566,8 +566,11 @@ app.uid = null; } }); - require(['taskbar'], function(taskbar) { + require(['taskbar', 'helpers'], function(taskbar, helpers) { taskbar.init(); + + // templates.js helpers + helpers.register(); }); }); }; diff --git a/public/src/helpers.js b/public/src/helpers.js deleted file mode 100644 index a89aeae0e2..0000000000 --- a/public/src/helpers.js +++ /dev/null @@ -1,35 +0,0 @@ -"use strict"; -/*global templates*/ - - -(function(module) { - var helpers = {}; - - helpers.displayUsersLink = function(config) { - return (config.loggedIn || !config.privateUserInfo); - }; - - helpers.buildMetaTag = function(tag) { - var name = tag.name ? 'name="' + tag.name + '" ' : '', - property = tag.property ? 'property="' + tag.property + '" ' : '', - content = tag.content ? 'content="' + tag.content.replace(/\n/g, ' ') + '" ' : ''; - - return ''; - }; - - if ('undefined' !== typeof window) { - $(document).ready(module.exports); - } - - module.exports = function() { - var templates = templates || require('templates.js'); - - templates.registerHelper('displayUsersLink', helpers.displayUsersLink); - templates.registerHelper('buildMetaTag', helpers.buildMetaTag); - }; - -})('undefined' === typeof module ? { - module: { - exports: {} - } -} : module); diff --git a/public/src/modules/helpers.js b/public/src/modules/helpers.js new file mode 100644 index 0000000000..1d13f93bf7 --- /dev/null +++ b/public/src/modules/helpers.js @@ -0,0 +1,59 @@ +;(function(exports) { + "use strict"; + /* globals define */ + + // export the class if we are in a Node-like system. + if (typeof module === 'object' && module.exports === exports) { + exports = module.exports/* = SemVer*/; + } + + var helpers = {}; + + helpers.displayUsersLink = function(config) { + return (config.loggedIn || !config.privateUserInfo); + }; + + helpers.buildMetaTag = function(tag) { + var name = tag.name ? 'name="' + tag.name + '" ' : '', + property = tag.property ? 'property="' + tag.property + '" ' : '', + content = tag.content ? 'content="' + tag.content.replace(/\n/g, ' ') + '" ' : ''; + + return ''; + }; + + // Groups helpers + helpers.membershipBtn = function(groupObj) { + if (groupObj.isMember) { + return ''; + } else { + if (groupObj.pending) { + return ''; + } else { + return ''; + } + } + }; + + exports.register = function() { + var templates; + + if (typeof module === 'object') { + templates = require('templates.js'); + } else { + templates = window.templates; + } + + templates.registerHelper('displayUsersLink', helpers.displayUsersLink); + templates.registerHelper('buildMetaTag', helpers.buildMetaTag); + }; + + // Use the define() function if we're in AMD land + if (typeof define === 'function' && define.amd) { + define('helpers', exports); + } + +})( + typeof exports === 'object' ? exports : + typeof define === 'function' && define.amd ? {} : + helpers = {} +); diff --git a/src/meta/js.js b/src/meta/js.js index c653a15de9..a960d108ee 100644 --- a/src/meta/js.js +++ b/src/meta/js.js @@ -45,7 +45,6 @@ module.exports = function(Meta) { 'public/src/variables.js', 'public/src/widgets.js', 'public/src/translator.js', - 'public/src/helpers.js', 'public/src/overrides.js' ], rjs: [] diff --git a/src/webserver.js b/src/webserver.js index 8d905b99b6..01dee2b91c 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -18,7 +18,7 @@ var path = require('path'), routes = require('./routes'), emitter = require('./emitter'), - helpers = require('./../public/src/helpers')(), + helpers = require('./../public/src/modules/helpers'), net; if(nconf.get('ssl')) { @@ -48,6 +48,9 @@ if(nconf.get('ssl')) { middleware = middleware(app); routes(app, middleware); + // Load server-side template helpers + helpers.register(); + // Cache static files on production if (global.env !== 'development') { app.enable('cache');