index.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. <div id="vehicle_list">
  33. <label for="vehicle">Choose a vehicle:
  34. <select name="vehicle" id="vehicle" onchange="requestBranches(this.value);">
  35. {% for vehicle in get_vehicle_names() %}
  36. <option value="{{vehicle}}" {% if vehicle == get_default_vehicle_name() %} selected {% endif %}>{{vehicle}}</option>
  37. {% endfor %}
  38. </select>
  39. </label>
  40. </div>
  41. <p></p>
  42. <div id="branch_list"></div>
  43. <p></p>
  44. <div id="board_list"></div>
  45. <p></p>
  46. <div id="build_options"></div>
  47. <br>
  48. <input type="submit" value="Generate" id="submit" disabled>
  49. </form>
  50. </div>
  51. <hr>
  52. <p>Exisiting builds (click on the status of a build to view it):</p>
  53. <div id="build_status"></div>
  54. <br/>
  55. <script>
  56. function init() {
  57. refresh_builds();
  58. requestBranches(document.getElementById("vehicle").value);
  59. }
  60. function refresh_builds() {
  61. var output = document.getElementById('build_status');
  62. var xhr = new XMLHttpRequest();
  63. xhr.open('GET', "/builds/status.html");
  64. // disable cache, thanks to: https://stackoverflow.com/questions/22356025/force-cache-control-no-cache-in-chrome-via-xmlhttprequest-on-f5-reload
  65. xhr.setRequestHeader("Cache-Control", "no-cache, no-store, max-age=0");
  66. xhr.setRequestHeader("Expires", "Tue, 01 Jan 1980 1:00:00 GMT");
  67. xhr.setRequestHeader("Pragma", "no-cache");
  68. xhr.onload = function () {
  69. if (xhr.status === 200) {
  70. output.innerHTML = xhr.responseText;
  71. }
  72. setTimeout(refresh_builds, 5000)
  73. }
  74. xhr.send();
  75. }
  76. function requestBoardsAndFeatures(branch) {
  77. var xhr = new XMLHttpRequest();
  78. xhr.open('GET', '/boards_and_features/'+branch); // branch consists of both remote and branch_name in format - remote/branch_name. e.g. upstream/master
  79. document.getElementById('board_list').innerHTML = "<p>Please wait. Fetching boards on branch "+branch+" ...";
  80. document.getElementById('build_options').innerHTML = "<p>Please wait. Fetching build options on branch "+branch+" ...";
  81. document.getElementById("submit").disabled = true;
  82. document.getElementById("branch").disabled = true;
  83. xhr.onload = function () {
  84. if (xhr.status == 200) {
  85. response_json = JSON.parse(xhr.response);
  86. boards = response_json['boards'];
  87. default_board = response_json['default_board'];
  88. features = response_json['features'];
  89. fillBoards(boards, default_board);
  90. fillBuildOptions(features);
  91. document.getElementById("submit").disabled = false;
  92. } else {
  93. document.getElementById('board_list').innerHTML = "Something went wrong. Please try again. (Response says: "+xhr.response+")";
  94. document.getElementById('build_options').innerHTML = "";
  95. }
  96. document.getElementById("branch").disabled = false;
  97. }
  98. xhr.send();
  99. }
  100. function fillBoards(boards, default_board) {
  101. var output = document.getElementById('board_list');
  102. output.innerHTML = "<p>Please select the required options for the custom firmware build, then hit 'Generate'.</p>"+
  103. "<label for='board'>Choose a board: "+
  104. "<select name='board' id='board'>"+
  105. "</select>"+
  106. "</label>";
  107. boardList = document.getElementById("board")
  108. boards.forEach(board => {
  109. opt = document.createElement('option');
  110. opt.value = board;
  111. opt.innerHTML = board;
  112. opt.selected = (board === default_board);
  113. boardList.appendChild(opt);
  114. });
  115. }
  116. function fillBuildOptions(buildOptions) {
  117. var output = document.getElementById('build_options');
  118. output.innerHTML = "<label for='features'>Select Features: "+
  119. "<ul class='collapsibleList' id='outer_list'></ul>"+
  120. "</label>";
  121. outerList = document.getElementById("outer_list");
  122. buildOptions.forEach(category => {
  123. outerListItem = document.createElement('li');
  124. outerListItem.innerHTML = category['name'];
  125. innerList = document.createElement('ul');
  126. category['options'].forEach(option => {
  127. innerListItem = document.createElement('li');
  128. checkBox = document.createElement('input');
  129. checkBox.type = "checkbox";
  130. checkBox.name = option['label'];
  131. checkBox.id = option['label'];
  132. checkBox.value = "1";
  133. checkBox.checked = (option['default'] == 1);
  134. checkBox.addEventListener('click', function handleClick(event) {
  135. dependencies(option['label'], option['dependency']);
  136. });
  137. innerListItem.appendChild(checkBox);
  138. innerListItem.appendChild(document.createTextNode(option['description']));
  139. innerList.appendChild(innerListItem);
  140. });
  141. outerListItem.appendChild(innerList);
  142. outerList.appendChild(outerListItem);
  143. });
  144. CollapsibleLists.apply();
  145. }
  146. function dependencies(f_label, f_dependency1) {
  147. cb = document.getElementById(f_label);
  148. switch (cb.name) {
  149. case f_label:
  150. console.log("bol");
  151. const f_dependency = f_dependency1.split(",")
  152. var arrayLength = f_dependency.length;
  153. for (var i = 0; i < arrayLength; i++) {
  154. console.log(i);
  155. if (document.getElementById(f_dependency[i]).checked == false) {
  156. document.getElementById(f_dependency[i]).checked = cb.checked;
  157. }
  158. }
  159. break;
  160. }
  161. }
  162. function requestBranches(vehicle) {
  163. var xhr = new XMLHttpRequest();
  164. xhr.open('GET', '/get_allowed_branches/'+vehicle);
  165. document.getElementById("submit").disabled = true;
  166. document.getElementById("vehicle").disabled = true;
  167. xhr.onload = function () {
  168. if (xhr.status == 200) {
  169. response = JSON.parse(xhr.response);
  170. branches = response['branches'];
  171. default_branch = response['default_branch'];
  172. old_branch = document.getElementById("branch");
  173. fillBranches(branches);
  174. document.getElementById("submit").disabled = false;
  175. if (old_branch == null || old_branch.value != default_branch){
  176. // branch has changed
  177. // fetch boards and features again
  178. requestBoardsAndFeatures(default_branch);
  179. }
  180. } else {
  181. document.getElementById('branch_list').innerHTML = "Something went wrong. Please try again. (Response says: "+xhr.response+")";
  182. }
  183. document.getElementById("vehicle").disabled = false;
  184. }
  185. xhr.send();
  186. }
  187. function fillBranches(branches) {
  188. var output = document.getElementById('branch_list');
  189. output.innerHTML = "<label for='branch'>Choose a branch: "+
  190. "<select name='branch' id='branch' onchange='requestBoardsAndFeatures(this.value);'>"+
  191. "</select>"+
  192. "</label>";
  193. branchList = document.getElementById("branch");
  194. branches.forEach(branch => {
  195. opt = document.createElement('option');
  196. opt.value = branch['full_name'];
  197. opt.innerHTML = branch['label'];
  198. opt.selected = (branch['full_name'] === default_branch);
  199. branchList.appendChild(opt);
  200. });
  201. }
  202. </script>
  203. </div>
  204. </body>
  205. <hr>
  206. <footer>Created by Will Piper, <a href=https://github.com/ArduPilot/CustomBuild>Source Code</a>.</footer>
  207. </html>