From 33bf343709e70d13d4a1929f5fb7f355d29fca65 Mon Sep 17 00:00:00 2001 From: SergeyEzhin Date: Sat, 24 Jul 2021 01:38:54 +0300 Subject: [PATCH] [DE mobile] Changed encoding options --- apps/common/mobile/lib/store/encoding.js | 70 --------- .../mobile/src/controller/Encoding.jsx | 94 ++++++++++++ .../mobile/src/controller/Main.jsx | 17 +-- .../src/controller/settings/Download.jsx | 91 +++++------- .../src/controller/settings/Encoding.jsx | 43 ------ .../mobile/src/store/mainStore.js | 2 - .../mobile/src/view/Encoding.jsx | 136 ++++++++++++++++++ .../mobile/src/view/settings/Encoding.jsx | 57 -------- .../mobile/src/view/settings/Settings.jsx | 10 -- .../mobile/src/controller/Encoding.jsx | 1 - .../mobile/src/store/mainStore.js | 2 - .../mobile/src/view/Encoding.jsx | 3 - .../mobile/src/view/settings/Settings.jsx | 2 +- 13 files changed, 278 insertions(+), 250 deletions(-) delete mode 100644 apps/common/mobile/lib/store/encoding.js create mode 100644 apps/documenteditor/mobile/src/controller/Encoding.jsx delete mode 100644 apps/documenteditor/mobile/src/controller/settings/Encoding.jsx create mode 100644 apps/documenteditor/mobile/src/view/Encoding.jsx delete mode 100644 apps/documenteditor/mobile/src/view/settings/Encoding.jsx diff --git a/apps/common/mobile/lib/store/encoding.js b/apps/common/mobile/lib/store/encoding.js deleted file mode 100644 index 41ad838d6d..0000000000 --- a/apps/common/mobile/lib/store/encoding.js +++ /dev/null @@ -1,70 +0,0 @@ -import {action, observable, makeObservable} from 'mobx'; - -export class storeEncoding { - constructor() { - makeObservable(this, { - type: observable, - mode: observable, - setMode: action, - advOptions: observable, - formatOptions: observable, - pages: observable, - pagesName: observable, - initOptions: action, - valueEncoding: observable, - nameEncoding: observable, - initPages: action, - changeEncoding: action, - valueDelimeter: observable, - nameDelimeter: observable, - changeDelimeter: action, - namesDelimeter: observable, - valuesDelimeter: observable, - initNamesDelimeter: action - }); - } - - type; - mode = 1; - pages = []; - pagesName = []; - advOptions; - formatOptions; - valueEncoding; - nameEncoding; - namesDelimeter = []; - valuesDelimeter = [4, 2, 3, 1, 5]; - nameDelimeter; - valueDelimeter; - - initOptions ({type, advOptions, formatOptions}) { - this.type = type; - this.advOptions = advOptions; - this.formatOptions = formatOptions; - } - - initPages() { - for (let page of this.advOptions.asc_getCodePages()) { - this.pages.push(page.asc_getCodePage()); - this.pagesName.push(page.asc_getCodePageName()); - } - } - - initNamesDelimeter(names) { - this.namesDelimeter = names; - } - - setMode(value) { - this.mode = value; - } - - changeEncoding(value) { - this.nameEncoding = this.pagesName[this.pages.indexOf(value)]; - this.valueEncoding = value; - } - - changeDelimeter(value) { - this.nameDelimeter = this.namesDelimeter[this.valuesDelimeter.indexOf(value)]; - this.valueDelimeter = value; - } -} diff --git a/apps/documenteditor/mobile/src/controller/Encoding.jsx b/apps/documenteditor/mobile/src/controller/Encoding.jsx new file mode 100644 index 0000000000..87c4c434f5 --- /dev/null +++ b/apps/documenteditor/mobile/src/controller/Encoding.jsx @@ -0,0 +1,94 @@ +import React, { Component } from 'react'; +import { Device } from '../../../../common/mobile/utils/device'; +import { f7 } from "framework7-react"; +import { Encoding } from "../view/Encoding"; + +class EncodingController extends Component { + constructor(props) { + super(props); + + this.onSaveFormat = this.onSaveFormat.bind(this); + this.closeModal = this.closeModal.bind(this); + this.state = { + isOpen: false + }; + + Common.Notifications.on('engineCreated', api => { + api.asc_registerCallback('asc_onAdvancedOptions', (type, advOptions, mode, formatOptions) => { + this.initEncoding(type, advOptions, mode, formatOptions); + }); + }); + + Common.Notifications.on('openEncoding', (type, advOptions, mode, formatOptions) => { + this.initEncoding(type, advOptions, mode, formatOptions); + }); + } + + initEncoding(type, advOptions, mode, formatOptions) { + if(type === Asc.c_oAscAdvancedOptionsID.CSV) { + Common.Notifications.trigger('preloader:close'); + Common.Notifications.trigger('preloader:endAction', Asc.c_oAscAsyncActionType['BlockInteraction'], -256, true); + + this.mode = mode; + this.advOptions = advOptions; + this.formatOptions = formatOptions; + this.pages = []; + this.pagesName = []; + + const recommendedSettings = this.advOptions.asc_getRecommendedSettings(); + + this.initPages(); + this.valueEncoding = recommendedSettings.asc_getCodePage(); + + this.setState({ + isOpen: true + }); + } + } + + initPages() { + for (let page of this.advOptions.asc_getCodePages()) { + this.pages.push(page.asc_getCodePage()); + this.pagesName.push(page.asc_getCodePageName()); + } + } + + closeModal() { + if (Device.phone) { + f7.sheet.close('.encoding-popup', true); + } else { + f7.popover.close('#encoding-popover'); + } + + this.setState({isOpen: false}); + } + + onSaveFormat(valueEncoding) { + const api = Common.EditorApi.get(); + + this.closeModal(); + + if(this.mode === 2) { + this.formatOptions && this.formatOptions.asc_setAdvancedOptions(new Asc.asc_CTextOptions(valueEncoding)); + api.asc_DownloadAs(this.formatOptions); + } else { + api.asc_setAdvancedOptions(Asc.c_oAscAdvancedOptionsID.CSV, new Asc.asc_CTextOptions(valueEncoding)); + } + } + + render() { + return ( + this.state.isOpen && + + ); + } +} + +export default EncodingController; \ No newline at end of file diff --git a/apps/documenteditor/mobile/src/controller/Main.jsx b/apps/documenteditor/mobile/src/controller/Main.jsx index 9ead458704..fdd3dd364c 100644 --- a/apps/documenteditor/mobile/src/controller/Main.jsx +++ b/apps/documenteditor/mobile/src/controller/Main.jsx @@ -16,7 +16,7 @@ import EditorUIController from '../lib/patch'; import ErrorController from "./Error"; import LongActionsController from "./LongActions"; import PluginsController from '../../../../common/mobile/lib/controller/Plugins.jsx'; - +import EncodingController from "./Encoding"; @inject( "storeAppOptions", "storeDocumentSettings", @@ -26,9 +26,8 @@ import PluginsController from '../../../../common/mobile/lib/controller/Plugins. "storeTableSettings", "storeDocumentInfo", "storeChartSettings", - "storeApplicationSettings", - "storeEncoding" - ) + "storeApplicationSettings" +) class MainController extends Component { constructor(props) { super(props); @@ -608,14 +607,15 @@ class MainController extends Component { storeDocumentSettings.addSchemes(arr); }); - const storeEncoding = this.props.storeEncoding; - // Downloaded Advanced Options + this.api.asc_registerCallback('asc_onAdvancedOptions', (type, advOptions, mode, formatOptions) => { const {t} = this.props; const _t = t("Settings", { returnObjects: true }); - onAdvancedOptions(type, advOptions, mode, formatOptions, _t, this._isDocReady, this.props.storeAppOptions.canRequestClose, this.isDRM, storeEncoding); - if(type == Asc.c_oAscAdvancedOptionsID.DRM) this.isDRM = true; + if(type == Asc.c_oAscAdvancedOptionsID.DRM) { + onAdvancedOptions(type, _t, this._isDocReady, this.props.storeAppOptions.canRequestClose, this.isDRM); + this.isDRM = true; + } }); } @@ -821,6 +821,7 @@ class MainController extends Component { {EditorUIController.getEditCommentControllers && EditorUIController.getEditCommentControllers()} + ) } diff --git a/apps/documenteditor/mobile/src/controller/settings/Download.jsx b/apps/documenteditor/mobile/src/controller/settings/Download.jsx index a5e6935256..c4b4182dbc 100644 --- a/apps/documenteditor/mobile/src/controller/settings/Download.jsx +++ b/apps/documenteditor/mobile/src/controller/settings/Download.jsx @@ -13,7 +13,7 @@ class DownloadController extends Component { closeModal() { if (Device.phone) { - f7.sheet.close('.settings-popup', true); + f7.sheet.close('.settings-popup', false); } else { f7.popover.close('#settings-popover'); } @@ -31,11 +31,10 @@ class DownloadController extends Component { _t.notcriticalErrorTitle, () => { if (format == Asc.c_oAscFileType.TXT) { - const canRequestClose = this.props.storeAppOptions.canRequestClose; - const storeEncoding = this.props.storeEncoding; const advOptions = api.asc_getAdvancedOptions(); + this.closeModal(); + Common.Notifications.trigger('openEncoding', Asc.c_oAscAdvancedOptionsID.TXT, advOptions, 2, new Asc.asc_CDownloadOptions(format)); - onAdvancedOptions(Asc.c_oAscAdvancedOptionsID.TXT, advOptions, 2, new Asc.asc_CDownloadOptions(format), _t, true, canRequestClose, false, storeEncoding); } else { this.closeModal(); @@ -62,67 +61,53 @@ class DownloadController extends Component { } } -const DownloadWithTranslation = inject("storeAppOptions", "storeEncoding")(observer(withTranslation()(DownloadController))); +const DownloadWithTranslation = inject("storeAppOptions")(observer(withTranslation()(DownloadController))); -const onAdvancedOptions = (type, advOptions, mode, formatOptions, _t, isDocReady, canRequestClose, isDRM, storeEncoding) => { +const onAdvancedOptions = (type, _t, isDocReady, canRequestClose, isDRM) => { if ($$('.dlg-adv-options.modal-in').length > 0) return; const api = Common.EditorApi.get(); - if (type == Asc.c_oAscAdvancedOptionsID.TXT) { - Common.Notifications.trigger('preloader:close'); - Common.Notifications.trigger('preloader:endAction', Asc.c_oAscAsyncActionType['BlockInteraction'], -256, true); - - const recommendedSettings = advOptions.asc_getRecommendedSettings(); + Common.Notifications.trigger('preloader:close'); + Common.Notifications.trigger('preloader:endAction', Asc.c_oAscAsyncActionType['BlockInteraction'], -256, true); - storeEncoding.initOptions({type, advOptions, formatOptions}); - storeEncoding.initPages(); - storeEncoding.setMode(mode); - storeEncoding.changeEncoding(recommendedSettings.asc_getCodePage()); - - f7.views.current.router.navigate('/encoding/'); - } - else if (type == Asc.c_oAscAdvancedOptionsID.DRM) { - Common.Notifications.trigger('preloader:close'); - Common.Notifications.trigger('preloader:endAction', Asc.c_oAscAsyncActionType['BlockInteraction'], -256, true); - const buttons = [{ - text: 'OK', - bold: true, - onClick: function () { - const password = document.getElementById('modal-password').value; - api.asc_setAdvancedOptions(type, new Asc.asc_CDRMAdvancedOptions(password)); - if (!isDocReady) { - Common.Notifications.trigger('preloader:beginAction', Asc.c_oAscAsyncActionType['BlockInteraction'], -256); - } + const buttons = [{ + text: 'OK', + bold: true, + onClick: function () { + const password = document.getElementById('modal-password').value; + api.asc_setAdvancedOptions(type, new Asc.asc_CDRMAdvancedOptions(password)); + if (!isDocReady) { + Common.Notifications.trigger('preloader:beginAction', Asc.c_oAscAsyncActionType['BlockInteraction'], -256); } - }]; - - if(isDRM) { - f7.dialog.create({ - text: _t.txtIncorrectPwd, - buttons : [{ - text: 'OK', - bold: true, - }] - }).open(); } + }]; - if (canRequestClose) - buttons.push({ - text: _t.closeButtonText, - onClick: function () { - Common.Gateway.requestClose(); - } - }); + if(isDRM) { f7.dialog.create({ - title: _t.advDRMOptions, - text: _t.textOpenFile, - content: Device.ios ? - '
' : '
', - buttons: buttons, - cssClass: 'dlg-adv-options' + text: _t.txtIncorrectPwd, + buttons : [{ + text: 'OK', + bold: true, + }] }).open(); } + + if (canRequestClose) + buttons.push({ + text: _t.closeButtonText, + onClick: function () { + Common.Gateway.requestClose(); + } + }); + f7.dialog.create({ + title: _t.advDRMOptions, + text: _t.textOpenFile, + content: Device.ios ? + '
' : '
', + buttons: buttons, + cssClass: 'dlg-adv-options' + }).open(); }; diff --git a/apps/documenteditor/mobile/src/controller/settings/Encoding.jsx b/apps/documenteditor/mobile/src/controller/settings/Encoding.jsx deleted file mode 100644 index a86ecb784c..0000000000 --- a/apps/documenteditor/mobile/src/controller/settings/Encoding.jsx +++ /dev/null @@ -1,43 +0,0 @@ -import React, { Component } from 'react'; -import { Device } from '../../../../../common/mobile/utils/device'; -import { f7 } from "framework7-react"; -import { Encoding } from "../../view/settings/Encoding"; -import { observer, inject } from "mobx-react"; - -class EncodingController extends Component { - constructor(props) { - super(props); - this.onSaveFormat = this.onSaveFormat.bind(this); - } - - closeModal() { - if (Device.phone) { - f7.sheet.close('.settings-popup', true); - } else { - f7.popover.close('#settings-popover'); - } - } - - onSaveFormat(mode, valueEncoding) { - const api = Common.EditorApi.get(); - - this.closeModal(); - - if(mode === 2) { - const formatOptions = this.props.storeEncoding.formatOptions; - formatOptions && formatOptions.asc_setAdvancedOptions(new Asc.asc_CTextOptions(valueEncoding)); - api.asc_DownloadAs(formatOptions); - } else { - const type = this.props.storeEncoding.type; - api.asc_setAdvancedOptions(type, new Asc.asc_CTextOptions(valueEncoding)); - } - } - - render() { - return ( - - ); - } -} - -export default inject("storeEncoding")(observer(EncodingController)); \ No newline at end of file diff --git a/apps/documenteditor/mobile/src/store/mainStore.js b/apps/documenteditor/mobile/src/store/mainStore.js index c880e30c23..57fa6ee885 100644 --- a/apps/documenteditor/mobile/src/store/mainStore.js +++ b/apps/documenteditor/mobile/src/store/mainStore.js @@ -10,7 +10,6 @@ import {storeTableSettings} from "./tableSettings"; import {storeChartSettings} from "./chartSettings"; import {storeDocumentInfo} from "./documentInfo"; import {storeApplicationSettings} from './applicationSettings'; -import {storeEncoding} from "../../../../common/mobile/lib/store/encoding"; import {storeAppOptions} from "./appOptions"; import {storePalette} from "./palette"; import {storeReview} from "./review"; @@ -21,7 +20,6 @@ export const stores = { storeFocusObjects: new storeFocusObjects(), storeDocumentSettings: new storeDocumentSettings(), users: new storeUsers(), - storeEncoding: new storeEncoding(), storeTextSettings: new storeTextSettings(), storeParagraphSettings: new storeParagraphSettings(), storeShapeSettings: new storeShapeSettings(), diff --git a/apps/documenteditor/mobile/src/view/Encoding.jsx b/apps/documenteditor/mobile/src/view/Encoding.jsx new file mode 100644 index 0000000000..2898bc53d4 --- /dev/null +++ b/apps/documenteditor/mobile/src/view/Encoding.jsx @@ -0,0 +1,136 @@ +import React, {Component, useEffect, useState} from 'react'; +import { f7, Page, Navbar, List, ListItem, BlockTitle, ListButton, Popover, Popup, View, Link } from "framework7-react"; +import { useTranslation } from "react-i18next"; +import { Device } from '../../../../common/mobile/utils/device'; + +const PageEncoding = props => { + const { t } = useTranslation(); + const _t = t("View.Settings", { returnObjects: true }); + const pagesName = props.pagesName; + const pages = props.pages; + const [stateEncoding, setStateEncoding] = useState(props.valueEncoding); + const nameEncoding = pagesName[pages.indexOf(stateEncoding)]; + const mode = props.mode; + + const changeStateEncoding = value => { + setStateEncoding(value); + } + + return ( + + + + {_t.textEncoding} + + + + + {mode === 2 ? + props.closeModal()}> + : null} + props.onSaveFormat(stateEncoding)}> + + + + + ) +}; + +const PageEncodingList = props => { + const { t } = useTranslation(); + const _t = t("View.Settings", { returnObjects: true }); + const [currentEncoding, changeCurrentEncoding] = useState(props.stateEncoding); + const pages = props.pages; + const pagesName = props.pagesName; + + return ( + + + {_t.textChooseEncoding} + + {pagesName.map((name, index) => { + return ( + { + changeCurrentEncoding(pages[index]); + props.changeStateEncoding(pages[index]); + f7.views.current.router.back(); + }}> + ) + })} + + + ) +}; + +class EncodingView extends Component { + constructor(props) { + super(props); + } + + render() { + const show_popover = this.props.usePopover; + + return ( + show_popover ? + + + : + + + + ) + } +} + +const routes = [ + { + path: '/encoding-list/', + component: PageEncodingList + } +]; + +const Encoding = props => { + useEffect(() => { + if ( Device.phone ) + f7.popup.open('.encoding-popup'); + else f7.popover.open('#encoding-popover', "#btn-settings"); + + return () => { + } + }); + + return ( + + ) +}; + +export {Encoding, PageEncodingList} \ No newline at end of file diff --git a/apps/documenteditor/mobile/src/view/settings/Encoding.jsx b/apps/documenteditor/mobile/src/view/settings/Encoding.jsx deleted file mode 100644 index 9b5d9740df..0000000000 --- a/apps/documenteditor/mobile/src/view/settings/Encoding.jsx +++ /dev/null @@ -1,57 +0,0 @@ -import React from 'react'; -import { observer, inject } from "mobx-react"; -import { f7, Page, Navbar, List, ListItem, BlockTitle, ListButton } from "framework7-react"; -import { useTranslation } from "react-i18next"; - -const PageEncoding = props => { - const { t } = useTranslation(); - const _t = t("Settings", { returnObjects: true }); - const storeEncoding = props.storeEncoding; - const valueEncoding= storeEncoding.valueEncoding; - const nameEncoding = storeEncoding.nameEncoding; - const mode = storeEncoding.mode; - - return ( - - - {_t.textEncoding} - - - - - props.onSaveFormat(mode, valueEncoding)}> - - - ) -} - -const PageEncodingList = props => { - const { t } = useTranslation(); - const _t = t("Settings", { returnObjects: true }); - const storeEncoding = props.storeEncoding; - const valueEncoding = storeEncoding.valueEncoding; - const pages = storeEncoding.pages; - const pagesName = storeEncoding.pagesName; - - return ( - - - {_t.textChooseEncoding} - - {pagesName.map((name, index) => { - return ( - { - storeEncoding.changeEncoding(pages[index]); - f7.views.current.router.back(); - }}> - ) - })} - - - ) -} - -const Encoding = inject("storeEncoding")(observer(PageEncoding)); -const EncodingList = inject("storeEncoding")(observer(PageEncodingList)); - -export {EncodingList, Encoding} \ No newline at end of file diff --git a/apps/documenteditor/mobile/src/view/settings/Settings.jsx b/apps/documenteditor/mobile/src/view/settings/Settings.jsx index 48a930fcba..93f40c4aac 100644 --- a/apps/documenteditor/mobile/src/view/settings/Settings.jsx +++ b/apps/documenteditor/mobile/src/view/settings/Settings.jsx @@ -12,8 +12,6 @@ import ApplicationSettingsController from "../../controller/settings/Application import { DocumentFormats, DocumentMargins, DocumentColorSchemes } from "./DocumentSettings"; import { MacrosSettings } from "./ApplicationSettings"; import About from '../../../../../common/mobile/lib/view/About'; -import EncodingController from '../../controller/settings/Encoding'; -import { EncodingList } from '../../view/settings/Encoding'; const routes = [ { @@ -55,14 +53,6 @@ const routes = [ { path: '/about/', component: About - }, - { - path: '/encoding/', - component: EncodingController - }, - { - path: '/encoding-list/', - component: EncodingList } ]; diff --git a/apps/spreadsheeteditor/mobile/src/controller/Encoding.jsx b/apps/spreadsheeteditor/mobile/src/controller/Encoding.jsx index 9dfa3ae646..068a9f5638 100644 --- a/apps/spreadsheeteditor/mobile/src/controller/Encoding.jsx +++ b/apps/spreadsheeteditor/mobile/src/controller/Encoding.jsx @@ -89,7 +89,6 @@ class EncodingController extends Component { { closeModal={props.closeModal} onSaveFormat={props.onSaveFormat} mode={props.mode} - formatOptions={props.formatOptions} pages={props.pages} pagesName={props.pagesName} namesDelimeter={props.namesDelimeter} diff --git a/apps/spreadsheeteditor/mobile/src/view/settings/Settings.jsx b/apps/spreadsheeteditor/mobile/src/view/settings/Settings.jsx index 4e5d384a6f..2a0e42c8e6 100644 --- a/apps/spreadsheeteditor/mobile/src/view/settings/Settings.jsx +++ b/apps/spreadsheeteditor/mobile/src/view/settings/Settings.jsx @@ -65,7 +65,7 @@ const routes = [ ]; -const SettingsList = inject("storeAppOptions", "storeEncoding")(observer(props => { +const SettingsList = inject("storeAppOptions")(observer(props => { const { t } = useTranslation(); const _t = t('View.Settings', {returnObjects: true}); const navbar =