From aca53aa722604c4b8f868c3899df910b303726cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Sat, 18 Jan 2014 17:52:39 +0100 Subject: [PATCH] BUGFIX: display links to other periods at the bottom of the top/:period page --- .../controllers/_discovery_controller.js | 24 +++++++++++++++++++ .../discovery_categories_controller.js | 7 +----- .../controllers/discovery_top_controller.js | 20 ++-------------- .../discovery_topics_controller.js | 14 +++++------ .../navigation_default_controller.js | 15 ------------ .../javascripts/discourse/lib/computed.js | 24 ++++++++++++++++++- .../discourse/routes/discovery_route.js | 16 +++++++++++++ .../routes/discovery_route_builders.js | 23 +++++++++++++----- .../discourse/routes/discovery_top_routes.js | 2 +- .../components/basic-topic-list.js.handlebars | 2 +- .../templates/discovery/topics.js.handlebars | 22 ++++++++++------- .../templates/featured_topics.js.handlebars | 2 +- .../list/topic_list_item.js.handlebars | 2 +- 13 files changed, 108 insertions(+), 65 deletions(-) create mode 100644 app/assets/javascripts/discourse/controllers/_discovery_controller.js diff --git a/app/assets/javascripts/discourse/controllers/_discovery_controller.js b/app/assets/javascripts/discourse/controllers/_discovery_controller.js new file mode 100644 index 00000000000..0613340edac --- /dev/null +++ b/app/assets/javascripts/discourse/controllers/_discovery_controller.js @@ -0,0 +1,24 @@ +/** + The base controller for discoverying topics + + @class DiscoveryController + @extends Discourse.Controller + @namespace Discourse + @module Discourse +**/ +Discourse.DiscoveryController = Discourse.ObjectController.extend({ + + showMoreUrl: function(period) { + var url = '', category = this.get('category'); + if (category) { + url = '/category/' + Discourse.Category.slugFor(category) + (this.get('noSubcategories') ? '/none' : '') + '/l'; + } + url += '/top/' + period; + return url; + }, + + showMoreDailyUrl: function() { return this.showMoreUrl('daily'); }.property('category', 'noSubcategories'), + showMoreWeeklyUrl: function() { return this.showMoreUrl('weekly'); }.property('category', 'noSubcategories'), + showMoreMonthlyUrl: function() { return this.showMoreUrl('monthly'); }.property('category', 'noSubcategories'), + showMoreYearlyUrl: function() { return this.showMoreUrl('yearly'); }.property('category', 'noSubcategories'), +}); diff --git a/app/assets/javascripts/discourse/controllers/discovery_categories_controller.js b/app/assets/javascripts/discourse/controllers/discovery_categories_controller.js index 34cd727b095..24a45ec6af7 100644 --- a/app/assets/javascripts/discourse/controllers/discovery_categories_controller.js +++ b/app/assets/javascripts/discourse/controllers/discovery_categories_controller.js @@ -6,7 +6,7 @@ @namespace Discourse @module Discourse **/ -Discourse.DiscoveryCategoriesController = Discourse.ObjectController.extend({ +Discourse.DiscoveryCategoriesController = Discourse.DiscoveryController.extend({ needs: ['modal'], actions: { @@ -19,11 +19,6 @@ Discourse.DiscoveryCategoriesController = Discourse.ObjectController.extend({ return Discourse.User.currentProp('staff'); }.property(), - // clear a pinned topic - clearPin: function(topic) { - topic.clearPin(); - }, - moveCategory: function(categoryId, position){ this.get('model.categories').moveCategory(categoryId, position); }, diff --git a/app/assets/javascripts/discourse/controllers/discovery_top_controller.js b/app/assets/javascripts/discourse/controllers/discovery_top_controller.js index ff77d8e0554..7405c6f977b 100644 --- a/app/assets/javascripts/discourse/controllers/discovery_top_controller.js +++ b/app/assets/javascripts/discourse/controllers/discovery_top_controller.js @@ -6,9 +6,7 @@ @namespace Discourse @module Discourse **/ -Discourse.DiscoveryTopController = Discourse.ObjectController.extend({ - category: null, - +Discourse.DiscoveryTopController = Discourse.DiscoveryController.extend({ redirectedToTopPageReason: function() { // no need for a reason if the default homepage is 'top' if (Discourse.Utilities.defaultHomepage() === 'top') { return null; } @@ -24,19 +22,5 @@ Discourse.DiscoveryTopController = Discourse.ObjectController.extend({ return null; }.property(), - hasDisplayedAllTopLists: Em.computed.and('content.yearly', 'content.monthly', 'content.weekly', 'content.daily'), - - showMoreUrl: function(period) { - var url = '', category = this.get('category'); - if (category) { - url = '/category/' + Discourse.Category.slugFor(category) + (this.get('noSubcategories') ? '/none' : '') + '/l'; - } - url += '/top/' + period; - return url; - }, - - showMoreDailyUrl: function() { return this.showMoreUrl('daily'); }.property('category', 'noSubcategories'), - showMoreWeeklyUrl: function() { return this.showMoreUrl('weekly'); }.property('category', 'noSubcategories'), - showMoreMonthlyUrl: function() { return this.showMoreUrl('monthly'); }.property('category', 'noSubcategories'), - showMoreYearlyUrl: function() { return this.showMoreUrl('yearly'); }.property('category', 'noSubcategories'), + hasDisplayedAllTopLists: Em.computed.and('content.yearly', 'content.monthly', 'content.weekly', 'content.daily') }); diff --git a/app/assets/javascripts/discourse/controllers/discovery_topics_controller.js b/app/assets/javascripts/discourse/controllers/discovery_topics_controller.js index 22fad099959..a3873ffdd47 100644 --- a/app/assets/javascripts/discourse/controllers/discovery_topics_controller.js +++ b/app/assets/javascripts/discourse/controllers/discovery_topics_controller.js @@ -6,18 +6,13 @@ @namespace Discourse @module Discourse **/ -Discourse.DiscoveryTopicsController = Discourse.ObjectController.extend({ +Discourse.DiscoveryTopicsController = Discourse.DiscoveryController.extend({ actions: { // Star a topic toggleStar: function(topic) { topic.toggleStar(); }, - // clear a pinned topic - clearPin: function(topic) { - topic.clearPin(); - }, - // Show newly inserted topics showInserted: function() { var tracker = Discourse.TopicTrackingState.current(); @@ -46,8 +41,13 @@ Discourse.DiscoveryTopicsController = Discourse.ObjectController.extend({ hasTopics: Em.computed.gt('topics.length', 0), showTable: Em.computed.or('hasTopics', 'topicTrackingState.hasIncoming'), - latest: Em.computed.equal('filter', 'latest'), allLoaded: Em.computed.empty('more_topics_url'), + latest: Discourse.computed.endWith('filter', 'latest'), + top: Em.computed.notEmpty('period'), + yearly: Em.computed.equal('period', 'yearly'), + monthly: Em.computed.equal('period', 'monthly'), + weekly: Em.computed.equal('period', 'weekly'), + daily: Em.computed.equal('period', 'daily'), updateTitle: function(){ Discourse.notifyTitle(this.get('topicTrackingState.incomingCount')); diff --git a/app/assets/javascripts/discourse/controllers/navigation_default_controller.js b/app/assets/javascripts/discourse/controllers/navigation_default_controller.js index 9c2a48a1051..5d4e9760c76 100644 --- a/app/assets/javascripts/discourse/controllers/navigation_default_controller.js +++ b/app/assets/javascripts/discourse/controllers/navigation_default_controller.js @@ -7,21 +7,6 @@ @module Discourse **/ Discourse.NavigationDefaultController = Discourse.Controller.extend({ - needs: ['composer', 'discoveryTopics'], - - actions: { - createTopic: function() { - var topicsController = this.get('controllers.discoveryTopics'); - this.get('controllers.composer').open({ - categoryId: this.get('category.id'), - action: Discourse.Composer.CREATE_TOPIC, - draft: topicsController.get('draft'), - draftKey: topicsController.get('draft_key'), - draftSequence: topicsController.get('draft_sequence') - }); - } - }, - categories: function() { return Discourse.Category.list(); }.property(), diff --git a/app/assets/javascripts/discourse/lib/computed.js b/app/assets/javascripts/discourse/lib/computed.js index 38512f58e9c..5dab103d774 100644 --- a/app/assets/javascripts/discourse/lib/computed.js +++ b/app/assets/javascripts/discourse/lib/computed.js @@ -88,6 +88,28 @@ Discourse.computed = { }))); }); return computed.property.apply(computed, args); - } + }, + + /** + Returns whether properties end with a string + + @method i18n + @params {String} properties* to check + @params {String} substring the substring + @return {Function} computedProperty function + **/ + endWith: function() { + var args = Array.prototype.slice.call(arguments, 0); + var substring = args.pop(); + var computed = Ember.computed(function() { + var self = this; + return _.all(args.map(function(a) { return self.get(a); }), function(s) { + var position = s.length - substring.length, + lastIndex = s.lastIndexOf(substring); + return lastIndex !== -1 && lastIndex === position; + }); + }); + return computed.property.apply(computed, args); + }, }; diff --git a/app/assets/javascripts/discourse/routes/discovery_route.js b/app/assets/javascripts/discourse/routes/discovery_route.js index f7093391abc..dbedf8d3dd0 100644 --- a/app/assets/javascripts/discourse/routes/discovery_route.js +++ b/app/assets/javascripts/discourse/routes/discovery_route.js @@ -19,6 +19,22 @@ Discourse.DiscoveryRoute = Discourse.Route.extend({ didTransition: function() { this.send('loadingComplete'); + }, + + // clear a pinned topic + clearPin: function(topic) { + topic.clearPin(); + }, + + createTopic: function() { + var topicsController = this.controllerFor('discoveryTopics'); + this.controllerFor('composer').open({ + categoryId: topicsController.get('category.id'), + action: Discourse.Composer.CREATE_TOPIC, + draft: topicsController.get('draft'), + draftKey: topicsController.get('draft_key'), + draftSequence: topicsController.get('draft_sequence') + }); } } }); diff --git a/app/assets/javascripts/discourse/routes/discovery_route_builders.js b/app/assets/javascripts/discourse/routes/discovery_route_builders.js index 4b2b4b0b8f9..a2380088a9e 100644 --- a/app/assets/javascripts/discourse/routes/discovery_route_builders.js +++ b/app/assets/javascripts/discourse/routes/discovery_route_builders.js @@ -22,9 +22,12 @@ function buildTopicRoute(filter) { }, setupController: function(controller, model) { - var filterText = I18n.t('filters.' + filter.replace('/', '.') + '.title', {count: 0}); + var period = filter.indexOf('/') > 0 ? filter.split('/')[1] : '', + filterText = I18n.t('filters.' + filter.replace('/', '.') + '.title', {count: 0}); + Discourse.set('title', I18n.t('filters.with_topics', {filter: filterText})); - this.controllerFor('discoveryTopics').set('model', model); + + this.controllerFor('discoveryTopics').setProperties({ model: model, category: null, period: period }); this.controllerFor('navigationDefault').set('canCreateTopic', model.get('can_create_topic')); }, @@ -76,12 +79,20 @@ function buildCategoryRoute(filter, params) { }, setupController: function(controller, model) { - var topics = this.get('topics'); + var topics = this.get('topics'), + period = filter.indexOf('/') > 0 ? filter.split('/')[1] : '', + filterText = I18n.t('filters.' + filter.replace('/', '.') + '.title', {count: 0}); + + Discourse.set('title', I18n.t('filters.with_category', { filter: filterText, category: model.get('name').capitalize() })); - var filterText = I18n.t('filters.' + filter.replace('/', '.') + '.title', {count: 0}); - Discourse.set('title', I18n.t('filters.with_category', {filter: filterText, category: model.get('name').capitalize()})); - this.controllerFor('discoveryTopics').set('model', topics); this.controllerFor('navigationCategory').set('canCreateTopic', topics.get('can_create_topic')); + this.controllerFor('discoveryTopics').setProperties({ + model: topics, + category: model, + period: period, + noSubcategories: params && !!params.no_subcategories + }); + this.set('topics', null); }, diff --git a/app/assets/javascripts/discourse/routes/discovery_top_routes.js b/app/assets/javascripts/discourse/routes/discovery_top_routes.js index ea34efa8e70..1ac90293c35 100644 --- a/app/assets/javascripts/discourse/routes/discovery_top_routes.js +++ b/app/assets/javascripts/discourse/routes/discovery_top_routes.js @@ -48,7 +48,7 @@ Discourse.DiscoveryTopCategoryRoute = Discourse.Route.extend({ this.controllerFor('search').set('searchContext', model); - var opts = { category: model, filterMode: filterMode}; + var opts = { category: model, filterMode: filterMode }; opts.noSubcategories = noSubcategories; opts.canEditCategory = Discourse.User.current('staff'); this.controllerFor('navigationCategory').setProperties(opts); diff --git a/app/assets/javascripts/discourse/templates/components/basic-topic-list.js.handlebars b/app/assets/javascripts/discourse/templates/components/basic-topic-list.js.handlebars index 6fb157d8645..e363af35a36 100644 --- a/app/assets/javascripts/discourse/templates/components/basic-topic-list.js.handlebars +++ b/app/assets/javascripts/discourse/templates/components/basic-topic-list.js.handlebars @@ -57,7 +57,7 @@ {{number topic.views numberKey="views_long"}} {{#if topic.bumped}} - {{unboundAge topic.created_at}} + {{unboundAge topic.created_at}} {{unboundAge topic.bumped_at}} diff --git a/app/assets/javascripts/discourse/templates/discovery/topics.js.handlebars b/app/assets/javascripts/discourse/templates/discovery/topics.js.handlebars index 362f4f47a45..c3ad6b835e7 100644 --- a/app/assets/javascripts/discourse/templates/discovery/topics.js.handlebars +++ b/app/assets/javascripts/discourse/templates/discovery/topics.js.handlebars @@ -54,17 +54,23 @@ {{#if loadingMore}}
{{i18n topic.loading_more}}
{{/if}} - -

- {{footerMessage}} - {{#if allLoaded}} + {{#if allLoaded}} +

{{#if latest}} {{#if can_create_topic}} - {{i18n topic.suggest_create_topic}} + {{footerMessage}}{{i18n topic.suggest_create_topic}} {{/if}} {{else}} - {{#link-to "discovery.categories"}}{{i18n topic.browse_all_categories}}{{/link-to}} {{i18n or}} {{#link-to 'discovery.latest'}}{{i18n topic.view_latest_topics}}{{/link-to}} + {{#if top}} + {{#link-to "discovery.categories"}}{{i18n topic.browse_all_categories}}{{/link-to}}, {{#link-to 'discovery.latest'}}{{i18n topic.view_latest_topics}}{{/link-to}} {{i18n or}} {{i18n filters.top.other_periods}} + {{#unless yearly}}{{i18n filters.top.this_year}}{{/unless}} + {{#unless monthly}}{{i18n filters.top.this_month}}{{/unless}} + {{#unless weekly}}{{i18n filters.top.this_week}}{{/unless}} + {{#unless daily}}{{i18n filters.top.today}}{{/unless}} + {{else}} + {{footerMessage}}{{#link-to "discovery.categories"}}{{i18n topic.browse_all_categories}}{{/link-to}} {{i18n or}} {{#link-to 'discovery.latest'}}{{i18n topic.view_latest_topics}}{{/link-to}} + {{/if}} {{/if}} - {{/if}} -

+ + {{/if}} diff --git a/app/assets/javascripts/discourse/templates/featured_topics.js.handlebars b/app/assets/javascripts/discourse/templates/featured_topics.js.handlebars index 2b4a48f81bd..b4f15abdacc 100644 --- a/app/assets/javascripts/discourse/templates/featured_topics.js.handlebars +++ b/app/assets/javascripts/discourse/templates/featured_topics.js.handlebars @@ -52,7 +52,7 @@ {{number posts_count}} - {{{unboundAge created_at}}} + {{{unboundAge created_at}}} {{/each}} diff --git a/app/assets/javascripts/discourse/templates/list/topic_list_item.js.handlebars b/app/assets/javascripts/discourse/templates/list/topic_list_item.js.handlebars index 3fb9b77a2c3..57882f5cf3e 100644 --- a/app/assets/javascripts/discourse/templates/list/topic_list_item.js.handlebars +++ b/app/assets/javascripts/discourse/templates/list/topic_list_item.js.handlebars @@ -54,7 +54,7 @@ {{#if bumped}} - {{unboundAge created_at}} + {{unboundAge created_at}} {{unboundAge bumped_at}}