mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-01-11 16:42:34 -06:00
Gracefully informed the user that the database is already connected when they click on 'Connect Database...'. Fixes #3694
This commit is contained in:
parent
0fc2afb829
commit
d61b8eb1b3
@ -17,5 +17,6 @@ Housekeeping
|
||||
Bug fixes
|
||||
*********
|
||||
|
||||
| `Issue #3694 <https://redmine.postgresql.org/issues/3694>`_ - Gracefully informed the user that the database is already connected when they click on "Connect Database...".
|
||||
| `Issue #4279 <https://redmine.postgresql.org/issues/4279>`_ - Ensure that file browse "home" button should point to $HOME rather than /.
|
||||
| `Issue #5422 <https://redmine.postgresql.org/issues/5422>`_ - Ensure that the dependencies tab shows correct information for Synonyms.
|
@ -456,30 +456,33 @@ class DatabaseView(PGChildNodeView):
|
||||
from pgadmin.utils.driver import get_driver
|
||||
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(sid)
|
||||
conn = manager.connection(did=did, auto_reconnect=True)
|
||||
status, errmsg = conn.connect()
|
||||
|
||||
if not status:
|
||||
current_app.logger.error(
|
||||
"Could not connected to database(#{0}).\nError: {1}".format(
|
||||
did, errmsg
|
||||
already_connected = conn.connected()
|
||||
if not already_connected:
|
||||
status, errmsg = conn.connect()
|
||||
if not status:
|
||||
current_app.logger.error(
|
||||
"Could not connected to database(#{0}).\nError: {1}"
|
||||
.format(
|
||||
did, errmsg
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
return internal_server_error(errmsg)
|
||||
else:
|
||||
current_app.logger.info('Connection Established for Database Id: \
|
||||
%s' % (did))
|
||||
|
||||
return make_json_response(
|
||||
success=1,
|
||||
info=_("Database connected."),
|
||||
data={
|
||||
'icon': 'pg-icon-database',
|
||||
'connected': True,
|
||||
'info_prefix': '{0}/{1}'.
|
||||
format(Server.query.filter_by(id=sid)[0].name, conn.db)
|
||||
}
|
||||
)
|
||||
return internal_server_error(errmsg)
|
||||
else:
|
||||
current_app.logger.info(
|
||||
'Connection Established for Database Id: \
|
||||
%s' % (did)
|
||||
)
|
||||
return make_json_response(
|
||||
success=1,
|
||||
info=_("Database connected."),
|
||||
data={
|
||||
'icon': 'pg-icon-database',
|
||||
'already_connected': already_connected,
|
||||
'connected': True,
|
||||
'info_prefix': '{0}/{1}'.
|
||||
format(Server.query.filter_by(id=sid)[0].name, conn.db)
|
||||
}
|
||||
)
|
||||
|
||||
def disconnect(self, gid, sid, did):
|
||||
"""Disconnect the database."""
|
||||
|
@ -520,7 +520,6 @@ define('pgadmin.node.database', [
|
||||
tree.deselect(item);
|
||||
tree.setInode(item);
|
||||
}
|
||||
|
||||
if (res && res.data) {
|
||||
if(typeof res.data.connected == 'boolean') {
|
||||
data.connected = res.data.connected;
|
||||
@ -530,11 +529,17 @@ define('pgadmin.node.database', [
|
||||
data.icon = res.data.icon;
|
||||
tree.addIcon(item, {icon: data.icon});
|
||||
}
|
||||
if(res.data.already_connected) {
|
||||
res.info = gettext('Database already connected.');
|
||||
}
|
||||
if(res.data.info_prefix) {
|
||||
res.info = `${_.escape(res.data.info_prefix)} - ${res.info}`;
|
||||
}
|
||||
|
||||
Alertify.success(res.info);
|
||||
if(res.data.already_connected) {
|
||||
Alertify.info(res.info);
|
||||
} else {
|
||||
Alertify.success(res.info);
|
||||
}
|
||||
obj.trigger('connected', obj, item, data);
|
||||
pgBrowser.Events.trigger(
|
||||
'pgadmin:database:connected', item, data
|
||||
|
Loading…
Reference in New Issue
Block a user