1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-03 16:10:26 +00:00

repair code error

This commit is contained in:
shanshuirenjia
2018-12-14 15:49:24 +08:00
parent 7b182d6105
commit e62f59b2a8
3 changed files with 75 additions and 40 deletions

View File

@@ -99,6 +99,7 @@ class GenerateShareLink extends React.Component {
generateShareLink = () => { generateShareLink = () => {
let isValid = this.validateParamsInput(); let isValid = this.validateParamsInput();
if (isValid) { if (isValid) {
this.setState({errorInfo: ''});
let { itemPath, repoID } = this.props; let { itemPath, repoID } = this.props;
let { password, expireDays } = this.state; let { password, expireDays } = this.state;
let permissions = this.permissions; let permissions = this.permissions;
@@ -122,6 +123,7 @@ class GenerateShareLink extends React.Component {
isShowPasswordInput: false, isShowPasswordInput: false,
expireDays: '', expireDays: '',
isExpireChecked: false, isExpireChecked: false,
errorInfo: '',
}); });
this.permissions = { this.permissions = {
'can_edit': false, 'can_edit': false,
@@ -163,7 +165,7 @@ class GenerateShareLink extends React.Component {
if (this.isExpireDaysNoLimit) { if (this.isExpireDaysNoLimit) {
if (isExpireChecked) { if (isExpireChecked) {
if (!expireDays) { if (!expireDays) {
this.setState({errorInfo: gettext('Please enter days')}); this.setState({errorInfo: 'Please enter days'});
return false; return false;
} }
let flag = reg.test(expireDays); let flag = reg.test(expireDays);
@@ -175,7 +177,7 @@ class GenerateShareLink extends React.Component {
} }
} else { } else {
if (!expireDays) { if (!expireDays) {
this.setState({errorInfo: gettext('Please enter days')}); this.setState({errorInfo: 'Please enter days'});
return false; return false;
} }
let flag = reg.test(expireDays); let flag = reg.test(expireDays);
@@ -284,7 +286,7 @@ class GenerateShareLink extends React.Component {
<Input type="radio" name="radio1" onChange={this.setPermission('preview')} />{' '}{gettext('Preview only')} <Input type="radio" name="radio1" onChange={this.setPermission('preview')} />{' '}{gettext('Preview only')}
</Label> </Label>
</FormGroup> </FormGroup>
<Label className="err-message">{this.state.errorInfo}</Label><br /> <Label className="err-message">{gettext(this.state.errorInfo)}</Label><br />
<Button onClick={this.generateShareLink}>{gettext('Generate')}</Button> <Button onClick={this.generateShareLink}>{gettext('Generate')}</Button>
</Form> </Form>
); );

View File

@@ -9,7 +9,7 @@ import GenerateUploadLink from './generate-upload-link';
import '../../css/share-link-dialog.css'; import '../../css/share-link-dialog.css';
const propTypes = { const propTypes = {
itemType: PropTypes.bool.isRequired, // there will be three choose: ['library', 'dir', 'file'] itemType: PropTypes.string.isRequired, // there will be three choose: ['library', 'dir', 'file']
itemName: PropTypes.string.isRequired, itemName: PropTypes.string.isRequired,
itemPath: PropTypes.string.isRequired, itemPath: PropTypes.string.isRequired,
toggleDialog: PropTypes.func.isRequired, toggleDialog: PropTypes.func.isRequired,

View File

@@ -1,5 +1,5 @@
import React, { Component } from 'react'; import React, { Component, Fragment } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import moment from 'moment'; import moment from 'moment';
import { Link } from '@reach/router'; import { Link } from '@reach/router';
@@ -8,6 +8,8 @@ import { gettext, siteRoot, storages, canGenerateShareLink, canGenerateUploadLin
import { Utils } from '../../utils/utils'; import { Utils } from '../../utils/utils';
import { seafileAPI } from '../../utils/seafile-api'; import { seafileAPI } from '../../utils/seafile-api';
import RenameInput from '../../components/rename-input'; import RenameInput from '../../components/rename-input';
import ModalPotal from '../../components/modal-portal';
import ShareDialog from '../../components/dialog/share-dialog';
const propTypes = { const propTypes = {
data: PropTypes.object.isRequired, data: PropTypes.object.isRequired,
@@ -29,6 +31,7 @@ class Item extends Component {
showOpIcon: false, showOpIcon: false,
operationMenuOpen: false, operationMenuOpen: false,
showChangeLibName: false, showChangeLibName: false,
isShowSharedDialog: false,
highlight: false, highlight: false,
}; };
} }
@@ -73,7 +76,11 @@ class Item extends Component {
share = (e) => { share = (e) => {
e.preventDefault(); e.preventDefault();
// TODO this.setState({isShowSharedDialog: true});
}
toggleShareDialog = () => {
this.setState({isShowSharedDialog: false});
} }
showDeleteItemPopup = (e) => { showDeleteItemPopup = (e) => {
@@ -232,43 +239,69 @@ class Item extends Component {
); );
const desktopItem = ( const desktopItem = (
<tr className={this.state.highlight ? 'tr-highlight' : ''} onMouseOver={this.handleMouseOver} onMouseOut={this.handleMouseOut}> <Fragment>
<td><img src={data.icon_url} title={data.icon_title} alt={data.icon_title} width="24" /></td> <tr className={this.state.highlight ? 'tr-highlight' : ''} onMouseOver={this.handleMouseOver} onMouseOut={this.handleMouseOut}>
<td> <td><img src={data.icon_url} title={data.icon_title} alt={data.icon_title} width="24" /></td>
{this.state.showChangeLibName && ( <td>
<RenameInput {this.state.showChangeLibName && (
name={data.repo_name} <RenameInput
onRenameConfirm={this.onRenameConfirm} name={data.repo_name}
onRenameCancel={this.onRenameCancel} onRenameConfirm={this.onRenameConfirm}
/> onRenameCancel={this.onRenameCancel}
)} />
{!this.state.showChangeLibName && data.repo_name && ( )}
<Link to={data.url}>{data.repo_name}</Link> {!this.state.showChangeLibName && data.repo_name && (
)} <Link to={data.url}>{data.repo_name}</Link>
{!this.state.showChangeLibName && !data.repo_name && )}
(gettext('Broken (please contact your administrator to fix this library)')) {!this.state.showChangeLibName && !data.repo_name &&
} (gettext('Broken (please contact your administrator to fix this library)'))
</td> }
<td>{data.repo_name ? desktopOperations : ''}</td> </td>
<td>{Utils.formatSize({bytes: data.size})}</td> <td>{data.repo_name ? desktopOperations : ''}</td>
{storages.length ? <td>{data.storage_name}</td> : null} <td>{Utils.formatSize({bytes: data.size})}</td>
<td title={moment(data.last_modified).format('llll')}>{moment(data.last_modified).fromNow()}</td> {storages.length ? <td>{data.storage_name}</td> : null}
</tr> <td title={moment(data.last_modified).format('llll')}>{moment(data.last_modified).fromNow()}</td>
</tr>
{this.state.isShowSharedDialog && (
<ModalPotal>
<ShareDialog
itemType={'library'}
itemName={data.repo_name}
itemPath={'/'}
repoID={data.repo_id}
toggleDialog={this.toggleShareDialog}
/>
</ModalPotal>
)}
</Fragment>
); );
const mobileItem = ( const mobileItem = (
<tr className={this.state.highlight ? 'tr-highlight' : ''} onMouseOver={this.handleMouseOver} onMouseOut={this.handleMouseOut}> <Fragment>
<td><img src={data.icon_url} title={data.icon_title} alt={data.icon_title} width="24" /></td> <tr className={this.state.highlight ? 'tr-highlight' : ''} onMouseOver={this.handleMouseOver} onMouseOut={this.handleMouseOut}>
<td> <td><img src={data.icon_url} title={data.icon_title} alt={data.icon_title} width="24" /></td>
{data.repo_name ? <td>
<Link to={data.url}>{data.repo_name}</Link> : {data.repo_name ?
gettext('Broken (please contact your administrator to fix this library)')} <Link to={data.url}>{data.repo_name}</Link> :
<br /> gettext('Broken (please contact your administrator to fix this library)')}
<span className="item-meta-info">{Utils.formatSize({bytes: data.size})}</span> <br />
<span className="item-meta-info" title={moment(data.last_modified).format('llll')}>{moment(data.last_modified).fromNow()}</span> <span className="item-meta-info">{Utils.formatSize({bytes: data.size})}</span>
</td> <span className="item-meta-info" title={moment(data.last_modified).format('llll')}>{moment(data.last_modified).fromNow()}</span>
<td>{data.repo_name ? mobileOperations : ''}</td> </td>
</tr> <td>{data.repo_name ? mobileOperations : ''}</td>
</tr>
{this.state.isShowSharedDialog && (
<ModalPotal>
<ShareDialog
itemType={'library'}
itemName={data.repo_name}
itemPath={'/'}
repoID={data.repo_id}
toggleDialog={this.toggleShareDialog}
/>
</ModalPotal>
)}
</Fragment>
); );
return window.innerWidth >= 768 ? desktopItem : mobileItem; return window.innerWidth >= 768 ? desktopItem : mobileItem;