[DE mobile] Make main controller

This commit is contained in:
JuliaSvinareva 2021-04-09 21:08:13 +03:00
parent 904e9baf05
commit 8d6ea8f464
4 changed files with 111 additions and 7 deletions

View file

@ -49,7 +49,10 @@
"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.",
"errorAccessDeny": "You are trying to perform an action you do not have rights for.<br>Please contact your Document Server administrator." "errorAccessDeny": "You are trying to perform an action you do not have rights for.<br>Please contact your Document Server administrator.",
"errorUpdateVersion": "The file version has been changed. The page will be reloaded.",
"titleUpdateVersion": "Version changed"
}, },
"Error": { "Error": {
"criticalErrorTitle": "Error", "criticalErrorTitle": "Error",

View file

@ -32,6 +32,7 @@ class LongActions extends Component {
api.asc_registerCallback('asc_onOpenDocumentProgress', this.onOpenDocument); api.asc_registerCallback('asc_onOpenDocumentProgress', this.onOpenDocument);
}); });
Common.Notifications.on('preloader:endAction', this.onLongActionEnd); Common.Notifications.on('preloader:endAction', this.onLongActionEnd);
Common.Notifications.on('preloader:beginAction', this.onLongActionBegin);
Common.Notifications.on('preloader:close', this.closePreloader); Common.Notifications.on('preloader:close', this.closePreloader);
} }
@ -42,6 +43,7 @@ class LongActions extends Component {
api.asc_unregisterCallback('asc_onOpenDocumentProgress', this.onOpenDocument); api.asc_unregisterCallback('asc_onOpenDocumentProgress', this.onOpenDocument);
Common.Notifications.off('preloader:endAction', this.onLongActionEnd); Common.Notifications.off('preloader:endAction', this.onLongActionEnd);
Common.Notifications.off('preloader:beginAction', this.onLongActionBegin);
Common.Notifications.off('preloader:close', this.closePreloader); Common.Notifications.off('preloader:close', this.closePreloader);
} }

View file

