add top page

This commit is contained in:
Régis Hanol
2013-12-24 00:50:36 +01:00
parent b90e811825
commit 567d2bd23c
57 changed files with 532 additions and 324 deletions
@@ -24,7 +24,7 @@ Discourse.AdminSiteContentEditRoute = Discourse.Route.extend({
this.render('admin/templates/site_content_edit', {into: 'admin/templates/site_contents'});
},
exit: function() {
deactivate: function() {
this._super();
this.render('admin/templates/site_contents_empty', {into: 'admin/templates/site_contents'});
},
@@ -25,19 +25,6 @@ Discourse.ListController = Discourse.Controller.extend({
});
}.property("category"),
/**
Refresh our current topic list
@method refresh
**/
refresh: function() {
var listTopicsController = this.get('controllers.listTopics');
listTopicsController.set('model.loaded', false);
this.load(this.get('filterMode')).then(function (topicList) {
listTopicsController.set('model', topicList);
});
},
/**
Load a list based on a filter
@@ -135,5 +122,5 @@ Discourse.ListController = Discourse.Controller.extend({
});
Discourse.ListController.reopenClass({
filters: ['latest', 'hot', 'favorited', 'read', 'unread', 'new', 'posted']
filters: <%= Discourse.filters.map(&:to_s) %>
});
@@ -6,8 +6,8 @@
@namespace Discourse
@module Discourse
**/
var validNavNames = ['latest', 'hot', 'categories', 'category', 'favorited', 'unread', 'new', 'read', 'posted'];
var validAnon = ['latest', 'hot', 'categories', 'category'];
var validNavNames = <%= Discourse.top_menu_items.map(&:to_s) %>;
var validAnon = <%= Discourse.anonymous_top_menu_items.map(&:to_s) %>;
Discourse.NavItem = Discourse.Model.extend({
@@ -0,0 +1,34 @@
/**
A data model representing a list of top topic lists
@class TopList
@extends Discourse.Model
@namespace Discourse
@module Discourse
**/
Discourse.TopList = Discourse.Model.extend({});
Discourse.TopList.reopenClass({
find: function() {
return PreloadStore.getAndRemove("top_list", function() {
return Discourse.ajax("/top.json");
}).then(function (result) {
var topList = Discourse.TopList.create({
can_create_topic: result.can_create_topic,
yearly: Discourse.TopicList.from(result.yearly),
monthly: Discourse.TopicList.from(result.monthly),
weekly: Discourse.TopicList.from(result.weekly),
daily: Discourse.TopicList.from(result.daily)
});
// disable sorting
topList.setProperties({
"yearly.sortOrder": undefined,
"monthly.sortOrder": undefined,
"weekly.sortOrder": undefined,
"daily.sortOrder": undefined
});
return topList;
});
}
});
@@ -181,6 +181,28 @@ Discourse.TopicList.reopenClass({
});
},
from: function(result, filter, params) {
var topicList = Discourse.TopicList.create({
inserted: Em.A(),
filter: filter,
params: params || {},
topics: Discourse.TopicList.topicsFrom(result),
can_create_topic: result.topic_list.can_create_topic,
more_topics_url: result.topic_list.more_topics_url,
draft_key: result.topic_list.draft_key,
draft_sequence: result.topic_list.draft_sequence,
draft: result.topic_list.draft,
canViewRankDetails: result.topic_list.can_view_rank_details,
loaded: true
});
if (result.topic_list.filtered_category) {
topicList.set('category', Discourse.Category.create(result.topic_list.filtered_category));
}
return topicList;
},
/**
Lists topics on a given menu item
@@ -206,24 +228,7 @@ Discourse.TopicList.reopenClass({
find: function(filter, params) {
return PreloadStore.getAndRemove("topic_list", finderFor(filter, params)).then(function(result) {
var topicList = Discourse.TopicList.create({
inserted: Em.A(),
filter: filter,
params: params || {},
topics: Discourse.TopicList.topicsFrom(result),
can_create_topic: result.topic_list.can_create_topic,
more_topics_url: result.topic_list.more_topics_url,
draft_key: result.topic_list.draft_key,
draft_sequence: result.topic_list.draft_sequence,
draft: result.topic_list.draft,
canViewRankDetails: result.topic_list.can_view_rank_details,
loaded: true
});
if (result.topic_list.filtered_category) {
topicList.set('category', Discourse.Category.create(result.topic_list.filtered_category));
}
return topicList;
return Discourse.TopicList.from(result, filter, params);
});
}
@@ -167,9 +167,9 @@ Discourse.TopicTrackingState = Discourse.Model.extend({
lookupCount: function(name, category){
var categoryName = Em.get(category, "name");
if(name==="new") {
if(name === "new") {
return this.countNew(categoryName);
} else if(name==="unread") {
} else if(name === "unread") {
return this.countUnread(categoryName);
} else {
categoryName = name.split("/")[1];
@@ -30,20 +30,25 @@ Discourse.Route.buildRoutes(function() {
router.route(filter + "Category", { path: "/category/:slug/l/" + filter + "/more" });
router.route(filter + "Category", { path: "/category/:parentSlug/:slug/l/" + filter });
router.route(filter + "Category", { path: "/category/:parentSlug/:slug/l/" + filter + "/more" });
});
// the homepage is the first item of the 'top_menu' site setting
var homepage = Discourse.SiteSettings.top_menu.split("|")[0].split(",")[0];
this.route(homepage, { path: '/' });
// categories page
this.route('categories', { path: '/categories' });
// category
this.route('category', { path: '/category/:slug' });
this.route('category', { path: '/category/:slug/more' });
this.route('categoryNone', { path: '/category/:slug/none' });
this.route('categoryNone', { path: '/category/:slug/none/more' });
this.route('category', { path: '/category/:parentSlug/:slug' });
this.route('category', { path: '/category/:parentSlug/:slug/more' });
// top page
this.route('top', { path: '/top' });
});
// User routes
@@ -58,8 +63,8 @@ Discourse.Route.buildRoutes(function() {
});
this.resource('userPrivateMessages', { path: '/private-messages' }, function() {
this.route('mine', {path: '/mine'});
this.route('unread', {path: '/unread'});
this.route('mine', { path: '/mine' });
this.route('unread', { path: '/unread' });
});
this.resource('preferences', { path: '/preferences' }, function() {
@@ -10,12 +10,13 @@ Discourse.FilteredListRoute = Discourse.Route.extend({
redirect: function() { Discourse.redirectIfLoginRequired(this); },
exit: function() {
deactivate: function() {
this._super();
var listController = this.controllerFor('list');
listController.set('canCreateTopic', false);
listController.set('filterMode', '');
this.controllerFor('list').setProperties({
canCreateTopic: false,
filterMode: ''
});
},
renderTemplate: function() {
@@ -63,9 +63,7 @@ Discourse.ListCategoryNoneRoute = Discourse.ListCategoryRoute.extend({
});
Discourse.ListController.filters.forEach(function(filter) {
Discourse["List" + (filter.capitalize()) + "CategoryRoute"] = Discourse.ListCategoryRoute.extend({
filter: filter
});
Discourse["List" + filter.capitalize() + "CategoryRoute"] = Discourse.ListCategoryRoute.extend({ filter: filter });
});
@@ -0,0 +1,24 @@
Discourse.ListTopRoute = Discourse.Route.extend({
activate: function() {
// will mark the "top" navigation item as selected
this.controllerFor('list').setProperties({
filterMode: 'top',
category: null
});
},
model: function() {
return Discourse.TopList.find();
},
renderTemplate: function() {
this.render('top', { into: 'list', outlet: 'listView' });
},
deactivate: function() {
// Clear any filters when we leave the route
Discourse.URL.set('queryParams', null);
}
});
@@ -73,7 +73,7 @@ Discourse.PreferencesAboutRoute = Discourse.RestrictedUserRoute.extend({
},
// A bit odd, but if we leave to /preferences we need to re-render that outlet
exit: function() {
deactivate: function() {
this._super();
this.render('preferences', { into: 'user', outlet: 'userOutlet', controller: 'preferences' });
},
@@ -119,7 +119,7 @@ Discourse.PreferencesEmailRoute = Discourse.RestrictedUserRoute.extend({
},
// A bit odd, but if we leave to /preferences we need to re-render that outlet
exit: function() {
deactivate: function() {
this._super();
this.render('preferences', { into: 'user', outlet: 'userOutlet', controller: 'preferences' });
}
@@ -143,7 +143,7 @@ Discourse.PreferencesUsernameRoute = Discourse.RestrictedUserRoute.extend({
},
// A bit odd, but if we leave to /preferences we need to re-render that outlet
exit: function() {
deactivate: function() {
this._super();
this.render('preferences', { into: 'user', outlet: 'userOutlet', controller: 'preferences' });
},
@@ -73,4 +73,4 @@
{{/if}}
{{else}}
<div class='spinner'>{{i18n loading}}</div>
{{/if}}
{{/if}}
@@ -0,0 +1,9 @@
<h2>{{i18n filters.top.this_year}}</h2>
{{basic-topic-list topicList=content.yearly}}
<h2>{{i18n filters.top.this_month}}</h2>
{{basic-topic-list topicList=content.monthly}}
<h2>{{i18n filters.top.this_week}}</h2>
{{basic-topic-list topicList=content.weekly}}
<h2>{{i18n filters.top.today}}</h2>
{{basic-topic-list topicList=content.daily}}
<h3>{{#link-to "list.categories"}}{{i18n topic.browse_all_categories}}{{/link-to}} {{i18n or}} {{#link-to 'list.latest'}}{{i18n topic.view_latest_topics}}{{/link-to}}</h3>
@@ -60,7 +60,4 @@ Discourse.ListTopicsView = Discourse.View.extend(Discourse.LoadMore, {
this.saveScrollPosition();
}
});
@@ -28,7 +28,7 @@ Discourse.TopicListItemView = Discourse.GroupedView.extend({
didInsertElement: function() {
var session = Discourse.Session.current();
// // highligth the last topic viewed
// highligth the last topic viewed
if (session.get('lastTopicIdViewed') === this.get('content.id')) {
session.set('lastTopicIdViewed', null);
this.highlight();