mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-09 02:42:47 +00:00
improve account module
This commit is contained in:
@@ -2,8 +2,8 @@ import React, { Component } from 'react';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
import { Utils } from '../../utils/utils';
|
import { Utils } from '../../utils/utils';
|
||||||
import editorUtilities from '../../utils/editor-utilties';
|
import { seafileAPI } from '../../utils/seafile-api';
|
||||||
import { siteRoot, gettext } from '../../utils/constants';
|
import { siteRoot, gettext, appAvatarURL } from '../../utils/constants';
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
isAdminPanel: PropTypes.bool,
|
isAdminPanel: PropTypes.bool,
|
||||||
@@ -21,12 +21,8 @@ class Account extends Component {
|
|||||||
isStaff: false,
|
isStaff: false,
|
||||||
isOrgStaff: false,
|
isOrgStaff: false,
|
||||||
usageRate: '',
|
usageRate: '',
|
||||||
avatarURL: '',
|
|
||||||
};
|
};
|
||||||
}
|
this.isFirstMounted = true;
|
||||||
|
|
||||||
componentDidMount(){
|
|
||||||
this.getAccountInfo();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps) {
|
componentDidUpdate(prevProps) {
|
||||||
@@ -71,24 +67,23 @@ class Account extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onClickAccount = () => {
|
onClickAccount = () => {
|
||||||
this.setState({
|
if (this.isFirstMounted) {
|
||||||
showInfo: !this.state.showInfo,
|
seafileAPI.getAccountInfo().then(resp => {
|
||||||
});
|
this.setState({
|
||||||
}
|
userName: resp.data.name,
|
||||||
|
contactEmail: resp.data.email,
|
||||||
getAccountInfo = () => {
|
usageRate: resp.data.space_usage,
|
||||||
editorUtilities.getAccountInfo().then(resp => {
|
quotaUsage: Utils.bytesToSize(resp.data.usage),
|
||||||
this.setState({
|
quotaTotal: Utils.bytesToSize(resp.data.total),
|
||||||
userName: resp.data.name,
|
isStaff: resp.data.is_staff,
|
||||||
contactEmail: resp.data.email,
|
isOrgStaff: resp.data.is_org_staff === 1 ? true : false,
|
||||||
usageRate: resp.data.space_usage,
|
showInfo: !this.state.showInfo,
|
||||||
quotaUsage: Utils.bytesToSize(resp.data.usage),
|
});
|
||||||
quotaTotal: Utils.bytesToSize(resp.data.total),
|
|
||||||
isStaff: resp.data.is_staff,
|
|
||||||
isOrgStaff: resp.data.is_org_staff === 1 ? true : false,
|
|
||||||
avatarURL: resp.data.avatar_url
|
|
||||||
});
|
});
|
||||||
});
|
this.isFirstMounted = false;
|
||||||
|
} else {
|
||||||
|
this.setState({showInfo: !this.state.showInfo});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
renderMenu = () => {
|
renderMenu = () => {
|
||||||
@@ -118,21 +113,14 @@ class Account extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderAvatar = () => {
|
renderAvatar = () => {
|
||||||
if (this.state.avatarURL) {
|
return (<img src={appAvatarURL} width="36" height="36" className="avatar" alt={gettext('Avatar')} />);
|
||||||
return (
|
|
||||||
<img src={this.state.avatarURL} width="36" height="36" className="avatar" alt={gettext('Avatar')} />
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<img src="" width="36" height="36" className="avatar" alt={gettext('Avatar')} />
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div id="account">
|
<div id="account">
|
||||||
<a id="my-info" onClick={this.onClickAccount} className="account-toggle no-deco d-none d-md-block" aria-label="View profile and more">
|
<a id="my-info" onClick={this.onClickAccount} className="account-toggle no-deco d-none d-md-block" aria-label="View profile and more">
|
||||||
<span><img src={this.state.avatarURL} width="36" height="36" className="avatar" alt={gettext('Avatar')} /></span>
|
<span>{this.renderAvatar()}</span>
|
||||||
<span className="fas fa-caret-down vam"></span>
|
<span className="fas fa-caret-down vam"></span>
|
||||||
</a>
|
</a>
|
||||||
<span className="account-toggle sf2-icon-more mobile-icon d-md-none" aria-label="View profile and more" onClick={this.onClickAccount}></span>
|
<span className="account-toggle sf2-icon-more mobile-icon d-md-none" aria-label="View profile and more" onClick={this.onClickAccount}></span>
|
||||||
|
@@ -16,6 +16,7 @@ export const lang = window.app.config.lang;
|
|||||||
export const fileServerRoot = window.app.config.fileServerRoot;
|
export const fileServerRoot = window.app.config.fileServerRoot;
|
||||||
export const seafileVersion = window.app.config.seafileVersion;
|
export const seafileVersion = window.app.config.seafileVersion;
|
||||||
export const serviceURL = window.app.config.serviceURL;
|
export const serviceURL = window.app.config.serviceURL;
|
||||||
|
export const appAvatarURL = window.app.config.avatarURL;
|
||||||
|
|
||||||
//pageOptions
|
//pageOptions
|
||||||
export const seafileCollabServer = window.app.pageOptions.seafileCollabServer;
|
export const seafileCollabServer = window.app.pageOptions.seafileCollabServer;
|
||||||
|
@@ -24,6 +24,7 @@ from seahub.settings import SEAFILE_VERSION, SITE_TITLE, SITE_NAME, \
|
|||||||
|
|
||||||
from seahub.constants import DEFAULT_ADMIN
|
from seahub.constants import DEFAULT_ADMIN
|
||||||
from seahub.utils import get_site_name, get_service_url
|
from seahub.utils import get_site_name, get_service_url
|
||||||
|
from seahub.avatar.templatetags.avatar_tags import api_avatar_url
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from seahub.settings import SEACLOUD_MODE
|
from seahub.settings import SEACLOUD_MODE
|
||||||
@@ -86,7 +87,10 @@ def base(request):
|
|||||||
custom_favicon_file = os.path.join(MEDIA_ROOT, CUSTOM_FAVICON_PATH)
|
custom_favicon_file = os.path.join(MEDIA_ROOT, CUSTOM_FAVICON_PATH)
|
||||||
if os.path.exists(custom_favicon_file):
|
if os.path.exists(custom_favicon_file):
|
||||||
favicon_path = CUSTOM_FAVICON_PATH
|
favicon_path = CUSTOM_FAVICON_PATH
|
||||||
|
|
||||||
|
username = request.user.username
|
||||||
|
avatar_url, is_default, date_uploaded = api_avatar_url(username, 72)
|
||||||
|
|
||||||
result = {
|
result = {
|
||||||
'seafile_version': SEAFILE_VERSION,
|
'seafile_version': SEAFILE_VERSION,
|
||||||
'site_title': config.SITE_TITLE,
|
'site_title': config.SITE_TITLE,
|
||||||
@@ -130,6 +134,7 @@ def base(request):
|
|||||||
'service_url': get_service_url().rstrip('/'),
|
'service_url': get_service_url().rstrip('/'),
|
||||||
'enable_file_scan': ENABLE_FILE_SCAN,
|
'enable_file_scan': ENABLE_FILE_SCAN,
|
||||||
'enable_work_weixin_departments': ENABLE_WORK_WEIXIN_DEPARTMENTS,
|
'enable_work_weixin_departments': ENABLE_WORK_WEIXIN_DEPARTMENTS,
|
||||||
|
'avatar_url': request.build_absolute_uri(avatar_url),
|
||||||
}
|
}
|
||||||
|
|
||||||
if request.user.is_staff:
|
if request.user.is_staff:
|
||||||
|
@@ -43,6 +43,7 @@
|
|||||||
fileServerRoot: '{{ FILE_SERVER_ROOT }}',
|
fileServerRoot: '{{ FILE_SERVER_ROOT }}',
|
||||||
serviceURL: '{{ service_url }}',
|
serviceURL: '{{ service_url }}',
|
||||||
seafileVersion: '{{ seafile_version }}',
|
seafileVersion: '{{ seafile_version }}',
|
||||||
|
avatarURL: '{{ avatar_url }}'
|
||||||
},
|
},
|
||||||
pageOptions: {
|
pageOptions: {
|
||||||
csrfToken: "{{ csrf_token }}",
|
csrfToken: "{{ csrf_token }}",
|
||||||
|
Reference in New Issue
Block a user