ES6: Remove dynamically generated static routes. They were causing lots

of confusion and bugs.
This commit is contained in:
Robin Ward 2014-07-29 14:24:16 -04:00
parent df9bd3d666
commit 16dfedef8f
9 changed files with 36 additions and 56 deletions

View file

@ -0,0 +1,9 @@
export default Em.ObjectController.extend({
showLoginButton: Em.computed.equal('path', 'login'),
actions: {
markFaqRead: function() {
Discourse.ajax("/users/read-faq", { method: "POST" });
}
}
});

View file

@ -1,27 +0,0 @@
/**
This controller supports displaying static content.
@class StaticController
@extends Em.ObjectController
@namespace Discourse
@module Discourse
**/
Discourse.StaticController = Em.ObjectController.extend({
showLoginButton: Em.computed.equal('path', 'login'),
actions: {
markFaqRead: function() {
Discourse.ajax("/users/read-faq", { method: "POST" });
}
}
});
Discourse.StaticController.reopenClass({
PAGES: ['faq', 'tos', 'privacy', 'guidelines'],
CONFIGS: {
'faq': 'faq_url',
'tos': 'tos_url',
'privacy': 'privacy_policy_url'
}
});

View file

@ -1,20 +1,17 @@
/** var configs = {
The routes used for rendering static content 'faq': 'faq_url',
'tos': 'tos_url',
@class StaticRoute 'privacy': 'privacy_policy_url'
@extends Discourse.Route };
@namespace Discourse
@module Discourse
**/
Discourse.StaticController.PAGES.forEach(function(page) {
Discourse[page.capitalize() + "Route"] = Discourse.Route.extend({
export default function(page) {
return Discourse.Route.extend({
renderTemplate: function() { renderTemplate: function() {
this.render('static'); this.render('static');
}, },
beforeModel: function(transition) { beforeModel: function(transition) {
var configKey = Discourse.StaticController.CONFIGS[page]; var configKey = configs[page];
if (configKey && Discourse.SiteSettings[configKey].length > 0) { if (configKey && Discourse.SiteSettings[configKey].length > 0) {
transition.abort(); transition.abort();
Discourse.URL.redirectTo(Discourse.SiteSettings[configKey]); Discourse.URL.redirectTo(Discourse.SiteSettings[configKey]);
@ -36,4 +33,5 @@ Discourse.StaticController.PAGES.forEach(function(page) {
this.controllerFor('static').set('model', model); this.controllerFor('static').set('model', model);
} }
}); });
}); }

View file

@ -1,13 +1,4 @@
/** Discourse.StaticPage = Em.Object.extend();
A model that repreesnts a static page in Discourse
@class StaticPage
@extends Em.Object
@namespace Discourse
@module Discourse
**/
Discourse.StaticPage = Em.Object.extend({
});
Discourse.StaticPage.reopenClass({ Discourse.StaticPage.reopenClass({
find: function(path) { find: function(path) {
@ -27,4 +18,3 @@ Discourse.StaticPage.reopenClass({
}); });
} }
}); });

View file

@ -7,12 +7,6 @@
Discourse.Route.buildRoutes(function() { Discourse.Route.buildRoutes(function() {
var router = this; var router = this;
// Generate static page routes
// e.g., faq, tos, privacy, login
_.each(Discourse.StaticController.PAGES, function (page) {
router.route(page, { path: '/' + page });
});
// Error page // Error page
this.route('exception', { path: '/exception' }); this.route('exception', { path: '/exception' });
@ -93,6 +87,10 @@ Discourse.Route.buildRoutes(function() {
this.route('signup', {path: '/signup'}); this.route('signup', {path: '/signup'});
this.route('login', {path: '/login'}); this.route('login', {path: '/login'});
this.route('faq', {path: '/faq'});
this.route('tos', {path: '/tos'});
this.route('privacy', {path: '/privacy'});
this.route('guidelines', {path: '/guidelines'});
this.resource('badges', function() { this.resource('badges', function() {
this.route('show', {path: '/:id/:slug'}); this.route('show', {path: '/:id/:slug'});

View file

@ -0,0 +1,3 @@
import staticRouteBuilder from 'discourse/lib/static-route-builder';
export default staticRouteBuilder('faq');

View file

@ -0,0 +1,3 @@
import FaqRoute from 'discourse/routes/faq';
export default FaqRoute;

View file

@ -0,0 +1,3 @@
import staticRouteBuilder from 'discourse/lib/static-route-builder';
export default staticRouteBuilder('privacy');

View file

@ -0,0 +1,3 @@
import staticRouteBuilder from 'discourse/lib/static-route-builder';
export default staticRouteBuilder('tos');