command_line_builds.html 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. {% extends "base.html" %}
  2. {% load projecttags %}
  3. {% load humanize %}
  4. {% block title %} Import Builds from eventlogs - Toaster {% endblock %}
  5. {% block pagecontent %}
  6. <div class="container-fluid">
  7. <div id="overlay" class="hide">
  8. <div class="spinner">
  9. <div class="fa-spin">
  10. </div>
  11. </div>
  12. </div>
  13. <div class="row">
  14. <div class="col-md-12">
  15. <div class="page-header">
  16. <div class="row">
  17. <div class="col-md-6">
  18. <h1>Import command line builds</h1>
  19. </div>
  20. {% if import_all %}
  21. <div class="col-md-6">
  22. <button id="import_all" type="button" class="btn btn-primary navbar-btn navbar-right">
  23. <span class="glyphicon glyphicon-upload" style="vertical-align: top;"></span> Import All
  24. </button>
  25. </div>
  26. {% endif %}
  27. </div>
  28. </div>
  29. {% if messages %}
  30. <div class="row-fluid" id="empty-state-{{table_name}}">
  31. {% for message in messages %}
  32. <div class="alert alert-danger">{{message}}</div>
  33. {%endfor%}
  34. </div>
  35. {% endif %}
  36. <div class="row">
  37. <h4 style="margin-left: 15px;"><strong>Import eventlog file</strong></h4>
  38. <form method="POST" enctype="multipart/form-data" action="{% url 'cmdlines' %}" id="form_file">
  39. {% csrf_token %}
  40. <div class="col-md-6" style="padding-left: 20px;">
  41. <div class="row">
  42. <input type="hidden" value="{{dir}}" name="dir">
  43. <div class="col-md-3"> {{ form.eventlog_file}} </div>
  44. </div>
  45. <div class="row" style="padding-top: 10px;">
  46. <div class="col-md-6">
  47. <button id="file_import" type="submit" disabled="disabled" class="btn btn-default navbar-btn" >
  48. <span class="glyphicon glyphicon-upload" style="vertical-align: top;"></span> Import
  49. </button>
  50. </div>
  51. </div>
  52. </div>
  53. </form>
  54. </div>
  55. <div class="row" style="padding-top: 20px;">
  56. <div class="col-md-8 ">
  57. <h4><strong>Eventlogs from existing build directory: </strong>
  58. <a href="#" data-toggle="tooltip" title="{{dir}}">
  59. <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-info-circle" viewBox="0 0 16 16" data-toggle="tooltip">
  60. <path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14m0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16"/>
  61. <path d="m8.93 6.588-2.29.287-.082.38.45.083c.294.07.352.176.288.469l-.738 3.468c-.194.897.105 1.319.808 1.319.545 0 1.178-.252 1.465-.598l.088-.416c-.2.176-.492.246-.686.246-.275 0-.375-.193-.304-.533zM9 4.5a1 1 0 1 1-2 0 1 1 0 0 1 2 0"/>
  62. </svg>
  63. </a>
  64. </h4>
  65. {% if files %}
  66. <div class="table-responsive">
  67. <table class="table col-md-6 table-bordered table-hover">
  68. <thead>
  69. <tr class="row">
  70. <th scope="col">Name</th>
  71. <th scope="col">Size</th>
  72. <th scope="col">Action</th>
  73. </tr>
  74. </thead>
  75. <tbody>
  76. {% for file in files %}
  77. <tr class="row" style="height: 48px;">
  78. <th scope="row" class="col-md-4" style="vertical-align: middle;">
  79. <input type="hidden" value="{{file.name}}" name="{{file.name}}">{{file.name}}
  80. </th>
  81. <td class="col-md-4 align-middle" style="vertical-align: middle;">{{file.size|filesizeformat}}</td>
  82. <td class="col-md-4 align-middle" style="vertical-align: middle;">
  83. {% if file.imported == True and file.build_id is not None %}
  84. <a href="{% url 'builddashboard' file.build_id %}">Build Details</a>
  85. {% elif request.session.file == file.name or request.session.all_builds %}
  86. <a data-toggle="tooltip" title="Build in progress">
  87. <span class="glyphicon glyphicon-upload" style="font-size: 18px; color:grey"></span>
  88. </a>
  89. {%else%}
  90. <a onclick="_ajax_update('{{file.name}}', false, '{{dir}}')" data-toggle="tooltip" title="Import File">
  91. <span class="glyphicon glyphicon-upload" style="font-size: 18px;"></span>
  92. </a>
  93. {%endif%}
  94. </td>
  95. </tr>
  96. {% endfor%}
  97. </tbody>
  98. </table>
  99. </div>
  100. {% else %}
  101. <div class="row-fluid" id="empty-state-{{table_name}}">
  102. <div class="alert alert-info">Sorry - no files found</div>
  103. </div>
  104. {%endif%}
  105. </div>
  106. </div>
  107. </div>
  108. </div>
  109. </div>
  110. <script>
  111. function _ajax_update(file, all, dir){
  112. function getCookie(name) {
  113. var cookieValue = null;
  114. if (document.cookie && document.cookie !== '') {
  115. var cookies = document.cookie.split(';');
  116. for (var i = 0; i < cookies.length; i++) {
  117. var cookie = jQuery.trim(cookies[i]);
  118. // Does this cookie string begin with the name we want?
  119. if (cookie.substring(0, name.length + 1) === (name + '=')) {
  120. cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
  121. break;
  122. }
  123. }
  124. }
  125. return cookieValue;
  126. }
  127. var csrftoken = getCookie('csrftoken');
  128. function csrfSafeMethod(method) {
  129. // these HTTP methods do not require CSRF protection
  130. return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
  131. }
  132. $.ajaxSetup({
  133. beforeSend: function (xhr, settings) {
  134. if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
  135. xhr.setRequestHeader("X-CSRFToken", csrftoken);
  136. }
  137. }
  138. });
  139. $.ajax({
  140. url:'/toastergui/cmdline/',
  141. type: "POST",
  142. data: {file: file, all: all, dir: dir},
  143. success:function(data){
  144. window.location = '/toastergui/builds/'
  145. },
  146. complete:function(data){
  147. },
  148. error:function (xhr, textStatus, thrownError){
  149. console.log('fail');
  150. }
  151. });
  152. }
  153. $('#import_all').on('click', function(){
  154. _ajax_update("{{files | safe}}", true, "{{dir | safe}}");
  155. });
  156. $('#import_page').hide();
  157. $(function () {
  158. $('[data-toggle="tooltip"]').tooltip()
  159. })
  160. $("#id_eventlog_file").change(function(){
  161. $('#file_import').prop("disabled", false);
  162. $('#file_import').addClass('btn-primary')
  163. $('#file_import').removeClass('btn-default')
  164. })
  165. $(document).ajaxStart(function(){
  166. $('#overlay').removeClass('hide');
  167. window.setTimeout(
  168. function() {
  169. window.location = '/toastergui/builds/'
  170. }, 10000)
  171. });
  172. $( "#form_file").on( "submit", function( event ) {
  173. $('#overlay').removeClass('hide');
  174. window.setTimeout(
  175. function() {
  176. window.location = '/toastergui/builds/'
  177. }, 10000)
  178. });
  179. </script>
  180. {% endblock %}