mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-02 07:27:04 +00:00
@@ -5,8 +5,7 @@ import classnames from 'classnames';
|
|||||||
import '../../../css/switch.css';
|
import '../../../css/switch.css';
|
||||||
|
|
||||||
function Switch(props) {
|
function Switch(props) {
|
||||||
const { onChange, checked, placeholder, disabled, className, size } = props;
|
const { onChange, checked, placeholder, disabled, className, size, textPosition } = props;
|
||||||
|
|
||||||
return(
|
return(
|
||||||
<div className={classnames('seahub-switch position-relative', className, size)}>
|
<div className={classnames('seahub-switch position-relative', className, size)}>
|
||||||
<label className="custom-switch">
|
<label className="custom-switch">
|
||||||
@@ -18,8 +17,13 @@ function Switch(props) {
|
|||||||
name="custom-switch-checkbox"
|
name="custom-switch-checkbox"
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
/>
|
/>
|
||||||
<span className="custom-switch-description text-truncate">{placeholder}</span>
|
{textPosition === 'left' &&
|
||||||
<span className="custom-switch-indicator"></span>
|
<span className="custom-switch-description text-truncate">{placeholder}</span>
|
||||||
|
}
|
||||||
|
<span className={classnames('custom-switch-indicator', {'disabled': disabled})}></span>
|
||||||
|
{textPosition === 'right' &&
|
||||||
|
<span className="custom-switch-description text-truncate">{placeholder}</span>
|
||||||
|
}
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -31,7 +35,12 @@ Switch.propTypes = {
|
|||||||
placeholder: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
placeholder: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
||||||
className: PropTypes.string,
|
className: PropTypes.string,
|
||||||
size: PropTypes.oneOf(['large', 'small', undefined]),
|
size: PropTypes.oneOf(['large', 'small', undefined]),
|
||||||
onChange: PropTypes.func.isRequired,
|
textPosition: PropTypes.oneOf(['left', 'right', undefined]),
|
||||||
|
onChange: PropTypes.func,
|
||||||
|
};
|
||||||
|
|
||||||
|
Switch.defaultProps = {
|
||||||
|
textPosition: 'left',
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Switch;
|
export default Switch;
|
||||||
|
@@ -1,14 +1,14 @@
|
|||||||
import React, { Component, Fragment } from 'react';
|
import React, { Component, Fragment } from 'react';
|
||||||
import { Form, FormGroup, Input, Label } from 'reactstrap';
|
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import isHotkey from 'is-hotkey';
|
import isHotkey from 'is-hotkey';
|
||||||
import MediaQuery from 'react-responsive';
|
import MediaQuery from 'react-responsive';
|
||||||
import { seafileAPI } from '../../utils/seafile-api';
|
import { seafileAPI } from '../../utils/seafile-api';
|
||||||
import { gettext, siteRoot, username, enableSeafileAI } from '../../utils/constants';
|
import { gettext, siteRoot, enableSeafileAI } from '../../utils/constants';
|
||||||
import SearchResultItem from './search-result-item';
|
import SearchResultItem from './search-result-item';
|
||||||
import { Utils } from '../../utils/utils';
|
import { Utils } from '../../utils/utils';
|
||||||
import { isMac } from '../../utils/extra-attributes';
|
import { isMac } from '../../utils/extra-attributes';
|
||||||
import toaster from '../toast';
|
import toaster from '../toast';
|
||||||
|
import Switch from '../common/switch';
|
||||||
|
|
||||||
const INDEX_STATE = {
|
const INDEX_STATE = {
|
||||||
RUNNING: 'running',
|
RUNNING: 'running',
|
||||||
@@ -567,10 +567,38 @@ class Search extends Component {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
renderSwitch = () => {
|
||||||
|
const { indexState } = this.state;
|
||||||
|
if (indexState === INDEX_STATE.FINISHED || indexState === INDEX_STATE.RUNNING) {
|
||||||
|
return (
|
||||||
|
<Switch
|
||||||
|
checked={true}
|
||||||
|
placeholder={gettext('Turn on semantic search for this library')}
|
||||||
|
className="w-100 mt-1"
|
||||||
|
size="small"
|
||||||
|
textPosition='right'
|
||||||
|
disabled
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
} else if (indexState === '' || indexState === INDEX_STATE.UNCREATED) {
|
||||||
|
return (
|
||||||
|
<Switch
|
||||||
|
checked={false}
|
||||||
|
placeholder={gettext('Turn on semantic search for this library')}
|
||||||
|
className="w-100 mt-1"
|
||||||
|
size="small"
|
||||||
|
onChange={this.onCreateIndex}
|
||||||
|
textPosition='right'
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let width = this.state.width !== 'default' ? this.state.width : '';
|
let width = this.state.width !== 'default' ? this.state.width : '';
|
||||||
let style = {'width': width};
|
let style = {'width': width};
|
||||||
const { searchPageUrl, isMaskShow, indexState, isCloseShow, resultItems } = this.state;
|
const { isMaskShow, isCloseShow } = this.state;
|
||||||
const placeholder = `${this.props.placeholder}${isMaskShow ? '' : ` (${controlKey} + f )`}`;
|
const placeholder = `${this.props.placeholder}${isMaskShow ? '' : ` (${controlKey} + f )`}`;
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
@@ -593,9 +621,6 @@ class Search extends Component {
|
|||||||
ref={this.inputRef}
|
ref={this.inputRef}
|
||||||
onKeyDown={this.onKeydownHandler}
|
onKeyDown={this.onKeydownHandler}
|
||||||
/>
|
/>
|
||||||
{(this.state.isCloseShow && username) &&
|
|
||||||
<a href={searchPageUrl} className="search-icon-right input-icon-addon fas fa-external-link-alt search-icon-arrow"></a>
|
|
||||||
}
|
|
||||||
{this.state.isCloseShow &&
|
{this.state.isCloseShow &&
|
||||||
<button type="button" className="search-icon-right input-icon-addon fas fa-times border-0 bg-transparent mr-4" onClick={this.onCloseHandler} aria-label={gettext('Close')}></button>
|
<button type="button" className="search-icon-right input-icon-addon fas fa-times border-0 bg-transparent mr-4" onClick={this.onCloseHandler} aria-label={gettext('Close')}></button>
|
||||||
}
|
}
|
||||||
@@ -605,14 +630,7 @@ class Search extends Component {
|
|||||||
onScroll={this.onResultListScroll}
|
onScroll={this.onResultListScroll}
|
||||||
ref={this.searchContainer}
|
ref={this.searchContainer}
|
||||||
>
|
>
|
||||||
{isCloseShow && this.props.isLibView && enableSeafileAI &&
|
{isCloseShow && this.props.isLibView && enableSeafileAI && this.renderSwitch()}
|
||||||
<Form>
|
|
||||||
<FormGroup check>
|
|
||||||
<Input type="radio" name="radio1" checked={indexState === INDEX_STATE.FINISHED} onChange={() => {this.onCreateIndex()}}/>
|
|
||||||
<Label>{gettext('Turn on semantic search for this library.')}</Label>
|
|
||||||
</FormGroup>
|
|
||||||
</Form>
|
|
||||||
}
|
|
||||||
{this.renderSearchResult()}
|
{this.renderSearchResult()}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -639,9 +657,6 @@ class Search extends Component {
|
|||||||
onChange={this.onChangeHandler}
|
onChange={this.onChangeHandler}
|
||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
/>
|
/>
|
||||||
{(this.state.isCloseShow && username) &&
|
|
||||||
<a href={searchPageUrl} className="search-icon-right input-icon-addon fas fa-external-link-alt search-icon-arrow"></a>
|
|
||||||
}
|
|
||||||
{this.state.isCloseShow &&
|
{this.state.isCloseShow &&
|
||||||
<button type="button" className="search-icon-right input-icon-addon fas fa-times border-0 bg-transparent" onClick={this.onCloseHandler} aria-label={gettext('Close')}></button>
|
<button type="button" className="search-icon-right input-icon-addon fas fa-times border-0 bg-transparent" onClick={this.onCloseHandler} aria-label={gettext('Close')}></button>
|
||||||
}
|
}
|
||||||
|
@@ -83,6 +83,10 @@
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.dropdown-search-result-container .seahub-switch .custom-switch {
|
||||||
|
padding-left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.search-result-container .search-result-none {
|
.search-result-container .search-result-none {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
line-height: 4rem;
|
line-height: 4rem;
|
||||||
|
@@ -2,6 +2,11 @@
|
|||||||
width: 22px;
|
width: 22px;
|
||||||
height: 12px;
|
height: 12px;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.seahub-switch.small .custom-switch-indicator.disabled {
|
||||||
|
cursor: default;
|
||||||
}
|
}
|
||||||
|
|
||||||
.seahub-switch.small .custom-switch-indicator:before {
|
.seahub-switch.small .custom-switch-indicator:before {
|
||||||
|
@@ -1037,14 +1037,12 @@ class LibContentView extends React.Component {
|
|||||||
seafileAPI.renameFile(repoID, path, newName).then(() => {
|
seafileAPI.renameFile(repoID, path, newName).then(() => {
|
||||||
this.renameItemAjaxCallback(path, newName);
|
this.renameItemAjaxCallback(path, newName);
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
|
let errMessage = '';
|
||||||
let errMessage = "";
|
|
||||||
if (error.response.status == 403 && error.response.data && error.response.data['error_msg']) {
|
if (error.response.status == 403 && error.response.data && error.response.data['error_msg']) {
|
||||||
errMessage = error.response.data['error_msg'];
|
errMessage = error.response.data['error_msg'];
|
||||||
} else {
|
} else {
|
||||||
errMessage = Utils.getErrorMsg(error);
|
errMessage = Utils.getErrorMsg(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errMessage === gettext('Error')) {
|
if (errMessage === gettext('Error')) {
|
||||||
let name = Utils.getFileName(path);
|
let name = Utils.getFileName(path);
|
||||||
errMessage = gettext('Renaming {name} failed').replace('{name}', name);
|
errMessage = gettext('Renaming {name} failed').replace('{name}', name);
|
||||||
|
Reference in New Issue
Block a user