-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request 'feature/convert-with-password' (#97) from feature…
…/convert-with-password into develop Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/DocSpace-client/pulls/97 Reviewed-by: Alexey Safronov <alexey.safronov@onlyoffice.com>
- Loading branch information
Showing
18 changed files
with
1,078 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
{ | ||
"AccessPasswordMessage": "This file is protected, please enter the password to access it or download in original format.", | ||
"ChooseFormatText": "Choose the format for each file to be downloaded", | ||
"ConvertMessage": "If you choose to convert the file to a format different from the original, some data might be lost.", | ||
"ConvertToZip": "Files will be compressed into the <strong>.zip file</strong>", | ||
"CustomFormat": "Custom format", | ||
"OriginalFormat": "Original format" | ||
"DownloadOriginalFormat": "In original format", | ||
"FileProtectionMessage": "These files are protected. Please try entering the password for all files. If you don't remember the password but need these files, you can download them in their original format or simply remove them from the list.", | ||
"OriginalFormat": "Original format", | ||
"ProtectedFiles": "Protected files", | ||
"PasswordEntered": "Password entered", | ||
"RemovedFromList": "Removed from list" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
202 changes: 202 additions & 0 deletions
202
packages/client/src/components/dialogs/DownloadDialog/OnePasswordRow.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,202 @@ | ||
// (c) Copyright Ascensio System SIA 2009-2024 | ||
// | ||
// This program is a free software product. | ||
// You can redistribute it and/or modify it under the terms | ||
// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software | ||
// Foundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended | ||
// to the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of | ||
// any third-party rights. | ||
// | ||
// This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty | ||
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see | ||
// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html | ||
// | ||
// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021. | ||
// | ||
// The interactive user interfaces in modified source and object code versions of the Program must | ||
// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3. | ||
// | ||
// Pursuant to Section 7(b) of the License you must retain the original Product logo when | ||
// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under | ||
// trademark law for use of our trademarks. | ||
// | ||
// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing | ||
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0 | ||
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode | ||
// (c) Copyright Ascensio System SIA 2009-2024 | ||
// | ||
// This program is a free software product. | ||
// You can redistribute it and/or modify it under the terms | ||
// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software | ||
// Foundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended | ||
// to the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of | ||
// any third-party rights. | ||
// | ||
// This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty | ||
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see | ||
// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html | ||
// | ||
// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021. | ||
// | ||
// The interactive user interfaces in modified source and object code versions of the Program must | ||
// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3. | ||
// | ||
// Pursuant to Section 7(b) of the License you must retain the original Product logo when | ||
// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under | ||
// trademark law for use of our trademarks. | ||
// | ||
// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing | ||
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0 | ||
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode | ||
|
||
import { useState, useRef, useEffect, useCallback } from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { inject, observer } from "mobx-react"; | ||
|
||
import DownloadAsReactSvgUrl from "PUBLIC_DIR/images/download-as.react.svg?url"; | ||
|
||
import { | ||
ModalDialog, | ||
ModalDialogType, | ||
} from "@docspace/shared/components/modal-dialog"; | ||
import { IconButton } from "@docspace/shared/components/icon-button"; | ||
import { Button } from "@docspace/shared/components/button"; | ||
import { Text } from "@docspace/shared/components/text"; | ||
|
||
import { StyledSinglePasswordFile } from "./StyledDownloadDialog"; | ||
import SimulatePassword from "../../../components/SimulatePassword"; | ||
|
||
const OnePasswordRow = ({ | ||
item, | ||
getItemIcon, | ||
onDownload, | ||
downloadItems, | ||
onClosePanel, | ||
visible, | ||
}) => { | ||
const [password, setPassword] = useState(""); | ||
const { t } = useTranslation(["DownloadDialog", "Files", "Common"]); | ||
const inputRef = useRef(null); | ||
|
||
const onChangePassword = (password) => { | ||
setPassword(password); | ||
}; | ||
|
||
const updateDownloadItem = (fileId, updates) => { | ||
const files = [...downloadItems]; | ||
const itemToUpdate = files.find((item) => item.id === fileId); | ||
Object.assign(itemToUpdate, updates); | ||
return files; | ||
}; | ||
|
||
const onDowloadInOriginal = () => { | ||
const files = updateDownloadItem(item.id, { format: item.fileExst }); | ||
onDownload(files); | ||
}; | ||
|
||
const onDownloadWithPassword = () => { | ||
if (!password.trim().length) return; | ||
|
||
const files = updateDownloadItem(item.id, { | ||
password, | ||
}); | ||
onDownload(files); | ||
}; | ||
|
||
const onRemoveFromDowload = () => { | ||
const fileId = item.id; | ||
|
||
const files = downloadItems.filter((item) => item.id !== fileId); | ||
if (!files.length) { | ||
onClosePanel(); | ||
return; | ||
} | ||
onDownload(files); | ||
}; | ||
|
||
const onKeyUp = (event) => { | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
|
||
if (event.key === "Enter") { | ||
onDownloadWithPassword(); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
window.addEventListener("keyup", onKeyUp, true); | ||
|
||
return () => { | ||
window.removeEventListener("keyup", onKeyUp, true); | ||
}; | ||
}, [onKeyUp]); | ||
|
||
const element = getItemIcon(item); | ||
|
||
return ( | ||
<ModalDialog | ||
visible={visible} | ||
displayType={ModalDialogType.modal} | ||
onClose={onClosePanel} | ||
autoMaxHeight | ||
> | ||
<ModalDialog.Header>{t("Translations:DownloadAs")}</ModalDialog.Header> | ||
<ModalDialog.Body> | ||
<StyledSinglePasswordFile> | ||
<Text>{t("AccessPasswordMessage")}</Text> | ||
<div className="single-password_content"> | ||
<div className="single-password_row"> | ||
{element} | ||
<Text fontWeight="600" fontSize="14px" className="password-title"> | ||
{item.title} | ||
</Text> | ||
</div> | ||
<IconButton | ||
size={16} | ||
iconName={DownloadAsReactSvgUrl} | ||
onClick={onDowloadInOriginal} | ||
/> | ||
</div> | ||
<SimulatePassword | ||
onChange={onChangePassword} | ||
forwardedRef={inputRef} | ||
/> | ||
</StyledSinglePasswordFile> | ||
</ModalDialog.Body> | ||
<ModalDialog.Footer> | ||
<Button | ||
label={t("Common:ContinueButton")} | ||
size="normal" | ||
primary | ||
onClick={onDownloadWithPassword} | ||
isDisabled={!password.trim().length} | ||
scale | ||
/> | ||
<Button | ||
label={t("Common:CancelButton")} | ||
size="normal" | ||
onClick={onRemoveFromDowload} | ||
scale | ||
/> | ||
</ModalDialog.Footer> | ||
</ModalDialog> | ||
); | ||
}; | ||
export default inject(({ dialogsStore }) => { | ||
const { | ||
setDownloadItems, | ||
downloadItems, | ||
sortedPasswordFiles, | ||
downloadDialogVisible: visible, | ||
} = dialogsStore; | ||
|
||
const item = sortedPasswordFiles[0]; | ||
|
||
return { | ||
item, | ||
setDownloadItems, | ||
downloadItems, | ||
sortedPasswordFiles, | ||
visible, | ||
}; | ||
})(observer(OnePasswordRow)); |
Oops, something went wrong.