Fixed Bug 52443 - Client.Files. Fixed downloadAs action

This commit is contained in:
Nikita Gopienko 2021-09-13 11:09:59 +03:00
parent b70a9cd115
commit 74011d7328
6 changed files with 213 additions and 364 deletions

View File

@ -156,18 +156,4 @@ export const TenantTrustedDomainsType = Object.freeze({
All: 2,
});
export const FilesFormats = Object.freeze({
OriginalFormat: 0,
TxtFormat: 1,
DocxFormat: 2,
OdtFormat: 3,
OdsFormat: 4,
OdpFormat: 5,
PdfFormat: 6,
RtfFormat: 7,
XlsxFormat: 8,
PptxFormat: 9,
CustomFormat: 10,
});
export const PasswordLimitSpecialCharacters = "!@#$%^&*";

View File

@ -45,9 +45,11 @@ class LinkWithDropdown extends React.Component {
}
}
onClickDropDownItem = (item) => {
onClickDropDownItem = (e) => {
const { key } = e.target.dataset;
const item = this.props.data.find((x) => x.key === key);
this.setIsOpen(!this.state.isOpen);
item.onClick && item.onClick();
item && item.onClick && item.onClick(e);
};
shouldComponentUpdate(nextProps, nextState) {
@ -115,7 +117,8 @@ class LinkWithDropdown extends React.Component {
className="drop-down-item"
key={item.key}
{...item}
onClick={this.onClickDropDownItem.bind(this.props, item)}
onClick={this.onClickDropDownItem}
data-key={item.key}
/>
))}
</DropDown>

View File

