<%inherit file='base.mako'/>

<!-- BEGIN sidebar -->
<div id="sidebar">
<div class="box">
<div class="box_header">Load Sample Data</div>

<p>
<input type="button" value="Load Crime-Solver Data" onclick="window.location.href='loadData';" />
</p>
<p>
<input type="button" value="Load Movie-Rating Data" onclick="window.location.href='loadData?dataset=movie';" />
</p>

<p>
After data is loaded,
sample queries will appear in the other box.
</p>

<p>
% if session.has_key('loaded') :
    % if session['loaded']:
        <span class="success">Confirmation</span>: Sample data loaded. Visit the Schema tab to see the tables.
    % else:
        <span class="error">Error</span>: Sample data loading failed.
    % endif
    <%
    del session['loaded']
    session.save()
    %>
% else:
    <span class="warning">Warning</span>: Loading sample data will destroy any existing tables.
% endif
</p>

</div>
</div>
<!-- END sidebar -->

<%
tc = c.tcnx.cursor()
tc.execute("\d")
dataset = ''
for table in tc.fetchall():
    if table[0] == 'movies':
        dataset = 'movie'
        break
    if table[0] == 'sawperson':
        dataset = 'crime'
        break
c.tcnx.commit()

import os
if dataset == 'movie':
    f = open(os.path.join(config['pylons.paths']['static_files'], 'triql', 'movie_query.triql'))
elif dataset == 'crime':
    f = open(os.path.join(config['pylons.paths']['static_files'], 'triql', 'crime_query.triql'))
%>

<!-- BEGIN content -->
<div id="content">
<div class="box">
% if dataset != '':
    <div class="box_header">Sample Queries for ${dataset} Data</div>
% else:
    <div class="box_header">Sample Queries </div>
% endif

<p>
Click on a query to place it in the execution box, then
press "Execute".
</p>

% if dataset != '':
    <%
    str=''
    %>
    % for line in f:
        % if line.strip() != "":
            % if line.startswith("--"):
                <span class="comment"><em>${line}</em></span><br />
            % elif line.rstrip().endswith(';'):
                <%
                str += line
                %>
                <p><a href="index?execute=False&query=${str}"><pre>${str}</pre></a></p>
                <%
                str = ''
                %>
            % else:
                <%
                str += line + ' '
                %>
            % endif
        % endif
    % endfor
% endif

</div>
</div>
<!-- END content -->
