1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-05 17:02:47 +00:00

Optimized code structure (#2430)

* combine utils file

* modify file position
This commit is contained in:
shanshuirenjia
2018-10-09 10:56:59 +08:00
committed by Daniel Pan
parent a2cc17778c
commit c0d645962f
45 changed files with 87 additions and 96 deletions

View File

@@ -1,9 +1,8 @@
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import { keyCodes, bytesToSize } from '../utils';
import { Utils } from '../../utils/utils';
import editorUtilities from '../../utils/editor-utilties';
import { siteRoot, gettext } from '../constants';
import { siteRoot, gettext } from '../../utils/constants';
class Account extends Component {
constructor(props) {
@@ -53,10 +52,10 @@ class Account extends Component {
}
handleDocumentClick = (e) => {
if (e && (e.which === 3 || (e.type === 'keyup' && e.which !== keyCodes.tab))) return;
if (e && (e.which === 3 || (e.type === 'keyup' && e.which !== Utils.keyCodes.tab))) return;
const container = this.getContainer();
if (container.contains(e.target) && container !== e.target && (e.type !== 'keyup' || e.which === keyCodes.tab)) {
if (container.contains(e.target) && container !== e.target && (e.type !== 'keyup' || e.which === Utils.keyCodes.tab)) {
return;
}
@@ -77,8 +76,8 @@ class Account extends Component {
userName: resp.data.name,
contactEmail: resp.data.email,
usageRate: resp.data.space_usage,
quotaUsage: bytesToSize(resp.data.usage),
quotaTotal: bytesToSize(resp.data.total),
quotaUsage: Utils.bytesToSize(resp.data.usage),
quotaTotal: Utils.bytesToSize(resp.data.total),
isStaff: resp.data.is_staff,
avatarURL: resp.data.avatar_url
});

View File

@@ -1,6 +1,6 @@
import React from 'react';
import { seafileAPI } from '../../utils/seafile-api';
const gettext = window.gettext;
import { gettext } from '../../utils/constants';
class Notification extends React.Component {
constructor(props) {

View File

@@ -1,28 +0,0 @@
export const dirPath = '/';
export const gettext = window.gettext;
export const siteRoot = window.app.config.siteRoot;
export const loginUrl = window.app.config.loginUrl;
export const avatarInfo = window.app.config.avatarInfo;
export const logoPath = window.app.config.logoPath;
export const mediaUrl = window.app.config.mediaUrl;
export const siteTitle = window.app.config.siteTitle;
export const logoWidth = window.app.config.logoWidth;
export const logoHeight = window.app.config.logoHeight;
export const isPro = window.app.config.isPro === "True";
export const lang = window.app.config.lang;
export const fileServerRoot = window.app.config.fileServerRoot;
// wiki
export const slug = window.wiki ? window.wiki.config.slug : '';
export const repoID = window.wiki ? window.wiki.config.repoId : '';
export const serviceUrl = window.wiki ? window.wiki.config.serviceUrl : '';
export const initialFilePath = window.wiki ? window.wiki.config.initial_file_path : '';
export const permission = window.wiki ? window.wiki.config.permission === 'True' : '';
// file history
export const PER_PAGE = 25;
export const historyRepoID = window.fileHistory ? window.fileHistory.pageOptions.repoID : '';
export const repoName = window.fileHistory ? window.fileHistory.pageOptions.repoName : '';
export const filePath = window.fileHistory ? window.fileHistory.pageOptions.filePath : '';
export const fileName = window.fileHistory ? window.fileHistory.pageOptions.fileName : '';

View File

@@ -1,5 +1,5 @@
import React from 'react';
import { gettext } from '../constants';
import { gettext } from '../../utils/constants';
import OperationMenu from './operation-menu';
class OperationGroup extends React.Component {

View File

@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { gettext } from '../constants';
import { gettext } from '../../utils/constants';
const propTypes = {
currentItem: PropTypes.object.isRequired,

View File

@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { siteRoot, lang } from '../constants';
import { siteRoot, lang } from '../../utils/constants';
import NodeMenuControl from '../menu-component/node-menu-control';
import moment from 'moment';

View File

@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { gettext } from '../constants';
import { gettext } from '../../utils/constants';
const propTypes = {
isMenuShow: PropTypes.bool.isRequired,

View File

@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { gettext } from '../constants';
import { gettext } from '../../utils/constants';
import DraftListItem from './draft-list-item';
const propTypes = {

View File

@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { gettext, filePath } from '../constants';
import { gettext, filePath } from '../../utils/constants';
import URLDecorator from '../../utils/url-decorator';
const propTypes = {

View File

@@ -5,7 +5,7 @@ import Loading from '../loading';
import axios from 'axios';
import editUtilties from '../../utils/editor-utilties';
import URLDecorator from '../../utils/url-decorator';
import { filePath } from '../constants';
import { filePath } from '../../utils/constants';
const propTypes = {
hasMore: PropTypes.bool.isRequired,

View File

@@ -1,6 +1,6 @@
import React from 'react';
import PropsType from 'prop-types';
import { siteRoot, mediaUrl, logoPath, logoWidth, logoHeight, siteTitle } from './constants';
import { siteRoot, mediaUrl, logoPath, logoWidth, logoHeight, siteTitle } from '../utils/constants';
const propsType = {
onCloseSidePanel: PropsType.func.isRequired,

View File

@@ -1,6 +1,6 @@
import React from 'react';
import { Link } from '@reach/router';
import { gettext, siteRoot } from './constants';
import { gettext, siteRoot } from '../utils/constants';
import { seafileAPI } from '../utils/seafile-api';
class MainSideNav extends React.Component {

View File

@@ -1,5 +1,5 @@
import React from 'react';
import { gettext } from '../../constants';
import { gettext } from '../../../utils/constants';
import { Button, Modal, ModalHeader, Input, ModalBody, ModalFooter, Form, FormGroup, Label, Col, FormText } from 'reactstrap';
class CreateFileForder extends React.Component {

View File

@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { gettext } from '../../constants';
import { gettext } from '../../../utils/constants';
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
const propTypes = {

View File

@@ -1,5 +1,5 @@
import React from 'react';
import { gettext } from '../../constants';
import { gettext } from '../../../utils/constants';
import { Button, Modal, ModalHeader, Input, ModalBody, ModalFooter } from 'reactstrap';
class Rename extends React.Component {

View File

@@ -1,5 +1,5 @@
import React from 'react';
import { gettext } from '../constants';
import { gettext } from '../../utils/constants';
class NodeMenu extends React.Component {

View File

@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { gettext } from './constants';
import { gettext } from '../utils/constants';
const propTypes = {
onShowMore: PropTypes.func.isRequired

View File

@@ -1,5 +1,5 @@
import React, { Component } from 'react';
import { repoID, siteRoot } from '../constants';
import { repoID, siteRoot } from '../../utils/constants';
import SearchResultItem from './search-result-item';
import editorUtilities from '../../utils/editor-utilties';
import More from '../more';

View File

@@ -1,6 +1,6 @@
import React from 'react';
import { gettext, siteRoot } from './constants';
import { Modal, ModalBody } from 'reactstrap';
import { gettext, siteRoot } from '../utils/constants';
class About extends React.Component {
constructor(props) {

View File

@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { isPro, gettext } from '../../components/constants';
import { isPro, gettext } from '../../utils/constants';
import Search from '../search/search';
import Notification from '../common/notification';
import Account from '../common/account';

View File

@@ -1,6 +1,6 @@
import React from 'react';
import { gettext, repoID, slug, permission, siteRoot } from '../constants';
import { encodePath } from '../utils';
import { gettext, repoID, slug, permission, siteRoot } from '../../utils/constants';
import { Utils } from '../../utils/utils';
import PropTypes from 'prop-types';
const propTypes = {
@@ -35,7 +35,7 @@ class PathToolbar extends React.Component {
</ul>
);
} else if (permission) {
historyUrl = siteRoot + 'repo/file_revisions/' + repoID + '/?p=' + encodePath(this.props.filePath) + '&referer=' + encodeURIComponent(location.href);
historyUrl = siteRoot + 'repo/file_revisions/' + repoID + '/?p=' + Utils.encodePath(this.props.filePath) + '&referer=' + encodeURIComponent(location.href);
return (
<ul className="path-toolbar">
<li className="toolbar-item"><a className="op-link sf2-icon-history" href={historyUrl} title={gettext('History')} aria-label={gettext('History')}></a></li>

View File

@@ -1,5 +1,5 @@
import React from 'react';
import { serviceUrl } from '../constants';
import { serviceUrl } from '../../utils/constants';
import OperationGroup from '../dirent-operation/operation-group';
class TreeDirList extends React.Component {

View File

@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { gettext, repoID } from '../constants';
import { gettext, repoID } from '../../utils/constants';
import editorUtilities from '../../utils/editor-utilties';
import URLDecorator from '../../utils/url-decorator';
import ZipDownloadDialog from '../dialog/zip-download-dialog';

View File

@@ -1,6 +1,6 @@
import React from 'react';
import MenuControl from '../menu-component/node-menu-control';
import { permission } from '../constants';
import { permission } from '../../utils/constants';
function sortByType(a, b) {
if (a.type == 'dir' && b.type != 'dir') {

View File

@@ -1,6 +1,6 @@
import Node from './node';
import moment from 'moment';
import { bytesToSize } from '../utils';
import { Utils } from '../../utils/utils';
const lang = window.app.config.lang;
moment.locale(lang);
@@ -184,7 +184,7 @@ class Tree {
var node = new Node({
name: model.name,
type: model.type,
size: bytesToSize(model.size),
size: Utils.bytesToSize(model.size),
last_update_time: moment.unix(model.last_update_time).fromNow(),
permission: model.permission,
parent_path: model.parent_path,
@@ -214,7 +214,7 @@ class Tree {
let node = new Node({
name: nodeObj.name,
type: nodeObj.type,
size: bytesToSize(nodeObj.size),
size: Utils.bytesToSize(nodeObj.size),
last_update_time: moment.unix(nodeObj.last_update_time).fromNow(),
permission: nodeObj.permission,
parent_path: nodeObj.parent_path,
@@ -244,7 +244,7 @@ class Tree {
var newNode = new Node({
name: node.name,
type: node.type,
size: bytesToSize(node.size),
size: Utils.bytesToSize(node.size),
last_update_time: moment.unix(node.last_update_time).fromNow(),
permission: node.permission,
parent_path: node.parent_path,

View File

@@ -1,29 +0,0 @@
export const keyCodes = {
esc: 27,
space: 32,
tab: 9,
up: 38,
down: 40
};
export function bytesToSize(bytes) {
if (typeof(bytes) == 'undefined') return ' ';
if(bytes < 0) return '--';
const sizes = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB'];
if (bytes === 0) return bytes + ' ' + sizes[0];
const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1000)), 10);
if (i === 0) return bytes + ' ' + sizes[i];
return (bytes / (1000 ** i)).toFixed(1) + ' ' + sizes[i];
}
export function encodePath(path) {
let path_arr = path.split('/');
let path_arr_ = [];
for (let i = 0, len = path_arr.length; i < len; i++) {
path_arr_.push(encodeURIComponent(path_arr[i]));
}
return path_arr_.join('/');
}