From 4ed5ebbf13c87aaa67a2440ea9bf68c34daeb396 Mon Sep 17 00:00:00 2001 From: apedley Date: Sun, 3 Sep 2017 16:05:20 -0500 Subject: [PATCH 1/2] Added dropping database when it is closed fixes #118 --- src/ui/directives/sidebar/sidebarCtrl.js | 121 ++++++++++++++--------- 1 file changed, 77 insertions(+), 44 deletions(-) diff --git a/src/ui/directives/sidebar/sidebarCtrl.js b/src/ui/directives/sidebar/sidebarCtrl.js index eb8fe2b0..b8420b0d 100644 --- a/src/ui/directives/sidebar/sidebarCtrl.js +++ b/src/ui/directives/sidebar/sidebarCtrl.js @@ -1,5 +1,5 @@ 'use strict'; - +const Promise = require('bluebird'); angular.module('app').controller('sidebarCtrl', [ '$scope', '$timeout', @@ -56,6 +56,8 @@ angular.module('app').controller('sidebarCtrl', [ $scope.openDatabaseContextMenu = function openDatabaseContextMenu(database, connection) { if (!database || !connection) return; + var scope = this; + menuService.showMenu([{ label: 'New Collection', click: () => { @@ -72,24 +74,26 @@ angular.module('app').controller('sidebarCtrl', [ confirmButtonMessage: 'Yes', cancelButtonMessage: 'No' }).result.then(() => { - database.drop() - .then(() => { - notificationService.success('Database dropped'); - - tabCache.removeByDatabase(database); - - let index = connection.databases.indexOf(database); - if (index >= 0) { - connection.databases.splice(index, 1); - } - }) - .catch((err) => { - logger.error(err); - notificationService.error({ - title: 'Error dropping database', - message: err + _openDatabase(database, connection).then(() => { + database.drop() + .then(() => { + notificationService.success('Database dropped'); + + tabCache.removeByDatabase(database); + + let index = connection.databases.indexOf(database); + if (index >= 0) { + connection.databases.splice(index, 1); + } + }) + .catch((err) => { + logger.error(err); + notificationService.error({ + title: 'Error dropping database', + message: err + }); }); - }); + }) }); }); } @@ -160,42 +164,26 @@ angular.module('app').controller('sidebarCtrl', [ }]); }; - $scope.openDatabase = function openDatabase(database, connection) { + $scope.openDatabase = function openDatabase(database, connection, callback) { if (!database) return; if (!database.isOpen) { - if (connection) { //collapse other databases with the same connection - _.each(connection.databases, (database) => { - _collapseDatabase(database); - }); - } - - database.opening = true; - - database.open() + _openDatabase(database, connection) .then(() => { - $timeout(() => { - database.isOpen = true; - }); + _toggleFolders(database); }) - .catch((err) => { - $timeout(() => { - notificationService.error({ - title: 'Error opening database', - message: err - }); + .catch(err => { + logger.error(err); + notificationService.error({ + title: 'Error dropping database', + message: err }); }) - .finally(() => { - $timeout(() => { - database.opening = false; - }); - }); } else { _collapseDatabase(database); + _toggleFolders(database); } - database.showFolders = !database.showFolders; }; //collections @@ -251,6 +239,10 @@ angular.module('app').controller('sidebarCtrl', [ database.isOpen = false; } + function _toggleFolders(database) { + database.showFolders = !database.showFolders; + } + function _listCollections(database) { database.loadingCollections = true; database.listCollections() @@ -278,5 +270,46 @@ angular.module('app').controller('sidebarCtrl', [ }); }); } + + + function _openDatabase(database, connection) { + return new Promise(function (resolve, reject) { + if (database.isOpen) { + return resolve(true); + } + if (!connection) { + return reject('No connection'); + } + _.each(connection.databases, (database) => { + _collapseDatabase(database); + }); + + database.opening = true; + + database.open() + .then(() => { + $timeout(() => { + database.isOpen = true; + resolve(true); + }); + }) + .catch((err) => { + $timeout(() => { + notificationService.error({ + title: 'Error opening database', + message: err + }); + reject(err); + }); + }) + .finally(() => { + $timeout(() => { + database.opening = false; + }); + }); + + + }); + } } -]); +]); \ No newline at end of file From f616ac09dbd60969ab0119cc325d3712c1c452b6 Mon Sep 17 00:00:00 2001 From: apedley Date: Sun, 3 Sep 2017 17:18:51 -0500 Subject: [PATCH 2/2] New collection and new database modals not focus input --- src/ui/components/addCollection/addCollection.html | 4 ++-- src/ui/components/addCollection/addCollectionCtrl.js | 10 +++++++++- src/ui/components/addDatabase/addDatabase.html | 4 ++-- src/ui/components/addDatabase/addDatabaseCtrl.js | 10 +++++++++- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/ui/components/addCollection/addCollection.html b/src/ui/components/addCollection/addCollection.html index d042f97f..c78a6e1a 100644 --- a/src/ui/components/addCollection/addCollection.html +++ b/src/ui/components/addCollection/addCollection.html @@ -5,9 +5,9 @@