mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 19:08:10 -05:00
ES6: Remove dynamically generated static routes. They were causing lots
of confusion and bugs.
This commit is contained in:
parent
df9bd3d666
commit
16dfedef8f
9 changed files with 36 additions and 56 deletions
|
@ -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" });
|
||||
}
|
||||
}
|
||||
});
|
|
@ -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'
|
||||
}
|
||||
});
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -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({
|
|||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -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'});
|
||||
|
|
3
app/assets/javascripts/discourse/routes/faq.js.es6
Normal file
3
app/assets/javascripts/discourse/routes/faq.js.es6
Normal file
|
@ -0,0 +1,3 @@
|
|||
import staticRouteBuilder from 'discourse/lib/static-route-builder';
|
||||
|
||||
export default staticRouteBuilder('faq');
|
|
@ -0,0 +1,3 @@
|
|||
import FaqRoute from 'discourse/routes/faq';
|
||||
|
||||
export default FaqRoute;
|
3
app/assets/javascripts/discourse/routes/privacy.js.es6
Normal file
3
app/assets/javascripts/discourse/routes/privacy.js.es6
Normal file
|
@ -0,0 +1,3 @@
|
|||
import staticRouteBuilder from 'discourse/lib/static-route-builder';
|
||||
|
||||
export default staticRouteBuilder('privacy');
|
3
app/assets/javascripts/discourse/routes/tos.js.es6
Normal file
3
app/assets/javascripts/discourse/routes/tos.js.es6
Normal file
|
@ -0,0 +1,3 @@
|
|||
import staticRouteBuilder from 'discourse/lib/static-route-builder';
|
||||
|
||||
export default staticRouteBuilder('tos');
|
Loading…
Reference in a new issue