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

View file

@ -1,13 +1,4 @@
/**
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 = Em.Object.extend();
Discourse.StaticPage.reopenClass({
find: function(path) {
@ -27,4 +18,3 @@ Discourse.StaticPage.reopenClass({
});
}
});

View file

@ -7,12 +7,6 @@
Discourse.Route.buildRoutes(function() {
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
this.route('exception', { path: '/exception' });
@ -93,6 +87,10 @@ Discourse.Route.buildRoutes(function() {
this.route('signup', {path: '/signup'});
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.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');