Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/editor extention #311

Merged
merged 13 commits into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions products/ASC.Files/Client/src/HOCs/withContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { combineUrl } from "@appserver/common/utils";
import config from "../../package.json";
import EditingWrapperComponent from "../components/EditingWrapperComponent";
import { getTitleWithoutExst } from "../helpers/files-helpers";

import { getDefaultFileName } from "../helpers/utils";
export default function withContent(WrappedContent) {
class WithContent extends React.Component {
constructor(props) {
Expand All @@ -23,7 +23,7 @@ export default function withContent(WrappedContent) {
const { item, fileActionId, fileActionExt } = props;
let titleWithoutExt = getTitleWithoutExst(item);
if (fileActionId === -1 && item.id === fileActionId) {
titleWithoutExt = this.getDefaultName(fileActionExt);
titleWithoutExt = getDefaultFileName(fileActionExt);
}

this.state = { itemTitle: titleWithoutExt };
Expand All @@ -32,25 +32,25 @@ export default function withContent(WrappedContent) {
componentDidUpdate(prevProps) {
const { fileActionId, fileActionExt } = this.props;
if (fileActionId === -1 && fileActionExt !== prevProps.fileActionExt) {
const itemTitle = this.getDefaultName(fileActionExt);
const itemTitle = getDefaultFileName(fileActionExt);
this.setState({ itemTitle });
}
}

getDefaultName = (format) => {
const { t } = this.props;

switch (format) {
case "docx":
return t("NewDocument");
case "xlsx":
return t("NewSpreadsheet");
case "pptx":
return t("NewPresentation");
default:
return t("NewFolder");
}
};
// getDefaultName = (format) => {
TatianaLopaeva marked this conversation as resolved.
Show resolved Hide resolved
// const { t } = this.props;

// switch (format) {
// case "docx":
// return t("NewDocument");
// case "xlsx":
// return t("NewSpreadsheet");
// case "pptx":
// return t("NewPresentation");
// default:
// return t("NewFolder");
// }
// };

completeAction = (id) => {
const { editCompleteAction, item } = this.props;
Expand Down
8 changes: 7 additions & 1 deletion products/ASC.Files/Client/src/HOCs/withLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { isMobile } from "react-device-detect";

import Loaders from "@appserver/common/components/Loaders";

const pathname = window.location.pathname.toLowerCase();
const isEditor = pathname.indexOf("doceditor") !== -1;

let loadTimeout = null;
const withLoader = (WrappedComponent) => (Loader) => {
const withLoader = (props) => {
Expand Down Expand Up @@ -33,7 +36,10 @@ const withLoader = (WrappedComponent) => (Loader) => {
};
}, [isLoading]);

return firstLoad || !isLoaded || (isMobile && inLoad) || !tReady ? (
return (!isEditor && firstLoad) ||
!isLoaded ||
(isMobile && inLoad) ||
!tReady ? (
Loader ? (
Loader
) : viewAs === "tile" ? (
Expand Down
35 changes: 35 additions & 0 deletions products/ASC.Files/Client/src/helpers/i18n.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import i18n from "i18next";
import Backend from "i18next-http-backend";
import { LANGUAGE } from "@appserver/common/constants";
import config from "../../package.json";
import { loadLanguagePath } from "@appserver/common/utils";

const newInstance = i18n.createInstance();

newInstance.use(Backend).init({
lng: localStorage.getItem(LANGUAGE) || "en",
fallbackLng: "en",
load: "all",
//debug: true,

interpolation: {
escapeValue: false, // not needed for react as it escapes by default
format: function (value, format) {
if (format === "lowercase") return value.toLowerCase();
return value;
},
},

backend: {
loadPath: loadLanguagePath(config.homepage),
},

ns: ["Home"],
defaultNS: "Home",

react: {
useSuspense: false,
},
});

export default newInstance;
62 changes: 61 additions & 1 deletion products/ASC.Files/Client/src/helpers/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import authStore from "@appserver/common/store/AuthStore";

import { AppServerConfig } from "@appserver/common/constants";
import config from "../../package.json";
import { combineUrl } from "@appserver/common/utils";
import {
addFileToRecentlyViewed,
createFile,
} from "@appserver/common/api/files";
import i18n from "./i18n";
export const setDocumentTitle = (subTitle = null) => {
const { isAuthenticated, settingsStore, product: currentModule } = authStore;
const { organizationName } = settingsStore;
Expand All @@ -19,3 +26,56 @@ export const setDocumentTitle = (subTitle = null) => {

document.title = title;
};

export const getDefaultFileName = (format) => {
switch (format) {
case "docx":
return i18n.t("NewDocument");
case "xlsx":
return i18n.t("NewSpreadsheet");
case "pptx":
return i18n.t("NewPresentation");
default:
return i18n.t("NewFolder");
}
};

export const createNewFile = async (folderId, fileName, open = true) => {
const file = await createFile(folderId, fileName);

open && (await openDocEditor(file.id));

return file;
};

export const addFileToRecent = async (fileId) => {
try {
await addFileToRecentlyViewed(fileId);
console.log("Pushed to recently viewed");
} catch (e) {
console.error(e);
}
};
export const openDocEditor = async (
id,
providerKey = null,
tab = null,
url = null
) => {
if (!providerKey) {
await addFileToRecent(id);
}

return Promise.resolve(
tab
? (tab.location = url)
: window.open(
combineUrl(
AppServerConfig.proxyURL,
config.homepage,
`/doceditor?fileId=${id}`
),
"_blank"
)
);
};
30 changes: 2 additions & 28 deletions products/ASC.Files/Client/src/store/FilesStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { combineUrl } from "@appserver/common/utils";
import { updateTempContent } from "@appserver/common/utils";
import { thumbnailStatuses } from "../helpers/constants";
import { isMobile } from "react-device-detect";
import { openDocEditor } from "../helpers/utils";

const { FilesFilter } = api;

Expand Down Expand Up @@ -1371,34 +1372,7 @@ class FilesStore {
};

openDocEditor = (id, providerKey = null, tab = null, url = null) => {
if (providerKey) {
tab
? (tab.location = url)
: window.open(
combineUrl(
AppServerConfig.proxyURL,
config.homepage,
`/doceditor?fileId=${id}`
),
"_blank"
);
} else {
return this.addFileToRecentlyViewed(id)
.then(() => console.log("Pushed to recently viewed"))
.catch((e) => console.error(e))
.finally(
tab
? (tab.location = url)
: window.open(
combineUrl(
AppServerConfig.proxyURL,
config.homepage,
`/doceditor?fileId=${id}`
),
"_blank"
)
);
}
return openDocEditor(id, providerKey, tab, url);
};

createThumbnails = () => {
Expand Down
1 change: 1 addition & 0 deletions products/ASC.Files/Client/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ var config = {
exposes: {
"./app": "./src/Files.jsx",
"./SharingDialog": "./src/components/panels/SharingDialog",
"./utils": "./src/helpers/utils.js",
},
shared: {
...deps,
Expand Down
Loading