{{extend 'layout.html'}}
{{if request.function=='index':}}

{{=T("Available Databases and Tables")}}

{{if not databases:}}{{=T("No databases in this application")}}{{pass}}
{{for db in sorted(databases):}} {{for table in databases[db].tables:}} {{qry='%s.%s.id>0'%(db,table)}} {{tbl=databases[db][table]}} {{if hasattr(tbl,'_primarykey'):}} {{if tbl._primarykey:}} {{firstkey=tbl[tbl._primarykey[0]]}} {{if firstkey.type in ['string','text']:}} {{qry='%s.%s.%s!=""'%(db,table,firstkey.name)}} {{else:}} {{qry='%s.%s.%s>0'%(db,table,firstkey.name)}} {{pass}} {{else:}} {{qry=''}} {{pass}} {{pass}} {{pass}} {{pass}}
» {{=A("%s.%s" % (db,table),_href=URL('select',args=[db],vars=dict(query=qry)))}} {{=A(str(T('New Record')),_href=URL('insert',args=[db,table]),_class="btn btn-primary")}}
{{=LOAD('appadmin', 'hooks', ajax=True)}}
{{elif request.function=='select':}}

{{=XML(str(T("Database %s select"))%A(request.args[0],_href=URL('index'))) }}

{{if tb:}}

{{=T('Traceback')}}

    {{=tb}}
  
{{pass}} {{if table:}} {{=A(str(T('New Record')),_href=URL('insert',args=[request.args[0],table]),_class="btn btn-primary", _role="button")}}


{{=T("Rows in Table")}}


{{else:}}

{{=T("Rows selected")}}


{{pass}} {{=form}}

{{=T('The "query" is a condition like "db.table1.field1==\'value\'". Something like "db.table1.field1==db.table2.field2" results in a SQL JOIN.')}}
{{=T('Use (...)&(...) for AND, (...)|(...) for OR, and ~(...) for NOT to build more complex queries.')}}
{{=T('"update" is an optional expression like "field1=\'newvalue\'". You cannot update or delete the results of a JOIN')}}



{{=T("%s selected", nrows)}}

