Web: Files: store: refactoring contextOptionsStore
This commit is contained in:
parent
43491f42a9
commit
98f30631b2
@ -1,70 +1,59 @@
|
||||
import { makeAutoObservable, action } from "mobx";
|
||||
import store from "studio/store";
|
||||
import versionHistoryStore from "./VersionHistoryStore";
|
||||
import filesActionsStore from "./FilesActionsStore";
|
||||
import dialogsStore from "./DialogsStore";
|
||||
import filesStore from "./FilesStore";
|
||||
import mediaViewerDataStore from "./MediaViewerDataStore";
|
||||
import selectedFolderStore from "./SelectedFolderStore";
|
||||
import { makeAutoObservable } from "mobx";
|
||||
import copy from "copy-to-clipboard";
|
||||
|
||||
import config from "../../package.json";
|
||||
import { combineUrl } from "@appserver/common/utils";
|
||||
import { AppServerConfig, FileAction } from "@appserver/common/constants";
|
||||
|
||||
import store from "studio/store";
|
||||
import toastr from "studio/toastr";
|
||||
import copy from "copy-to-clipboard";
|
||||
import config from "../../package.json";
|
||||
|
||||
const { homepage } = config;
|
||||
|
||||
const { setIsVerHistoryPanel, fetchFileVersions } = versionHistoryStore;
|
||||
const { openDocEditor, fileActionStore } = filesStore;
|
||||
const { setAction } = fileActionStore;
|
||||
const { setMediaViewerData } = mediaViewerDataStore;
|
||||
const { isRootFolder } = selectedFolderStore;
|
||||
const {
|
||||
setFavoriteAction,
|
||||
finalizeVersionAction,
|
||||
lockFileAction,
|
||||
onSelectItem,
|
||||
duplicateAction,
|
||||
setThirdpartyInfo,
|
||||
deleteFileAction,
|
||||
openLocationAction,
|
||||
deleteFolderAction,
|
||||
} = filesActionsStore;
|
||||
|
||||
const {
|
||||
setSharingPanelVisible,
|
||||
setChangeOwnerPanelVisible,
|
||||
setMoveToPanelVisible,
|
||||
setCopyPanelVisible,
|
||||
setRemoveItem,
|
||||
setDeleteThirdPartyDialogVisible,
|
||||
} = dialogsStore;
|
||||
|
||||
class ContextOptionsStore {
|
||||
t = null;
|
||||
history = null;
|
||||
filesStore;
|
||||
fileActionStore;
|
||||
selectedFolderStore;
|
||||
filesActionsStore;
|
||||
dialogsStore;
|
||||
versionHistoryStore;
|
||||
mediaViewerDataStore;
|
||||
|
||||
constructor() {
|
||||
makeAutoObservable(this, {
|
||||
getFilesContextOptions: action,
|
||||
});
|
||||
constructor(
|
||||
filesStore,
|
||||
fileActionStore,
|
||||
selectedFolderStore,
|
||||
filesActionsStore,
|
||||
dialogsStore,
|
||||
versionHistoryStore,
|
||||
mediaViewerDataStore
|
||||
) {
|
||||
makeAutoObservable(this);
|
||||
this.filesStore = filesStore;
|
||||
this.fileActionStore = fileActionStore;
|
||||
this.selectedFolderStore = selectedFolderStore;
|
||||
this.filesActionsStore = filesActionsStore;
|
||||
this.dialogsStore = dialogsStore;
|
||||
this.versionHistoryStore = versionHistoryStore;
|
||||
this.mediaViewerDataStore = mediaViewerDataStore;
|
||||
//getFilesContextOptions: action,
|
||||
}
|
||||
|
||||
onOpenLocation = () => {
|
||||
const { id, folderId, isFolder } = filesStore.selection[0];
|
||||
const { id, folderId, isFolder } = this.filesStore.selection[0];
|
||||
const locationId = isFolder ? id : folderId;
|
||||
openLocationAction(locationId, isFolder);
|
||||
this.filesActionsStore.openLocationAction(locationId, isFolder);
|
||||
};
|
||||
|
||||
showVersionHistory = () => {
|
||||
const { isTabletView } = store.auth.settingsStore;
|
||||
const { id } = filesStore.selection[0];
|
||||
const { id } = this.filesStore.selection[0];
|
||||
|
||||
if (!isTabletView) {
|
||||
fetchFileVersions(id + "");
|
||||
setIsVerHistoryPanel(true);
|
||||
this.versionHistoryStore.fetchFileVersions(id + "");
|
||||
this.versionHistoryStore.setIsVerHistoryPanel(true);
|
||||
} else {
|
||||
this.history.push(
|
||||
combineUrl(AppServerConfig.proxyURL, homepage, `/${id}/history`) //TODO: something better
|
||||
@ -73,9 +62,10 @@ class ContextOptionsStore {
|
||||
};
|
||||
|
||||
onClickFavorite = (e) => {
|
||||
const { id } = filesStore.selection[0];
|
||||
const { id } = this.filesStore.selection[0];
|
||||
const { action } = e.currentTarget.dataset;
|
||||
setFavoriteAction(action, id)
|
||||
this.filesActionsStore
|
||||
.setFavoriteAction(action, id)
|
||||
.then(() =>
|
||||
action === "mark"
|
||||
? toastr.success(this.t("MarkedAsFavorite")) // TODO: t
|
||||
@ -88,25 +78,34 @@ class ContextOptionsStore {
|
||||
};
|
||||
|
||||
finalizeVersion = () => {
|
||||
const { id } = filesStore.selection[0];
|
||||
finalizeVersionAction(id).catch((err) => toastr.error(err));
|
||||
const { id } = this.filesStore.selection[0];
|
||||
this.filesActionsStore
|
||||
.finalizeVersionAction(id)
|
||||
.catch((err) => toastr.error(err));
|
||||
};
|
||||
|
||||
lockFile = () => {
|
||||
const { id, locked } = filesStore.selection[0];
|
||||
lockFileAction(id, !locked).catch((err) => toastr.error(err));
|
||||
const { id, locked } = this.filesStore.selection[0];
|
||||
this.filesActionsStore
|
||||
.lockFileAction(id, !locked)
|
||||
.catch((err) => toastr.error(err));
|
||||
};
|
||||
|
||||
onClickShare = () => {
|
||||
onSelectItem(filesStore.selection[0]);
|
||||
setSharingPanelVisible(true);
|
||||
this.filesActionsStore.onSelectItem(this.filesStore.selection[0]);
|
||||
this.dialogsStore.setSharingPanelVisible(true);
|
||||
};
|
||||
|
||||
onOwnerChange = () => setChangeOwnerPanelVisible(true);
|
||||
onOwnerChange = () => this.dialogsStore.setChangeOwnerPanelVisible(true);
|
||||
|
||||
onClickLinkForPortal = () => {
|
||||
//const isFile = !!fileExst;
|
||||
const { id, isFolder, canOpenPlayer, webUrl } = filesStore.selection[0];
|
||||
const {
|
||||
id,
|
||||
isFolder,
|
||||
canOpenPlayer,
|
||||
webUrl,
|
||||
} = this.filesStore.selection[0];
|
||||
copy(
|
||||
!isFolder
|
||||
? canOpenPlayer
|
||||
@ -119,41 +118,40 @@ class ContextOptionsStore {
|
||||
};
|
||||
|
||||
onClickLinkEdit = () => {
|
||||
const { id, providerKey } = filesStore.selection[0];
|
||||
openDocEditor(id, providerKey);
|
||||
const { id, providerKey } = this.filesStore.selection[0];
|
||||
this.filesStore.openDocEditor(id, providerKey);
|
||||
};
|
||||
|
||||
onMediaFileClick = (fileId) => {
|
||||
const { id } = filesStore.selection[0];
|
||||
const { id } = this.filesStore.selection[0];
|
||||
const itemId = typeof fileId !== "object" ? fileId : id;
|
||||
setMediaViewerData({ visible: true, id: itemId });
|
||||
this.mediaViewerDataStore.setMediaViewerData({ visible: true, id: itemId });
|
||||
};
|
||||
|
||||
onClickDownload = () => {
|
||||
const { viewUrl } = filesStore.selection[0];
|
||||
const { viewUrl } = this.filesStore.selection[0];
|
||||
window.open(viewUrl, "_blank");
|
||||
};
|
||||
|
||||
onMoveAction = () => setMoveToPanelVisible(true);
|
||||
onCopyAction = () => setCopyPanelVisible(true);
|
||||
onMoveAction = () => this.dialogsStore.setMoveToPanelVisible(true);
|
||||
onCopyAction = () => this.dialogsStore.setCopyPanelVisible(true);
|
||||
|
||||
onDuplicate = () => {
|
||||
duplicateAction(
|
||||
filesStore.selection[0],
|
||||
this.t("CopyOperation")
|
||||
).catch((err) => toastr.error(err));
|
||||
this.filesActionsStore
|
||||
.duplicateAction(this.filesStore.selection[0], this.t("CopyOperation"))
|
||||
.catch((err) => toastr.error(err));
|
||||
};
|
||||
|
||||
onClickRename = () => {
|
||||
const { fileExst, id } = filesStore.selection[0];
|
||||
setAction({
|
||||
const { fileExst, id } = this.filesStore.selection[0];
|
||||
this.fileActionStore.setAction({
|
||||
type: FileAction.Rename,
|
||||
extension: fileExst,
|
||||
id,
|
||||
});
|
||||
};
|
||||
|
||||
onChangeThirdPartyInfo = () => setThirdpartyInfo();
|
||||
onChangeThirdPartyInfo = () => this.filesActionsStore.setThirdpartyInfo();
|
||||
|
||||
onClickDelete = () => {
|
||||
const {
|
||||
@ -162,12 +160,16 @@ class ContextOptionsStore {
|
||||
folderId,
|
||||
parentId,
|
||||
providerKey,
|
||||
} = filesStore.selection[0];
|
||||
const isThirdPartyFolder = providerKey && isRootFolder;
|
||||
} = this.filesStore.selection[0];
|
||||
const isThirdPartyFolder =
|
||||
providerKey && this.selectedFolderStore.isRootFolder;
|
||||
if (isThirdPartyFolder) {
|
||||
const splitItem = id.split("-");
|
||||
setRemoveItem({ id: splitItem[splitItem.length - 1], title });
|
||||
setDeleteThirdPartyDialogVisible(true);
|
||||
this.dialogsStore.setRemoveItem({
|
||||
id: splitItem[splitItem.length - 1],
|
||||
title,
|
||||
});
|
||||
this.dialogsStore.setDeleteThirdPartyDialogVisible(true);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -176,10 +178,12 @@ class ContextOptionsStore {
|
||||
};
|
||||
|
||||
fileExst
|
||||
? deleteFileAction(id, folderId, translations)
|
||||
? this.filesActionsStore
|
||||
.deleteFileAction(id, folderId, translations)
|
||||
.then(() => toastr.success(this.t("FileRemoved")))
|
||||
.catch((err) => toastr.error(err))
|
||||
: deleteFolderAction(id, parentId, translations)
|
||||
: this.filesActionsStore
|
||||
.deleteFolderAction(id, parentId, translations)
|
||||
.then(() => toastr.success(this.t("FolderRemoved")))
|
||||
.catch((err) => toastr.error(err));
|
||||
};
|
||||
@ -191,7 +195,8 @@ class ContextOptionsStore {
|
||||
this.history = history;
|
||||
|
||||
const isSharable = access !== 1 && access !== 0;
|
||||
const isThirdPartyFolder = providerKey && isRootFolder;
|
||||
const isThirdPartyFolder =
|
||||
providerKey && this.selectedFolderStore.isRootFolder;
|
||||
|
||||
return contextOptions.map((option) => {
|
||||
switch (option) {
|
||||
@ -378,4 +383,4 @@ class ContextOptionsStore {
|
||||
};
|
||||
}
|
||||
|
||||
export default new ContextOptionsStore();
|
||||
export default ContextOptionsStore;
|
||||
|
@ -1,119 +0,0 @@
|
||||
import { makeAutoObservable } from "mobx";
|
||||
import store from "studio/store";
|
||||
import { updateTempContent } from "@appserver/common/utils";
|
||||
import filesStore from "./FilesStore";
|
||||
import treeFoldersStore from "./TreeFoldersStore";
|
||||
import config from "../../package.json";
|
||||
|
||||
const { auth } = store;
|
||||
const { isAdmin } = auth;
|
||||
|
||||
class InitFilesStore {
|
||||
isLoaded = false;
|
||||
isLoading = false;
|
||||
viewAs = "row";
|
||||
dragging = false;
|
||||
privacyInstructions = "https://www.onlyoffice.com/private-rooms.aspx";
|
||||
isInit = false;
|
||||
|
||||
tooltipPageX = 0;
|
||||
tooltipPageY = 0;
|
||||
startDrag = false;
|
||||
|
||||
constructor() {
|
||||
const pathname = window.location.pathname.toLowerCase();
|
||||
this.isEditor = pathname.indexOf("doceditor") !== -1;
|
||||
|
||||
makeAutoObservable(this);
|
||||
}
|
||||
|
||||
setIsLoaded = (isLoaded) => {
|
||||
this.isLoaded = isLoaded;
|
||||
};
|
||||
|
||||
setViewAs = (viewAs) => {
|
||||
this.viewAs = viewAs;
|
||||
};
|
||||
|
||||
setDragging = (dragging) => {
|
||||
this.dragging = dragging;
|
||||
};
|
||||
|
||||
setIsLoading = (isLoading) => {
|
||||
this.isLoading = isLoading;
|
||||
};
|
||||
|
||||
setStartDrag = (startDrag) => {
|
||||
this.startDrag = startDrag;
|
||||
};
|
||||
|
||||
setTooltipPosition = (tooltipPageX, tooltipPageY) => {
|
||||
this.tooltipPageX = tooltipPageX;
|
||||
this.tooltipPageY = tooltipPageY;
|
||||
};
|
||||
|
||||
get tooltipValue() {
|
||||
if (!this.dragging) return null;
|
||||
|
||||
const selectionLength = filesStore.selection.length;
|
||||
const elementTitle = selectionLength && filesStore.selection[0].title;
|
||||
const singleElement = selectionLength === 1;
|
||||
const filesCount = singleElement ? elementTitle : selectionLength;
|
||||
const { isShareFolder, isCommonFolder } = treeFoldersStore;
|
||||
|
||||
let operationName;
|
||||
|
||||
if (isAdmin && isShareFolder) {
|
||||
operationName = "copy";
|
||||
} else if (!isAdmin && (isShareFolder || isCommonFolder)) {
|
||||
operationName = "copy";
|
||||
} else {
|
||||
operationName = "move";
|
||||
}
|
||||
|
||||
return operationName === "copy"
|
||||
? singleElement
|
||||
? { label: "TooltipElementCopyMessage", filesCount }
|
||||
: { label: "TooltipElementsCopyMessage", filesCount }
|
||||
: singleElement
|
||||
? { label: "TooltipElementMoveMessage", filesCount }
|
||||
: { label: "TooltipElementsMoveMessage", filesCount };
|
||||
}
|
||||
|
||||
initFiles = () => {
|
||||
if (this.isInit) return;
|
||||
this.isInit = true;
|
||||
|
||||
const isAuthenticated = auth.isAuthenticated;
|
||||
const {
|
||||
getPortalCultures,
|
||||
isDesktopClient,
|
||||
getIsEncryptionSupport,
|
||||
getEncryptionKeys,
|
||||
setModuleInfo,
|
||||
} = auth.settingsStore;
|
||||
|
||||
setModuleInfo(config.homepage, config.id);
|
||||
|
||||
const requests = [];
|
||||
|
||||
updateTempContent();
|
||||
if (!isAuthenticated) {
|
||||
return this.setIsLoaded(true);
|
||||
} else {
|
||||
updateTempContent(isAuthenticated);
|
||||
}
|
||||
|
||||
if (!this.isEditor) {
|
||||
requests.push(getPortalCultures(), treeFoldersStore.fetchTreeFolders());
|
||||
|
||||
if (isDesktopClient) {
|
||||
requests.push(getIsEncryptionSupport(), getEncryptionKeys());
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.all(requests);
|
||||
};
|
||||
}
|
||||
|
||||
export default new InitFilesStore();
|
@ -13,6 +13,7 @@ import MediaViewerDataStore from "./MediaViewerDataStore";
|
||||
import UploadDataStore from "./UploadDataStore";
|
||||
import SecondaryProgressDataStore from "./SecondaryProgressDataStore";
|
||||
import PrimaryProgressDataStore from "./PrimaryProgressDataStore";
|
||||
import ContextOptionsStore from "./ContextOptionsStore";
|
||||
|
||||
import versionHistoryStore from "./VersionHistoryStore";
|
||||
import dialogsStore from "./DialogsStore";
|
||||
@ -57,6 +58,16 @@ const filesActionsStore = new FilesActionsStore(
|
||||
|
||||
const mediaViewerDataStore = new MediaViewerDataStore(filesStore);
|
||||
|
||||
const contextOptionsStore = new ContextOptionsStore(
|
||||
filesStore,
|
||||
fileActionStore,
|
||||
selectedFolderStore,
|
||||
filesActionsStore,
|
||||
dialogsStore,
|
||||
versionHistoryStore,
|
||||
mediaViewerDataStore
|
||||
);
|
||||
|
||||
const stores = {
|
||||
filesStore,
|
||||
settingsStore,
|
||||
@ -68,6 +79,7 @@ const stores = {
|
||||
treeFoldersStore,
|
||||
selectedFolderStore,
|
||||
filesActionsStore,
|
||||
contextOptionsStore,
|
||||
};
|
||||
|
||||
export default stores;
|
||||
|
Loading…
Reference in New Issue
Block a user