Commit 6d7284b2 authored by svilayphiou's avatar svilayphiou
Browse files

commenting my mess

parent 44a7308c
......@@ -41,7 +41,7 @@
var this_url = new URL(window.location.href);
// BEGIN DIFF
// DIFF: SHOWS ALL VERSIONS OF ONE PICTURE ////////////////////////////////////
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;
......@@ -61,32 +61,33 @@
});
});
// BLOB
// BLOB //////////////////////////////////////
var blob = this_url.searchParams.get("blob");
var path = this_url.searchParams.get("path");
if (blob){
var blob_url = "https://gitlab.constantvzw.org/api/v4/projects/456/repository/blobs/" + blob + "/raw";
console.log(blob_url);
const blob_elt = document.querySelector('#blob');
fetch(blob_url)
.then((resp) => resp.blob())
.then(function(data){
console.log(data);
var mime = data["type"];
// if PNG, JPG, or GIF
if(mime == "image/png" | mime == "image/jpg" | mime == "image/gif") {
let img = document.createElement('img');
img.src = blob_url;
blob_elt.appendChild(img);
} else if (mime == "text/plain" | mime == "image/svg+xml") {
}
// if TXT, SVG, code...
else if (mime == "text/plain" | mime == "image/svg+xml") {
var reader = new FileReader();
reader.onloadend=function(){
console.log(reader.result);
blob_elt.innerHTML = reader.result;
};
reader.readAsText(data);
}
// DOWNLOAD RAW FILE
let raw = document.createElement('a');
project_path = [gitlab_url, user_name, project_name].join('/');
raw.href = project_path + "/raw/master/" + path;
......@@ -97,7 +98,8 @@ console.log(data);
})
}
// BEGIN TREE
// TREE ////////////////////////////////////////////////////
// IF WE'RE LOOKING AT A BLOB, OUTPUTS THE CURRENT TREE
if (blob) {
var path = this_url.searchParams.get("path");
path = path.split('/').slice(0, -1).join('/');
......@@ -106,15 +108,20 @@ console.log(data);
}
const tree_elt = document.querySelector('#tree');
if(path) {
// IF SUBFOLDER
var tree_url = "https://gitlab.constantvzw.org/api/v4/projects/456/repository/tree?path=" + path;
let h3 = document.createElement('h3');
h3.innerHTML = "You're visiting: " + path;
tree_elt.appendChild(h3);
// BREADCRUMB
let breadcrumb = document.createElement('h3');
breadcrumb.innerHTML = "You're visiting: " + path;
tree_elt.appendChild(breadcrumb);
// LINK TO PREVIOUS FOLDER
previous_path = path.split('/').slice(0, -1).join('/');
let li = document.createElement('li');
li.innerHTML = "<a href='?path=" + previous_path + "'>..</a>";
tree_elt.appendChild(li);
} else {
}
// IF ROOT FOLDER
else {
var tree_url = "https://gitlab.constantvzw.org/api/v4/projects/456/repository/tree";
}
......@@ -127,7 +134,6 @@ console.log(data);
if (file.type == 'tree') {
li.innerHTML = "<a href='?path=" + file.path + "' >" + file.name + "</a>";
} else {
console.log(file.path);
li.innerHTML = "<a href='?path=" + file.path + "&blob=" + file.id + "' >" + file.name + "</a>";
}
tree_elt.appendChild(li);
......@@ -155,7 +161,7 @@ console.log(data);
});
// END TREE
// BEGIN COMMITS
// COMMITS ///////////////////////////////
let commits_url = "https://gitlab.constantvzw.org/api/v4/projects/456/repository/commits?per_page=100";
let page = 1;
var pages;
......
Supports Markdown
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