{{if start>0:}}{{=A(T('previous %s rows') % step,_href=URL('select',args=request.args[0],vars=dict(start=start-step)),_class="btn btn-primary")}}{{pass}} {{if stop {{linkto = lambda f, t, r: URL('update', args=[request.args[0], r, f]) if f else "#"}} {{upload=URL('download',args=request.args[0])}} {{=SQLTABLE(rows,linkto,upload,orderby=True,query=query,_class='table table-striped table-bordered sortable')}}
{{pass}}


{{=T("Import/Export")}}


{{=T("export as csv file")}} {{=formcsv or ''}} {{elif request.function=='insert':}}

{{=T("Database")}} {{=A(request.args[0],_href=URL('index'))}} {{if hasattr(table,'_primarykey'):}} {{fieldname=table._primarykey[0]}} {{dbname=request.args[0]}} {{tablename=request.args[1]}} {{cond = table[fieldname].type in ['string','text'] and '!=""' or '>0'}} {{=T("Table")}} {{=A(tablename,_href=URL('select',args=dbname,vars=dict(query='%s.%s.%s%s'%(dbname,tablename,fieldname,cond))))}} {{else:}} {{=T("Table")}} {{=A(request.args[1],_href=URL('select',args=request.args[0],vars=dict(query='%s.%s.id>0'%tuple(request.args[:2]))))}} {{pass}}

{{=T("New Record")}}


{{=form}} {{elif request.function=='update':}}

{{=T("Database")}} {{=A(request.args[0],_href=URL('index'))}} {{if hasattr(table,'_primarykey'):}} {{fieldname=request.vars.keys()[0]}} {{dbname=request.args[0]}} {{tablename=request.args[1]}} {{cond = table[fieldname].type in ['string','text'] and '!=""' or '>0'}} {{=T("Table")}} {{=A(tablename,_href=URL('select',args=dbname,vars=dict(query='%s.%s.%s%s'%(dbname,tablename,fieldname,cond))))}} {{=T("Record")}} {{=A('%s=%s'%request.vars.items()[0],_href=URL('update',args=request.args[:2],vars=request.vars))}} {{else:}} {{=T("Table")}} {{=A(request.args[1],_href=URL('select',args=request.args[0],vars=dict(query='%s.%s.id>0'%tuple(request.args[:2]))))}} {{=T("Record id")}} {{=A(request.args[2],_href=URL('update',args=request.args[:3]))}} {{pass}}

{{=T("Edit current record")}}



{{=form}} {{elif request.function=='state':}}

{{=T("Internal State")}}

{{=T("Current request")}}

{{=BEAUTIFY(request)}}

{{=T("Current response")}}

{{=BEAUTIFY(response)}}

{{=T("Current session")}}

{{=BEAUTIFY(session)}} {{elif request.function == 'ccache':}}

{{T("Cache")}}

{{T("Statistics")}}

{{=T("Overview")}}

{{=T.M("Number of entries: **%s**", total['entries'])}}

{{if total['entries'] > 0:}}

{{=T.M("Hit Ratio: **%(ratio)s%%** (**%(hits)s** %%{hit(hits)} and **%(misses)s** %%{miss(misses)})", dict( ratio=total['ratio'], hits=total['hits'], misses=total['misses']))}}

{{=T("Size of cache:")}} {{if object_stats:}} {{=T.M("**%(items)s** %%{item(items)}, **%(bytes)s** %%{byte(bytes)}", dict(items=total['objects'], bytes=total['bytes']))}} {{if total['bytes'] > 524287:}} {{=T.M("(**%.0d MB**)", total['bytes'] / 1048576)}} {{pass}} {{else:}} {{=T.M("**not available** (requires the Python [[Pympler https://pypi.python.org/pypi/Pympler popup]] library)")}} {{pass}}

{{=T.M("Cache contains items up to **%(hours)02d** %%{hour(hours)} **%(min)02d** %%{minute(min)} **%(sec)02d** %%{second(sec)} old.", dict(hours=total['oldest'][0], min=total['oldest'][1], sec=total['oldest'][2]))}}

{{=BUTTON(T('Cache Keys'), _onclick='jQuery("#all_keys").toggle().toggleClass( "w2p_hidden" );')}}
{{=total['keys']}}

{{pass}}

{{=T("RAM")}}

{{=T.M("Number of entries: **%s**", ram['entries'])}}

{{if ram['entries'] > 0:}}

{{=T.M("Hit Ratio: **%(ratio)s%%** (**%(hits)s** %%{hit(hits)} and **%(misses)s** %%{miss(misses)})", dict( ratio=ram['ratio'], hits=ram['hits'], misses=ram['misses']))}}

{{=T("Size of cache:")}} {{if object_stats:}} {{=T.M("**%(items)s** items, **%(bytes)s** %%{byte(bytes)}", dict(items=ram['objects'], bytes=ram['bytes']))}} {{if ram['bytes'] > 524287:}} {{=T.M("(**%.0d MB**)", ram['bytes'] / 10485576)}} {{pass}} {{else:}} {{=T.M("``**not available**``:red (requires the Python [[Pympler https://pypi.python.org/pypi/Pympler popup]] library)")}} {{pass}}

{{=T.M("RAM contains items up to **%(hours)02d** %%{hour(hours)} **%(min)02d** %%{minute(min)} **%(sec)02d** %%{second(sec)} old.", dict(hours=ram['oldest'][0], min=ram['oldest'][1], sec=ram['oldest'][2]))}}

{{=BUTTON(T('RAM Cache Keys'), _onclick='jQuery("#ram_keys").toggle().toggleClass( "w2p_hidden" );')}}
{{=ram['keys']}}

{{pass}}

{{=T("DISK")}}

{{=T.M("Number of entries: **%s**", disk['entries'])}}

{{if disk['entries'] > 0:}}

{{=T.M("Hit Ratio: **%(ratio)s%%** (**%(hits)s** %%{hit(hits)} and **%(misses)s** %%{miss(misses)})", dict(ratio=disk['ratio'], hits=disk['hits'], misses=disk['misses']))}}

{{=T("Size of cache:")}} {{if object_stats:}} {{=T.M("**%(items)s** %%{item(items)}, **%(bytes)s** %%{byte(bytes)}", dict( items=disk['objects'], bytes=disk['bytes']))}} {{if disk['bytes'] > 524287:}} {{=T.M("(**%.0d MB**)", disk['bytes'] / 1048576)}} {{pass}} {{else:}} {{=T.M("``**not available**``:red (requires the Python [[Pympler https://pypi.python.org/pypi/Pympler popup]] library)")}} {{pass}}

{{=T.M("DISK contains items up to **%(hours)02d** %%{hour(hours)} **%(min)02d** %%{minute(min)} **%(sec)02d** %%{second(sec)} old.", dict(hours=disk['oldest'][0], min=disk['oldest'][1], sec=disk['oldest'][2]))}}

{{=BUTTON(T('Disk Cache Keys'), _onclick='jQuery("#disk_keys").toggle().toggleClass( "w2p_hidden" );')}}
{{=disk['keys']}}

{{pass}}

{{=T("Manage Cache")}}

{{=form}}

{{pass}} {{if request.function=='d3_graph_model':}}

{{=T("Graph Model")}}

{{if not databases:}} {{=T("No databases in this application")}} {{else:}}
{{pass}} {{pass}} {{if request.function == 'manage':}}

{{=heading}}

{{for k, tablename in enumerate(tablenames):}}
{{=LOAD(f='manage.load', args=[request.args(0), k], ajax=True)}}
{{pass}}
{{pass}}