def Storage(params=None): handle_params(params) data = [] with pg_connection(*current_user.get_config()) as (con, cur, err): with pg_log_err('list storage query'): cur.execute(query('list-storage')) data = cur.fetchall() display_schemas = params.getlist('schema') schemas = set() treemap_data = {'name': 'root', 'children': []} for (schema_name, table_name, t_size, t_tuples) in data: schemas.add(schema_name) if schema_name in display_schemas or len(display_schemas) == 0: treemap_data['children'].append({'schema_name': schema_name, 'name': table_name, 'size': int(t_size), 'rows': int(t_tuples)}) p = Page() # Header p.add_page(Header(title='Storage', js=['static/pages/storage.js', 'static/lib/d3/d3.js', 'static/lib/d3/lib/colorbrewer/colorbrewer.js'], css=['static/pages/storage.css'])) p.add_page(Navigation(page='storage')) with p.div({'class': 'container-fluid'}): with p.div({'class': 'row form-row'}): with p.div({'class': 'col-md-10'}): with p.form({'id': 'schema-form', 'class': 'form-inline'}): for schema in schemas: with p.label({'class': 'checkbox-inline'}): checked = (schema in display_schemas or len(display_schemas) == 0) and 'checked' or '' with p.input({'type': 'checkbox', 'name': 'schema', 'value': '%s' % schema}, args=[checked]): p.content(schema) with p.div({'class': 'col-md-2'}): with p.form({'id': 'mode-form', 'class': 'form-inline'}): with p.label({'class': 'radio-inline'}): with p.input({'type': 'radio', 'name': 'mode', 'value': 'size'}, args=['checked']): p.content('Size') with p.label({'class': 'radio-inline'}): with p.input({'type': 'radio', 'name': 'mode', 'value': 'rows'}): p.content('Rows (est.)') with p.div({'class': 'row'}): with p.div({'class': 'col-md-12'}): with p.div({'id': 'treemap-chart'}): pass with p.script(): p.content('PGUI.STORAGE.mk_treemap_chart(%s);' % json.dumps(treemap_data)) p.add_page(Footer()) return p
def Login(params=None, title=None): """ Renders the login page. There is no separate login for the application, this is passed to the database! """ p = Page() p.content('<!DOCTYPE html>') with p.html(): with p.head(): with p.title(): p.content('pgui - Login') with p.link({'href': 'static/lib/bootstrap/bootstrap-3.3.4-dist/css/bootstrap.css', 'rel': 'stylesheet'}): pass with p.link({'href': 'static/login.css', 'rel': 'stylesheet'}): pass with p.body(): with p.div({'class': 'container'}): with p.form({'method': 'POST', 'class': 'login'}): with p.h2({'class': 'login-header'}): p.content('Connect to a postgres database server') with p.label({'for': 'name', 'class': 'sr-only'}): p.content('User name') with p.input({'type': 'input', 'id': 'name', 'name': 'name', 'class': 'form-control', 'placeholder': 'User name'}): pass with p.label({'for': 'password', 'class': 'sr-only'}): p.content('Password') with p.input({'type': 'password', 'id': 'password', 'name': 'password', 'class': 'form-control', 'placeholder': 'Password'}): pass with p.label({'for': 'host', 'class': 'sr-only'}): p.control('Host') with p.input({'type': 'input', 'id': 'host', 'name': 'host', 'class': 'form-control', 'value': 'localhost'}): pass with p.label({'for': 'port', 'class': 'sr-only'}): p.content('Port') with p.input({'type': 'input', 'id': 'port', 'name': 'port', 'class': 'form-control', 'value': '5432'}): pass with p.button({'class': 'btn btn-lg btn-success btn-block', 'type': 'submit'}, args=['autofocus']): p.content('Connect') with p.div({'class': 'login'}): if 'err' in params and params['err']: for err in params['err']: with p.code(): p.content(err) return p
def Storage(params=None): handle_params(params) data = [] with pg_connection(*current_user.get_config()) as (con, cur, err): with pg_log_err('list storage query'): cur.execute(query('list-storage')) data = cur.fetchall() display_schemas = params.getlist('schema') schemas = set() treemap_data = {'name': 'root', 'children': []} for (schema_name, table_name, t_size, t_tuples) in data: schemas.add(schema_name) if schema_name in display_schemas or len(display_schemas) == 0: treemap_data['children'].append({ 'schema_name': schema_name, 'name': table_name, 'size': int(t_size), 'rows': int(t_tuples) }) p = Page() # Header p.add_page( Header(title='Storage', js=[ 'static/pages/storage.js', 'static/lib/d3/d3.js', 'static/lib/d3/lib/colorbrewer/colorbrewer.js' ], css=['static/pages/storage.css'])) p.add_page(Navigation(page='storage')) with p.div({'class': 'container-fluid'}): with p.div({'class': 'row form-row'}): with p.div({'class': 'col-md-10'}): with p.form({'id': 'schema-form', 'class': 'form-inline'}): for schema in schemas: with p.label({'class': 'checkbox-inline'}): checked = (schema in display_schemas or len(display_schemas) == 0) and 'checked' or '' with p.input( { 'type': 'checkbox', 'name': 'schema', 'value': '%s' % schema }, args=[checked]): p.content(schema) with p.div({'class': 'col-md-2'}): with p.form({'id': 'mode-form', 'class': 'form-inline'}): with p.label({'class': 'radio-inline'}): with p.input( { 'type': 'radio', 'name': 'mode', 'value': 'size' }, args=['checked']): p.content('Size') with p.label({'class': 'radio-inline'}): with p.input({ 'type': 'radio', 'name': 'mode', 'value': 'rows' }): p.content('Rows (est.)') with p.div({'class': 'row'}): with p.div({'class': 'col-md-12'}): with p.div({'id': 'treemap-chart'}): pass with p.script(): p.content('PGUI.STORAGE.mk_treemap_chart(%s);' % json.dumps(treemap_data)) p.add_page(Footer()) return p
def Login(params=None, title=None): """ Renders the login page. There is no separate login for the application, this is passed to the database! """ p = Page() p.content('<!DOCTYPE html>') with p.html(): with p.head(): with p.title(): p.content('pgui - Login') with p.link({ 'href': 'static/lib/bootstrap/bootstrap-3.3.4-dist/css/bootstrap.css', 'rel': 'stylesheet' }): pass with p.link({'href': 'static/login.css', 'rel': 'stylesheet'}): pass with p.body(): with p.div({'class': 'container'}): with p.form({'method': 'POST', 'class': 'login'}): with p.h2({'class': 'login-header'}): p.content('Connect to a postgres database server') with p.label({'for': 'name', 'class': 'sr-only'}): p.content('User name') with p.input({ 'type': 'input', 'id': 'name', 'name': 'name', 'class': 'form-control', 'placeholder': 'User name' }): pass with p.label({'for': 'password', 'class': 'sr-only'}): p.content('Password') with p.input({ 'type': 'password', 'id': 'password', 'name': 'password', 'class': 'form-control', 'placeholder': 'Password' }): pass with p.label({'for': 'host', 'class': 'sr-only'}): p.control('Host') with p.input({ 'type': 'input', 'id': 'host', 'name': 'host', 'class': 'form-control', 'value': 'localhost' }): pass with p.label({'for': 'port', 'class': 'sr-only'}): p.content('Port') with p.input({ 'type': 'input', 'id': 'port', 'name': 'port', 'class': 'form-control', 'value': '5432' }): pass with p.button( { 'class': 'btn btn-lg btn-success btn-block', 'type': 'submit' }, args=['autofocus']): p.content('Connect') with p.div({'class': 'login'}): if 'err' in params and params['err']: for err in params['err']: with p.code(): p.content(err) return p