Commit 237afd5d authored by svilayphiou's avatar svilayphiou
Browse files

A first test page to retrieve the tree, all the commits, the iceberg, the...

A first test page to retrieve the tree, all the commits, the iceberg, the readme and the whole history of one file
parent e14c0a58
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Commits</title>
<style>
.tree:before {
content: "█";
}
img {
max-width: 200px;
max-height: 200px;
}
</style>
</head>
<body>
<h1>Contour</h1>
<h2>File history</h2>
<div id="file_history"></div>
<h2>Tree</h2>
<ul id="tree"></ul>
<h2>README</h2>
<div id="readme"></div>
<h2>ICEBERG</h2>
<div id="iceberg"></div>
<h2>Commits</h2>
<ul id="commits"></ul>
<script type="text/javascript" charset="utf-8">
// BEGIN DIFF
const file_elt = document.querySelector('#file_history');
const file_path = 'communication%2Fbanners%2Fbanner-eflux.png';
const file_commits_url = "https://gitlab.constantvzw.org/api/v4/projects/456/repository/commits?path=" + file_path;
fetch(file_commits_url)
.then((resp) => resp.json())
.then(function(data){
return data.map(function(file) {
blob_id = file.id;
const commit_url = "https://gitlab.constantvzw.org/api/v4/projects/456/repository/files/" + file_path + "?ref=" + blob_id;
fetch(commit_url)
.then((resp) => resp.json())
.then(function(data){
let img = document.createElement('img');
img.src = 'data:image/jpeg;base64,' + data['content'];
file_elt.appendChild(img);
});
});
});
// BEGIN TREE
const tree_elt = document.querySelector('#tree');
const tree_url = "https://gitlab.constantvzw.org/api/v4/projects/456/repository/tree";
var README = "";
fetch(tree_url)
.then((resp) => resp.json())
.then(function(data){
return data.map(function(file) {
let li = document.createElement('li');
li.classList.add(file.type);
li.innerHTML = file.name;
tree_elt.appendChild(li);
// README
if (file.name == "README.md"){
README = file.id;
const readme_elt = document.querySelector('#readme');
const readme_url = "https://gitlab.constantvzw.org/api/v4/projects/456/repository/blobs/" + README + "/raw";
fetch(readme_url)
.then((resp) => resp.text())
.then(function(data){
readme_elt.innerHTML = data;
})
}
// ICEBERG
if (file.name == "iceberg"){
iceberg = file.id;
const iceberg_elt = document.querySelector('#iceberg');
const iceberg_url = "https://gitlab.constantvzw.org/api/v4/projects/456/repository/tree/?path=iceberg";
fetch(iceberg_url)
.then((resp) => resp.json())
.then(function(data){
return data.map(function(iceberg) {
let img = document.createElement('img');
img.src = "https://gitlab.constantvzw.org/osp/work.contour/raw/master/" + iceberg.path;
iceberg_elt.appendChild(img);
});
})
}
})
})
.catch(function(error) {
console.log(JSON.stringify(error));
});
// END TREE
//
// BEGIN COMMITS
let commits_url = "https://gitlab.constantvzw.org/api/v4/projects/456/repository/commits?per_page=100";
let page = 1;
var pages;
function getAllCommits(){
const commits_elt = document.querySelector('#commits');
commits_url = "https://gitlab.constantvzw.org/api/v4/projects/456/repository/commits?per_page=100&page=" + page;
fetch(commits_url)
.then(function(resp){
pages = resp.headers.get("X-Total-Pages");
return resp.json();
})
.then(function(data){
return data.map(function(commit) {
let li = document.createElement('li'),
time = document.createElement('time'),
msg = document.createElement('p'),
author = document.createElement('p');
msg.classList.add("msg");
author.classList.add("author");
time.innerHTML = commit.created_at;
msg.innerHTML = commit.message;
author.innerHTML = commit.author_name;
li.appendChild(time);
li.appendChild(msg);
li.appendChild(author);
commits_elt.appendChild(li);
})
})
.then(function(){
if (page < pages){
page += 1;
commits_url = "https://gitlab.constantvzw.org/api/v4/projects/456/repository/commits?per_page=100&page=" + page;
getAllCommits();
}
})
//.catch(function(error) {
// console.log(JSON.stringify(error));
//});
}
getAllCommits();
// END COMMITS
</script>
</body>
</html>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment