mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-12 21:30:39 +00:00
update group in real time (#7141)
This commit is contained in:
@@ -3,6 +3,11 @@ export const EVENT_BUS_TYPE = {
|
||||
CURRENT_LIBRARY_CHANGED: 'current_library_changed',
|
||||
SEARCH_LIBRARY_CONTENT: 'search_library_content',
|
||||
|
||||
// group
|
||||
ADD_NEW_GROUP: 'add_new_group',
|
||||
ADD_SHARED_REPO_INO_GROUP: 'add_shared_repo_into_group',
|
||||
UNSHARE_REPO_TO_GROUP: 'unshare_repo_to_group',
|
||||
|
||||
RESTORE_IMAGE: 'restore_image',
|
||||
OPEN_MARKDOWN: 'open_markdown',
|
||||
};
|
||||
|
@@ -1,5 +1,16 @@
|
||||
class EventBus {
|
||||
subscribers = {};
|
||||
|
||||
constructor() {
|
||||
this.instance = null;
|
||||
this.subscribers = {};
|
||||
}
|
||||
|
||||
static getInstance() {
|
||||
if (this.instance) return this.instance;
|
||||
this.instance = new EventBus();
|
||||
return this.instance;
|
||||
}
|
||||
|
||||
|
||||
subscribe(type, handler) {
|
||||
if (!this.subscribers[type]) {
|
||||
|
@@ -8,6 +8,8 @@ import Loading from '../../../components/loading';
|
||||
import toaster from '../../../components/toast';
|
||||
import EmptyTip from '../../../components/empty-tip';
|
||||
import SharePermissionEditor from '../../../components/select-editor/share-permission-editor';
|
||||
import EventBus from '../../common/event-bus';
|
||||
import { EVENT_BUS_TYPE } from '../../common/event-bus-type';
|
||||
|
||||
const itemPropTypes = {
|
||||
item: PropTypes.object.isRequired,
|
||||
@@ -153,7 +155,9 @@ class RepoShareAdminGroupShares extends Component {
|
||||
}
|
||||
|
||||
deleteItem = (item) => {
|
||||
const eventBus = EventBus.getInstance();
|
||||
seafileAPI.deleteShareToGroupItem(item.repo_id, item.path, 'group', item.share_to).then(res => {
|
||||
eventBus.dispatch(EVENT_BUS_TYPE.UNSHARE_REPO_TO_GROUP, { repo_id: item.repo_id, group_id: item.share_to });
|
||||
let items = this.state.items.filter(shareItem => {
|
||||
return shareItem.path + shareItem.share_to !== item.path + item.share_to;
|
||||
});
|
||||
|
@@ -22,6 +22,7 @@ const propTypes = {
|
||||
itemType: PropTypes.string.isRequired, // there will be three choose: ['library', 'dir', 'file']
|
||||
itemName: PropTypes.string.isRequired,
|
||||
itemPath: PropTypes.string.isRequired,
|
||||
repo: PropTypes.object,
|
||||
toggleDialog: PropTypes.func.isRequired,
|
||||
repoID: PropTypes.string.isRequired,
|
||||
repoEncrypted: PropTypes.bool,
|
||||
@@ -86,7 +87,6 @@ class ShareDialog extends React.Component {
|
||||
};
|
||||
|
||||
renderDirContent = () => {
|
||||
|
||||
if (!this.state.isRepoJudgemented) {
|
||||
return <Loading />;
|
||||
}
|
||||
@@ -223,6 +223,7 @@ class ShareDialog extends React.Component {
|
||||
itemPath={this.props.itemPath}
|
||||
repoID={this.props.repoID}
|
||||
isRepoOwner={this.state.isRepoOwner}
|
||||
repo={this.props.repo}
|
||||
onAddCustomPermissionToggle={this.onAddCustomPermissionToggle}
|
||||
/>
|
||||
</TabPane>
|
||||
|
@@ -7,6 +7,8 @@ import { Utils } from '../../utils/utils';
|
||||
import toaster from '../toast';
|
||||
import SharePermissionEditor from '../select-editor/share-permission-editor';
|
||||
import { SeahubSelect, NoGroupMessage } from '../common/select';
|
||||
import EventBus from '../common/event-bus';
|
||||
import { EVENT_BUS_TYPE } from '../common/event-bus-type';
|
||||
|
||||
class GroupItem extends React.Component {
|
||||
|
||||
@@ -115,6 +117,7 @@ const propTypes = {
|
||||
repoID: PropTypes.string.isRequired,
|
||||
repoType: PropTypes.string,
|
||||
isRepoOwner: PropTypes.bool.isRequired,
|
||||
repo: PropTypes.object,
|
||||
onAddCustomPermissionToggle: PropTypes.func,
|
||||
};
|
||||
|
||||
@@ -200,13 +203,12 @@ class ShareToGroup extends React.Component {
|
||||
};
|
||||
|
||||
shareToGroup = () => {
|
||||
|
||||
let path = this.props.itemPath;
|
||||
let repoID = this.props.repoID;
|
||||
let isGroupOwnedRepo = this.props.isGroupOwnedRepo;
|
||||
|
||||
const eventBus = EventBus.getInstance();
|
||||
const { isGroupOwnedRepo, itemPath: path, repoID } = this.props;
|
||||
const { permission, selectedOption } = this.state;
|
||||
const targetGroupId = selectedOption.id;
|
||||
if (isGroupOwnedRepo) {
|
||||
seafileAPI.shareGroupOwnedRepoToGroup(repoID, this.state.permission, this.state.selectedOption['id'], path).then(res => {
|
||||
seafileAPI.shareGroupOwnedRepoToGroup(repoID, permission, targetGroupId, path).then(res => {
|
||||
let errorMsg = [];
|
||||
if (res.data.failed.length > 0) {
|
||||
for (let i = 0 ; i < res.data.failed.length ; i++) {
|
||||
@@ -224,6 +226,11 @@ class ShareToGroup extends React.Component {
|
||||
return sharedItem;
|
||||
});
|
||||
|
||||
if (this.props.repo && res.data.success.length > 0) {
|
||||
const sharedRepo = { ...this.props.repo, permission: res.data.success[0].permission };
|
||||
eventBus.dispatch(EVENT_BUS_TYPE.ADD_SHARED_REPO_INO_GROUP, { repo: sharedRepo, group_id: targetGroupId });
|
||||
}
|
||||
|
||||
this.setState({
|
||||
errorMsg: errorMsg,
|
||||
sharedItems: this.state.sharedItems.concat(items),
|
||||
@@ -235,7 +242,7 @@ class ShareToGroup extends React.Component {
|
||||
toaster.danger(errMessage);
|
||||
});
|
||||
} else {
|
||||
seafileAPI.shareFolder(repoID, path, 'group', this.state.permission, [this.state.selectedOption['id']]).then(res => {
|
||||
seafileAPI.shareFolder(repoID, path, 'group', permission, [targetGroupId]).then(res => {
|
||||
let errorMsg = [];
|
||||
if (res.data.failed.length > 0) {
|
||||
for (let i = 0 ; i < res.data.failed.length ; i++) {
|
||||
@@ -243,6 +250,11 @@ class ShareToGroup extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
if (this.props.repo && res.data.success.length > 0) {
|
||||
const sharedRepo = { ...this.props.repo, permission: res.data.success[0].permission };
|
||||
eventBus.dispatch(EVENT_BUS_TYPE.ADD_SHARED_REPO_INO_GROUP, { repo: sharedRepo, group_id: targetGroupId });
|
||||
}
|
||||
|
||||
this.setState({
|
||||
errorMsg: errorMsg,
|
||||
sharedItems: this.state.sharedItems.concat(res.data.success),
|
||||
@@ -257,10 +269,12 @@ class ShareToGroup extends React.Component {
|
||||
};
|
||||
|
||||
deleteShareItem = (groupID) => {
|
||||
let path = this.props.itemPath;
|
||||
let repoID = this.props.repoID;
|
||||
if (this.props.isGroupOwnedRepo) {
|
||||
const eventBus = EventBus.getInstance();
|
||||
const { isGroupOwnedRepo, itemPath: path, repoID } = this.props;
|
||||
if (isGroupOwnedRepo) {
|
||||
seafileAPI.deleteGroupOwnedRepoSharedGroupItem(repoID, groupID, path).then(() => {
|
||||
eventBus.dispatch(EVENT_BUS_TYPE.UNSHARE_REPO_TO_GROUP, { repo_id: repoID, group_id: groupID });
|
||||
|
||||
this.setState({
|
||||
sharedItems: this.state.sharedItems.filter(item => { return item.group_info.id !== groupID; })
|
||||
});
|
||||
@@ -270,6 +284,8 @@ class ShareToGroup extends React.Component {
|
||||
});
|
||||
} else {
|
||||
seafileAPI.deleteShareToGroupItem(repoID, path, 'group', groupID).then(() => {
|
||||
eventBus.dispatch(EVENT_BUS_TYPE.UNSHARE_REPO_TO_GROUP, { repo_id: repoID, group_id: groupID });
|
||||
|
||||
this.setState({
|
||||
sharedItems: this.state.sharedItems.filter(item => { return item.group_info.id !== groupID; })
|
||||
});
|
||||
|
@@ -18,6 +18,8 @@ import FilesSubNav from '../components/files-sub-nav';
|
||||
import { SUB_NAV_ITEM_HEIGHT } from '../constants';
|
||||
import { isWorkWeixin } from './wechat/weixin-utils';
|
||||
import WechatDialog from './wechat/wechat-dialog';
|
||||
import { EVENT_BUS_TYPE } from './common/event-bus-type';
|
||||
import EventBus from './common/event-bus';
|
||||
|
||||
const propTypes = {
|
||||
currentTab: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
|
||||
@@ -26,6 +28,7 @@ const propTypes = {
|
||||
};
|
||||
|
||||
class MainSideNav extends React.Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
@@ -93,6 +96,10 @@ class MainSideNav extends React.Component {
|
||||
const { groupItems: newList } = this.state;
|
||||
newList.push(newGroup);
|
||||
this.filesNavHeight += SUB_NAV_ITEM_HEIGHT;
|
||||
|
||||
const eventBus = EventBus.getInstance();
|
||||
eventBus.dispatch(EVENT_BUS_TYPE.ADD_NEW_GROUP, { group: newGroup });
|
||||
|
||||
this.setState({
|
||||
groupItems: newList
|
||||
});
|
||||
|
@@ -744,6 +744,7 @@ class SharedRepoListItem extends React.Component {
|
||||
itemName={repo.repo_name}
|
||||
itemPath={'/'}
|
||||
repoID={repo.repo_id}
|
||||
repo={repo}
|
||||
repoEncrypted={repo.encrypted}
|
||||
enableDirPrivateShare={true}
|
||||
userPerm={repo.permission}
|
||||
|
Reference in New Issue
Block a user