From dbd33f687c50cb232231870166d6f83d7d3014fc Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Thu, 17 Sep 2015 12:56:39 +0930 Subject: [PATCH] Remove "custom" home page input Also add an API to let extensions define additional default route options. Allowing default routes with parameters (e.g. /d/123) is very difficult because of the way Mithril routing works, and it doesn't have a convincing use-case to justify the trouble. So I've removed the custom input altogether. closes #427 --- js/admin/src/components/BasicsPage.js | 37 ++++++++++++++++++--------- js/forum/src/initializers/boot.js | 9 ++++--- src/Forum/ForumServiceProvider.php | 9 +++++-- 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/js/admin/src/components/BasicsPage.js b/js/admin/src/components/BasicsPage.js index c3654d6ccb..eb1b49918d 100644 --- a/js/admin/src/components/BasicsPage.js +++ b/js/admin/src/components/BasicsPage.js @@ -4,6 +4,7 @@ import Select from 'flarum/components/Select'; import Button from 'flarum/components/Button'; import Alert from 'flarum/components/Alert'; import saveConfig from 'flarum/utils/saveConfig'; +import ItemList from 'flarum/utils/ItemList'; export default class BasicsPage extends Component { constructor(...args) { @@ -72,18 +73,12 @@ export default class BasicsPage extends Component {
Choose the page which users will first see when they visit your forum. If entering a custom value, use the path relative to the forum root.
, - , - + this.homePageItems().toArray().map(({path, label}) => + + ) ] })} @@ -120,6 +115,24 @@ export default class BasicsPage extends Component { return this.fields.some(key => this.values[key]() !== config[key]); } + /** + * Build a list of options for the default homepage. Each option must be an + * object with `path` and `label` properties. + * + * @return {ItemList} + * @public + */ + homePageItems() { + const items = new ItemList(); + + items.add('allDiscussions', { + path: '/all', + label: 'All Discussions' + }); + + return items; + } + onsubmit(e) { e.preventDefault(); diff --git a/js/forum/src/initializers/boot.js b/js/forum/src/initializers/boot.js index 3ba967930a..ada9b09657 100644 --- a/js/forum/src/initializers/boot.js +++ b/js/forum/src/initializers/boot.js @@ -24,14 +24,15 @@ export default function boot(app) { // able to click on the 'back' button to go home, regardless of which page // they started on. const defaultRoute = app.forum.attribute('defaultRoute'); + let defaultAction = 'index'; for (const i in app.routes) { - if (app.routes[i].path === defaultRoute) { - app.routes[i].path = '/'; - app.history.push(i, '/'); - } + if (app.routes[i].path === defaultRoute) defaultAction = i; } + app.routes[defaultAction].path = '/'; + app.history.push(defaultAction, '/'); + m.startComputation(); m.mount(document.getElementById('app-navigation'), Navigation.component({className: 'App-backControl', drawer: true})); diff --git a/src/Forum/ForumServiceProvider.php b/src/Forum/ForumServiceProvider.php index 0edd323e63..2b2bb93177 100644 --- a/src/Forum/ForumServiceProvider.php +++ b/src/Forum/ForumServiceProvider.php @@ -63,7 +63,7 @@ protected function routes() $routes->get( '/all', 'flarum.forum.index', - $this->action('Flarum\Forum\Actions\IndexAction') + $defaultAction = $this->action('Flarum\Forum\Actions\IndexAction') ); $routes->get( @@ -129,11 +129,16 @@ protected function routes() event(new RegisterForumRoutes($routes)); $settings = $this->app->make('Flarum\Core\Settings\SettingsRepository'); + $defaultRoute = $settings->get('default_route'); + + if (isset($routes->getRouteData()[0]['GET'][$defaultRoute])) { + $defaultAction = $routes->getRouteData()[0]['GET'][$defaultRoute]; + } $routes->get( '/', 'flarum.forum.default', - $routes->getRouteData()[0]['GET'][$settings->get('default_route')] + $defaultAction ); }