@ -37,9 +37,12 @@ class MainController extends Component {
this._state = { this._state = {
licenseType: false, licenseType: false,
isFromGatewayDownloadAs: false isFromGatewayDownloadAs: false,
isDocModified: false
}; };
this.defaultTitleText = __APP_TITLE_TEXT__;
const { t } = this.props; const { t } = this.props;
this._t = t('Main', {returnObjects:true}); this._t = t('Main', {returnObjects:true});
} }
@ -178,6 +181,10 @@ class MainController extends Component {
}; };
const onDocumentContentReady = () => { const onDocumentContentReady = () => {
if (this.props.storeAppOptions.isEdit && this.needToUpdateVersion) {
Common.Notifications.trigger('api:disconnect');
}
this.applyLicense(); this.applyLicense();
Common.Gateway.documentReady(); Common.Gateway.documentReady();
@ -221,11 +228,24 @@ class MainController extends Component {
Common.Notifications.trigger('engineCreated', this.api); Common.Notifications.trigger('engineCreated', this.api);
Common.EditorApi = {get: () => this.api}; Common.EditorApi = {get: () => this.api};
// Set font rendering mode
let value = LocalStorage.getItem("de-settings-fontrender");
if (value === null) {
value = window.devicePixelRatio > 1 ? '1' : '0';
}
switch (value) {
case '0': this.api.SetFontRenderingMode(3); break;
case '1': this.api.SetFontRenderingMode(1); break;
case '2': this.api.SetFontRenderingMode(2); break;
}
Common.Utils.Metric.setCurrentMetric(1); //pt
this.appOptions = {}; this.appOptions = {};
this.bindEvents(); this.bindEvents();
Common.Gateway.on('init', loadConfig); Common.Gateway.on('init', loadConfig);
// Common.Gateway.on('showmessage', _.bind(me.onExternalMessage, me)); Common.Gateway.on('showmessage', this.onExternalMessage.bind(this));
Common.Gateway.on('opendocument', loadDocument); Common.Gateway.on('opendocument', loadDocument);
Common.Gateway.appReady(); Common.Gateway.appReady();
}, error => { }, error => {
@ -401,6 +421,11 @@ class MainController extends Component {
} }
bindEvents() { bindEvents() {
this.api.asc_registerCallback('asc_onDocumentUpdateVersion', this.onUpdateVersion.bind(this));
this.api.asc_registerCallback('asc_onServerVersion', this.onServerVersion.bind(this));
this.api.asc_registerCallback('asc_onDocumentName', this.onDocumentName.bind(this));
this.api.asc_registerCallback('asc_onPrintUrl', this.onPrintUrl.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);
}); });
@ -485,10 +510,6 @@ class MainController extends Component {
storeDocumentInfo.switchIsLoaded(true); storeDocumentInfo.switchIsLoaded(true);
}); });
this.api.asc_registerCallback('asc_onDocumentName', (name) => {
// console.log(name);
});
// Color Schemes // Color Schemes
this.api.asc_registerCallback('asc_onSendThemeColorSchemes', (arr) => { this.api.asc_registerCallback('asc_onSendThemeColorSchemes', (arr) => {
@ -563,6 +584,83 @@ class MainController extends Component {
Common.Gateway.requestClose(); Common.Gateway.requestClose();
} }
onUpdateVersion (callback) {
const _t = this._t;
this.needToUpdateVersion = true;
Common.Notifications.trigger('preloader:endAction', Asc.c_oAscAsyncActionType['BlockInteraction'], this.LoadingDocument);
f7.dialog.alert(
_t.errorUpdateVersion,
_t.titleUpdateVersion,
() => {
Common.Gateway.updateVersion();
if (callback) {
callback.call(this);
}
Common.Notifications.trigger('preloader:beginAction', Asc.c_oAscAsyncActionType['BlockInteraction'], this.LoadingDocument);
});
}
onDocumentName () {
this.updateWindowTitle(true);
}
updateWindowTitle (force) {
const isModified = this.api.isDocumentModified();
if (this._state.isDocModified !== isModified || force) {
const title = this.defaultTitleText;
if (window.document.title != title) {
window.document.title = title;
}
this._isDocReady && (this._state.isDocModified !== isModified) && Common.Gateway.setDocumentModified(isModified);
this._state.isDocModified = isModified;
}
}
onPrintUrl (url) {
if (this.iframePrint) {
this.iframePrint.parentNode.removeChild(this.iframePrint);
this.iframePrint = null;
}
if (!this.iframePrint) {
this.iframePrint = document.createElement("iframe");
this.iframePrint.id = "id-print-frame";
this.iframePrint.style.display = 'none';
this.iframePrint.style.visibility = "hidden";
this.iframePrint.style.position = "fixed";
this.iframePrint.style.right = "0";
this.iframePrint.style.bottom = "0";
document.body.appendChild(this.iframePrint);
this.iframePrint.onload = function() {
this.iframePrint.contentWindow.focus();
this.iframePrint.contentWindow.print();
this.iframePrint.contentWindow.blur();
window.focus();
};
}
if (url) {
this.iframePrint.src = url;
}
}
onExternalMessage (msg) {
if (msg && msg.msg) {
msg.msg = (msg.msg).toString();
f7.notification.create({
//title: uiApp.params.modalTitle,
text: [msg.msg.charAt(0).toUpperCase() + msg.msg.substring(1)],
closeButton: true
}).open();
Common.component.Analytics.trackEvent('External Error');
}
}
render() { render() {
return ( return (
<Fragment> <Fragment>

View file

@ -164,6 +164,7 @@ module.exports = {
__PUBLISHER_PHONE__: JSON.stringify('+371 633-99867'), __PUBLISHER_PHONE__: JSON.stringify('+371 633-99867'),
__PUBLISHER_URL__: JSON.stringify('https://www.onlyoffice.com'), __PUBLISHER_URL__: JSON.stringify('https://www.onlyoffice.com'),
__PUBLISHER_NAME__: JSON.stringify('Ascensio System SIA'), __PUBLISHER_NAME__: JSON.stringify('Ascensio System SIA'),
__APP_TITLE_TEXT__: JSON.stringify(process.env.APP_TITLE_TEXT ? process.env.APP_TITLE_TEXT : 'ONLYOFFICE')
}), }),
...(env === 'production' ? [ ...(env === 'production' ? [