Skip to content

Commit

Permalink
Remove "custom" home page input
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tobyzerner committed Sep 17, 2015
1 parent e038c5c commit dbd33f6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
37 changes: 25 additions & 12 deletions js/admin/src/components/BasicsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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>
)
]
})}

Expand Down Expand Up @@ -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();

Expand Down
9 changes: 5 additions & 4 deletions js/forum/src/initializers/boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}));
Expand Down
9 changes: 7 additions & 2 deletions src/Forum/ForumServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
);
}

Expand Down

0 comments on commit dbd33f6

Please sign in to comment.