<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US"
  lang="en-US"
  metal:use-macro="here/main_template/macros/master"
  i18n:domain="eea">

<body>
<div metal:fill-slot="content-core"
        tal:define="options view/test_query;
                    isDaviz view/isDavizInstalled;
                    arguments view/getArguments;
                    arguments python: '?' + arguments if arguments else ''">

     <h3 i18n:translate="">Download this dataset</h3>
     <label i18n:translate="">Formats suitable for human consumption</label>
     <div class="eea-sparql-downloads">
       <a tal:attributes="href string:${context/absolute_url}/download.table${arguments}"
           tal:content="string:HTML"></a>
       <a tal:attributes="href string:${context/absolute_url}/download.csv${arguments}"
           tal:content="string:CSV"></a>
       <a tal:attributes="href string:${context/absolute_url}/download.tsv${arguments}"
           tal:content="string:TSV"></a>
    </div>
    <label i18n:translate="">Formats suitable for machine-to-machine communication</label>
    <div class="eea-sparql-downloads">
       <a tal:attributes="href string:${context/absolute_url}/download.json"
           tal:content="string:JSON"></a>
       <a tal:attributes="href string:${context/absolute_url}/download.exhibit${arguments}"
           tal:content="string:Exhibit JSON"></a>
       <a tal:attributes="href string:${context/absolute_url}/download.xml"
           tal:content="string:XML"></a>
       <a tal:attributes="href string:${context/absolute_url}/download.schema.xml"
           i18n:translate="">
            XML with Schema
       </a>
    </div>

    <h3 i18n:translate="">Dataset preview</h3>
    <h4 tal:condition="context/sparql_static">(Static Query)</h4>
    <h4 tal:condition="not:context/sparql_static">(Live Query)</h4>
    <div tal:define="data options/data">
      <div class="eea-sparql-table" style="overflow: hidden">
        <metal:table use-macro="here/@@sparql.preview/macros/table" />
      </div>
    </div>

    <p class="sparql-stats" tal:condition="options/data">
      Received
      <span class="number" tal:content="python:len(options['data']['rows'])"/>
      rows<tal:block condition="python:'duration' in options"> in
      <span class="number" tal:content="python:'%.3f' % options['duration']"/>
      seconds</tal:block>.
    </p>

    <label i18n:translate="">JSON Url:</label>
    <br/>
    <a tal:attributes="href string:${context/absolute_url}/daviz.json"
       tal:content="string:${context/absolute_url}/daviz.json">link</a>

    <h3 i18n:translate="">For system integrators</h3>
    <label i18n:translate="">Linked Data query (SPARQL)</label>
    <p i18n:translate="">The following info can be used by a system developer /
    database administrator in order to retrieve this dataset programmatically
    over the web using a SPARQL client.</p>
    <p class="linkeddata-icon discreet" i18n:translate="">
    Are you new to Linked Data technology? visit http://linkeddata.org
    </p>
    <br/>
    <label i18n:translate="">SPARQL Endpoint:</label>
    <br/>
    <span tal:content="context/endpoint_url">endpoint</span>
    <br/>
    <br/>
    <label i18n:translate="">SPARQL Query:</label>

    <form tal:condition="options/arg_spec"
          name="method-arguments" method="get">
      <table>
        <tr tal:repeat="arg options/arg_spec">
          <td class="form-label" tal:content="arg"/>
          <td tal:define="input_name python:'%s:utf8:ustring' % (arg,); has_results python:view.hasResults(arg)">
            <input tal:condition="not: has_results"
                   size="50"
                   tal:define="prev_value python:request.form.get(arg)"
                   tal:attributes="name input_name; value prev_value; id input_name"/>
            <select tal:condition="has_results"
                    tal:attributes="name input_name; id input_name">
              <option value="default">Please select a value for the argument</option>
              <option tal:repeat="result python:view.getQueryResults(arg)"
                      tal:attributes="value python:result[0]; selected python:(str(result[0]) == request.form.get(arg))"
                      tal:content="python:result[1]"
                      size="50"/>
            </select>
          </td>
        </tr>
        <tr><td colspan="2"><input type="submit" value="Execute" i18n:attributes="value"/></td></tr>
      </table>
    </form>

    <blockquote class="sparql-query"
            tal:condition="options/query_with_comments|nothing"
            tal:content="structure options/query_with_comments"/>


    <p class="sparql-has-result"
       tal:define="has_result options/data/has_result|nothing"
       tal:condition="python: has_result is not None">

          <tal:block condition="has_result" i18n:translate="">
              Query will return a result.
          </tal:block>
          <tal:block condition="not:has_result" i18n:translate="">
              Query will not return a result.
          </tal:block>

    </p>

    <div tal:condition="options/error|nothing">
        <h4 style="color:red">Error when running query:</h4>
        <blockquote class="sparql-error" tal:content="options/error"/>
    </div>

    <tal:block tal:condition="python: isDaviz">
        <br/>
        <br/>
        <input type="button" class="context" value="Create New Visualization"
            tal:attributes="onclick string:javascript:document.location='${context/absolute_url}/daviz-create-new.html';"/>
    </tal:block>

</div>
</body>
</html>
