Plugins refactoring

This commit is contained in:
Julia Radzhabova 2019-05-21 13:02:55 +03:00
parent f827114731
commit 2d8059a61d
10 changed files with 180 additions and 74 deletions

View file

@ -105,27 +105,26 @@ define([
loadConfig: function(data) { loadConfig: function(data) {
var me = this; var me = this;
me.appOptions.lang = data.config.lang; me.configPlugins = data.config.plugins;
me.appOptions.plugins = data.config.plugins; me.editor = !!window.DE ? 'word' : !!window.PE ? 'slide' : 'cell';
me.appOptions.editor = !!window.DE ? 'word' : !!window.PE ? 'slide' : 'cell'; },
if ( me.appOptions.plugins ) { loadPlugins: function() {
me.plugins.autostart = me.appOptions.plugins.autostart; if (this.configPlugins && this.configPlugins.pluginsData && this.configPlugins.pluginsData.length>0)
me.getAppConfigPlugins(me.appOptions.plugins); this.getAppConfigPlugins(this.configPlugins, false);
} else
this.plugins.configpluginsdata = false;
var server_plugins_url = '../../../../plugins.json'; var server_plugins_url = '../../../../plugins.json',
me = this;
Common.Utils.loadConfig(server_plugins_url, function (obj) { Common.Utils.loadConfig(server_plugins_url, function (obj) {
if ( obj != 'error' ) { if ( obj != 'error' ) {
me.plugins.autostart = _.union(me.plugins.autostart, obj.autostart);
me.getServerPlugins(obj); me.getServerPlugins(obj);
} }
}); });
}, },
onAppShowed: function (config) { onAppShowed: function (config) {
this.appOptions.isEdit = config.isEdit;
// this.appOptions.canPlugins = config.canPlugins;
}, },
setApi: function(api) { setApi: function(api) {
@ -137,28 +136,30 @@ define([
this.api.asc_registerCallback("asc_onPluginMouseUp", _.bind(this.onPluginMouseUp, this)); this.api.asc_registerCallback("asc_onPluginMouseUp", _.bind(this.onPluginMouseUp, this));
this.api.asc_registerCallback("asc_onPluginMouseMove", _.bind(this.onPluginMouseMove, this)); this.api.asc_registerCallback("asc_onPluginMouseMove", _.bind(this.onPluginMouseMove, this));
this.api.asc_registerCallback('asc_onPluginsReset', _.bind(this.resetPluginsList, this)); this.api.asc_registerCallback('asc_onPluginsReset', _.bind(this.resetPluginsList, this));
// this.api.asc_registerCallback('asc_onPluginsInit', _.bind(me.updatePluginsList, me)); this.api.asc_registerCallback('asc_onPluginsInit', _.bind(this.parsePlugins, this));
/** /**
* sometime plugins info from server can be received after * sometime plugins info from server can be received after
* AppShowed event, so try to parse info there * AppShowed event, so try to parse info there
**/ **/
if ( this.plugins.serverpluginsdata == undefined ) { // if ( this.plugins.serverpluginsdata == undefined ) {
console.log('set api: plugins data from server is late') // console.log('set api: plugins data from server is late')
} else // } else
if ( this.plugins.serverpluginsdata === false ) { // if ( this.plugins.serverpluginsdata === false ) {
console.log('set api: error for plugins data from server'); // console.log('set api: error for plugins data from server');
} else { // } else {
this.parsePlugins(this.plugins.serverpluginsdata); // this.parsePlugins(this.plugins.serverpluginsdata);
} // }
if ( this.appOptions.canPlugins )
this.refreshPluginsList();
this.loadPlugins();
return this; return this;
}, },
setMode: function(mode) { setMode: function(mode) {
this.appOptions = mode;
this.customPluginsComplete = !this.appOptions.canBrandingExt;
if (this.appOptions.canBrandingExt)
this.getAppCustomPlugins(this.configPlugins);
return this; return this;
}, },
@ -462,18 +463,20 @@ define([
applyUICustomization: function () { applyUICustomization: function () {
var me = this; var me = this;
if ( me.plugins.uicustom ) { if ( me.customPluginsComplete && me.plugins.uicustom ) {
me.plugins.uicustom.forEach(function (c) { me.plugins.uicustom.forEach(function (c) {
if ( c.code ) eval(c.code); if ( c.code ) eval(c.code);
}); });
return true;
} }
return false;
}, },
parsePlugins: function(pluginsdata, silent/*, uiCustomize*/) { parsePlugins: function(pluginsdata, uiCustomize) {
var me = this; var me = this;
var pluginStore = this.getApplication().getCollection('Common.Collections.Plugins'), var pluginStore = this.getApplication().getCollection('Common.Collections.Plugins'),
isEdit = me.appOptions.isEdit, isEdit = me.appOptions.isEdit,
editor = me.appOptions.editor; editor = me.editor;
if ( pluginsdata instanceof Array ) { if ( pluginsdata instanceof Array ) {
var arr = [], arrUI = [], var arr = [], arrUI = [],
lang = me.appOptions.lang.split(/[\-_]/)[0]; lang = me.appOptions.lang.split(/[\-_]/)[0];
@ -539,12 +542,10 @@ define([
} }
}); });
// if ( uiCustomize!==false ) // from ui customizer in editor config or desktop event if ( uiCustomize!==false ) // from ui customizer in editor config or desktop event
// this.UICustomizePlugins = arrUI; me.plugins.uicustom = arrUI;
if ( arrUI.length )
me.plugins.uicustom = _.union(me.plugins.uicustom, arrUI);
// if ( !uiCustomize && pluginStore) if ( !uiCustomize && pluginStore)
{ {
arr = pluginStore.models.concat(arr); arr = pluginStore.models.concat(arr);
arr.sort(function(a, b){ arr.sort(function(a, b){
@ -556,20 +557,21 @@ define([
return (rank_b==0) ? -1 : 1; return (rank_b==0) ? -1 : 1;
return 0; return 0;
}); });
pluginStore.reset(arr, {silent: !!silent}); pluginStore.reset(arr);
// this.appOptions.canPlugins = !pluginStore.isEmpty(); this.appOptions.canPlugins = !pluginStore.isEmpty();
} }
} }
// else if (!uiCustomize){ else if (!uiCustomize){
// this.appOptions.canPlugins = false; this.appOptions.canPlugins = false;
// } }
// if (!uiCustomize) if (!uiCustomize)
// this.getApplication().getController('LeftMenu').enablePlugins(); this.getApplication().getController('LeftMenu').enablePlugins();
// if (this.appOptions.canPlugins) { if (this.appOptions.canPlugins) {
// this.getApplication().getController('Common.Controllers.Plugins').setMode(this.appOptions).runAutoStartPlugins(plugins.autostart); this.refreshPluginsList();
// } this.runAutoStartPlugins();
}
}, },
getServerPlugins: function (config) { getServerPlugins: function (config) {
@ -586,6 +588,26 @@ define([
})).then(function(values) { })).then(function(values) {
me.plugins.serverpluginsdata = values; me.plugins.serverpluginsdata = values;
// console.log('server plugins data received'); // console.log('server plugins data received');
var autostart = [];
if (values.length>0) {
var val = config.autostart || config.autoStartGuid;
if (typeof (val) == 'string')
val = [val];
config.autoStartGuid && console.warn("Obsolete: The autoStartGuid parameter is deprecated. Please check the documentation for new plugin connection configuration.");
autostart = val || [];
}
if (me.plugins.configpluginsdata === undefined) {
// loading config plugins
me.plugins.autostart = autostart;
} else if (me.plugins.configpluginsdata===false) {
//load only server plugins
me.plugins.autostart = autostart;
me.parsePlugins(me.plugins.serverpluginsdata, false);
} else {
me.plugins.autostart = me.plugins.autostart.concat(autostart);
me.parsePlugins((me.plugins.configpluginsdata ? me.plugins.configpluginsdata : []).concat(me.plugins.serverpluginsdata ? me.plugins.serverpluginsdata : []), false);
}
}).catch(function(e) { }).catch(function(e) {
me.plugins.serverpluginsdata = false; me.plugins.serverpluginsdata = false;
console.log('getServerPlugins error: ' + e.message); console.log('getServerPlugins error: ' + e.message);
@ -593,11 +615,55 @@ define([
}, },
getAppConfigPlugins: function (config) { getAppConfigPlugins: function (config) {
if ( config.UIpluginsData ) { var me = this;
Promise.all(config.pluginsData.map(function(url) {
return fetch(url)
.then(function(response) {
if ( response.ok ) return response.json();
else return 'error';
}).then(function(json) {
json.baseUrl = url.substring(0, url.lastIndexOf("config.json"));
return json;
});
})).then(function(values) {
me.plugins.configpluginsdata = values;
var autostart = [];
if (values.length>0) {
var val = config.autostart || config.autoStartGuid;
if (typeof (val) == 'string')
val = [val];
config.autoStartGuid && console.warn("Obsolete: The autoStartGuid parameter is deprecated. Please check the documentation for new plugin connection configuration.");
autostart = val || [];
}
// console.log('config plugins data received');
if (me.plugins.serverpluginsdata === undefined) {
// loading server plugins
me.plugins.autostart = autostart;
} else if (me.plugins.serverpluginsdata===false) {
//load only config plugins
me.plugins.autostart = autostart;
me.parsePlugins(me.plugins.configpluginsdata, false);
} else {
me.plugins.autostart = autostart.concat(me.plugins.autostart);
me.parsePlugins((me.plugins.configpluginsdata ? me.plugins.configpluginsdata : []).concat(me.plugins.serverpluginsdata ? me.plugins.serverpluginsdata : []), false);
}
}).catch(function(e) {
me.plugins.configpluginsdata = false;
console.log('getServerPlugins error: ' + e.message);
});
},
getAppCustomPlugins: function (config) {
if ( config && config.UIpluginsData ) {
var me = this; var me = this;
Promise.all(config.UIpluginsData.map(function(url) { Promise.all(config.UIpluginsData.map(function(url) {
return fetch(url) return fetch(url)
.then(function(response) {return response.json();}) .then(function(response) {
// console.log('1: ' + response);
return response.json();
})
.then(function(json) { .then(function(json) {
json.baseUrl = url.substring(0, url.lastIndexOf("config.json")); json.baseUrl = url.substring(0, url.lastIndexOf("config.json"));
return json; return json;
@ -606,17 +672,31 @@ define([
me.parsePlugins(values, true); me.parsePlugins(values, true);
if ( me.plugins.uicustom ) { if ( me.plugins.uicustom ) {
me.plugins.uicustom.forEach(function (c) { Promise.all(me.plugins.uicustom.map(function(c) {
fetch(c.url) return fetch(c.url)
.then(function (response) {return response.text();}) .then(function(response) {
.then(function (text) {c.code = text;}); // console.log('2: ' + response);
return response.text();
})
.then(function(text) {
// console.log('3: ' + text);
c.code = text;
return text;
});
})).then(function(values) {
me.customPluginsComplete = true;
}).catch(function(e) {
console.log('error: ' + e.message);
me.customPluginsComplete = true;
}); });
} }
}).catch(function(e) { }).catch(function(e) {
console.log('error: ' + e.message); console.log('error: ' + e.message);
me.customPluginsComplete = true;
}); });
} } else
}, this.customPluginsComplete = true;
}
}, Common.Controllers.Plugins || {})); }, Common.Controllers.Plugins || {}));
}); });

View file

@ -953,9 +953,9 @@ define([
application.getController('Common.Controllers.ExternalMergeEditor').setApi(this.api).loadConfig({config:this.editorConfig, customization: this.editorConfig.customization}); application.getController('Common.Controllers.ExternalMergeEditor').setApi(this.api).loadConfig({config:this.editorConfig, customization: this.editorConfig.customization});
pluginsController.setApi(me.api); pluginsController.setApi(me.api);
if ( (me.appOptions.canPlugins = pluginsController.appOptions.canPlugins) ) // if ( (me.appOptions.canPlugins = pluginsController.appOptions.canPlugins) )
pluginsController.runAutoStartPlugins(); // pluginsController.runAutoStartPlugins();
leftmenuController.enablePlugins(); // leftmenuController.enablePlugins();
documentHolderController.setApi(me.api); documentHolderController.setApi(me.api);
documentHolderController.createDelayedElements(); documentHolderController.createDelayedElements();
@ -1186,6 +1186,7 @@ define([
this.appOptions.canRename && appHeader.setCanRename(true); this.appOptions.canRename && appHeader.setCanRename(true);
this.appOptions.canBrandingExt = params.asc_getCanBranding() && (typeof this.editorConfig.customization == 'object' || this.editorConfig.plugins); this.appOptions.canBrandingExt = params.asc_getCanBranding() && (typeof this.editorConfig.customization == 'object' || this.editorConfig.plugins);
this.getApplication().getController('Common.Controllers.Plugins').setMode(this.appOptions);
this.applyModeCommonElements(); this.applyModeCommonElements();
this.applyModeEditorElements(); this.applyModeEditorElements();
@ -1661,6 +1662,7 @@ define([
}, },
hidePreloader: function() { hidePreloader: function() {
var UICustomizationComplete = true;
if (!this._state.customizationDone) { if (!this._state.customizationDone) {
this._state.customizationDone = true; this._state.customizationDone = true;
if (this.appOptions.customization) { if (this.appOptions.customization) {
@ -1672,14 +1674,21 @@ define([
Common.Utils.applyCustomization(this.appOptions.customization, mapCustomizationElements); Common.Utils.applyCustomization(this.appOptions.customization, mapCustomizationElements);
if (this.appOptions.canBrandingExt) { if (this.appOptions.canBrandingExt) {
Common.Utils.applyCustomization(this.appOptions.customization, mapCustomizationExtElements); Common.Utils.applyCustomization(this.appOptions.customization, mapCustomizationExtElements);
this.getApplication().getController('Common.Controllers.Plugins').applyUICustomization(); UICustomizationComplete = this.getApplication().getController('Common.Controllers.Plugins').applyUICustomization();
} }
} }
Common.NotificationCenter.trigger('layout:changed', 'main'); Common.NotificationCenter.trigger('layout:changed', 'main');
$('#loading-mask').hide().remove();
Common.Controllers.Desktop.process('preloader:hide'); var me = this;
var timer_sl = setInterval(function() {
(!UICustomizationComplete) && (UICustomizationComplete = me.getApplication().getController('Common.Controllers.Plugins').applyUICustomization());
if (UICustomizationComplete) {
clearInterval(timer_sl);
$('#loading-mask').hide().remove();
Common.Controllers.Desktop.process('preloader:hide');
}
}, 10);
}, },
onDownloadUrl: function(url) { onDownloadUrl: function(url) {

View file

@ -19,7 +19,7 @@
overflow: hidden; overflow: hidden;
border: none; border: none;
background-color: #f4f4f4; background-color: #f4f4f4;
z-index: 100; z-index: 10000;
} }
.loader-page { .loader-page {

View file

@ -20,7 +20,7 @@
overflow: hidden; overflow: hidden;
border: none; border: none;
background-color: #f4f4f4; background-color: #f4f4f4;
z-index: 100; z-index: 10000;
} }
.loader-page { .loader-page {

View file

@ -704,9 +704,9 @@ define([
application.getController('Common.Controllers.ExternalDiagramEditor').setApi(this.api).loadConfig({config:this.editorConfig, customization: this.editorConfig.customization}); application.getController('Common.Controllers.ExternalDiagramEditor').setApi(this.api).loadConfig({config:this.editorConfig, customization: this.editorConfig.customization});
pluginsController.setApi(me.api); pluginsController.setApi(me.api);
if ( (me.appOptions.canPlugins = pluginsController.appOptions.canPlugins) ) // if ( (me.appOptions.canPlugins = pluginsController.appOptions.canPlugins) )
pluginsController.runAutoStartPlugins(); // pluginsController.runAutoStartPlugins();
leftmenuController.enablePlugins(); // leftmenuController.enablePlugins();
documentHolderController.setApi(me.api); documentHolderController.setApi(me.api);
documentHolderController.createDelayedElements(); documentHolderController.createDelayedElements();
@ -917,6 +917,7 @@ define([
this.appOptions.canRename && appHeader.setCanRename(true); this.appOptions.canRename && appHeader.setCanRename(true);
this.appOptions.canBrandingExt = params.asc_getCanBranding() && (typeof this.editorConfig.customization == 'object' || this.editorConfig.plugins); this.appOptions.canBrandingExt = params.asc_getCanBranding() && (typeof this.editorConfig.customization == 'object' || this.editorConfig.plugins);
this.getApplication().getController('Common.Controllers.Plugins').setMode(this.appOptions);
this.applyModeCommonElements(); this.applyModeCommonElements();
this.applyModeEditorElements(); this.applyModeEditorElements();
@ -1386,6 +1387,7 @@ define([
}, },
hidePreloader: function() { hidePreloader: function() {
var UICustomizationComplete = true;
if (!this._state.customizationDone) { if (!this._state.customizationDone) {
this._state.customizationDone = true; this._state.customizationDone = true;
if (this.appOptions.customization) { if (this.appOptions.customization) {
@ -1397,14 +1399,21 @@ define([
Common.Utils.applyCustomization(this.appOptions.customization, mapCustomizationElements); Common.Utils.applyCustomization(this.appOptions.customization, mapCustomizationElements);
if (this.appOptions.canBrandingExt) { if (this.appOptions.canBrandingExt) {
Common.Utils.applyCustomization(this.appOptions.customization, mapCustomizationExtElements); Common.Utils.applyCustomization(this.appOptions.customization, mapCustomizationExtElements);
this.getApplication().getController('Common.Controllers.Plugins').applyUICustomization(); UICustomizationComplete = this.getApplication().getController('Common.Controllers.Plugins').applyUICustomization();
} }
} }
Common.NotificationCenter.trigger('layout:changed', 'main'); Common.NotificationCenter.trigger('layout:changed', 'main');
$('#loading-mask').hide().remove();
Common.Controllers.Desktop.process('preloader:hide'); var me = this;
var timer_sl = setInterval(function() {
(!UICustomizationComplete) && (UICustomizationComplete = me.getApplication().getController('Common.Controllers.Plugins').applyUICustomization());
if (UICustomizationComplete) {
clearInterval(timer_sl);
$('#loading-mask').hide().remove();
Common.Controllers.Desktop.process('preloader:hide');
}
}, 10);
}, },
onDownloadUrl: function(url) { onDownloadUrl: function(url) {

View file

@ -18,7 +18,7 @@
overflow: hidden; overflow: hidden;
border: none; border: none;
background-color: #f4f4f4; background-color: #f4f4f4;
z-index: 100; z-index: 10000;
} }
.loader-page { .loader-page {

View file

@ -20,7 +20,7 @@
overflow: hidden; overflow: hidden;
border: none; border: none;
background-color: #f4f4f4; background-color: #f4f4f4;
z-index: 100; z-index: 10000;
} }
.loader-page { .loader-page {

View file

@ -682,9 +682,9 @@ define([
if (!me.appOptions.isEditMailMerge && !me.appOptions.isEditDiagram) { if (!me.appOptions.isEditMailMerge && !me.appOptions.isEditDiagram) {
pluginsController.setApi(me.api); pluginsController.setApi(me.api);
if ( (me.appOptions.canPlugins = pluginsController.appOptions.canPlugins) ) // if ( (me.appOptions.canPlugins = pluginsController.appOptions.canPlugins) )
pluginsController.runAutoStartPlugins(); // pluginsController.runAutoStartPlugins();
leftmenuController.enablePlugins(); // leftmenuController.enablePlugins();
} }
leftMenuView.disableMenu('all',false); leftMenuView.disableMenu('all',false);
@ -941,6 +941,7 @@ define([
if (!this.appOptions.isEditDiagram && !this.appOptions.isEditMailMerge) { if (!this.appOptions.isEditDiagram && !this.appOptions.isEditMailMerge) {
this.appOptions.canBrandingExt = params.asc_getCanBranding() && (typeof this.editorConfig.customization == 'object' || this.editorConfig.plugins); this.appOptions.canBrandingExt = params.asc_getCanBranding() && (typeof this.editorConfig.customization == 'object' || this.editorConfig.plugins);
this.getApplication().getController('Common.Controllers.Plugins').setMode(this.appOptions);
} }
this.applyModeCommonElements(); this.applyModeCommonElements();
@ -1519,6 +1520,7 @@ define([
}, },
hidePreloader: function() { hidePreloader: function() {
var UICustomizationComplete = true;
if (!this._state.customizationDone) { if (!this._state.customizationDone) {
this._state.customizationDone = true; this._state.customizationDone = true;
if (this.appOptions.customization) { if (this.appOptions.customization) {
@ -1530,15 +1532,21 @@ define([
Common.Utils.applyCustomization(this.appOptions.customization, mapCustomizationElements); Common.Utils.applyCustomization(this.appOptions.customization, mapCustomizationElements);
if (this.appOptions.canBrandingExt) { if (this.appOptions.canBrandingExt) {
Common.Utils.applyCustomization(this.appOptions.customization, mapCustomizationExtElements); Common.Utils.applyCustomization(this.appOptions.customization, mapCustomizationExtElements);
this.getApplication().getController('Common.Controllers.Plugins').applyUICustomization(); UICustomizationComplete = this.getApplication().getController('Common.Controllers.Plugins').applyUICustomization();
} }
} }
this.stackLongActions.pop({id: InitApplication, type: Asc.c_oAscAsyncActionType.BlockInteraction}); this.stackLongActions.pop({id: InitApplication, type: Asc.c_oAscAsyncActionType.BlockInteraction});
Common.NotificationCenter.trigger('layout:changed', 'main'); Common.NotificationCenter.trigger('layout:changed', 'main');
$('#loading-mask').hide().remove(); var me = this;
var timer_sl = setInterval(function() {
Common.Controllers.Desktop.process('preloader:hide'); (!UICustomizationComplete) && (UICustomizationComplete = me.getApplication().getController('Common.Controllers.Plugins').applyUICustomization());
if (UICustomizationComplete) {
clearInterval(timer_sl);
$('#loading-mask').hide().remove();
Common.Controllers.Desktop.process('preloader:hide');
}
}, 10);
}, },
onDownloadUrl: function(url) { onDownloadUrl: function(url) {

View file

@ -17,7 +17,7 @@
overflow: hidden; overflow: hidden;
border: none; border: none;
background-color: #f4f4f4; background-color: #f4f4f4;
z-index: 100; z-index: 10000;
} }
.loader-page { .loader-page {

View file

@ -19,7 +19,7 @@
overflow: hidden; overflow: hidden;
border: none; border: none;
background-color: #f4f4f4; background-color: #f4f4f4;
z-index: 100; z-index: 10000;
} }
.loader-page { .loader-page {