Add branch selector
This commit is contained in:
parent
d91d766654
commit
59acf38f5d
47
index.html
47
index.html
@ -9,7 +9,11 @@
|
||||
<p>
|
||||
<input type="button" value="Test Requests" onclick="test_request()" />
|
||||
</p>
|
||||
<h1>Render a Rule</h1>
|
||||
<h3><label for="branch-name-selector">Repository branch</label></h3>
|
||||
<select id="branch-name-selector" onchange="onChangeBranch(this.value)">
|
||||
<!-- dynamically filled by initBranchNameSelector() -->
|
||||
</select>
|
||||
<h3>Render a Rule</h3>
|
||||
<select onchange="renderRule(this.value)">
|
||||
<option value="">--Please choose a rule--</option>
|
||||
<option value="S3457/c-family">S3457/c-family</option>
|
||||
@ -21,6 +25,35 @@
|
||||
</body>
|
||||
<script src="asciidoctor/asciidoctor.js"></script>
|
||||
<script>
|
||||
function init() {
|
||||
initBranchNameSelector();
|
||||
}
|
||||
|
||||
function initBranchNameSelector() {
|
||||
let selectElement = document.getElementById("branch-name-selector");
|
||||
httpGetGithubApi("/repos/SonarSource/rspec/branches", function(body) {
|
||||
let branchList = JSON.parse(body);
|
||||
for (let i = 0; i < branchList.length; i++) {
|
||||
let branchName = branchList[i].name;
|
||||
addSelectOption(selectElement, branchName, branchName);
|
||||
if (branchName === "master") {
|
||||
selectElement.selectedIndex = i;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function addSelectOption(/*object*/selectElement, /*string*/value, /*string*/text) {
|
||||
const opt = document.createElement('option');
|
||||
opt.appendChild(document.createTextNode(text));
|
||||
opt.value = value;
|
||||
selectElement.appendChild(opt);
|
||||
}
|
||||
|
||||
function onChangeBranch(/*string*/branchName) {
|
||||
|
||||
}
|
||||
|
||||
function renderRule(/*string*/ruleId) {
|
||||
if (ruleId === "") {
|
||||
document.getElementById("div-result").innerHTML = "";
|
||||
@ -36,10 +69,13 @@
|
||||
});
|
||||
}
|
||||
|
||||
function httpGet(/*string*/url, /*function*/bodyConsumer) /*void*/ {
|
||||
function httpGet(/*string*/url, /*function*/bodyConsumer, /*string?*/accept) /*void*/ {
|
||||
if (typeof accept === "undefined") {
|
||||
accept = "*";
|
||||
}
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', url, true);
|
||||
xhr.setRequestHeader("Accept", "*");
|
||||
xhr.setRequestHeader("Accept", accept);
|
||||
xhr.onreadystatechange = function() {
|
||||
if(xhr.readyState === 4) {
|
||||
if (xhr.status === 0 /*local files*/ || xhr.status === 200) {
|
||||
@ -52,8 +88,9 @@
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
function init() {
|
||||
|
||||
function httpGetGithubApi(/*string*/relativeUrl, /*function*/bodyConsumer) {
|
||||
const url = "https://api.github.com" + relativeUrl;
|
||||
httpGet(url, bodyConsumer, "application/vnd.github.v3.html");
|
||||
}
|
||||
|
||||
function test_request() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user