2019-04-04 17:19:10 +08:00
|
|
|
import React, { Fragment } from 'react';
|
|
|
|
import ReactDOM from 'react-dom';
|
|
|
|
import AppHeader from './pages/data-grid/app-header';
|
|
|
|
import AppMain from './pages/data-grid/app-main';
|
|
|
|
import { seafileAPI } from './utils/seafile-api';
|
|
|
|
import { Utils } from './utils/utils';
|
|
|
|
import { gettext } from './utils/constants';
|
|
|
|
import toaster from './components/toast';
|
|
|
|
|
|
|
|
import './css/layout.css';
|
|
|
|
import './css/file-view-data-grid.css';
|
2019-04-26 07:45:07 +08:00
|
|
|
import './css/react-context-menu.css';
|
2019-04-04 17:19:10 +08:00
|
|
|
|
2019-05-07 17:58:53 +08:00
|
|
|
const { repoID, fileName, filePath } = window.app.pageOptions;
|
2019-04-04 17:19:10 +08:00
|
|
|
|
|
|
|
class ViewFileSDB extends React.Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2019-05-06 13:28:34 +08:00
|
|
|
isContentChanged: false,
|
2019-04-04 17:19:10 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-05-07 17:58:53 +08:00
|
|
|
onContentChanged = () => {
|
|
|
|
this.setState({isContentChanged: true});
|
2019-04-04 17:19:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
onSave = () => {
|
2019-05-07 17:58:53 +08:00
|
|
|
this.setState({isContentChanged: false});
|
|
|
|
|
2019-04-04 17:19:10 +08:00
|
|
|
let data = this.refs.data_grid.serializeGridData();
|
2019-05-07 17:58:53 +08:00
|
|
|
|
2019-04-04 17:19:10 +08:00
|
|
|
let dirPath = Utils.getDirName(filePath);
|
|
|
|
seafileAPI.getUpdateLink(repoID, dirPath).then(res => {
|
|
|
|
let updateLink = res.data;
|
2019-05-07 17:58:53 +08:00
|
|
|
seafileAPI.updateFile(updateLink, filePath, fileName, JSON.stringify(data)).then(res => {
|
2019-04-04 17:19:10 +08:00
|
|
|
toaster.success(gettext('File saved.'));
|
|
|
|
}).catch(() => {
|
|
|
|
toaster.success(gettext('File save failed.'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Fragment>
|
2019-05-07 17:58:53 +08:00
|
|
|
<AppHeader onSave={this.onSave} isContentChanged={this.state.isContentChanged} />
|
|
|
|
<AppMain ref="data_grid" onContentChanged={this.onContentChanged} onSave={this.onSave} />
|
2019-04-04 17:19:10 +08:00
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ReactDOM.render(
|
|
|
|
<ViewFileSDB />,
|
|
|
|
document.getElementById('wrapper')
|
|
|
|
);
|