term_search.html 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. {% extends 'base.html' %}
  2. {% block title %}Term Search{% endblock %}
  3. {% block content %}
  4. <p>Enter terms to query:</p>
  5. <dl>
  6. <dt>Logic</dt>
  7. <dd>use "and" or "or" logic to concatenate multiple query criteria.</dd>
  8. <dt>Predicate</dt>
  9. <dd>a fully qualified or namespace-prefixed
  10. predicate URI in SPARQL notation, e.g.
  11. <code>&lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#type&gt;</code>
  12. or
  13. <code>skos:prefLabel</code>.
  14. For a full list of namespace prefixes supported by this system,
  15. see the collapsable namespace reference at the bottom of this page.
  16. </dd>
  17. <dt>Operand</dt>
  18. <dd> Select an operand for the comparison. The "Matches Term" operand
  19. expects an RDF literal or URI, all others a string.</dd>
  20. <dt>Value</dt>
  21. <dd>Value to compare against. If "Matches Term" is selected, an RDF URI
  22. or literal in SPARQL notation should be used, e.g.
  23. <code>&lt;http://ex.org/ns/A&gt;</code>
  24. or
  25. <code>"title"^^xsd:string</code>.
  26. For other operands, use a plain string without quotes.</dd>
  27. </dd>
  28. </dl>
  29. <form id="term-search-form" method="POST" action="">
  30. <div class="my-sm-3 mb-2">
  31. <label for="logic">Logic</label>
  32. <select class="form-control" name="logic">
  33. <option value="and" selected>AND</option>
  34. <option value="or">OR</option>
  35. </select>
  36. </div>
  37. <div id="term-cont">
  38. <div class="term-block form-row">
  39. <div class="form-group col-md-4">
  40. <label for="pred[]">Predicate</label>
  41. <input type="text" class="form-control" name="pred[]">
  42. </div>
  43. <div class="form-group col-md-2">
  44. <label for="op[]">Operand</label>
  45. <select class="form-control" name="op[]">
  46. {% for op in operands %}
  47. <option value="{{op[0]}}">{{op[1]}}</option>
  48. {% endfor %}
  49. </select>
  50. </div>
  51. <div class="form-group col-md-5">
  52. <label for="val[]">Value</label>
  53. <input type="text" class="form-control" name="val[]">
  54. </div>
  55. <div class="form-group col-md-1">
  56. <a class="delete-row btn btn-danger" href="#">- Remove</a>
  57. </div>
  58. </div>
  59. </div>
  60. <div class="form-row my-sm-3">
  61. <a class="add-row btn btn-success" id="add-row" href="#">+ Add Row</a>
  62. </div>
  63. <div class="form-row my-sm-3">
  64. <input type="submit" id="submit-query" class="btn btn-primary btn-lg">
  65. </div>
  66. </form>
  67. <div id="search-results-wrap"></div>
  68. {% include 'namespaces.html' %}
  69. {% endblock %}
  70. {% block tail_js %}
  71. <script>
  72. function format_fields() {
  73. var conds = [];
  74. var terms = ['pred', 'op', 'val'];
  75. for (term of terms) {
  76. $(":input[name='" + term + "[]']").each(function(i) {
  77. if (typeof conds[i] == 'undefined') {
  78. conds[i] = {};
  79. }
  80. conds[i][term] = $(this).val();
  81. });
  82. }
  83. return conds
  84. }
  85. $(function(){
  86. $('.term-block').first().find('.delete-row').hide();
  87. $('#add-row').on('click', function(){
  88. var term = $('.term-block').last().clone(true, true);
  89. term.find('input[type="text"]').val('');
  90. term.find('select').val('');
  91. term.find('.delete-row').show();
  92. term.appendTo('#term-cont');
  93. });
  94. $('.delete-row').on('click', function(){
  95. $(this).closest('.term-block').remove();
  96. });
  97. $('#term-search-form').submit(function(ev) {
  98. $.ajax({
  99. type: 'POST',
  100. url: '',
  101. data: JSON.stringify({
  102. terms: format_fields(),
  103. logic: $('select[name="logic"]').val(),
  104. }),
  105. contentType: 'application/json; charset=utf-8',
  106. dataType: 'json',
  107. encode: true
  108. })
  109. .done(function(data) {
  110. //var cont = $('#search-results-wrap')
  111. $('#search-results-wrap').removeClass('bg-danger')
  112. .html('<h2>Search Results</h2>'
  113. + '<ul id="url-list"></ul>');
  114. for (url of data) {
  115. $('#url-list').append(
  116. '<li><a href="' + url + '">'
  117. + url + '</a></li>');
  118. }
  119. })
  120. .fail(function(data) {
  121. $('#search-results-wrap').addClass('bg-danger')
  122. .html(data.responseText);
  123. });
  124. ev.preventDefault();
  125. });
  126. });
  127. </script>
  128. {% endblock %}