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
This commit is contained in:
Toby Zerner 2015-09-17 12:56:39 +09:30
parent e038c5c9d9
commit dbd33f687c
3 changed files with 37 additions and 18 deletions

View File

@ -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 {
<div className="helpText">
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.
</div>,
<label className="checkbox">
<input type="radio" name="homePage" value="/all" checked={this.values.default_route() === '/all'} onclick={m.withAttr('value', this.values.default_route)}/>
All Discussions
</label>,
<label className="checkbox">
<input type="radio" name="homePage" value="custom" checked={this.values.default_route() !== '/all'} onclick={() => {
this.values.default_route('');
m.redraw(true);
this.$('.BasicsPage-homePage input').select();
}}/>
Custom <input className="FormControl" value={this.values.default_route()} oninput={m.withAttr('value', this.values.default_route)} style={this.values.default_route() !== '/all' ? 'margin-top: 5px' : 'display:none'}/>
</label>
this.homePageItems().toArray().map(({path, label}) =>
<label className="checkbox">
<input type="radio" name="homePage" value={path} checked={this.values.default_route() === path} onclick={m.withAttr('value', this.values.default_route)}/>
{label}
</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();

View File

@ -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}));

View File

@ -63,7 +63,7 @@ class ForumServiceProvider extends ServiceProvider
$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 @@ class ForumServiceProvider extends ServiceProvider
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
);
}