Commit da89f926 authored by svilayphiou's avatar svilayphiou
Browse files

blob reading as plain text

parent b6df53c3
......@@ -40,14 +40,13 @@
<h3>Tree</h3>
<ul v-for="blob in fileList">
<li v-bind:class="blob.type">
<a v-on:click.prevent="folder(blob.path)" href="#">
<!-- v-on:click.prevent="file(blob.id)" -->
<a v-on:click.prevent="tree(blob.type, blob.path, blob.id)" href="#">
<span v-if="blob.type === 'tree'"></span>
[[ blob.name ]]
</a>
</li>
</ul>
<div id="blob">
<div id="blob" :key="bloup">
[[ bloup ]]
</div>
</section>
......@@ -101,7 +100,6 @@
// T R E E
var fileList = [];
var bloup = "*";
var treeURL = "https://gitlab.constantvzw.org/api/v4/projects/" + repoID + "/repository/tree?per_page=100";
fetch(treeURL).then(function(resp){ return resp.json(); })
.then(function(data){
......@@ -114,37 +112,34 @@
el: '#tree',
data: {
fileList,
bloup
bloup: "?"
},
delimiters: ['[[',']]'],
methods: {
folder: function(path){
var treeURL = "https://gitlab.constantvzw.org/api/v4/projects/" + repoID + "/repository/tree?per_page=100&path="+ path;
console.log(fileList);
fileList.splice(0);
console.log(fileList);
fetch(treeURL).then(function(resp){ return resp.json(); })
.then(function(data){
console.log("ok");
return data.map(function(file) {
fileList.push(file);
})
})
tree: function(type, path, blobID){
vm = this;
if (type == "tree") {
var treeURL = "https://gitlab.constantvzw.org/api/v4/projects/" + repoID + "/repository/tree?per_page=100&path="+ path;
fileList.splice(0);
fetch(treeURL).then(function(resp){ return resp.json(); })
.then(function(data){
return data.map(function(file) {
fileList.push(file);
})
})
} else {
let blobURL = "https://gitlab.constantvzw.org/api/v4/projects/" + repoID + "/repository/blobs/" + blobID + "/raw";
fetch(blobURL).then((resp) => resp.blob())
.then(function(data){
var reader = new FileReader();
reader.readAsText(data);
reader.onloadend=function(){
vm.bloup = reader.result;
};
})
}
},
file: function(blobID){
console.log(this);
let blobURL = "https://gitlab.constantvzw.org/api/v4/projects/" + repoID + "/repository/blobs/" + blobID + "/raw";
console.log(blobURL);
fetch(blobURL).then((resp) => resp.blob())
.then(function(data){
console.log(data)
var reader = new FileReader();
reader.readAsText(data);
reader.onloadend=function(){
bloup = reader.result;
};
console.log(bloup);
})
}
}
})
......
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