From 904e9baf05e0b5524c1ec17e4c85dbef20275ffd Mon Sep 17 00:00:00 2001 From: JuliaSvinareva Date: Thu, 8 Apr 2021 21:00:44 +0300 Subject: [PATCH] [DE mobile] Long action handler moved to a separate controller --- apps/documenteditor/mobile/locale/en.json | 69 +++--- .../mobile/src/controller/Error.jsx | 7 +- .../mobile/src/controller/LongActions.jsx | 205 ++++++++++++++++++ .../mobile/src/controller/Main.jsx | 169 +-------------- 4 files changed, 251 insertions(+), 199 deletions(-) create mode 100644 apps/documenteditor/mobile/src/controller/LongActions.jsx diff --git a/apps/documenteditor/mobile/locale/en.json b/apps/documenteditor/mobile/locale/en.json index 3fd29bce3..c522a961a 100644 --- a/apps/documenteditor/mobile/locale/en.json +++ b/apps/documenteditor/mobile/locale/en.json @@ -46,40 +46,6 @@ "textCustomLoader": "Please note that according to the terms of the license you are not entitled to change the loader. Please contact our Sales Department to get a quote.", "textClose": "Close", - "openTitleText": "Opening Document", - "openTextText": "Opening document...", - "saveTitleText": "Saving Document", - "saveTextText": "Saving document...", - "loadFontsTitleText": "Loading Data", - "loadFontsTextText": "Loading data...", - "loadImagesTitleText": "Loading Images", - "loadImagesTextText": "Loading images...", - "loadFontTitleText": "Loading Data", - "loadFontTextText": "Loading data...", - "loadImageTitleText": "Loading Image", - "loadImageTextText": "Loading image...", - "downloadTitleText": "Downloading Document", - "downloadTextText": "Downloading document...", - "printTitleText": "Printing Document", - "printTextText": "Printing document...", - "uploadImageTitleText": "Uploading Image", - "uploadImageTextText": "Uploading image...", - "applyChangesTitleText": "Loading Data", - "applyChangesTextText": "Loading data...", - "savePreparingText": "Preparing to save", - "savePreparingTitle": "Preparing to save. Please wait...", - "mailMergeLoadFileText": "Loading Data Source...", - "mailMergeLoadFileTitle": "Loading Data Source", - "downloadMergeTitle": "Downloading", - "downloadMergeText": "Downloading...", - "sendMergeTitle": "Sending Merge", - "sendMergeText": "Sending Merge...", - "waitText": "Please, wait...", - "txtEditingMode": "Set editing mode...", - "loadingDocumentTitleText": "Loading document", - "loadingDocumentTextText": "Loading document...", - "textLoadingDocument": "Loading document", - "errorProcessSaveResult": "Saving is failed.", "criticalErrorTitle": "Error", "warnProcessRightsChange": "You have been denied the right to edit the file.", @@ -123,6 +89,41 @@ "criticalErrorExtText": "Press 'OK' to back to document list.", "notcriticalErrorTitle": "Warning" }, + "LongActions": { + "openTitleText": "Opening Document", + "openTextText": "Opening document...", + "saveTitleText": "Saving Document", + "saveTextText": "Saving document...", + "loadFontsTitleText": "Loading Data", + "loadFontsTextText": "Loading data...", + "loadImagesTitleText": "Loading Images", + "loadImagesTextText": "Loading images...", + "loadFontTitleText": "Loading Data", + "loadFontTextText": "Loading data...", + "loadImageTitleText": "Loading Image", + "loadImageTextText": "Loading image...", + "downloadTitleText": "Downloading Document", + "downloadTextText": "Downloading document...", + "printTitleText": "Printing Document", + "printTextText": "Printing document...", + "uploadImageTitleText": "Uploading Image", + "uploadImageTextText": "Uploading image...", + "applyChangesTitleText": "Loading Data", + "applyChangesTextText": "Loading data...", + "savePreparingText": "Preparing to save", + "savePreparingTitle": "Preparing to save. Please wait...", + "mailMergeLoadFileText": "Loading Data Source...", + "mailMergeLoadFileTitle": "Loading Data Source", + "downloadMergeTitle": "Downloading", + "downloadMergeText": "Downloading...", + "sendMergeTitle": "Sending Merge", + "sendMergeText": "Sending Merge...", + "waitText": "Please, wait...", + "txtEditingMode": "Set editing mode...", + "loadingDocumentTitleText": "Loading document", + "loadingDocumentTextText": "Loading document...", + "textLoadingDocument": "Loading document" + }, "Toolbar": { "dlgLeaveTitleText": "You leave the application", "dlgLeaveMsgText": "You have unsaved changes in this document. Click \\'Stay on this Page\\' to await the autosave of the document. Click \\'Leave this Page\\' to discard all the unsaved changes.", diff --git a/apps/documenteditor/mobile/src/controller/Error.jsx b/apps/documenteditor/mobile/src/controller/Error.jsx index ca7d93673..f1fd7074b 100644 --- a/apps/documenteditor/mobile/src/controller/Error.jsx +++ b/apps/documenteditor/mobile/src/controller/Error.jsx @@ -2,8 +2,9 @@ import React, { useEffect, useState } from 'react'; import { inject } from 'mobx-react'; import { f7 } from 'framework7-react'; import { useTranslation } from 'react-i18next'; +import LongActionsController from "./LongActions"; -const ErrorController = inject('storeAppOptions')(({storeAppOptions}) => { +const ErrorController = inject('storeAppOptions')(({storeAppOptions, LoadingDocument}) => { const {t} = useTranslation(); const _t = t("Error", { returnObjects: true }); @@ -27,8 +28,8 @@ const ErrorController = inject('storeAppOptions')(({storeAppOptions}) => { return; } - //this.hidePreloader(); - //this.onLongActionEnd(Asc.c_oAscAsyncActionType['BlockInteraction'], LoadingDocument); + Common.Notifications.trigger('preloader:close'); + Common.Notifications.trigger('preloader:endAction', Asc.c_oAscAsyncActionType['BlockInteraction'], LoadingDocument); const api = Common.EditorApi.get(); diff --git a/apps/documenteditor/mobile/src/controller/LongActions.jsx b/apps/documenteditor/mobile/src/controller/LongActions.jsx new file mode 100644 index 000000000..9b9fb6b8f --- /dev/null +++ b/apps/documenteditor/mobile/src/controller/LongActions.jsx @@ -0,0 +1,205 @@ +import React, { Component } from 'react'; +import { inject } from 'mobx-react'; +import { f7 } from 'framework7-react'; +import { withTranslation } from 'react-i18next'; +import IrregularStack from "../../../../common/mobile/utils/IrregularStack"; + +class LongActions extends Component { + constructor(props) { + super(props); + + this.stackLongActions = new IrregularStack({ + strongCompare : function(obj1, obj2){return obj1.id === obj2.id && obj1.type === obj2.type;}, + weakCompare : function(obj1, obj2){return obj1.type === obj2.type;} + }); + + this.onLongActionBegin = this.onLongActionBegin.bind(this); + this.onLongActionEnd = this.onLongActionEnd.bind(this); + this.onOpenDocument = this.onOpenDocument.bind(this); + this.closePreloader = this.closePreloader.bind(this); + } + + closePreloader() { + if (this.loadMask.el) { + f7.dialog.close(this.loadMask.el); + } + } + + componentDidMount() { + Common.Notifications.on('engineCreated', (api) => { + api.asc_registerCallback('asc_onStartAction', this.onLongActionBegin); + api.asc_registerCallback('asc_onEndAction', this.onLongActionEnd); + api.asc_registerCallback('asc_onOpenDocumentProgress', this.onOpenDocument); + }); + Common.Notifications.on('preloader:endAction', this.onLongActionEnd); + Common.Notifications.on('preloader:close', this.closePreloader); + } + + componentWillUnmount() { + const api = Common.EditorApi.get(); + api.asc_unregisterCallback('asc_onStartAction', this.onLongActionBegin); + api.asc_unregisterCallback('asc_onEndAction', this.onLongActionEnd); + api.asc_unregisterCallback('asc_onOpenDocumentProgress', this.onOpenDocument); + + Common.Notifications.off('preloader:endAction', this.onLongActionEnd); + Common.Notifications.off('preloader:close', this.closePreloader); + } + + onLongActionBegin (type, id) { + const action = {id: id, type: type}; + this.stackLongActions.push(action); + this.setLongActionView(action); + } + + onLongActionEnd (type, id) { + let action = {id: id, type: type}; + this.stackLongActions.pop(action); + + //this.updateWindowTitle(true); + + action = this.stackLongActions.get({type: Asc.c_oAscAsyncActionType.Information}); + + if (action) { + this.setLongActionView(action) + } + + action = this.stackLongActions.get({type: Asc.c_oAscAsyncActionType.BlockInteraction}); + + if (action) { + this.setLongActionView(action) + } else { + this.loadMask.el && this.loadMask.el.classList.contains('modal-in') && f7.dialog.close(this.loadMask.el); + } + } + + setLongActionView (action) { + const { t } = this.props; + const _t = t("LongActions", { returnObjects: true }); + let title = ''; + let text = ''; + switch (action.id) { + case Asc.c_oAscAsyncAction['Open']: + title = _t.openTitleText; + text = _t.openTextText; + break; + + case Asc.c_oAscAsyncAction['Save']: + title = _t.saveTitleText; + text = _t.saveTextText; + break; + + case Asc.c_oAscAsyncAction['LoadDocumentFonts']: + title = _t.loadFontsTitleText; + text = _t.loadFontsTextText; + break; + + case Asc.c_oAscAsyncAction['LoadDocumentImages']: + title = _t.loadImagesTitleText; + text = _t.loadImagesTextText; + break; + + case Asc.c_oAscAsyncAction['LoadFont']: + title = _t.loadFontTitleText; + text = _t.loadFontTextText; + break; + + case Asc.c_oAscAsyncAction['LoadImage']: + title = _t.loadImageTitleText; + text = _t.loadImageTextText; + break; + + case Asc.c_oAscAsyncAction['DownloadAs']: + title = _t.downloadTitleText; + text = _t.downloadTextText; + break; + + case Asc.c_oAscAsyncAction['Print']: + title = _t.printTitleText; + text = _t.printTextText; + break; + + case Asc.c_oAscAsyncAction['UploadImage']: + title = _t.uploadImageTitleText; + text = _t.uploadImageTextText; + break; + + case Asc.c_oAscAsyncAction['ApplyChanges']: + title = _t.applyChangesTitleText; + text = _t.applyChangesTextText; + break; + + case Asc.c_oAscAsyncAction['PrepareToSave']: + title = _t.savePreparingText; + text = _t.savePreparingTitle; + break; + + case Asc.c_oAscAsyncAction['MailMergeLoadFile']: + title = _t.mailMergeLoadFileText; + text = _t.mailMergeLoadFileTitle; + break; + + case Asc.c_oAscAsyncAction['DownloadMerge']: + title = _t.downloadMergeTitle; + text = _t.downloadMergeText; + break; + + case Asc.c_oAscAsyncAction['SendMailMerge']: + title = _t.sendMergeTitle; + text = _t.sendMergeText; + break; + + case Asc.c_oAscAsyncAction['Waiting']: + title = _t.waitText; + text = _t.waitText; + break; + + case ApplyEditRights: + title = _t.txtEditingMode; + text = _t.txtEditingMode; + break; + + case LoadingDocument: + title = _t.loadingDocumentTitleText; + text = _t.loadingDocumentTextText; + break; + default: + if (typeof action.id == 'string'){ + title = action.id; + text = action.id; + } + break; + } + + if (action.type === Asc.c_oAscAsyncActionType['BlockInteraction']) { + if (action.id === Asc.c_oAscAsyncAction['ApplyChanges']) { + return; + } + + if (this.loadMask && this.loadMask.el && this.loadMask.el.classList.contains('modal-in')) { + this.loadMask.el.getElementsByClassName('dialog-title')[0].innerHTML = title; + } else { + this.loadMask = f7.dialog.preloader(title); + } + } + + } + + onOpenDocument (progress) { + if (this.loadMask && this.loadMask.el) { + const $title = this.loadMask.el.getElementsByClassName('dialog-title')[0]; + const proc = (progress.asc_getCurrentFont() + progress.asc_getCurrentImage())/(progress.asc_getFontsCount() + progress.asc_getImagesCount()); + + const { t } = this.props; + const _t = t("LongActions", { returnObjects: true }); + $title.innerHTML = `${_t.textLoadingDocument}: ${Math.min(Math.round(proc * 100), 100)}%`; + } + } + + render() { + return null; + } +} + +const LongActionsController = withTranslation()(LongActions); + +export default LongActionsController; \ 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 d2e87f6a8..07aece297 100644 --- a/apps/documenteditor/mobile/src/controller/Main.jsx +++ b/apps/documenteditor/mobile/src/controller/Main.jsx @@ -4,7 +4,6 @@ import {inject} from "mobx-react"; import { f7 } from "framework7-react"; import { withTranslation } from 'react-i18next'; import { LocalStorage } from '../../../../common/mobile/utils/LocalStorage'; -import IrregularStack from '../../../../common/mobile/utils/IrregularStack'; import CollaborationController from '../../../../common/mobile/lib/controller/collaboration/Collaboration.jsx'; import {InitReviewController as ReviewController} from '../../../../common/mobile/lib/controller/collaboration/Review.jsx'; import { onAdvancedOptions } from './settings/Download.jsx'; @@ -17,6 +16,7 @@ import { import About from '../../../../common/mobile/lib/view/About'; import EditorUIController from '../lib/patch'; import ErrorController from "./Error"; +import LongActionsController from "./LongActions"; @inject( "storeAppOptions", @@ -33,20 +33,15 @@ class MainController extends Component { super(props); window.editorType = 'de'; + this.LoadingDocument = -256; + this._state = { licenseType: false, isFromGatewayDownloadAs: false }; - this.stackLongActions = new IrregularStack({ - strongCompare : function(obj1, obj2){return obj1.id === obj2.id && obj1.type === obj2.type;}, - weakCompare : function(obj1, obj2){return obj1.type === obj2.type;} - }); - const { t } = this.props; this._t = t('Main', {returnObjects:true}); - - this.LoadingDocument = -256; } initSdk() { @@ -192,8 +187,8 @@ class MainController extends Component { this._isDocReady = true; - f7.dialog.close(this.loadMask.el); - this.onLongActionEnd(Asc.c_oAscAsyncActionType['BlockInteraction'], this.LoadingDocument); + Common.Notifications.trigger('preloader:close'); + Common.Notifications.trigger('preloader:endAction', Asc.c_oAscAsyncActionType['BlockInteraction'], this.LoadingDocument); Common.Gateway.on('processsaveresult', this.onProcessSaveResult.bind(this)); Common.Gateway.on('processrightschange', this.onProcessRightsChange.bind(this)); @@ -406,10 +401,6 @@ class MainController extends Component { } bindEvents() { - this.api.asc_registerCallback('asc_onStartAction', this.onLongActionBegin.bind(this)); - this.api.asc_registerCallback('asc_onEndAction', this.onLongActionEnd.bind(this)); - this.api.asc_registerCallback('asc_onOpenDocumentProgress', this.onOpenDocument.bind(this)); - this.api.asc_registerCallback('asc_onSendThemeColors', (colors, standart_colors) => { Common.Utils.ThemeColor.setColors(colors, standart_colors); }); @@ -512,153 +503,6 @@ class MainController extends Component { }); } - onLongActionBegin (type, id) { - const action = {id: id, type: type}; - this.stackLongActions.push(action); - this.setLongActionView(action); - } - - onLongActionEnd (type, id) { - let action = {id: id, type: type}; - this.stackLongActions.pop(action); - - //this.updateWindowTitle(true); - - action = this.stackLongActions.get({type: Asc.c_oAscAsyncActionType.Information}); - - if (action) { - this.setLongActionView(action) - } - - action = this.stackLongActions.get({type: Asc.c_oAscAsyncActionType.BlockInteraction}); - - if (action) { - this.setLongActionView(action) - } else { - this.loadMask.el && this.loadMask.el.classList.contains('modal-in') && f7.dialog.close(this.loadMask.el); - } - } - - setLongActionView (action) { - const _t = this._t; - let title = ''; - let text = ''; - switch (action.id) { - case Asc.c_oAscAsyncAction['Open']: - title = _t.openTitleText; - text = _t.openTextText; - break; - - case Asc.c_oAscAsyncAction['Save']: - title = _t.saveTitleText; - text = _t.saveTextText; - break; - - case Asc.c_oAscAsyncAction['LoadDocumentFonts']: - title = _t.loadFontsTitleText; - text = _t.loadFontsTextText; - break; - - case Asc.c_oAscAsyncAction['LoadDocumentImages']: - title = _t.loadImagesTitleText; - text = _t.loadImagesTextText; - break; - - case Asc.c_oAscAsyncAction['LoadFont']: - title = _t.loadFontTitleText; - text = _t.loadFontTextText; - break; - - case Asc.c_oAscAsyncAction['LoadImage']: - title = _t.loadImageTitleText; - text = _t.loadImageTextText; - break; - - case Asc.c_oAscAsyncAction['DownloadAs']: - title = _t.downloadTitleText; - text = _t.downloadTextText; - break; - - case Asc.c_oAscAsyncAction['Print']: - title = _t.printTitleText; - text = _t.printTextText; - break; - - case Asc.c_oAscAsyncAction['UploadImage']: - title = _t.uploadImageTitleText; - text = _t.uploadImageTextText; - break; - - case Asc.c_oAscAsyncAction['ApplyChanges']: - title = _t.applyChangesTitleText; - text = _t.applyChangesTextText; - break; - - case Asc.c_oAscAsyncAction['PrepareToSave']: - title = _t.savePreparingText; - text = _t.savePreparingTitle; - break; - - case Asc.c_oAscAsyncAction['MailMergeLoadFile']: - title = _t.mailMergeLoadFileText; - text = _t.mailMergeLoadFileTitle; - break; - - case Asc.c_oAscAsyncAction['DownloadMerge']: - title = _t.downloadMergeTitle; - text = _t.downloadMergeText; - break; - - case Asc.c_oAscAsyncAction['SendMailMerge']: - title = _t.sendMergeTitle; - text = _t.sendMergeText; - break; - - case Asc.c_oAscAsyncAction['Waiting']: - title = _t.waitText; - text = _t.waitText; - break; - - case ApplyEditRights: - title = _t.txtEditingMode; - text = _t.txtEditingMode; - break; - - case LoadingDocument: - title = _t.loadingDocumentTitleText; - text = _t.loadingDocumentTextText; - break; - default: - if (typeof action.id == 'string'){ - title = action.id; - text = action.id; - } - break; - } - - if (action.type === Asc.c_oAscAsyncActionType['BlockInteraction']) { - if (action.id === Asc.c_oAscAsyncAction['ApplyChanges']) { - return; - } - - if (this.loadMask && this.loadMask.el && this.loadMask.el.classList.contains('modal-in')) { - this.loadMask.el.getElementsByClassName('dialog-title')[0].innerHTML = title; - } else { - this.loadMask = f7.dialog.preloader(title); - } - } - - } - - onOpenDocument (progress) { - if (this.loadMask && this.loadMask.el) { - const $title = this.loadMask.el.getElementsByClassName('dialog-title')[0]; - const proc = (progress.asc_getCurrentFont() + progress.asc_getCurrentImage())/(progress.asc_getFontsCount() + progress.asc_getImagesCount()); - - $title.innerHTML = `${this._t.textLoadingDocument}: ${Math.min(Math.round(proc * 100), 100)}%`; - } - } - onProcessSaveResult (data) { this.api.asc_OnSaveEnd(data.result); @@ -722,7 +566,8 @@ class MainController extends Component { render() { return ( - + +