|
@@ -8,15 +8,7 @@ import AccountAuth from '../model/AccountAuth';
|
|
|
import PresetsManager from '../ctrl/PresetsManager';
|
|
|
import PubSub from 'pubsub-js';
|
|
|
import VectorDataManager from '../ctrl/VectorDataManager';
|
|
|
-import request from 'request-promise-native';
|
|
|
-
|
|
|
-
|
|
|
-/*
|
|
|
- * Global variables definition
|
|
|
- */
|
|
|
-window.EDITOR_URL = window.location.origin + window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/')) + "/";
|
|
|
-window.UNUSABLE_ICONS = new Set();
|
|
|
-
|
|
|
+// import request from 'request-promise-native';
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -24,23 +16,15 @@ window.UNUSABLE_ICONS = new Set();
|
|
|
* It creates mostly everything.
|
|
|
*/
|
|
|
export default class App {
|
|
|
- constructor(uuid) {
|
|
|
- this.uuid = uuid;
|
|
|
+ constructor(params) {
|
|
|
+ this.el = params.el
|
|
|
+ this.id = params.id
|
|
|
+ }
|
|
|
+
|
|
|
+ init() {
|
|
|
this._initI18n();
|
|
|
- this._initCtrl();
|
|
|
-
|
|
|
- // Dynamically load config file
|
|
|
- request(window.EDITOR_URL + "/config.json")
|
|
|
- .then(configTxt => {
|
|
|
- window.CONFIG = JSON.parse(configTxt);
|
|
|
- window.EDITOR_NAME = window.CONFIG.editor_name;
|
|
|
- this._initView();
|
|
|
- })
|
|
|
- .catch(e => {
|
|
|
- console.error(e);
|
|
|
- alert("Can't load configuration file, please report this issue.");
|
|
|
- });
|
|
|
-
|
|
|
+ this._initCtrl();
|
|
|
+ this._initView();
|
|
|
this._initAuth();
|
|
|
}
|
|
|
|
|
@@ -50,9 +34,9 @@ export default class App {
|
|
|
*/
|
|
|
_initI18n() {
|
|
|
let locale = null;
|
|
|
- if(window.navigator.languages) {
|
|
|
- for(const l of window.navigator.languages) {
|
|
|
- if(I18n.supportedLocales.includes(l)) {
|
|
|
+ if (window.navigator.languages) {
|
|
|
+ for (const l of window.navigator.languages) {
|
|
|
+ if (I18n.supportedLocales.includes(l)) {
|
|
|
locale = l;
|
|
|
break;
|
|
|
}
|
|
@@ -81,8 +65,8 @@ export default class App {
|
|
|
* @private
|
|
|
*/
|
|
|
_initView() {
|
|
|
- ReactDOM.render(<Body uuid={this.uuid}/>, document.getElementById('root'));
|
|
|
- document.title=window.EDITOR_NAME;
|
|
|
+ ReactDOM.render(<Body uuid={this.uuid} />, document.getElementById(this.el));
|
|
|
+ document.title = window.EDITOR_NAME;
|
|
|
|
|
|
// Disabling context menu
|
|
|
document.oncontextmenu = () => {
|
|
@@ -90,10 +74,6 @@ export default class App {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
- updateMarkerPosition(datas){
|
|
|
- PubSub.publish('body.data.update', datas);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Launches authentication process
|
|
|
* @private
|
|
@@ -151,10 +131,10 @@ export default class App {
|
|
|
// });
|
|
|
// }
|
|
|
console.log("index ", data);
|
|
|
- if(!window.editor_user_auth.authenticated()) {
|
|
|
+ if (!window.editor_user_auth.authenticated()) {
|
|
|
window.editor_user_auth.authenticate(data, (err, res) => {
|
|
|
console.log('index ok');
|
|
|
- if(err) {
|
|
|
+ if (err) {
|
|
|
console.error(err);
|
|
|
alert("哎呀!尝试登录时出错。");
|
|
|
PubSub.publish("app.user.logout");
|
|
@@ -174,7 +154,7 @@ export default class App {
|
|
|
* @memberof App
|
|
|
*/
|
|
|
PubSub.subscribe("app.user.logout", (msg, data) => {
|
|
|
- if(window.editor_user_auth && window.editor_user_auth.authenticated()) {
|
|
|
+ if (window.editor_user_auth && window.editor_user_auth.authenticated()) {
|
|
|
window.editor_user_auth.logout();
|
|
|
}
|
|
|
|
|
@@ -222,8 +202,8 @@ export default class App {
|
|
|
* @private
|
|
|
*/
|
|
|
_checkAuth(res) {
|
|
|
- if(window.editor_user_auth.authenticated()) {
|
|
|
- if(this.authWait) {
|
|
|
+ if (window.editor_user_auth.authenticated()) {
|
|
|
+ if (this.authWait) {
|
|
|
clearInterval(this.authWait);
|
|
|
}
|
|
|
|
|
@@ -253,7 +233,7 @@ export default class App {
|
|
|
|
|
|
localStorage.setItem("editor_token", res.user_token);
|
|
|
}
|
|
|
- catch(e) {
|
|
|
+ catch (e) {
|
|
|
console.error(e);
|
|
|
PubSub.publish("app.user.logout");
|
|
|
}
|
|
@@ -299,12 +279,12 @@ export default class App {
|
|
|
_readURLParams(str) {
|
|
|
const u = str.split('?');
|
|
|
|
|
|
- if(u.length > 1) {
|
|
|
+ if (u.length > 1) {
|
|
|
const p = u[1].split('#')[0];
|
|
|
|
|
|
return p.split('&').filter(function (pair) {
|
|
|
return pair !== '';
|
|
|
- }).reduce(function(obj, pair){
|
|
|
+ }).reduce(function (obj, pair) {
|
|
|
var parts = pair.split('=');
|
|
|
obj[decodeURIComponent(parts[0])] = (null === parts[1]) ?
|
|
|
'' : decodeURIComponent(parts[1]);
|