[DE mobile] Long action handler moved to a separate controller

This commit is contained in:
JuliaSvinareva 2021-04-08 21:00:44 +03:00
parent 2ea2d5238e
commit 904e9baf05
4 changed files with 251 additions and 199 deletions

View file

@ -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.", "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", "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.", "errorProcessSaveResult": "Saving is failed.",
"criticalErrorTitle": "Error", "criticalErrorTitle": "Error",
"warnProcessRightsChange": "You have been denied the right to edit the file.", "warnProcessRightsChange": "You have been denied the right to edit the file.",
@ -123,6 +89,41 @@
"criticalErrorExtText": "Press 'OK' to back to document list.", "criticalErrorExtText": "Press 'OK' to back to document list.",
"notcriticalErrorTitle": "Warning" "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": { "Toolbar": {
"dlgLeaveTitleText": "You leave the application", "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.", "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.",

View file

@ -2,8 +2,9 @@ import React, { useEffect, useState } from 'react';
import { inject } from 'mobx-react'; import { inject } from 'mobx-react';
import { f7 } from 'framework7-react'; import { f7 } from 'framework7-react';
import { useTranslation } from 'react-i18next'; 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} = useTranslation();
const _t = t("Error", { returnObjects: true }); const _t = t("Error", { returnObjects: true });
@ -27,8 +28,8 @@ const ErrorController = inject('storeAppOptions')(({storeAppOptions}) => {
return; return;
} }
//this.hidePreloader(); Common.Notifications.trigger('preloader:close');
//this.onLongActionEnd(Asc.c_oAscAsyncActionType['BlockInteraction'], LoadingDocument); Common.Notifications.trigger('preloader:endAction', Asc.c_oAscAsyncActionType['BlockInteraction'], LoadingDocument);
const api = Common.EditorApi.get(); const api = Common.EditorApi.get();

View file

@ -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;

View file

@ -4,7 +4,6 @@ import {inject} from "mobx-react";
import { f7 } from "framework7-react"; import { f7 } from "framework7-react";
import { withTranslation } from 'react-i18next'; import { withTranslation } from 'react-i18next';
import { LocalStorage } from '../../../../common/mobile/utils/LocalStorage'; 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 CollaborationController from '../../../../common/mobile/lib/controller/collaboration/Collaboration.jsx';
import {InitReviewController as ReviewController} from '../../../../common/mobile/lib/controller/collaboration/Review.jsx'; import {InitReviewController as ReviewController} from '../../../../common/mobile/lib/controller/collaboration/Review.jsx';
import { onAdvancedOptions } from './settings/Download.jsx'; import { onAdvancedOptions } from './settings/Download.jsx';
@ -17,6 +16,7 @@ import {
import About from '../../../../common/mobile/lib/view/About'; import About from '../../../../common/mobile/lib/view/About';
import EditorUIController from '../lib/patch'; import EditorUIController from '../lib/patch';
import ErrorController from "./Error"; import ErrorController from "./Error";
import LongActionsController from "./LongActions";
@inject( @inject(
"storeAppOptions", "storeAppOptions",
@ -33,20 +33,15 @@ class MainController extends Component {
super(props); super(props);
window.editorType = 'de'; window.editorType = 'de';
this.LoadingDocument = -256;
this._state = { this._state = {
licenseType: false, licenseType: false,
isFromGatewayDownloadAs: 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; const { t } = this.props;
this._t = t('Main', {returnObjects:true}); this._t = t('Main', {returnObjects:true});
this.LoadingDocument = -256;
} }
initSdk() { initSdk() {
@ -192,8 +187,8 @@ class MainController extends Component {
this._isDocReady = true; this._isDocReady = true;
f7.dialog.close(this.loadMask.el); Common.Notifications.trigger('preloader:close');
this.onLongActionEnd(Asc.c_oAscAsyncActionType['BlockInteraction'], this.LoadingDocument); Common.Notifications.trigger('preloader:endAction', Asc.c_oAscAsyncActionType['BlockInteraction'], this.LoadingDocument);
Common.Gateway.on('processsaveresult', this.onProcessSaveResult.bind(this)); Common.Gateway.on('processsaveresult', this.onProcessSaveResult.bind(this));
Common.Gateway.on('processrightschange', this.onProcessRightsChange.bind(this)); Common.Gateway.on('processrightschange', this.onProcessRightsChange.bind(this));
@ -406,10 +401,6 @@ class MainController extends Component {
} }
bindEvents() { 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) => { this.api.asc_registerCallback('asc_onSendThemeColors', (colors, standart_colors) => {
Common.Utils.ThemeColor.setColors(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) { onProcessSaveResult (data) {
this.api.asc_OnSaveEnd(data.result); this.api.asc_OnSaveEnd(data.result);
@ -722,7 +566,8 @@ class MainController extends Component {
render() { render() {
return ( return (
<Fragment> <Fragment>
<ErrorController /> <LongActionsController />
<ErrorController LoadingDocument={this.LoadingDocument}/>
<CollaborationController /> <CollaborationController />
<ReviewController /> <ReviewController />
<CommentsController /> <CommentsController />