BUGFIX: display links to other periods at the bottom of the top/:period page
This commit is contained in:
parent
8d2e5041bc
commit
aca53aa722
13 changed files with 108 additions and 65 deletions
app/assets/javascripts/discourse
|
@ -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'),
|
||||||
|
});
|
|
@ -6,7 +6,7 @@
|
||||||
@namespace Discourse
|
@namespace Discourse
|
||||||
@module Discourse
|
@module Discourse
|
||||||
**/
|
**/
|
||||||
Discourse.DiscoveryCategoriesController = Discourse.ObjectController.extend({
|
Discourse.DiscoveryCategoriesController = Discourse.DiscoveryController.extend({
|
||||||
needs: ['modal'],
|
needs: ['modal'],
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
|
@ -19,11 +19,6 @@ Discourse.DiscoveryCategoriesController = Discourse.ObjectController.extend({
|
||||||
return Discourse.User.currentProp('staff');
|
return Discourse.User.currentProp('staff');
|
||||||
}.property(),
|
}.property(),
|
||||||
|
|
||||||
// clear a pinned topic
|
|
||||||
clearPin: function(topic) {
|
|
||||||
topic.clearPin();
|
|
||||||
},
|
|
||||||
|
|
||||||
moveCategory: function(categoryId, position){
|
moveCategory: function(categoryId, position){
|
||||||
this.get('model.categories').moveCategory(categoryId, position);
|
this.get('model.categories').moveCategory(categoryId, position);
|
||||||
},
|
},
|
||||||
|
|
|
@ -6,9 +6,7 @@
|
||||||
@namespace Discourse
|
@namespace Discourse
|
||||||
@module Discourse
|
@module Discourse
|
||||||
**/
|
**/
|
||||||
Discourse.DiscoveryTopController = Discourse.ObjectController.extend({
|
Discourse.DiscoveryTopController = Discourse.DiscoveryController.extend({
|
||||||
category: null,
|
|
||||||
|
|
||||||
redirectedToTopPageReason: function() {
|
redirectedToTopPageReason: function() {
|
||||||
// no need for a reason if the default homepage is 'top'
|
// no need for a reason if the default homepage is 'top'
|
||||||
if (Discourse.Utilities.defaultHomepage() === 'top') { return null; }
|
if (Discourse.Utilities.defaultHomepage() === 'top') { return null; }
|
||||||
|
@ -24,19 +22,5 @@ Discourse.DiscoveryTopController = Discourse.ObjectController.extend({
|
||||||
return null;
|
return null;
|
||||||
}.property(),
|
}.property(),
|
||||||
|
|
||||||
hasDisplayedAllTopLists: Em.computed.and('content.yearly', 'content.monthly', 'content.weekly', 'content.daily'),
|
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'),
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,18 +6,13 @@
|
||||||
@namespace Discourse
|
@namespace Discourse
|
||||||
@module Discourse
|
@module Discourse
|
||||||
**/
|
**/
|
||||||
Discourse.DiscoveryTopicsController = Discourse.ObjectController.extend({
|
Discourse.DiscoveryTopicsController = Discourse.DiscoveryController.extend({
|
||||||
actions: {
|
actions: {
|
||||||
// Star a topic
|
// Star a topic
|
||||||
toggleStar: function(topic) {
|
toggleStar: function(topic) {
|
||||||
topic.toggleStar();
|
topic.toggleStar();
|
||||||
},
|
},
|
||||||
|
|
||||||
// clear a pinned topic
|
|
||||||
clearPin: function(topic) {
|
|
||||||
topic.clearPin();
|
|
||||||
},
|
|
||||||
|
|
||||||
// Show newly inserted topics
|
// Show newly inserted topics
|
||||||
showInserted: function() {
|
showInserted: function() {
|
||||||
var tracker = Discourse.TopicTrackingState.current();
|
var tracker = Discourse.TopicTrackingState.current();
|
||||||
|
@ -46,8 +41,13 @@ Discourse.DiscoveryTopicsController = Discourse.ObjectController.extend({
|
||||||
|
|
||||||
hasTopics: Em.computed.gt('topics.length', 0),
|
hasTopics: Em.computed.gt('topics.length', 0),
|
||||||
showTable: Em.computed.or('hasTopics', 'topicTrackingState.hasIncoming'),
|
showTable: Em.computed.or('hasTopics', 'topicTrackingState.hasIncoming'),
|
||||||
latest: Em.computed.equal('filter', 'latest'),
|
|
||||||
allLoaded: Em.computed.empty('more_topics_url'),
|
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(){
|
updateTitle: function(){
|
||||||
Discourse.notifyTitle(this.get('topicTrackingState.incomingCount'));
|
Discourse.notifyTitle(this.get('topicTrackingState.incomingCount'));
|
||||||
|
|
|
@ -7,21 +7,6 @@
|
||||||
@module Discourse
|
@module Discourse
|
||||||
**/
|
**/
|
||||||
Discourse.NavigationDefaultController = Discourse.Controller.extend({
|
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() {
|
categories: function() {
|
||||||
return Discourse.Category.list();
|
return Discourse.Category.list();
|
||||||
}.property(),
|
}.property(),
|
||||||
|
|
|
@ -88,6 +88,28 @@ Discourse.computed = {
|
||||||
})));
|
})));
|
||||||
});
|
});
|
||||||
return computed.property.apply(computed, args);
|
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);
|
||||||
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,6 +19,22 @@ Discourse.DiscoveryRoute = Discourse.Route.extend({
|
||||||
|
|
||||||
didTransition: function() {
|
didTransition: function() {
|
||||||
this.send('loadingComplete');
|
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')
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -22,9 +22,12 @@ function buildTopicRoute(filter) {
|
||||||
},
|
},
|
||||||
|
|
||||||
setupController: function(controller, model) {
|
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}));
|
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'));
|
this.controllerFor('navigationDefault').set('canCreateTopic', model.get('can_create_topic'));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -76,12 +79,20 @@ function buildCategoryRoute(filter, params) {
|
||||||
},
|
},
|
||||||
|
|
||||||
setupController: function(controller, model) {
|
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('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);
|
this.set('topics', null);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ Discourse.DiscoveryTopCategoryRoute = Discourse.Route.extend({
|
||||||
|
|
||||||
this.controllerFor('search').set('searchContext', model);
|
this.controllerFor('search').set('searchContext', model);
|
||||||
|
|
||||||
var opts = { category: model, filterMode: filterMode};
|
var opts = { category: model, filterMode: filterMode };
|
||||||
opts.noSubcategories = noSubcategories;
|
opts.noSubcategories = noSubcategories;
|
||||||
opts.canEditCategory = Discourse.User.current('staff');
|
opts.canEditCategory = Discourse.User.current('staff');
|
||||||
this.controllerFor('navigationCategory').setProperties(opts);
|
this.controllerFor('navigationCategory').setProperties(opts);
|
||||||
|
|
|
@ -57,7 +57,7 @@
|
||||||
<td {{bind-attr class=":num :views topic.viewsHeat"}}>{{number topic.views numberKey="views_long"}}</td>
|
<td {{bind-attr class=":num :views topic.viewsHeat"}}>{{number topic.views numberKey="views_long"}}</td>
|
||||||
{{#if topic.bumped}}
|
{{#if topic.bumped}}
|
||||||
<td class='num activity'>
|
<td class='num activity'>
|
||||||
<a href="{{unbound topic.url}}" {{{bindAttr class=":age topic.ageCold"}}} title='{{i18n first_post}}: {{{rawDate topic.created_at}}}' >{{unboundAge topic.created_at}}</a>
|
<a href="{{unbound topic.url}}" {{{bind-attr class=":age topic.ageCold"}}} title='{{i18n first_post}}: {{{rawDate topic.created_at}}}' >{{unboundAge topic.created_at}}</a>
|
||||||
</td>
|
</td>
|
||||||
<td class='num activity last'>
|
<td class='num activity last'>
|
||||||
<a href="{{unbound topic.lastPostUrl}}" class='age' title='{{i18n last_post}}: {{{rawDate topic.bumped_at}}}'>{{unboundAge topic.bumped_at}}</a>
|
<a href="{{unbound topic.lastPostUrl}}" class='age' title='{{i18n last_post}}: {{{rawDate topic.bumped_at}}}'>{{unboundAge topic.bumped_at}}</a>
|
||||||
|
|
|
@ -54,17 +54,23 @@
|
||||||
{{#if loadingMore}}
|
{{#if loadingMore}}
|
||||||
<div class='topics-loading'>{{i18n topic.loading_more}}</div>
|
<div class='topics-loading'>{{i18n topic.loading_more}}</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
{{#if allLoaded}}
|
||||||
<h3>
|
<h3>
|
||||||
{{footerMessage}}
|
|
||||||
{{#if allLoaded}}
|
|
||||||
{{#if latest}}
|
{{#if latest}}
|
||||||
{{#if can_create_topic}}
|
{{#if can_create_topic}}
|
||||||
<a href='#' {{action createTopic}}>{{i18n topic.suggest_create_topic}}</a>
|
{{footerMessage}}<a href='#' {{action createTopic}}>{{i18n topic.suggest_create_topic}}</a>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{else}}
|
{{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}}<a href="{{unbound showMoreYearlyUrl}}" class='btn'>{{i18n filters.top.this_year}}</a>{{/unless}}
|
||||||
|
{{#unless monthly}}<a href="{{unbound showMoreMonthlyUrl}}" class='btn'>{{i18n filters.top.this_month}}</a>{{/unless}}
|
||||||
|
{{#unless weekly}}<a href="{{unbound showMoreWeeklyUrl}}" class='btn'>{{i18n filters.top.this_week}}</a>{{/unless}}
|
||||||
|
{{#unless daily}}<a href="{{unbound showMoreDailyUrl}}" class='btn'>{{i18n filters.top.today}}</a>{{/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}}
|
</h3>
|
||||||
</h3>
|
{{/if}}
|
||||||
</footer>
|
</footer>
|
||||||
|
|
|
@ -52,7 +52,7 @@
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td class='num posts'><span class='badge-posts'>{{number posts_count}}</span></td>
|
<td class='num posts'><span class='badge-posts'>{{number posts_count}}</span></td>
|
||||||
<td class='num age'><span {{bindAttr class=":age ageCold"}} title='{{rawDate created_at}}'>{{{unboundAge created_at}}}</span></td>
|
<td class='num age'><span {{bind-attr class=":age ageCold"}} title='{{rawDate created_at}}'>{{{unboundAge created_at}}}</span></td>
|
||||||
</tr>
|
</tr>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@
|
||||||
|
|
||||||
{{#if bumped}}
|
{{#if bumped}}
|
||||||
<td class='num activity'>
|
<td class='num activity'>
|
||||||
<a href="{{url}}" {{{bindAttr class=":age ageCold"}}} title='{{i18n first_post}}: {{{rawDate created_at}}}' >{{unboundAge created_at}}</a>
|
<a href="{{url}}" {{{bind-attr class=":age ageCold"}}} title='{{i18n first_post}}: {{{rawDate created_at}}}' >{{unboundAge created_at}}</a>
|
||||||
</td>
|
</td>
|
||||||
<td class='num activity last'>
|
<td class='num activity last'>
|
||||||
<a href="{{lastPostUrl}}" class='age' title='{{i18n last_post}}: {{{rawDate bumped_at}}}'>{{unboundAge bumped_at}}</a>
|
<a href="{{lastPostUrl}}" class='age' title='{{i18n last_post}}: {{{rawDate bumped_at}}}'>{{unboundAge bumped_at}}</a>
|
||||||
|
|
Reference in a new issue