mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Added connect now option in server create dialog. Fixes #1313
This commit is contained in:
parent
5dbbd8e638
commit
6b95d6ac75
@ -577,14 +577,50 @@ class ServerNode(PGChildNodeView):
|
||||
db.session.add(server)
|
||||
db.session.commit()
|
||||
|
||||
connected = False
|
||||
icon = "icon-server-not-connected"
|
||||
user = None
|
||||
|
||||
if 'connect_now' in data and data['connect_now']:
|
||||
if 'password' not in data or data["password"] == '':
|
||||
db.session.delete(server)
|
||||
db.session.commit()
|
||||
raise Exception("No password provided.")
|
||||
|
||||
password = data['password']
|
||||
password = encrypt(password, current_user.password)
|
||||
|
||||
from pgadmin.utils.driver import get_driver
|
||||
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(server.id)
|
||||
conn = manager.connection()
|
||||
|
||||
status, errmsg = conn.connect(
|
||||
password=password,
|
||||
server_types=ServerType.types()
|
||||
)
|
||||
|
||||
if not status:
|
||||
db.session.delete(server)
|
||||
db.session.commit()
|
||||
return make_json_response(
|
||||
status=401,
|
||||
success=0,
|
||||
errormsg=gettext("Unable to connect to server.")
|
||||
)
|
||||
else:
|
||||
user = manager.user_info
|
||||
connected = True
|
||||
icon = "icon-pg"
|
||||
|
||||
return jsonify(
|
||||
node=self.blueprint.generate_browser_node(
|
||||
"%d" % (server.id), server.servergroup_id,
|
||||
"%d" % server.id, server.servergroup_id,
|
||||
server.name,
|
||||
"icon-server-not-connected",
|
||||
icon,
|
||||
True,
|
||||
self.node_type,
|
||||
connected=False,
|
||||
user=user,
|
||||
connected=connected,
|
||||
server_type='pg' # Default server type
|
||||
)
|
||||
)
|
||||
@ -594,7 +630,7 @@ class ServerNode(PGChildNodeView):
|
||||
return make_json_response(
|
||||
status=410,
|
||||
success=0,
|
||||
errormsg=e.message
|
||||
errormsg=str(e)
|
||||
)
|
||||
|
||||
def sql(self, gid, sid):
|
||||
|
@ -586,7 +586,9 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
|
||||
port: 5432,
|
||||
db: 'postgres',
|
||||
username: '{{ username }}',
|
||||
role: null
|
||||
role: null,
|
||||
connect_now: true,
|
||||
password: undefined
|
||||
},
|
||||
// Default values!
|
||||
initialize: function(attrs, args) {
|
||||
@ -622,6 +624,9 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
|
||||
},{
|
||||
id: 'version', label:'{{ _('Version') }}', type: 'text', group: null,
|
||||
mode: ['properties'], visible: 'isConnected'
|
||||
},{
|
||||
id: 'connect_now', controlLabel:'{{ _('Connect now?') }}', type: 'checkbox',
|
||||
group: null, mode: ['create']
|
||||
},{
|
||||
id: 'comment', label:'{{ _('Comments') }}', type: 'multiline', group: null,
|
||||
mode: ['properties', 'edit', 'create']
|
||||
@ -637,6 +642,12 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
|
||||
},{
|
||||
id: 'username', label:'{{ _('User Name') }}', type: 'text', group: "{{ 'Connection' }}",
|
||||
mode: ['properties', 'edit', 'create'], disabled: 'isConnected'
|
||||
},{
|
||||
id: 'password', label:'{{ _('Password') }}', type: 'password',
|
||||
group: "{{ 'Connection' }}", control: 'input', mode: ['create'], deps: ['connect_now'],
|
||||
visible: function(m) {
|
||||
return m.get('connect_now') && m.isNew();
|
||||
}
|
||||
},{
|
||||
id: 'role', label:'{{ _('Role') }}', type: 'text', group: "{{ 'Connection' }}",
|
||||
mode: ['properties', 'edit', 'create'], disabled: 'isConnected'
|
||||
@ -676,6 +687,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
|
||||
self.errorModel.unset('id');
|
||||
}
|
||||
check_for_empty('name', '{{ _('Name must be specified.') }}');
|
||||
|
||||
check_for_empty(
|
||||
'host', '{{ _('Hostname or address must be specified.') }}'
|
||||
);
|
||||
|
@ -1344,3 +1344,8 @@ height: calc(100% - 35px);
|
||||
.pg-panel-statistics-container > table > thead > tr > th:last-child {
|
||||
border-right: 0px;
|
||||
}
|
||||
|
||||
.pgadmin-controls input[type="checkbox"]{
|
||||
margin-left: 0 !important;
|
||||
margin-top: 10px !important;
|
||||
}
|
Loading…
Reference in New Issue
Block a user