mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-22 20:08:19 +00:00
add table function
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React from 'react';
|
import React, { Fragment } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import Select from 'react-select';
|
import Select from 'react-select';
|
||||||
import makeAnimated from 'react-select/lib/animated';
|
import makeAnimated from 'react-select/lib/animated';
|
||||||
@@ -10,6 +10,7 @@ import { gettext } from '../../utils/constants';
|
|||||||
const propTypes = {
|
const propTypes = {
|
||||||
createDTable: PropTypes.func.isRequired,
|
createDTable: PropTypes.func.isRequired,
|
||||||
onAddDTable: PropTypes.func.isRequired,
|
onAddDTable: PropTypes.func.isRequired,
|
||||||
|
currentWorkspace: PropTypes.object,
|
||||||
};
|
};
|
||||||
|
|
||||||
class CreateTableDialog extends React.Component {
|
class CreateTableDialog extends React.Component {
|
||||||
@@ -66,16 +67,22 @@ class CreateTableDialog extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleSubmit = () => {
|
handleSubmit = () => {
|
||||||
if (!this.state.isSubmitBtnActive) {
|
if (!this.state.isSubmitBtnActive) return;
|
||||||
return;
|
if (!this.validateInputParams()) return;
|
||||||
|
const space = this.props.currentWorkspace;
|
||||||
|
const options = this.state.options;
|
||||||
|
let email;
|
||||||
|
if (space) {
|
||||||
|
for (let i = 0; i < options.length; i++) {
|
||||||
|
if ((space.owner_type === "Personal" && options[i].value === 'Personal') || (space.owner_type === "Group" && options[i].value === space.owner_name)) {
|
||||||
|
email = options[i].email;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
let isValid = this.validateInputParams();
|
|
||||||
if (isValid) {
|
|
||||||
let newName = this.state.tableName.trim();
|
|
||||||
let owner = this.state.selectedOption;
|
|
||||||
this.props.createDTable(newName, owner.email);
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
email = this.state.selectedOption.email;
|
||||||
|
}
|
||||||
|
this.props.createDTable(this.state.tableName.trim(), email);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleKeyPress = (e) => {
|
handleKeyPress = (e) => {
|
||||||
@@ -106,6 +113,7 @@ class CreateTableDialog extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const { currentWorkspace } = this.props;
|
||||||
return (
|
return (
|
||||||
<Modal isOpen={true} toggle={this.toggle}>
|
<Modal isOpen={true} toggle={this.toggle}>
|
||||||
<ModalHeader toggle={this.toggle}>{gettext('New Table')}</ModalHeader>
|
<ModalHeader toggle={this.toggle}>{gettext('New Table')}</ModalHeader>
|
||||||
@@ -123,6 +131,8 @@ class CreateTableDialog extends React.Component {
|
|||||||
</FormGroup>
|
</FormGroup>
|
||||||
</Form>
|
</Form>
|
||||||
{this.state.errMessage && <Alert color="danger" className="mt-2">{this.state.errMessage}</Alert>}
|
{this.state.errMessage && <Alert color="danger" className="mt-2">{this.state.errMessage}</Alert>}
|
||||||
|
{!currentWorkspace &&
|
||||||
|
<Fragment>
|
||||||
<Label>{gettext('Belong to')}</Label>
|
<Label>{gettext('Belong to')}</Label>
|
||||||
<Select
|
<Select
|
||||||
isClearable
|
isClearable
|
||||||
@@ -134,6 +144,8 @@ class CreateTableDialog extends React.Component {
|
|||||||
options={this.state.options}
|
options={this.state.options}
|
||||||
onChange={this.handleSelectChange}
|
onChange={this.handleSelectChange}
|
||||||
/>
|
/>
|
||||||
|
</Fragment>
|
||||||
|
}
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
<Button color="secondary" onClick={this.toggle}>{gettext('Cancel')}</Button>
|
<Button color="secondary" onClick={this.toggle}>{gettext('Cancel')}</Button>
|
||||||
|
@@ -45,3 +45,14 @@
|
|||||||
.add-workspace:hover {
|
.add-workspace:hover {
|
||||||
color: #202428;
|
color: #202428;
|
||||||
}
|
}
|
||||||
|
.workspace .table-heading {
|
||||||
|
padding: 0.25rem;
|
||||||
|
border-bottom: 1px solid #e6e6e6;
|
||||||
|
}
|
||||||
|
.workspace .sf3-font {
|
||||||
|
color: #949494;
|
||||||
|
font-size: 20px;
|
||||||
|
}
|
||||||
|
.workspace .add-table-range:hover {
|
||||||
|
background-color: #f8f8f8;
|
||||||
|
}
|
@@ -105,7 +105,7 @@ class Table extends Component {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<tr onMouseEnter={this.onMouseEnter} onMouseLeave={this.onMouseLeave} className={this.state.active ? 'tr-highlight' : ''}>
|
<tr onMouseEnter={this.onMouseEnter} onMouseLeave={this.onMouseLeave} className={this.state.active ? 'tr-highlight' : ''}>
|
||||||
<td><img src={siteRoot + 'media/img/data-base.svg'} alt="" width="24"/></td>
|
<td><span className="sf3-font sf3-font-form"></span></td>
|
||||||
<td>
|
<td>
|
||||||
{this.state.isTableRenaming &&
|
{this.state.isTableRenaming &&
|
||||||
<Rename
|
<Rename
|
||||||
@@ -217,6 +217,12 @@ class Workspace extends Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addTable = (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
this.props.setCurrentWorkspace(this.props.workspace);
|
||||||
|
this.props.onAddDTable();
|
||||||
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
componentWillReceiveProps(nextProps) {
|
||||||
if (nextProps.workspace.table_list !== this.props.workspace.table_list) {
|
if (nextProps.workspace.table_list !== this.props.workspace.table_list) {
|
||||||
this.setState({
|
this.setState({
|
||||||
@@ -228,16 +234,18 @@ class Workspace extends Component {
|
|||||||
render() {
|
render() {
|
||||||
let workspace = this.props.workspace;
|
let workspace = this.props.workspace;
|
||||||
let isPersonal = workspace.owner_type === 'Personal';
|
let isPersonal = workspace.owner_type === 'Personal';
|
||||||
|
let { tableList, isItemFreezed } = this.state;
|
||||||
|
|
||||||
return(
|
return(
|
||||||
<div className="workspace my-2">
|
<div className="workspace my-2">
|
||||||
<div>{isPersonal ? gettext('My Tables') : workspace.owner_name}</div>
|
<div className="table-heading">{isPersonal ? gettext('My Tables') : workspace.owner_name}</div>
|
||||||
|
{tableList.length > 0 ?
|
||||||
<table width="100%" className="table-vcenter">
|
<table width="100%" className="table-vcenter">
|
||||||
<colgroup>
|
<colgroup>
|
||||||
<col width="4%"/><col width="31%"/><col width="30%"/><col width="27%"/><col width="8%"/>
|
<col width="4%"/><col width="31%"/><col width="30%"/><col width="27%"/><col width="8%"/>
|
||||||
</colgroup>
|
</colgroup>
|
||||||
<tbody>
|
<tbody>
|
||||||
{this.state.tableList.map((table, index) => {
|
{tableList.map((table, index) => {
|
||||||
return (
|
return (
|
||||||
<Table
|
<Table
|
||||||
key={index}
|
key={index}
|
||||||
@@ -247,13 +255,25 @@ class Workspace extends Component {
|
|||||||
deleteTable={this.deleteTable}
|
deleteTable={this.deleteTable}
|
||||||
onFreezedItem={this.onFreezedItem}
|
onFreezedItem={this.onFreezedItem}
|
||||||
onUnfreezedItem={this.onUnfreezedItem}
|
onUnfreezedItem={this.onUnfreezedItem}
|
||||||
isItemFreezed={this.state.isItemFreezed}
|
isItemFreezed={isItemFreezed}
|
||||||
isPersonal={isPersonal}
|
isPersonal={isPersonal}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
<tr className={isItemFreezed ? "" : "add-table-range"}>
|
||||||
|
<td><span className="sf3-font sf3-font-add"></span></td>
|
||||||
|
<td><a href="#" onClick={this.addTable}>{gettext('Add a table')}</a></td>
|
||||||
|
<td></td><td></td><td></td>
|
||||||
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
:
|
||||||
|
<table width="100%" className="table-vcenter">
|
||||||
|
<tbody>
|
||||||
|
<tr><th className="text-center">{gettext('No tables')}</th></tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -277,13 +297,12 @@ class DTable extends Component {
|
|||||||
workspaceList: [],
|
workspaceList: [],
|
||||||
shareTableList: [],
|
shareTableList: [],
|
||||||
isShowAddDTableDialog: false,
|
isShowAddDTableDialog: false,
|
||||||
|
currentWorkspace: null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
onAddDTable = () => {
|
onAddDTable = () => {
|
||||||
this.setState({
|
this.setState({ isShowAddDTableDialog: !this.state.isShowAddDTableDialog });
|
||||||
isShowAddDTableDialog: !this.state.isShowAddDTableDialog,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
createDTable = (tableName, owner) => {
|
createDTable = (tableName, owner) => {
|
||||||
@@ -359,6 +378,10 @@ class DTable extends Component {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
setCurrentWorkspace = (currentWorkspace) => {
|
||||||
|
this.setState({ currentWorkspace: currentWorkspace });
|
||||||
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.listWorkspaces();
|
this.listWorkspaces();
|
||||||
this.listSharedTables();
|
this.listSharedTables();
|
||||||
@@ -367,7 +390,7 @@ class DTable extends Component {
|
|||||||
renderShareTablePanel = () => {
|
renderShareTablePanel = () => {
|
||||||
return (
|
return (
|
||||||
<div className="workspace my-2">
|
<div className="workspace my-2">
|
||||||
<div>{gettext('Shared with me')}</div>
|
<div className="table-heading">{gettext('Shared with me')}</div>
|
||||||
<table width="100%" className="table-vcenter">
|
<table width="100%" className="table-vcenter">
|
||||||
<colgroup>
|
<colgroup>
|
||||||
<col width="4%"/><col width="31%"/><col width="30%"/><col width="27%"/><col width="8%"/>
|
<col width="4%"/><col width="31%"/><col width="30%"/><col width="27%"/><col width="8%"/>
|
||||||
@@ -388,6 +411,13 @@ class DTable extends Component {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
newDtable = () => {
|
||||||
|
if (this.state.currentWorkspace) {
|
||||||
|
this.setState({ currentWorkspace: null });
|
||||||
|
}
|
||||||
|
this.onAddDTable();
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let personalWorkspace = this.state.workspaceList.filter(workspace => {
|
let personalWorkspace = this.state.workspaceList.filter(workspace => {
|
||||||
return workspace.owner_type === 'Personal';
|
return workspace.owner_type === 'Personal';
|
||||||
@@ -404,10 +434,10 @@ class DTable extends Component {
|
|||||||
<div className="operation">
|
<div className="operation">
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<MediaQuery query="(min-width: 768px)">
|
<MediaQuery query="(min-width: 768px)">
|
||||||
<Button className="btn btn-secondary operation-item" onClick={this.onAddDTable}>{gettext('New DTable')}</Button>
|
<Button className="btn btn-secondary operation-item" onClick={this.newDtable}>{gettext('New DTable')}</Button>
|
||||||
</MediaQuery>
|
</MediaQuery>
|
||||||
<MediaQuery query="(max-width: 767.8px)">
|
<MediaQuery query="(max-width: 767.8px)">
|
||||||
<Button className="btn btn-secondary operation-item my-1" onClick={this.onAddDTable}>{gettext('New DTable')}</Button>
|
<Button className="btn btn-secondary operation-item my-1" onClick={this.newDtable}>{gettext('New DTable')}</Button>
|
||||||
</MediaQuery>
|
</MediaQuery>
|
||||||
</Fragment>
|
</Fragment>
|
||||||
</div>
|
</div>
|
||||||
@@ -427,6 +457,8 @@ class DTable extends Component {
|
|||||||
{!this.state.loading &&
|
{!this.state.loading &&
|
||||||
<Workspace
|
<Workspace
|
||||||
workspace={personalWorkspace}
|
workspace={personalWorkspace}
|
||||||
|
onAddDTable={this.onAddDTable}
|
||||||
|
setCurrentWorkspace={this.setCurrentWorkspace}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
{(!this.state.shareTableLoading && this.state.shareTableList.length > 0) &&
|
{(!this.state.shareTableLoading && this.state.shareTableList.length > 0) &&
|
||||||
@@ -438,6 +470,8 @@ class DTable extends Component {
|
|||||||
<Workspace
|
<Workspace
|
||||||
key={index}
|
key={index}
|
||||||
workspace={workspace}
|
workspace={workspace}
|
||||||
|
onAddDTable={this.onAddDTable}
|
||||||
|
setCurrentWorkspace={this.setCurrentWorkspace}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
@@ -447,6 +481,7 @@ class DTable extends Component {
|
|||||||
<CreateTableDialog
|
<CreateTableDialog
|
||||||
createDTable={this.createDTable}
|
createDTable={this.createDTable}
|
||||||
onAddDTable={this.onAddDTable}
|
onAddDTable={this.onAddDTable}
|
||||||
|
currentWorkspace={this.state.currentWorkspace}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user