index.html 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>ArduPilot Custom Firmware Builder</title>
  6. <meta name="description"
  7. content="ArduPilot Custom Firmware Builder. It allows to build custom ArduPilot firmware by selecting the wanted features.">
  8. <meta name="author" content="ArduPilot Team">
  9. <meta name="viewport" content="width=device-width, initial-scale=1">
  10. <!-- OG Meta Tags to improve the way the post looks when you share the page on LinkedIn, Facebook, Google+ -->
  11. <meta property="og:site_name" content="ArduPilot"/>
  12. <meta property="og:site" content=""/>
  13. <meta property="og:title" content="ArduPilot Custom Firmware Builder"/>
  14. <meta property="og:description"
  15. content="ArduPilot Custom Firmware Builder. It allows to build custom ArduPilot firmware by selecting the wanted features."/>
  16. <!-- description shown in the actual shared post -->
  17. <meta property="og:type" content="website">
  18. <meta property="og:url" content="https://custom.ardupilot.org/">
  19. <meta property="og:image" content="https://ardupilot.org/application/files/6315/7552/1962/ArduPilot-Motto.png">
  20. <link rel="stylesheet" type="text/css" href="{{ url_for('static',filename='styles/main.css') }}">
  21. <script type="text/javascript" src="{{ url_for('static', filename='js/CollapsibleLists.js')}}"></script>
  22. </head>
  23. <body onload="javascript: init()">
  24. <div id="main">
  25. <a href="https://custom.ardupilot.org/">
  26. <div id="logo">
  27. </div>
  28. </a>
  29. <div id="menu">
  30. <h2>ArduPilot Custom Firmware Builder</h2>
  31. <form action="/generate" method="post">
  32. <label for="branch">Choose a branch:
  33. <select name="branch" id="branch" onchange="requestBoardsAndFeatures(this.value);">
  34. {% for branch in get_branches() %}
  35. <option value="{{branch}}" {% if branch == get_default_branch() %} selected {% endif %}>{{get_branches()[branch]}}</option>
  36. {% endfor %}
  37. </select>
  38. </label>
  39. <p></p>
  40. <label for="vehicle">Choose a vehicle:
  41. <select name="vehicle" id="vehicle">
  42. {% for vehicle in get_vehicles() %}
  43. <option value="{{vehicle}}" {% if vehicle == get_default_vehicle() %} selected {% endif %}>{{vehicle}}</option>
  44. {% endfor %}
  45. </select>
  46. </label>
  47. <div id="board_list"></div>
  48. <p></p>
  49. <div id="build_options"></div>
  50. <br>
  51. <input type="submit" value="Generate" id="submit" disabled>
  52. </form>
  53. </div>
  54. <hr>
  55. <p>Exisiting builds (click on the status of a build to view it):</p>
  56. <div id="build_status"></div>
  57. <br/>
  58. <script>
  59. function init() {
  60. refresh_builds();
  61. requestBoardsAndFeatures(document.getElementById('branch').value);
  62. }
  63. function refresh_builds() {
  64. var output = document.getElementById('build_status');
  65. var xhr = new XMLHttpRequest();
  66. xhr.open('GET', "/builds/status.html");
  67. // disable cache, thanks to: https://stackoverflow.com/questions/22356025/force-cache-control-no-cache-in-chrome-via-xmlhttprequest-on-f5-reload
  68. xhr.setRequestHeader("Cache-Control", "no-cache, no-store, max-age=0");
  69. xhr.setRequestHeader("Expires", "Tue, 01 Jan 1980 1:00:00 GMT");
  70. xhr.setRequestHeader("Pragma", "no-cache");
  71. xhr.onload = function () {
  72. if (xhr.status === 200) {
  73. output.innerHTML = xhr.responseText;
  74. }
  75. setTimeout(refresh_builds, 5000)
  76. }
  77. xhr.send();
  78. }
  79. function requestBoardsAndFeatures(branch) {
  80. var xhr = new XMLHttpRequest();
  81. xhr.open('GET', '/boards_and_features/'+branch); // branch consists of both remote and branch_name in format - remote/branch_name. e.g. upstream/master
  82. document.getElementById('board_list').innerHTML = "<p>Please wait. Fetching boards on branch "+branch+" ...";
  83. document.getElementById('build_options').innerHTML = "<p>Please wait. Fetching build options on branch "+branch+" ...";
  84. document.getElementById("submit").disabled = true;
  85. xhr.onload = function () {
  86. if (xhr.status == 200) {
  87. response_json = JSON.parse(xhr.response);
  88. boards = response_json['boards'];
  89. default_board = response_json['default_board'];
  90. features = response_json['features'];
  91. fillBoards(boards, default_board);
  92. fillBuildOptions(features);
  93. document.getElementById("submit").disabled = false;
  94. }
  95. }
  96. xhr.send();
  97. }
  98. function fillBoards(boards, default_board) {
  99. var output = document.getElementById('board_list');
  100. output.innerHTML = "<p>Please select the required options for the custom firmware build, then hit 'Generate'.</p>"+
  101. "<label for='board'>Choose a board: "+
  102. "<select name='board' id='board'>"+
  103. "</select>"+
  104. "</label>";
  105. boardList = document.getElementById("board")
  106. boards.forEach(board => {
  107. opt = document.createElement('option');
  108. opt.value = board;
  109. opt.innerHTML = board;
  110. opt.selected = (board === default_board);
  111. boardList.appendChild(opt);
  112. });
  113. }
  114. function fillBuildOptions(buildOptions) {
  115. var output = document.getElementById('build_options');
  116. output.innerHTML = "<label for='features'>Select Features: "+
  117. "<ul class='collapsibleList' id='outer_list'></ul>"+
  118. "</label>";
  119. outerList = document.getElementById("outer_list");
  120. buildOptions.forEach(category => {
  121. outerListItem = document.createElement('li');
  122. outerListItem.innerHTML = category['name'];
  123. innerList = document.createElement('ul');
  124. category['options'].forEach(option => {
  125. innerListItem = document.createElement('li');
  126. checkBox = document.createElement('input');
  127. checkBox.type = "checkbox";
  128. checkBox.name = option['label'];
  129. checkBox.id = option['label'];
  130. checkBox.value = "1";
  131. checkBox.checked = (option['default'] == 1);
  132. checkBox.addEventListener('click', function handleClick(event) {
  133. dependencies(option['label'], option['dependency']);
  134. });
  135. innerListItem.appendChild(checkBox);
  136. innerListItem.appendChild(document.createTextNode(option['description']));
  137. innerList.appendChild(innerListItem);
  138. });
  139. outerListItem.appendChild(innerList);
  140. outerList.appendChild(outerListItem);
  141. });
  142. CollapsibleLists.apply();
  143. }
  144. function dependencies(f_label, f_dependency1) {
  145. cb = document.getElementById(f_label);
  146. switch (cb.name) {
  147. case f_label:
  148. console.log("bol");
  149. const f_dependency = f_dependency1.split(",")
  150. var arrayLength = f_dependency.length;
  151. for (var i = 0; i < arrayLength; i++) {
  152. console.log(i);
  153. if (document.getElementById(f_dependency[i]).checked == false) {
  154. document.getElementById(f_dependency[i]).checked = cb.checked;
  155. }
  156. }
  157. break;
  158. }
  159. }
  160. </script>
  161. </div>
  162. </body>
  163. <hr>
  164. <footer>Created by Will Piper, <a href=https://github.com/ArduPilot/CustomBuild>Source Code</a>.</footer>
  165. </html>