Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added dropping database when it is closed fixes #118 #166

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ui/components/addCollection/addCollection.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<i class="close fa fa-plus rotate-45" ng-click="close()"></i>
</div>
<div class="modal-body">
<div class="form-group" ng-class="{ 'has-error' : !addCollectionForm.name.$valid && addCollectionFormSubmitted }">
<div class="form-group" ng-class="{ 'has-error' : !addCollectionForm.name.$valid && addCollectionFormSubmitted }" ng-init="setFocus()">
<label class="control-label">Name</label>
<input class="form-control" type="text" name="name" ng-model="form.name" required>
<input class="form-control" type="text" name="name" ng-model="form.name" required id="newCollection">
</div>
</div>
<div class="modal-footer clearfix">
Expand Down
10 changes: 9 additions & 1 deletion src/ui/components/addCollection/addCollectionCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ angular.module('app').controller('addCollectionCtrl', [
'$scope',
'$uibModalInstance',
'database',
'notificationService', ($scope, $uibModalInstance, database, notificationService) => {
'notificationService',
'$window', ($scope, $uibModalInstance, database, notificationService, $window) => {
const logger = require('lib/modules/logger');

$scope.close = function() {
Expand All @@ -28,5 +29,12 @@ angular.module('app').controller('addCollectionCtrl', [
logger.error(err);
});
};

$scope.setFocus = function() {
setTimeout(function() {
var collectionField = $window.document.getElementById('newCollection');
collectionField.focus();
}, 100);
}
}
]);
4 changes: 2 additions & 2 deletions src/ui/components/addDatabase/addDatabase.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<i class="close fa fa-plus rotate-45" ng-click="close()"></i>
</div>
<div class="modal-body">
<div class="form-group" ng-class="{ 'has-error' : !addDatabaseForm.name.$valid && addDatabaseFormSubmitted }">
<div class="form-group" ng-class="{ 'has-error' : !addDatabaseForm.name.$valid && addDatabaseFormSubmitted }" ng-init="setFocus()">
<label class="control-label">Name</label>
<input class="form-control" type="text" name="name" ng-model="form.name" required>
<input class="form-control" type="text" name="name" ng-model="form.name" required id="newDatabase">
</div>
</div>
<div class="modal-footer clearfix">
Expand Down
10 changes: 9 additions & 1 deletion src/ui/components/addDatabase/addDatabaseCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ angular.module('app').controller('addDatabaseCtrl', [
'$uibModalInstance',
'connection',
'notificationService',
function($scope, $uibModalInstance, connection, notificationService) {
'$window',
function($scope, $uibModalInstance, connection, notificationService, $window) {

$scope.close = function() {
$uibModalInstance.close(1);
Expand All @@ -30,5 +31,12 @@ angular.module('app').controller('addDatabaseCtrl', [
notificationService.error('Error creating a new database');
});
};

$scope.setFocus = function() {
setTimeout(function() {
var collectionField = $window.document.getElementById('newDatabase');
collectionField.focus();
}, 100);
}
}
]);
121 changes: 77 additions & 44 deletions src/ui/directives/sidebar/sidebarCtrl.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';

const Promise = require('bluebird');
angular.module('app').controller('sidebarCtrl', [
'$scope',
'$timeout',
Expand Down Expand Up @@ -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: () => {
Expand All @@ -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
});
});
});
})
});
});
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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;
});
});


});
}
}
]);
]);