mirror of
https://github.com/flarum/framework.git
synced 2025-05-23 15:19:56 +08:00

Improved consistency for existing core translation key names. See flarum/core#265 - Completely overhauled core en.yml - Replaced existing key names in all core JS files to match - Extracted a hardcoded string in IndexPage.js - Combined two app.trans calls in DiscussionControls.js - Removed hardcoded spaces from LogInModal.js and SignUpModal.js - Added two new keys from DiscussionControls.js (soft delete) - Created two new “reused keys” to YML to accommodate same
92 lines
2.3 KiB
JavaScript
92 lines
2.3 KiB
JavaScript
import avatar from 'flarum/helpers/avatar';
|
|
import username from 'flarum/helpers/username';
|
|
import Dropdown from 'flarum/components/Dropdown';
|
|
import LinkButton from 'flarum/components/LinkButton';
|
|
import Button from 'flarum/components/Button';
|
|
import ItemList from 'flarum/utils/ItemList';
|
|
import Separator from 'flarum/components/Separator';
|
|
import Group from 'flarum/models/Group';
|
|
|
|
/**
|
|
* The `SessionDropdown` component shows a button with the current user's
|
|
* avatar/name, with a dropdown of session controls.
|
|
*/
|
|
export default class SessionDropdown extends Dropdown {
|
|
static initProps(props) {
|
|
super.initProps(props);
|
|
|
|
props.className = 'SessionDropdown';
|
|
props.buttonClassName = 'Button Button--user Button--flat';
|
|
props.menuClassName = 'Dropdown-menu--right';
|
|
}
|
|
|
|
view() {
|
|
this.props.children = this.items().toArray();
|
|
|
|
return super.view();
|
|
}
|
|
|
|
getButtonContent() {
|
|
const user = app.session.user;
|
|
|
|
return [
|
|
avatar(user), ' ',
|
|
<span className="Button-label">{username(user)}</span>
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Build an item list for the contents of the dropdown menu.
|
|
*
|
|
* @return {ItemList}
|
|
*/
|
|
items() {
|
|
const items = new ItemList();
|
|
const user = app.session.user;
|
|
|
|
items.add('profile',
|
|
LinkButton.component({
|
|
icon: 'user',
|
|
children: app.trans('core.header_profile_button'),
|
|
href: app.route.user(user)
|
|
}),
|
|
100
|
|
);
|
|
|
|
items.add('settings',
|
|
LinkButton.component({
|
|
icon: 'cog',
|
|
children: app.trans('core.header_settings_button'),
|
|
href: app.route('settings')
|
|
}),
|
|
50
|
|
);
|
|
|
|
if (user.groups().some(group => group.id() === Group.ADMINISTRATOR_ID)) {
|
|
items.add('administration',
|
|
LinkButton.component({
|
|
icon: 'wrench',
|
|
children: app.trans('core.header_admin_button'),
|
|
href: app.forum.attribute('baseUrl') + '/admin',
|
|
target: '_blank',
|
|
config: () => {}
|
|
}),
|
|
0
|
|
);
|
|
}
|
|
|
|
items.add('separator', Separator.component(), -90);
|
|
|
|
items.add('logOut',
|
|
Button.component({
|
|
icon: 'sign-out',
|
|
children: app.trans('core.header_log_out_button'),
|
|
onclick: app.session.logout.bind(app.session)
|
|
}),
|
|
-100
|
|
);
|
|
|
|
return items;
|
|
}
|
|
}
|