@ -5,7 +5,6 @@ import RowContainer from "@appserver/components/row-container";
import Text from "@appserver/components/text";
import LinkWithDropdown from "@appserver/components/link-with-dropdown";
import styled from "styled-components";
import { FilesFormats } from "@appserver/common/constants";
const StyledDownloadContent = styled.div`
.row_content,
@ -24,222 +23,96 @@ const DownloadContent = (props) => {
onRowSelect,
getItemIcon,
titleFormat,
getTitleLabel,
type,
filesConverts,
title,
} = props;
const getTitleExtensions = () => {
let arr = [];
for (let item of items) {
const exst = item.fileExst;
const arrayExst = filesConverts.find((f) => f[exst])[exst];
arr = [...arr, ...arrayExst];
}
arr = arr.filter((x, pos) => arr.indexOf(x) !== pos);
arr = arr.filter((x, pos) => arr.indexOf(x) === pos);
const formats = [
{
key: "original",
label: t("OriginalFormat"),
onClick: onSelectFormat,
"data-format": t("OriginalFormat"),
"data-type": type,
},
];
for (let f of arr) {
formats.push({
key: f,
label: f,
onClick: onSelectFormat,
"data-format": f,
"data-type": type,
});
}
formats.push({
key: "custom",
label: t("CustomFormat"),
onClick: onSelectFormat,
"data-format": t("CustomFormat"),
"data-type": type,
});
return formats;
};
const getFormats = (item) => {
const documentFormats = [
{
key: "key1",
label: t("OriginalFormat"),
onClick: onSelectFormat.bind(
this,
FilesFormats.OriginalFormat,
item,
"document"
),
},
{
key: "key2",
label: ".txt",
onClick: onSelectFormat.bind(
this,
FilesFormats.TxtFormat,
item,
"document"
),
},
{
key: "key3",
label: ".docx",
onClick: onSelectFormat.bind(
this,
FilesFormats.DocxFormat,
item,
"document"
),
},
{
key: "key4",
label: ".odt",
onClick: onSelectFormat.bind(
this,
FilesFormats.OdtFormat,
item,
"document"
),
},
{
key: "key5",
label: ".pdf",
onClick: onSelectFormat.bind(
this,
FilesFormats.PdfFormat,
item,
"document"
),
},
{
key: "key6",
label: ".rtf",
onClick: onSelectFormat.bind(
this,
FilesFormats.RtfFormat,
item,
"document"
),
},
{
key: "key7",
label: t("CustomFormat"),
onClick: onSelectFormat.bind(
this,
FilesFormats.CustomFormat,
item,
"document"
),
},
];
const conversionFormats = item
? filesConverts.find((f) => f[item.fileExst])[item.fileExst]
: [];
const presentationFormats = [
const formats = [
{
key: "key1",
key: "original",
label: t("OriginalFormat"),
onClick: onSelectFormat.bind(
this,
FilesFormats.OriginalFormat,
item,
"presentation"
),
},
{
key: "key2",
label: ".odp",
onClick: onSelectFormat.bind(
this,
FilesFormats.OdpFormat,
item,
"presentation"
),
},
{
key: "key3",
label: ".pdf",
onClick: onSelectFormat.bind(
this,
FilesFormats.PdfFormat,
item,
"presentation"
),
},
{
key: "key4",
label: ".pptx",
onClick: onSelectFormat.bind(
this,
FilesFormats.PptxFormat,
item,
"presentation"
),
},
{
key: "key5",
label: t("CustomFormat"),
onClick: onSelectFormat.bind(
this,
FilesFormats.CustomFormat,
item,
"presentation"
),
},
];
const spreadsheetFormats = [
{
key: "key1",
label: t("OriginalFormat"),
onClick: onSelectFormat.bind(
this,
FilesFormats.OriginalFormat,
item,
"spreadsheet"
),
},
{
key: "key2",
label: ".odp",
onClick: onSelectFormat.bind(
this,
FilesFormats.OdsFormat,
item,
"spreadsheet"
),
},
{
key: "key3",
label: ".pdf",
onClick: onSelectFormat.bind(
this,
FilesFormats.PdfFormat,
item,
"spreadsheet"
),
},
{
key: "key4",
label: ".xlsx",
onClick: onSelectFormat.bind(
this,
FilesFormats.XlsxFormat,
item,
"spreadsheet"
),
},
{
key: "key5",
label: t("CustomFormat"),
onClick: onSelectFormat.bind(
this,
FilesFormats.CustomFormat,
item,
"spreadsheet"
),
onClick: onSelectFormat,
"data-format": t("OriginalFormat"),
"data-type": type,
"data-file-id": item.id,
},
];
for (let f of conversionFormats) {
formats.push({
key: f,
label: f,
onClick: onSelectFormat,
"data-format": f,
"data-type": type,
"data-file-id": item.id,
});
}
switch (type) {
case "document":
return documentFormats;
return formats;
case "spreadsheet":
return spreadsheetFormats;
return formats;
case "presentation":
return presentationFormats;
return formats;
default:
return [];
}
};
const getTitle = () => {
switch (type) {
case "document":
return t("Common:Documents");
case "spreadsheet":
return t("Translations:Spreadsheets");
case "presentation":
return t("Translations:Presentations");
default:
return "";
}
};
const title = getTitle();
const length = items.length;
const minHeight = length > 2 ? 110 : length * 50;
const showTitle = length > 1;
const formats = getFormats();
const documentsTitle = getTitleLabel(titleFormat);
const titleData = getTitleExtensions();
return (
<StyledDownloadContent>
@ -261,13 +134,13 @@ const DownloadContent = (props) => {
{checkedTitle || indeterminateTitle ? (
<LinkWithDropdown
containerWidth="auto"
data={formats}
data={titleData}
directionX="left"
directionY="bottom"
dropdownType="appearDashedAfterHover"
fontSize="12px"
>
{documentsTitle}
{titleFormat}
</LinkWithDropdown>
) : (
<></>
@ -284,8 +157,6 @@ const DownloadContent = (props) => {
{items.map((file) => {
const element = getItemIcon(file);
let dropdownItems = getFormats(file);
const format = getTitleLabel(file.format);
dropdownItems = dropdownItems.slice(1, -1);
dropdownItems = dropdownItems.filter(
(x) => x.label !== file.fileExst
);
@ -322,7 +193,7 @@ const DownloadContent = (props) => {
directionY="bottom"
fontSize="12px"
>
{format}
{file.format || t("OriginalFormat")}
</LinkWithDropdown>
) : (
<></>

View File

@ -13,12 +13,11 @@ import { downloadFormatFiles } from "@appserver/common/api/files";
import { TIMEOUT } from "../../../helpers/constants";
import DownloadContent from "./DownloadContent";
import { inject, observer } from "mobx-react";
import { FilesFormats } from "@appserver/common/constants";
class DownloadDialogComponent extends React.Component {
constructor(props) {
super(props);
const { sortedFiles } = this.props;
const { sortedFiles, t } = this.props;
this.state = {
documents: sortedFiles.documents,
@ -26,9 +25,9 @@ class DownloadDialogComponent extends React.Component {
presentations: sortedFiles.presentations,
other: sortedFiles.other,
documentsTitleFormat: FilesFormats.OriginalFormat,
spreadsheetsTitleFormat: FilesFormats.OriginalFormat,
presentationsTitleFormat: FilesFormats.OriginalFormat,
documentsTitleFormat: null,
spreadsheetsTitleFormat: null,
presentationsTitleFormat: null,
checkedDocTitle: true,
checkedSpreadsheetTitle: true,
@ -44,35 +43,6 @@ class DownloadDialogComponent extends React.Component {
onClose = () => this.props.setDownloadDialogVisible(false);
getTitleLabel = (format) => {
switch (format) {
case 0:
return this.props.t("OriginalFormat");
case 1:
return ".txt";
case 2:
return ".docx";
case 3:
return ".odt";
case 4:
return ".ods";
case 5:
return ".odp";
case 6:
return ".pdf";
case 7:
return ".rtf";
case 8:
return ".xlsx";
case 9:
return ".pptx";
case 10:
return this.props.t("CustomFormat");
default:
return "";
}
};
getDownloadItems = () => {
const { documents, spreadsheets, presentations, other } = this.state;
const files = [];
@ -83,9 +53,9 @@ class DownloadDialogComponent extends React.Component {
if (item.checked) {
if (item.fileExst) {
const format =
item.format === 0
item.format === this.props.t("OriginalFormat")
? item.fileExst
: this.getTitleLabel(item.format);
: item.format;
const viewUrl = item.viewUrl;
files.push({ key: item.id, value: format, viewUrl });
} else {
@ -168,85 +138,62 @@ class DownloadDialogComponent extends React.Component {
);
};
onSelectFormat = (format, file, type) => {
const { documents, spreadsheets, presentations } = this.state;
getNewArrayFiles = (fileId, array, format) => {
//Set all documents format
if (!fileId) {
for (let file of array) {
file.format =
format === this.props.t("CustomFormat") || file.fileExst === format
? this.props.t("OriginalFormat")
: format;
}
const newDocuments = documents;
const newSpreadsheets = spreadsheets;
const newPresentations = presentations;
return array;
} else {
//Set single document format
const newDoc = array.find((x) => x.id == fileId);
if (newDoc.format !== format) {
newDoc.format = format;
}
return array;
}
};
onSelectFormat = (e) => {
const { format, type, fileId } = e.target.dataset;
const { documents, spreadsheets, presentations } = this.state;
const { t } = this.props;
const newDocuments = documents.slice();
const newSpreadsheets = spreadsheets.slice();
const newPresentations = presentations.slice();
if (type === "document") {
//Set all documents format
if (!file) {
for (let file of newDocuments) {
file.format =
format === FilesFormats.CustomFormat || file.fileExst === format
? FilesFormats.OriginalFormat
: format;
}
this.setState({
documents: newDocuments,
documentsTitleFormat: format,
});
} else {
//Set single document format
const newDoc = newDocuments.find((x) => x.id === file.id);
if (newDoc.format !== format) {
newDoc.format = format;
this.setState({
documents: newDocuments,
documentsTitleFormat: FilesFormats.CustomFormat,
});
}
}
const documents = this.getNewArrayFiles(fileId, newDocuments, format);
this.setState({
documents,
documentsTitleFormat: !fileId ? format : t("CustomFormat"),
});
} else if (type === "spreadsheet") {
//Set all spreadsheets format
if (!file) {
for (let file of newSpreadsheets) {
file.format =
format === FilesFormats.CustomFormat || file.fileExst === format
? FilesFormats.OriginalFormat
: format;
}
this.setState({
spreadsheets: newSpreadsheets,
spreadsheetsTitleFormat: format,
});
} else {
//Set single spreadsheet format
const newSpreadsheet = newSpreadsheets.find((x) => x.id === file.id);
if (newSpreadsheet.format !== format) {
newSpreadsheet.format = format;
this.setState({
spreadsheets: newSpreadsheets,
spreadsheetsTitleFormat: FilesFormats.CustomFormat,
});
}
}
const spreadsheets = this.getNewArrayFiles(
fileId,
newSpreadsheets,
format
);
this.setState({
spreadsheets,
spreadsheetsTitleFormat: !fileId ? format : t("CustomFormat"),
});
} else if (type === "presentation") {
//Set all presentations format
if (!file) {
for (let file of newPresentations) {
file.format =
format === FilesFormats.CustomFormat || file.fileExst === format
? FilesFormats.OriginalFormat
: format;
}
this.setState({
presentations: newPresentations,
presentationsTitleFormat: format,
});
} else {
//Set single presentation format
const newPresentation = newPresentations.find((x) => x.id === file.id);
if (newPresentation.format !== format) {
newPresentation.format = format;
this.setState({
presentations: newPresentations,
presentationsTitleFormat: FilesFormats.CustomFormat,
});
}
}
const presentations = this.getNewArrayFiles(
fileId,
newPresentations,
format
);
this.setState({
presentations,
presentationsTitleFormat: !fileId ? format : t("CustomFormat"),
});
}
};
@ -396,7 +343,7 @@ class DownloadDialogComponent extends React.Component {
};
render() {
const { visible, t, tReady } = this.props;
const { visible, t, tReady, filesConverts } = this.props;
const {
documentsTitleFormat,
spreadsheetsTitleFormat,
@ -438,45 +385,48 @@ class DownloadDialogComponent extends React.Component {
{documents.length > 0 && (
<DownloadContent
t={t}
filesConverts={filesConverts}
checkedTitle={checkedDocTitle}
indeterminateTitle={indeterminateDocTitle}
items={documents}
onSelectFormat={this.onSelectFormat}
onRowSelect={this.onRowSelect}
getItemIcon={this.getItemIcon}
getTitleLabel={this.getTitleLabel}
titleFormat={documentsTitleFormat}
titleFormat={documentsTitleFormat || t("OriginalFormat")}
type="document"
title={t("Common:Documents")}
/>
)}
{spreadsheets.length > 0 && (
<DownloadContent
t={t}
filesConverts={filesConverts}
checkedTitle={checkedSpreadsheetTitle}
indeterminateTitle={indeterminateSpreadsheetTitle}
items={spreadsheets}
onSelectFormat={this.onSelectFormat}
onRowSelect={this.onRowSelect}
getItemIcon={this.getItemIcon}
getTitleLabel={this.getTitleLabel}
titleFormat={spreadsheetsTitleFormat}
titleFormat={spreadsheetsTitleFormat || t("OriginalFormat")}
type="spreadsheet"
title={t("Translations:Spreadsheets")}
/>
)}
{presentations.length > 0 && (
<DownloadContent
t={t}
filesConverts={filesConverts}
checkedTitle={checkedPresentationTitle}
indeterminateTitle={indeterminatePresentationTitle}
items={presentations}
onSelectFormat={this.onSelectFormat}
onRowSelect={this.onRowSelect}
getItemIcon={this.getItemIcon}
getTitleLabel={this.getTitleLabel}
titleFormat={presentationsTitleFormat}
titleFormat={presentationsTitleFormat || t("OriginalFormat")}
type="presentation"
title={t("Translations:Presentations")}
/>
)}
@ -551,7 +501,6 @@ class DownloadDialogComponent extends React.Component {
size="medium"
primary
onClick={this.onDownload}
//isLoading={isLoading}
/>
<Button
className="button-dialog"
@ -559,7 +508,6 @@ class DownloadDialogComponent extends React.Component {
label={t("Common:CancelButton")}
size="medium"
onClick={this.onClose}
//isLoading={isLoading}
/>
</ModalDialog.Footer>
</ModalDialogContainer>
@ -584,6 +532,7 @@ export default inject(
const { secondaryProgressDataStore } = uploadDataStore;
const { sortedFiles } = filesStore;
const { getIcon, getFolderIcon } = formatsStore.iconFormatsStore;
const { filesConverts } = formatsStore.docserviceStore;
const {
setSecondaryProgressBarData,
clearSecondaryProgressData,
@ -599,6 +548,7 @@ export default inject(
return {
sortedFiles,
visible,
filesConverts,
setSecondaryProgressBarData,
clearSecondaryProgressData,

View File

@ -5,33 +5,28 @@ class DocserviceStore {
coauthorDocs = [".pptx", ".ppsx", ".xlsx", ".csv", ".docx", ".txt"];
commentedDocs = [".docx", ".xlsx", ".pptx"];
convertDocs = [
".pptm",
".ppt",
".ppsm",
".pps",
".potx",
".potm",
".pot",
".odp",
".fodp",
".otp",
".xlsm",
".xls",
".xltx",
".xltm",
".xlt",
".ods",
".fods",
".ots",
".docm",
".doc",
".docx",
".docm",
".dot",
".dotx",
".dotm",
".dot",
".odt",
".fodt",
".ott",
".rtf",
".txt",
".html",
".htm",
".mht",
".pdf",
".djvu",
".fb2",
".epub",
".xps",
".doct",
".docy",
".gdoc",
];
editedDocs = [
".pptx",
@ -121,6 +116,50 @@ class DocserviceStore {
".xps",
];
filesConverts = [
{ ".csv": [".ods", ".pdf", ".xlsx"] },
{ ".doc": [".docx", ".odt", ".pdf", ".rtf", ".txt"] },
{ ".docm": [".docx", ".odt", ".pdf", ".rtf", ".txt"] },
{ ".doct": [".docx"] },
{ ".docx": [".odt", ".pdf", ".rtf", ".txt"] },
{ ".dot": [".docx", ".odt", ".pdf", ".rtf", ".txt"] },
{ ".dotm": [".docx", ".odt", ".pdf", ".rtf", ".txt"] },
{ ".dotx": [".docx", ".odt", ".pdf", ".rtf", ".txt"] },
{ ".epub": [".docx", ".odt", ".pdf", ".rtf", ".txt"] },
{ ".fb2": [".docx", ".odt", ".pdf", ".rtf", ".txt"] },
{ ".fodp": [".odp", ".pdf", ".pptx"] },
{ ".fods": [".csv", ".ods", ".pdf", ".xlsx"] },
{ ".fodt": [".docx", ".odt", ".pdf", ".rtf", ".txt"] },
{ ".html": [".docx", ".odt", ".pdf", ".rtf", ".txt"] },
{ ".mht": [".docx", ".odt", ".pdf", ".rtf", ".txt"] },
{ ".odp": [".pdf", ".pptx"] },
{ ".otp": [".odp", ".pdf", ".pptx"] },
{ ".ods": [".csv", ".pdf", ".xlsx"] },
{ ".ots": [".csv", ".ods", ".pdf", ".xlsx"] },
{ ".odt": [".docx", ".pdf", ".rtf", ".txt"] },
{ ".ott": [".docx", ".odt", ".pdf", ".rtf", ".txt"] },
{ ".pot": [".odp", ".pdf", ".pptx"] },
{ ".potm": [".odp", ".pdf", ".pptx"] },
{ ".potx": [".odp", ".pdf", ".pptx"] },
{ ".pps": [".odp", ".pdf", ".pptx"] },
{ ".ppsm": [".odp", ".pdf", ".pptx"] },
{ ".ppsx": [".odp", ".pdf", ".pptx"] },
{ ".ppt": [".odp", ".pdf", ".pptx"] },
{ ".pptm": [".odp", ".pdf", ".pptx"] },
{ ".pptt": [".pptx"] },
{ ".pptx": [".odp", ".pdf"] },
{ ".rtf": [".docx", ".odt", ".pdf", ".txt"] },
{ ".txt": [".docx", ".odt", ".pdf", ".rtf"] },
{ ".xls": [".csv", ".ods", ".pdf", ".xlsx"] },
{ ".xlsm": [".csv", ".ods", ".pdf", ".xlsx"] },
{ ".xlst": [".xlsx"] },
{ ".xlsx": [".csv", ".ods", ".pdf"] },
{ ".xlt": [".csv", ".ods", ".pdf", ".xlsx"] },
{ ".xltm": [".csv", ".ods", ".pdf", ".xlsx"] },
{ ".xltx": [".csv", ".ods", ".pdf", ".xlsx"] },
{ ".xps": [".pdf"] },
];
constructor() {
makeObservable(this, {});
}

View File

@ -6,7 +6,6 @@ import {
FileType,
FileAction,
AppServerConfig,
FilesFormats,
} from "@appserver/common/constants";
import history from "@appserver/common/history";
import { loopTreeFolders } from "../helpers/files-helpers";
@ -1208,8 +1207,8 @@ class FilesStore {
const {
isSpreadsheet,
isPresentation,
isDocument,
} = this.formatsStore.iconFormatsStore;
const { canWebEdit } = this.formatsStore.docserviceStore;
let sortedFiles = {
documents: [],
@ -1220,14 +1219,14 @@ class FilesStore {
for (let item of this.selection) {
item.checked = true;
item.format = FilesFormats.OriginalFormat;
item.format = null;
if (item.fileExst) {
if (isSpreadsheet(item.fileExst)) {
sortedFiles.spreadsheets.push(item);
} else if (isPresentation(item.fileExst)) {
sortedFiles.presentations.push(item);
} else if (item.fileExst !== ".pdf" && canWebEdit(item.fileExst)) {
} else if (isDocument(item.fileExst)) {
sortedFiles.documents.push(item);
} else {
sortedFiles.other.push(item);
@ -1278,11 +1277,12 @@ class FilesStore {
}
get isWebEditSelected() {
const { editedDocs } = this.formatsStore.docserviceStore;
const { filesConverts } = this.formatsStore.docserviceStore;
return this.selection.some((selected) => {
if (selected.isFolder === true || !selected.fileExst) return false;
return editedDocs.find((format) => selected.fileExst === format);
const index = filesConverts.findIndex((f) => f[selected.fileExst]);
return index !== -1;
});
}
@ -1377,9 +1377,9 @@ class FilesStore {
: splitValue.slice(1).join("_");
if (fileType === "file") {
newSelection.push(this.files.find((f) => f.id == id && f.fileExst));
newSelection.push(this.files.find((f) => f.id == id));
} else {
newSelection.push(this.folders.find((f) => f.id == id && !f.fileExst));
newSelection.push(this.folders.find((f) => f.id == id));
}
}