diff --git a/js/apps/system/_admin/aardvark/APP/frontend/js/routers/router.js b/js/apps/system/_admin/aardvark/APP/frontend/js/routers/router.js index d4617b9f13f1..d358f0383cc3 100644 --- a/js/apps/system/_admin/aardvark/APP/frontend/js/routers/router.js +++ b/js/apps/system/_admin/aardvark/APP/frontend/js/routers/router.js @@ -75,9 +75,9 @@ if (this.lastRoute) { // service replace logic - var replaceUrlFirst = this.lastRoute.split('/')[0]; - var replaceUrlSecond = this.lastRoute.split('/')[1]; - var replaceUrlThird = this.lastRoute.split('/')[2]; + const replaceUrlFirst = this.lastRoute.split('/')[0]; + const replaceUrlSecond = this.lastRoute.split('/')[1]; + const replaceUrlThird = this.lastRoute.split('/')[2]; if (replaceUrlFirst !== '#service') { if (window.App.replaceApp) { if (replaceUrlSecond !== 'install' && replaceUrlThird) { @@ -152,13 +152,13 @@ }, checkUser: function () { - var self = this; + const self = this; if (window.location.hash === '#login') { return; } - var startInit = function () { + const startInit = function () { this.initOnce(); // show hidden by default divs @@ -166,7 +166,7 @@ $('.navbar').show(); }.bind(this); - var callback = function (error, user) { + const callback = function (error, user) { if (frontendConfig.authenticationEnabled) { self.currentUser = user; if (error || user === null) { @@ -192,39 +192,17 @@ } }, - waitForInit: function (origin, param1, param2) { - if (!this.initFinished) { - setTimeout(function () { - if (!param1) { - origin(false); - } - if (param1 && !param2) { - origin(param1, false); - } - if (param1 && param2) { - origin(param1, param2, false); - } - }, 350); - } else { - if (!param1) { - origin(true); - } - if (param1 && !param2) { - origin(param1, true); - } - if (param1 && param2) { - origin(param1, param2, true); - } - } - }, + initialize: function () { + const self = this; - initFinished: false, + this.init = new Promise((resolve, reject) => { + self.initSucceeded = resolve; + self.initFailed = reject; + }); - initialize: function () { // check frontend config for global conf settings - if (frontendConfig.isCluster === true) { - this.isCluster = true; - } + this.isCluster = frontendConfig.isCluster; + if (typeof frontendConfig.foxxApiEnabled === 'boolean') { this.foxxApiEnabled = frontendConfig.foxxApiEnabled; } @@ -254,15 +232,10 @@ window.progressView = new window.ProgressView(); - var self = this; - this.userCollection = new window.ArangoUsers(); - this.initOnce = function () { - this.initOnce = function () {}; - - var callback = function (error, isCoordinator) { - self = this; + this.initOnce = _.once(function () { + const callback = function (error, isCoordinator) { if (isCoordinator === true) { self.coordinatorCollection.fetch({ success: function () { @@ -273,12 +246,12 @@ if (error) { console.log(error); } - }.bind(this); + }; window.isCoordinator(callback); if (frontendConfig.isCluster === false) { - this.initFinished = true; + this.initSucceeded(true); } this.arangoDatabase = new window.ArangoDatabase(); @@ -340,256 +313,228 @@ }); arangoHelper.initSigma(); - }.bind(this); + }).bind(this); - $(window).resize(function () { + $(window).on('resize', function () { self.handleResize(); }); - $(window).scroll(function () { - // self.handleScroll() - }); }, - handleScroll: function () { - const secondaryNavbar = $('.navbar > .secondary'); + cluster: function () { + this.checkUser(); - if ($(window).scrollTop() > 50) { - secondaryNavbar.css('top', $(window).scrollTop()); - secondaryNavbar.css('position', 'absolute'); - secondaryNavbar.css('z-index', '10'); - secondaryNavbar.css('width', $(window).width()); - } else { - secondaryNavbar.css('top', '0'); - secondaryNavbar.css('position', 'relative'); - secondaryNavbar.css('width', ''); - } + this.init.then(() => { + if (this.isCluster && frontendConfig.clusterApiJwtPolicy === 'jwt-all') { + // no privileges to use cluster/nodes from the web UI + this.routes[''] = 'collections'; + this.navigate('#collections', { trigger: true }); + return; + } + + if (!this.isCluster) { + if (this.currentDB.get('name') === '_system') { + this.routes[''] = 'dashboard'; + this.navigate('#dashboard', { trigger: true }); + } else { + this.routes[''] = 'collections'; + this.navigate('#collections', { trigger: true }); + } + return; + } + if (this.currentDB.get('name') !== '_system' && + !this.statisticsInAllDatabases) { + this.navigate('#nodes', { trigger: true }); + return; + } + + if (!this.clusterView) { + this.clusterView = new window.ClusterView({ + coordinators: this.coordinatorCollection, + dbServers: this.dbServers + }); + } + this.clusterView.render(); + }); }, - cluster: function (initialized) { + node: function (id) { this.checkUser(); - if (!initialized) { - this.waitForInit(this.cluster.bind(this)); - return; - } - if (this.isCluster && frontendConfig.clusterApiJwtPolicy === 'jwt-all') { - // no privileges to use cluster/nodes from the web UI - this.routes[''] = 'collections'; - this.navigate('#collections', { trigger: true }); - return; - } - if (!this.isCluster) { - if (this.currentDB.get('name') === '_system') { - this.routes[''] = 'dashboard'; - this.navigate('#dashboard', { trigger: true }); - } else { + this.init.then(() => { + if (this.isCluster && frontendConfig.clusterApiJwtPolicy === 'jwt-all') { + // no privileges to use cluster/nodes from the web UI this.routes[''] = 'collections'; this.navigate('#collections', { trigger: true }); + return; } - return; - } - if (this.currentDB.get('name') !== '_system' && - !this.statisticsInAllDatabases) { - this.navigate('#nodes', { trigger: true }); - return; - } - if (!this.clusterView) { - this.clusterView = new window.ClusterView({ + if (this.isCluster === false) { + this.routes[''] = 'dashboard'; + this.navigate('#dashboard', { trigger: true }); + return; + } + + if (this.nodeView) { + this.nodeView.remove(); + } + this.nodeView = new window.NodeView({ + coordid: id, coordinators: this.coordinatorCollection, dbServers: this.dbServers }); - } - this.clusterView.render(); + this.nodeView.render(); + }); }, - node: function (id, initialized) { + shards: function () { this.checkUser(); - if (!initialized || this.isCluster === undefined) { - this.waitForInit(this.node.bind(this), id); - return; - } - if (this.isCluster && frontendConfig.clusterApiJwtPolicy === 'jwt-all') { - // no privileges to use cluster/nodes from the web UI - this.routes[''] = 'collections'; - this.navigate('#collections', { trigger: true }); - return; - } - if (this.isCluster === false) { - this.routes[''] = 'dashboard'; - this.navigate('#dashboard', { trigger: true }); - return; - } - - if (this.nodeView) { - this.nodeView.remove(); - } - this.nodeView = new window.NodeView({ - coordid: id, - coordinators: this.coordinatorCollection, - dbServers: this.dbServers + this.init.then(() => { + if (this.isCluster === false) { + this.routes[''] = 'dashboard'; + this.navigate('#dashboard', { trigger: true }); + return; + } + // TODO re-enable React View, for now use old view: + // ReactDOM.render(React.createElement(window.ShardsReactView), + // document.getElementById('content')); + // Below code needs to be removed then again. + if (this.shardsView) { + this.shardsView.remove(); + } + this.shardsView = new window.ShardsView({ + dbServers: this.dbServers + }); + this.shardsView.render(); }); - this.nodeView.render(); }, - shards: function (initialized) { + distribution: function () { this.checkUser(); - if (!initialized || this.isCluster === undefined) { - this.waitForInit(this.shards.bind(this)); - return; - } - if (this.isCluster === false) { - this.routes[''] = 'dashboard'; - this.navigate('#dashboard', { trigger: true }); - return; - } - // TODO re-enable React View, for now use old view: - // ReactDOM.render(React.createElement(window.ShardsReactView), - // document.getElementById('content')); - // Below code needs to be removed then again. - if (this.shardsView) { - this.shardsView.remove(); - } - this.shardsView = new window.ShardsView({ - dbServers: this.dbServers - }); - this.shardsView.render(); + this.init.then(() => { + if (this.currentDB.get('name') !== '_system') { + if (!this.isCluster) { + this.routes[''] = 'dashboard'; + this.navigate('#dashboard', { trigger: true }); + } else { + this.routes[''] = 'cluster'; + this.navigate('#cluster', { trigger: true }); + } + return; + } + + if (this.shardDistributionView) { + this.shardDistributionView.remove(); + } + this.shardDistributionView = new window.ShardDistributionView({}); + this.shardDistributionView.render(); + }); }, - distribution: function (initialized) { + maintenance: function () { this.checkUser(); - if (!initialized || this.isCluster === undefined) { - this.waitForInit(this.distribution.bind(this)); - return; - } - if (this.currentDB.get('name') !== '_system') { - if (!this.isCluster) { - this.routes[''] = 'dashboard'; - this.navigate('#dashboard', { trigger: true }); - } else { - this.routes[''] = 'cluster'; - this.navigate('#cluster', { trigger: true }); - } - return; - } - if (this.shardDistributionView) { - this.shardDistributionView.remove(); - } - this.shardDistributionView = new window.ShardDistributionView({}); - this.shardDistributionView.render(); + this.init.then(() => { + if (frontendConfig.showMaintenanceStatus === false || this.currentDB.get( + 'name') !== '_system') { + if (!this.isCluster) { + this.routes[''] = 'dashboard'; + this.navigate('#dashboard', { trigger: true }); + } else { + this.routes[''] = 'cluster'; + this.navigate('#cluster', { trigger: true }); + } + + return; + } + if (this.maintenanceView) { + this.maintenanceView.remove(); + } + this.maintenanceView = new window.MaintenanceView({}); + this.maintenanceView.render(); + }); }, - maintenance: function (initialized) { + nodes: function () { this.checkUser(); - if (!initialized || this.isCluster === undefined) { - this.waitForInit(this.maintenance.bind(this)); - return; - } - if (frontendConfig.showMaintenanceStatus === false || this.currentDB.get( - 'name') !== '_system') { - if (!this.isCluster) { + + this.init.then(() => { + if (this.isCluster === false) { this.routes[''] = 'dashboard'; this.navigate('#dashboard', { trigger: true }); - } else { - this.routes[''] = 'cluster'; - this.navigate('#cluster', { trigger: true }); + return; } - - return; - } - if (this.maintenanceView) { - this.maintenanceView.remove(); - } - this.maintenanceView = new window.MaintenanceView({}); - this.maintenanceView.render(); + if (this.nodesView) { + this.nodesView.remove(); + } + this.nodesView = new window.NodesView({}); + this.nodesView.render(); + }); }, - nodes: function (initialized) { + cNodes: function () { this.checkUser(); - if (!initialized || this.isCluster === undefined) { - this.waitForInit(this.nodes.bind(this)); - return; - } - if (this.isCluster === false) { - this.routes[''] = 'dashboard'; - this.navigate('#dashboard', { trigger: true }); - return; - } - if (this.nodesView) { - this.nodesView.remove(); - } - this.nodesView = new window.NodesView({}); - this.nodesView.render(); - }, - cNodes: function (initialized) { - this.checkUser(); - if (!initialized || this.isCluster === undefined) { - this.waitForInit(this.cNodes.bind(this)); - return; - } - if (this.isCluster === false) { - this.routes[''] = 'dashboard'; - this.navigate('#dashboard', { trigger: true }); - return; - } - this.nodesView = new window.NodesView({ - coordinators: this.coordinatorCollection, - dbServers: this.dbServers[0], - toRender: 'coordinator' + this.init.then(() => { + if (this.isCluster === false) { + this.routes[''] = 'dashboard'; + this.navigate('#dashboard', { trigger: true }); + return; + } + this.nodesView = new window.NodesView({ + coordinators: this.coordinatorCollection, + dbServers: this.dbServers[0], + toRender: 'coordinator' + }); + this.nodesView.render(); }); - this.nodesView.render(); }, - dNodes: function (initialized) { + dNodes: function () { this.checkUser(); - if (!initialized || this.isCluster === undefined) { - this.waitForInit(this.dNodes.bind(this)); - return; - } - if (this.isCluster === false) { - this.routes[''] = 'dashboard'; - this.navigate('#dashboard', { trigger: true }); - return; - } - if (this.dbServers.length === 0) { - this.navigate('#cNodes', { trigger: true }); - return; - } - this.nodesView = new window.NodesView({ - coordinators: this.coordinatorCollection, - dbServers: this.dbServers[0], - toRender: 'dbserver' + this.init.then(() => { + if (this.isCluster === false) { + this.routes[''] = 'dashboard'; + this.navigate('#dashboard', { trigger: true }); + return; + } + if (this.dbServers.length === 0) { + this.navigate('#cNodes', { trigger: true }); + return; + } + + this.nodesView = new window.NodesView({ + coordinators: this.coordinatorCollection, + dbServers: this.dbServers[0], + toRender: 'dbserver' + }); + this.nodesView.render(); }); - this.nodesView.render(); }, - sNodes: function (initialized) { + sNodes: function () { this.checkUser(); - if (!initialized || this.isCluster === undefined) { - this.waitForInit(this.sNodes.bind(this)); - return; - } - if (this.isCluster === false) { - this.routes[''] = 'dashboard'; - this.navigate('#dashboard', { trigger: true }); - return; - } - this.scaleView = new window.ScaleView({ - coordinators: this.coordinatorCollection, - dbServers: this.dbServers[0] + this.init.then(() => { + if (this.isCluster === false) { + this.routes[''] = 'dashboard'; + this.navigate('#dashboard', { trigger: true }); + return; + } + + this.scaleView = new window.ScaleView({ + coordinators: this.coordinatorCollection, + dbServers: this.dbServers[0] + }); + this.scaleView.render(); }); - this.scaleView.render(); }, addAuth: function (xhr) { - var u = this.clusterPlan.get('user'); + const u = this.clusterPlan.get('user'); if (!u) { xhr.abort(); if (!this.isCheckingUser) { @@ -597,104 +542,100 @@ } return; } - var user = u.name; - var pass = u.passwd; - var token = user.concat(':', pass); + const user = u.name; + const pass = u.passwd; + const token = user.concat(':', pass); xhr.setRequestHeader('Authorization', 'Basic ' + btoa(token)); }, - logger: function (initialized) { + logger: function () { this.checkUser(); - if (!initialized) { - this.waitForInit(this.logger.bind(this)); - return; - } - if (this.loggerView) { - this.loggerView.remove(); - } + this.init.then(() => { + if (this.loggerView) { + this.loggerView.remove(); + } - var co = new window.ArangoLogs({ - upto: true, - loglevel: 4 - }); - this.loggerView = new window.LoggerView({ - collection: co + const co = new window.ArangoLogs({ + upto: true, + loglevel: 4 + }); + this.loggerView = new window.LoggerView({ + collection: co + }); + this.loggerView.render(true); }); - this.loggerView.render(true); }, - applicationDetail: function (mount, initialized) { + applicationDetail: function (mount) { this.checkUser(); - if (!initialized) { - this.waitForInit(this.applicationDetail.bind(this), mount); - return; - } - if (!this.foxxApiEnabled) { - this.navigate('#dashboard', { trigger: true }); - return; - } - var callback = function () { - if (this.hasOwnProperty('applicationDetailView')) { - this.applicationDetailView.remove(); + + this.init.then(() => { + if (!this.foxxApiEnabled) { + this.navigate('#dashboard', { trigger: true }); + return; } - this.applicationDetailView = new window.ApplicationDetailView({ - model: this.foxxList.get(decodeURIComponent(mount)) - }); + const callback = function () { + if (this.hasOwnProperty('applicationDetailView')) { + this.applicationDetailView.remove(); + } + this.applicationDetailView = new window.ApplicationDetailView({ + model: this.foxxList.get(decodeURIComponent(mount)) + }); - this.applicationDetailView.model = this.foxxList.get(decodeURIComponent(mount)); - this.applicationDetailView.render('swagger'); - }.bind(this); + this.applicationDetailView.model = this.foxxList.get(decodeURIComponent(mount)); + this.applicationDetailView.render('swagger'); + }.bind(this); - if (this.foxxList.length === 0) { - this.foxxList.fetch({ - cache: false, - success: function () { - callback(); - } - }); - } else { - callback(); - } + if (this.foxxList.length === 0) { + this.foxxList.fetch({ + cache: false, + success: function () { + callback(); + } + }); + } else { + callback(); + } + }); }, - storeDetail: function (mount, initialized) { + storeDetail: function (mount) { this.checkUser(); - if (!initialized) { - this.waitForInit(this.storeDetail.bind(this), mount); - return; - } - if (!this.foxxApiEnabled) { - this.navigate('#dashboard', { trigger: true }); - return; - } - var callback = function () { - if (this.hasOwnProperty('storeDetailView')) { - this.storeDetailView.remove(); + + this.init.then(() => { + if (!this.foxxApiEnabled) { + this.navigate('#dashboard', { trigger: true }); + return; } - this.storeDetailView = new window.StoreDetailView({ - model: this.foxxRepo.get(decodeURIComponent(mount)), - collection: this.foxxList - }); + const callback = function () { + if (this.hasOwnProperty('storeDetailView')) { + this.storeDetailView.remove(); + } + this.storeDetailView = new window.StoreDetailView({ + model: this.foxxRepo.get(decodeURIComponent(mount)), + collection: this.foxxList + }); - this.storeDetailView.model = this.foxxRepo.get(decodeURIComponent(mount)); - this.storeDetailView.render(); - }.bind(this); + this.storeDetailView.model = this.foxxRepo.get(decodeURIComponent(mount)); + this.storeDetailView.render(); + }.bind(this); - if (this.foxxRepo.length === 0) { - this.foxxRepo.fetch({ - cache: false, - success: function () { - callback(); - } - }); - } else { - callback(); - } + if (this.foxxRepo.length === 0) { + this.foxxRepo.fetch({ + cache: false, + success: function () { + callback(); + } + }); + } else { + callback(); + } + }); }, login: function () { - var callback = function (error, user) { + const callback = function (error, user) { if (!this.loginView) { this.loginView = new window.LoginView({ collection: this.userCollection @@ -710,375 +651,334 @@ this.userCollection.whoAmI(callback); }, - collections: function (initialized) { + collections: function () { this.checkUser(); - if (!initialized) { - this.waitForInit(this.collections.bind(this)); - return; - } - var self = this; - if (this.collectionsView) { - this.collectionsView.remove(); - } - this.collectionsView = new window.CollectionsView({ - collection: this.arangoCollectionsStore - }); - this.arangoCollectionsStore.fetch({ - cache: false, - success: function () { - self.collectionsView.render(); + + this.init.then(() => { + const self = this; + if (this.collectionsView) { + this.collectionsView.remove(); } + this.collectionsView = new window.CollectionsView({ + collection: this.arangoCollectionsStore + }); + this.arangoCollectionsStore.fetch({ + cache: false, + success: function () { + self.collectionsView.render(); + } + }); }); }, - cIndices: function (colname, initialized) { - var self = this; + cIndices: function (colname) { + const self = this; this.checkUser(); - if (!initialized) { - this.waitForInit(this.cIndices.bind(this), colname); - return; - } - this.arangoCollectionsStore.fetch({ - cache: false, - success: function () { - if (self.indicesView) { - self.indicesView.remove(); + + this.init.then(() => { + this.arangoCollectionsStore.fetch({ + cache: false, + success: function () { + if (self.indicesView) { + self.indicesView.remove(); + } + self.indicesView = new window.IndicesView({ + collectionName: colname, + collection: self.arangoCollectionsStore.findWhere({ + name: colname + }) + }); + self.indicesView.render(); } - self.indicesView = new window.IndicesView({ - collectionName: colname, - collection: self.arangoCollectionsStore.findWhere({ - name: colname - }) - }); - self.indicesView.render(); - } + }); }); }, - cSettings: function (colname, initialized) { - var self = this; + cSettings: function (colname) { + const self = this; this.checkUser(); - if (!initialized) { - this.waitForInit(this.cSettings.bind(this), colname); - return; - } - this.arangoCollectionsStore.fetch({ - cache: false, - success: function () { - self.settingsView = new window.SettingsView({ - collectionName: colname, - collection: self.arangoCollectionsStore.findWhere({ - name: colname - }) - }); - self.settingsView.render(); - } + + this.init.then(() => { + this.arangoCollectionsStore.fetch({ + cache: false, + success: function () { + self.settingsView = new window.SettingsView({ + collectionName: colname, + collection: self.arangoCollectionsStore.findWhere({ + name: colname + }) + }); + self.settingsView.render(); + } + }); }); }, - cSchema: function (colname, initialized) { - var self = this; + cSchema: function (colname) { + const self = this; this.checkUser(); - if (!initialized) { - this.waitForInit(this.cSchema.bind(this), colname); - return; - } - this.arangoCollectionsStore.fetch({ - cache: false, - success: function () { - self.settingsView = new window.ValidationView({ - collectionName: colname, - collection: self.arangoCollectionsStore.findWhere({ - name: colname - }) - }); - self.settingsView.render(); - } + + this.init.then(() => { + this.arangoCollectionsStore.fetch({ + cache: false, + success: function () { + self.settingsView = new window.ValidationView({ + collectionName: colname, + collection: self.arangoCollectionsStore.findWhere({ + name: colname + }) + }); + self.settingsView.render(); + } + }); }); }, - cInfo: function (colname, initialized) { - var self = this; + cInfo: function (colname) { + const self = this; this.checkUser(); - if (!initialized) { - this.waitForInit(this.cInfo.bind(this), colname); - return; - } - this.arangoCollectionsStore.fetch({ - cache: false, - success: function () { - self.infoView = new window.InfoView({ - collectionName: colname, - collection: self.arangoCollectionsStore.findWhere({ - name: colname - }) - }); - self.infoView.render(); - } - }); - }, - documents: function (colid, pageid, initialized) { - this.checkUser(); - if (!initialized) { - this.waitForInit(this.documents.bind(this), colid, pageid); - return; - } - if (this.documentsView) { - this.documentsView.unbindEvents(); - } - if (!this.documentsView) { - this.documentsView = new window.DocumentsView({ - collection: new window.ArangoDocuments(), - documentStore: this.arangoDocumentStore, - collectionsStore: this.arangoCollectionsStore + this.init.then(() => { + this.arangoCollectionsStore.fetch({ + cache: false, + success: function () { + self.infoView = new window.InfoView({ + collectionName: colname, + collection: self.arangoCollectionsStore.findWhere({ + name: colname + }) + }); + self.infoView.render(); + } }); - } - this.documentsView.setCollectionId(colid, pageid); - this.documentsView.render(); - this.documentsView.delegateEvents(); + }); }, - document: function (colid, docid, initialized) { + documents: function (colid, pageid) { this.checkUser(); - if (!initialized) { - this.waitForInit(this.document.bind(this), colid, docid); - return; - } - var mode; - if (this.documentView) { - if (this.documentView.defaultMode) { - mode = this.documentView.defaultMode; + + this.init.then(() => { + if (this.documentsView) { + this.documentsView.unbindEvents(); } - this.documentView.remove(); - } - this.documentView = new window.DocumentView({ - collection: this.arangoDocumentStore + if (!this.documentsView) { + this.documentsView = new window.DocumentsView({ + collection: new window.ArangoDocuments(), + documentStore: this.arangoDocumentStore, + collectionsStore: this.arangoCollectionsStore + }); + } + this.documentsView.setCollectionId(colid, pageid); + this.documentsView.render(); + this.documentsView.delegateEvents(); }); - this.documentView.colid = colid; - this.documentView.defaultMode = mode; + }, - var doc = window.location.hash.split('/')[2]; - var test = (doc.split('%').length - 1) % 3; + document: function (colid) { + this.checkUser(); - if (decodeURI(doc) !== doc && test !== 0) { - doc = decodeURIComponent(doc); - } - this.documentView.docid = doc; + this.init.then(() => { + let mode; + if (this.documentView) { + if (this.documentView.defaultMode) { + mode = this.documentView.defaultMode; + } + this.documentView.remove(); + } + this.documentView = new window.DocumentView({ + collection: this.arangoDocumentStore + }); + this.documentView.colid = colid; + this.documentView.defaultMode = mode; - this.documentView.render(); + let doc = window.location.hash.split('/')[2]; + const test = (doc.split('%').length - 1) % 3; - var callback = function (error, type) { - void (type); - if (!error) { - this.documentView.setType(); - } else { - this.documentView.renderNotFound(colid, true); + if (decodeURI(doc) !== doc && test !== 0) { + doc = decodeURIComponent(doc); } - }.bind(this); + this.documentView.docid = doc; - arangoHelper.collectionApiType(colid, null, callback); + this.documentView.render(); + + const callback = function (error, type) { + void (type); + if (!error) { + this.documentView.setType(); + } else { + this.documentView.renderNotFound(colid, true); + } + }.bind(this); + + arangoHelper.collectionApiType(colid, null, callback); + }); }, - query: function (initialized) { + query: function () { this.checkUser(); - if (!initialized) { - this.waitForInit(this.query.bind(this)); - return; - } - if (!this.queryView) { - this.queryView = new window.QueryView({ - collection: this.queryCollection - }); - } - this.queryView.render(); + + this.init.then(() => { + if (!this.queryView) { + this.queryView = new window.QueryView({ + collection: this.queryCollection + }); + } + this.queryView.render(); + }); }, - graph: function (name, initialized) { + graph: function (name) { this.checkUser(); - if (!initialized) { - this.waitForInit(this.graph.bind(this), name); - return; - } - // TODO better manage mechanism for both gv's - if (this.graphViewer) { - if (this.graphViewer.graphSettingsView) { - this.graphViewer.graphSettingsView.remove(); + this.init.then(() => { + // TODO better manage mechanism for both gv's + if (this.graphViewer) { + if (this.graphViewer.graphSettingsView) { + this.graphViewer.graphSettingsView.remove(); + } + this.graphViewer.killCurrentGraph(); + this.graphViewer.unbind(); + this.graphViewer.remove(); } - this.graphViewer.killCurrentGraph(); - this.graphViewer.unbind(); - this.graphViewer.remove(); - } - this.graphViewer = new window.GraphViewer({ - name: name, - documentStore: this.arangoDocumentStore, - collection: new window.GraphCollection(), - userConfig: this.userConfig + this.graphViewer = new window.GraphViewer({ + name: name, + documentStore: this.arangoDocumentStore, + collection: new window.GraphCollection(), + userConfig: this.userConfig + }); + this.graphViewer.render(); }); - this.graphViewer.render(); }, - graphSettings: function (name, initialized) { + graphSettings: function (name) { this.checkUser(); - if (!initialized) { - this.waitForInit(this.graphSettings.bind(this), name); - return; - } - if (this.graphSettingsView) { - this.graphSettingsView.remove(); - } - this.graphSettingsView = new window.GraphSettingsView({ - name: name, - userConfig: this.userConfig + + this.init.then(() => { + if (this.graphSettingsView) { + this.graphSettingsView.remove(); + } + this.graphSettingsView = new window.GraphSettingsView({ + name: name, + userConfig: this.userConfig + }); + this.graphSettingsView.render(); }); - this.graphSettingsView.render(); }, - helpUs: function (initialized) { + helpUs: function () { this.checkUser(); - if (!initialized) { - this.waitForInit(this.helpUs.bind(this)); - return; - } - if (!this.testView) { - this.helpUsView = new window.HelpUsView({}); - } - this.helpUsView.render(); + + this.init.then(() => { + if (!this.testView) { + this.helpUsView = new window.HelpUsView({}); + } + this.helpUsView.render(); + }); }, - support: function (initialized) { + support: function () { this.checkUser(); - if (!initialized) { - this.waitForInit(this.support.bind(this)); - return; - } - if (!this.testView) { - this.supportView = new window.SupportView({}); - } - this.supportView.render(); + + this.init.then(() => { + if (!this.testView) { + this.supportView = new window.SupportView({}); + } + this.supportView.render(); + }); }, - queryManagement: function (initialized) { + queryManagement: function () { this.checkUser(); - if (!initialized) { - this.waitForInit(this.queryManagement.bind(this)); - return; - } - if (this.queryManagementView) { - this.queryManagementView.remove(); - } - this.queryManagementView = new window.QueryManagementView({ - collection: undefined + + this.init.then(() => { + if (this.queryManagementView) { + this.queryManagementView.remove(); + } + this.queryManagementView = new window.QueryManagementView({ + collection: undefined + }); + this.queryManagementView.render(); }); - this.queryManagementView.render(); }, - databases: function (initialized) { + databases: function () { this.checkUser(); - if (!initialized) { - this.waitForInit(this.databases.bind(this)); - return; - } - var callback = function (error) { - if (error) { - arangoHelper.arangoError('DB', 'Could not get list of allowed databases'); - this.navigate('#', { trigger: true }); - $('#databaseNavi').css('display', 'none'); - $('#databaseNaviSelect').css('display', 'none'); - } else { - if (this.databaseView) { - // cleanup events and view - this.databaseView.remove(); + this.init.then(() => { + const callback = function (error) { + if (error) { + arangoHelper.arangoError('DB', 'Could not get list of allowed databases'); + this.navigate('#', { trigger: true }); + $('#databaseNavi').css('display', 'none'); + $('#databaseNaviSelect').css('display', 'none'); + } else { + if (this.databaseView) { + // cleanup events and view + this.databaseView.remove(); + } + this.databaseView = new window.DatabaseView({ + users: this.userCollection, + collection: this.arangoDatabase + }); + this.databaseView.render(); } - this.databaseView = new window.DatabaseView({ - users: this.userCollection, - collection: this.arangoDatabase - }); - this.databaseView.render(); - } - }.bind(this); + }.bind(this); - arangoHelper.databaseAllowed(callback); + arangoHelper.databaseAllowed(callback); + }); }, - dashboard: function (initialized) { + dashboard: function () { this.checkUser(); - if (!initialized) { - this.waitForInit(this.dashboard.bind(this)); - return; - } - if (this.dashboardView === undefined) { - this.dashboardView = new window.DashboardView({ - dygraphConfig: window.dygraphConfig, - database: this.arangoDatabase - }); - } - this.dashboardView.render(); + this.init.then(() => { + if (this.dashboardView === undefined) { + this.dashboardView = new window.DashboardView({ + dygraphConfig: window.dygraphConfig, + database: this.arangoDatabase + }); + } + this.dashboardView.render(); + }); }, - replication: function (initialized) { + replication: function () { this.checkUser(); - if (!initialized) { - this.waitForInit(this.replication.bind(this)); - return; - } - if (!this.replicationView) { - // this.replicationView.remove(); - this.replicationView = new window.ReplicationView({}); - } - this.replicationView.render(); + this.init.then(() => { + if (!this.replicationView) { + // this.replicationView.remove(); + this.replicationView = new window.ReplicationView({}); + } + this.replicationView.render(); + }); }, - applier: function (endpoint, database, initialized) { + applier: function (endpoint, database) { this.checkUser(); - if (!initialized) { - this.waitForInit(this.applier.bind(this), endpoint, database); - return; - } - if (this.applierView === undefined) { - this.applierView = new window.ApplierView({}); - } - this.applierView.endpoint = atob(endpoint); - this.applierView.database = atob(database); - this.applierView.render(); + this.init.then(() => { + if (this.applierView === undefined) { + this.applierView = new window.ApplierView({}); + } + this.applierView.endpoint = atob(endpoint); + this.applierView.database = atob(database); + this.applierView.render(); + }); }, - graphManagement: function (initialized) { + graphManagement: function () { this.checkUser(); - if (!initialized) { - this.waitForInit(this.graphManagement.bind(this)); - return; - } - if (this.graphManagementView) { - this.graphManagementView.undelegateEvents(); - } - this.graphManagementView = - new window.GraphManagementView( - { - collection: new window.GraphCollection(), - collectionCollection: this.arangoCollectionsStore - } - ); - this.graphManagementView.render(); - }, - showGraph: function (name, initialized) { - this.checkUser(); - if (!initialized) { - this.waitForInit(this.showGraph.bind(this), name); - return; - } - if (!this.graphManagementView) { + this.init.then(() => { + if (this.graphManagementView) { + this.graphManagementView.undelegateEvents(); + } this.graphManagementView = new window.GraphManagementView( { @@ -1086,142 +986,150 @@ collectionCollection: this.arangoCollectionsStore } ); - this.graphManagementView.render(name, true); - } else { - this.graphManagementView.loadGraphViewer(name); - } + this.graphManagementView.render(); + }); }, - applications: function (initialized) { + showGraph: function (name) { this.checkUser(); - if (!initialized) { - this.waitForInit(this.applications.bind(this)); - return; - } - if (!this.foxxApiEnabled) { - this.navigate('#dashboard', { trigger: true }); - return; - } - if (this.applicationsView === undefined) { - this.applicationsView = new window.ApplicationsView({ - collection: this.foxxList - }); - } - this.applicationsView.reload(); + + this.init.then(() => { + if (!this.graphManagementView) { + this.graphManagementView = + new window.GraphManagementView( + { + collection: new window.GraphCollection(), + collectionCollection: this.arangoCollectionsStore + } + ); + this.graphManagementView.render(name, true); + } else { + this.graphManagementView.loadGraphViewer(name); + } + }); }, - installService: function (initialized) { + applications: function () { this.checkUser(); - if (!initialized) { - this.waitForInit(this.installService.bind(this)); - return; - } - if (!this.foxxApiEnabled) { - this.navigate('#dashboard', { trigger: true }); - return; - } - if (!frontendConfig.foxxStoreEnabled) { - this.navigate('#services/install/upload', { trigger: true }); - return; - } - window.modalView.clearValidators(); - if (this.serviceInstallView) { - this.serviceInstallView.remove(); - } - this.serviceInstallView = new window.ServiceInstallView({ - collection: this.foxxRepo, - functionsCollection: this.foxxList + + this.init.then(() => { + if (!this.foxxApiEnabled) { + this.navigate('#dashboard', { trigger: true }); + return; + } + if (this.applicationsView === undefined) { + this.applicationsView = new window.ApplicationsView({ + collection: this.foxxList + }); + } + this.applicationsView.reload(); }); - this.serviceInstallView.render(); }, - installNewService: function (initialized) { + installService: function () { this.checkUser(); - if (!initialized) { - this.waitForInit(this.installNewService.bind(this)); - return; - } - if (!this.foxxApiEnabled) { - this.navigate('#dashboard', { trigger: true }); - return; - } - window.modalView.clearValidators(); - if (this.serviceNewView) { - this.serviceNewView.remove(); - } - this.serviceNewView = new window.ServiceInstallNewView({ - collection: this.foxxList + + this.init.then(() => { + if (!this.foxxApiEnabled) { + this.navigate('#dashboard', { trigger: true }); + return; + } + if (!frontendConfig.foxxStoreEnabled) { + this.navigate('#services/install/upload', { trigger: true }); + return; + } + window.modalView.clearValidators(); + if (this.serviceInstallView) { + this.serviceInstallView.remove(); + } + this.serviceInstallView = new window.ServiceInstallView({ + collection: this.foxxRepo, + functionsCollection: this.foxxList + }); + this.serviceInstallView.render(); }); - this.serviceNewView.render(); }, - installGitHubService: function (initialized) { + installNewService: function () { this.checkUser(); - if (!initialized) { - this.waitForInit(this.installGitHubService.bind(this)); - return; - } - if (!this.foxxApiEnabled) { - this.navigate('#dashboard', { trigger: true }); - return; - } - window.modalView.clearValidators(); - if (this.serviceGitHubView) { - this.serviceGitHubView.remove(); - } - this.serviceGitHubView = new window.ServiceInstallGitHubView({ - collection: this.foxxList + + this.init.then(() => { + if (!this.foxxApiEnabled) { + this.navigate('#dashboard', { trigger: true }); + return; + } + window.modalView.clearValidators(); + if (this.serviceNewView) { + this.serviceNewView.remove(); + } + this.serviceNewView = new window.ServiceInstallNewView({ + collection: this.foxxList + }); + this.serviceNewView.render(); }); - this.serviceGitHubView.render(); }, - installUrlService: function (initialized) { + installGitHubService: function () { this.checkUser(); - if (!initialized) { - this.waitForInit(this.installUrlService.bind(this)); - return; - } - if (!this.foxxApiEnabled) { - this.navigate('#dashboard', { trigger: true }); - return; - } - window.modalView.clearValidators(); - if (this.serviceUrlView) { - this.serviceUrlView.remove(); - } - this.serviceUrlView = new window.ServiceInstallUrlView({ - collection: this.foxxList + + this.init.then(() => { + if (!this.foxxApiEnabled) { + this.navigate('#dashboard', { trigger: true }); + return; + } + window.modalView.clearValidators(); + if (this.serviceGitHubView) { + this.serviceGitHubView.remove(); + } + this.serviceGitHubView = new window.ServiceInstallGitHubView({ + collection: this.foxxList + }); + this.serviceGitHubView.render(); }); - this.serviceUrlView.render(); }, - installUploadService: function (initialized) { + installUrlService: function () { this.checkUser(); - if (!initialized) { - this.waitForInit(this.installUploadService.bind(this)); - return; - } - if (!this.foxxApiEnabled) { - this.navigate('#dashboard', { trigger: true }); - return; - } - window.modalView.clearValidators(); - if (this.serviceUploadView) { - this.serviceUploadView.remove(); - } - this.serviceUploadView = new window.ServiceInstallUploadView({ - collection: this.foxxList + + this.init.then(() => { + if (!this.foxxApiEnabled) { + this.navigate('#dashboard', { trigger: true }); + return; + } + window.modalView.clearValidators(); + if (this.serviceUrlView) { + this.serviceUrlView.remove(); + } + this.serviceUrlView = new window.ServiceInstallUrlView({ + collection: this.foxxList + }); + this.serviceUrlView.render(); }); - this.serviceUploadView.render(); }, - handleSelectDatabase: function (initialized) { + installUploadService: function () { this.checkUser(); - if (!initialized) { - this.waitForInit(this.handleSelectDatabase.bind(this)); - return; - } - this.naviView.handleSelectDatabase(); + + this.init.then(() => { + if (!this.foxxApiEnabled) { + this.navigate('#dashboard', { trigger: true }); + return; + } + window.modalView.clearValidators(); + if (this.serviceUploadView) { + this.serviceUploadView.remove(); + } + this.serviceUploadView = new window.ServiceInstallUploadView({ + collection: this.foxxList + }); + this.serviceUploadView.render(); + }); + }, + + handleSelectDatabase: function () { + this.checkUser(); + + this.init.then(() => this.naviView.handleSelectDatabase()); }, handleResize: function () { @@ -1251,9 +1159,10 @@ } }, - userPermission: function (name, initialized) { + userPermission: function (name) { this.checkUser(); - if (initialized || initialized === null) { + + this.init.then(() => { if (this.userPermissionView) { this.userPermissionView.remove(); } @@ -1265,95 +1174,88 @@ }); this.userPermissionView.render(); - } else if (initialized === false) { - this.waitForInit(this.userPermissionView.bind(this), name); - } + }); }, - userView: function (name, initialized) { + userView: function (name) { this.checkUser(); - if (initialized || initialized === null) { + + this.init.then(() => { this.userView = new window.UserView({ collection: this.userCollection, username: name }); this.userView.render(); - } else if (initialized === false) { - this.waitForInit(this.userView.bind(this), name); - } + }); }, - userManagement: function (initialized) { + userManagement: function () { this.checkUser(); - if (!initialized) { - this.waitForInit(this.userManagement.bind(this)); - return; - } - if (this.userManagementView) { - this.userManagementView.remove(); - } - this.userManagementView = new window.UserManagementView({ - collection: this.userCollection - }); - this.userManagementView.render(); - }, + this.init.then(() => { + if (this.userManagementView) { + this.userManagementView.remove(); + } - userProfile: function (initialized) { - this.checkUser(); - if (!initialized) { - this.waitForInit(this.userProfile.bind(this)); - return; - } - if (!this.userManagementView) { this.userManagementView = new window.UserManagementView({ collection: this.userCollection }); - } - this.userManagementView.render(true); + this.userManagementView.render(); + }); }, - view: function (name, initialized) { - var self = this; + userProfile: function () { this.checkUser(); - if (!initialized) { - this.waitForInit(this.view.bind(this), name); - return; - } - if (this.viewView) { - this.viewView.remove(); - } - this.arangoViewsStore.fetch({ - success: function () { - self.viewView = new window.ViewView({ - model: self.arangoViewsStore.get(name), - name: name + this.init.then(() => { + if (!this.userManagementView) { + this.userManagementView = new window.UserManagementView({ + collection: this.userCollection }); - self.viewView.render(); } + this.userManagementView.render(true); }); }, - views: function (initialized) { + view: function (name) { + const self = this; this.checkUser(); - if (!initialized) { - this.waitForInit(this.views.bind(this)); - return; - } - if (this.viewsView) { - this.viewsView.remove(); - } - this.viewsView = new window.ViewsView({ - collection: this.arangoViewsStore + this.init.then(() => { + if (this.viewView) { + this.viewView.remove(); + } + + this.arangoViewsStore.fetch({ + success: function () { + self.viewView = new window.ViewView({ + model: self.arangoViewsStore.get(name), + name: name + }); + self.viewView.render(); + } + }); + }); + }, + + views: function () { + this.checkUser(); + + this.init.then(() => { + if (this.viewsView) { + this.viewsView.remove(); + } + + this.viewsView = new window.ViewsView({ + collection: this.arangoViewsStore + }); + this.viewsView.render(); }); - this.viewsView.render(); }, fetchDBS: function (callback) { - var self = this; - var cb = false; + const self = this; + let cb = false; this.coordinatorCollection.each(function (coordinator) { self.dbServers.push( @@ -1363,7 +1265,7 @@ ); }); - this.initFinished = true; + this.initSucceeded(true); _.each(this.dbServers, function (dbservers) { dbservers.fetch({ @@ -1387,6 +1289,5 @@ this.toUpdate.push(o); o.updateUrl(); } - }); }());