Commit abd9d112 authored by svilayphiou's avatar svilayphiou
Browse files

Put javascript into an external file.

parent a13c43b5
//var filterTree = new Vue({
// el: '#filter-tree',
// data: {
// name: 'Vue.js'
// },
// // define methods under the `methods` object
// methods: {
// greet: function (event) {
// // `this` inside methods points to the Vue instance
// alert('Hello ' + this.name + '!')
// // `event` is the native DOM event
// if (event) {
// alert(event.target.tagName)
// }
// }
// }
//})
// T R E E
const hiddenFile = /^\./;
var fileList = [];
var formerTree = [];
var blobHistory = [];
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){
return data.map(function(file) {
if (! file["name"].match(hiddenFile)) {
fileList.push(file);
}
})
})
var treeApp = new Vue({
el: '#tree',
data: {
fileList,
upPath: "/",
blobItem: "",
blobHistory
},
delimiters: ['[[',']]'],
methods: {
tree: function(type, path, blobID){
vm = this;
if (type == "tree") {
currentPath = path;
var treeURL = "https://gitlab.constantvzw.org/api/v4/projects/" + repoID + "/repository/tree?per_page=100&path="+ path;
vm.fileList.splice(0);
fetch(treeURL).then(function(resp){ return resp.json(); })
.then(function(data){
return data.map(function(file) {
if (! file["name"].match(hiddenFile)) {
vm.fileList.push(file);
}
})
})
} else if (type == "up") {
upPath = currentPath.split("/");
upPath.pop();
currentPath = upPath.join("");
var treeURL = "https://gitlab.constantvzw.org/api/v4/projects/" + repoID + "/repository/tree?per_page=100&path="+ upPath;
vm.fileList.splice(0);
fetch(treeURL).then(function(resp){ return resp.json(); })
.then(function(data){
return data.map(function(file) {
if (! file["name"].match(hiddenFile)) {
vm.fileList.push(file);
}
})
})
} else if (type == "blob") {
let blobURL = "https://gitlab.constantvzw.org/api/v4/projects/" + repoID + "/repository/blobs/" + blobID + "/raw";
fetch(blobURL).then((resp) => resp.blob())
.then(function(data){
// FILENAME
h4 = "<h4>" + path + "</h4>"
// DOWNLOAD RAW FILE
project_path = [gitlabURL, user_name, projectName].join('/');
href = project_path + "/raw/master/" + path;
a = '<p><a download href="' + href + '">Download file</a></p>';
var mime = data["type"];
// if PNG, JPG, or GIF
if(mime == "image/png" | mime == "image/jpeg" | mime == "image/jpg" | mime == "image/gif") {
// DIFF: SHOWS ALL VERSIONS OF ONE PICTURE ////////////////////////////////////
const file_commits_url = "https://gitlab.constantvzw.org/api/v4/projects/" + repoID + "/repository/commits?path=" + 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/" + repoID + "/repository/files/" + path.replace(/\//g, "%2F") + "?ref=" + blob_id;
fetch(commit_url)
.then((resp) => resp.json())
.then(function(data){
img = 'data:image/jpeg;base64,' + data['content'];
blobHistory.push(img);
});
log(blobHistory)
});
});
vm.blobItem = h4 + a + "<img src='" + blobURL+ "'i>";
}
// if TXT, SVG, code...
else if (mime == "text/plain" | mime == "image/svg+xml") {
var reader = new FileReader();
reader.readAsText(data);
reader.onloadend=function(){
vm.blobItem = h4 + a + reader.result;
};
}
else {
vm.blobItem = h4 + a;
}
})
}
},
}
})
// I M A G E S
var icebergList = [];
var processusList = [];
let icebergURL = "https://gitlab.constantvzw.org/api/v4/projects/" + repoID + "/repository/tree?path=iceberg";
let processusURL = "https://gitlab.constantvzw.org/api/v4/projects/" + repoID + "/repository/tree?path=processus";
getImages(repoID, icebergURL, icebergList);
getImages(repoID, processusURL, processusList);
var icebergApp = new Vue({
el: '#iceberg',
data: {
icebergList
}
})
var processusApp = new Vue({
el: '#processus',
data: {
processusList
}
})
function getImages(repoID, apiURL, imageList){
fetch(apiURL).then(function(resp){ return resp.json(); })
.then(function(data){
return data.map(function(image) {
item = {};
item.name = image.name;
project_path = [gitlabURL, user_name, projectName].join('/');
item.src = project_path + "/raw/" + projectBranch + "/" + image.path;
imageList.push(item);
})
});
}
......@@ -84,174 +84,9 @@
var gitlabURL = "http://gitlab.constantvzw.org";
var user_name = "osp";
var repoID = {{ project.id }};
//var filterTree = new Vue({
// el: '#filter-tree',
// data: {
// name: 'Vue.js'
// },
// // define methods under the `methods` object
// methods: {
// greet: function (event) {
// // `this` inside methods points to the Vue instance
// alert('Hello ' + this.name + '!')
// // `event` is the native DOM event
// if (event) {
// alert(event.target.tagName)
// }
// }
// }
//})
// T R E E
const hiddenFile = /^\./;
var fileList = [];
var formerTree = [];
var blobHistory = [];
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){
return data.map(function(file) {
if (! file["name"].match(hiddenFile)) {
fileList.push(file);
}
})
})
var treeApp = new Vue({
el: '#tree',
data: {
fileList,
upPath: "/",
blobItem: "",
blobHistory
},
delimiters: ['[[',']]'],
methods: {
tree: function(type, path, blobID){
vm = this;
if (type == "tree") {
currentPath = path;
var treeURL = "https://gitlab.constantvzw.org/api/v4/projects/" + repoID + "/repository/tree?per_page=100&path="+ path;
vm.fileList.splice(0);
fetch(treeURL).then(function(resp){ return resp.json(); })
.then(function(data){
return data.map(function(file) {
if (! file["name"].match(hiddenFile)) {
vm.fileList.push(file);
}
})
})
} else if (type == "up") {
upPath = currentPath.split("/");
upPath.pop();
currentPath = upPath.join("");
var treeURL = "https://gitlab.constantvzw.org/api/v4/projects/" + repoID + "/repository/tree?per_page=100&path="+ upPath;
vm.fileList.splice(0);
fetch(treeURL).then(function(resp){ return resp.json(); })
.then(function(data){
return data.map(function(file) {
if (! file["name"].match(hiddenFile)) {
vm.fileList.push(file);
}
})
})
} else if (type == "blob") {
let blobURL = "https://gitlab.constantvzw.org/api/v4/projects/" + repoID + "/repository/blobs/" + blobID + "/raw";
fetch(blobURL).then((resp) => resp.blob())
.then(function(data){
// FILENAME
h4 = "<h4>" + path + "</h4>"
// DOWNLOAD RAW FILE
project_path = [gitlabURL, user_name, '{{ project.name }}'].join('/');
href = project_path + "/raw/master/" + path;
a = '<p><a download href="' + href + '">Download file</a></p>';
var mime = data["type"];
// if PNG, JPG, or GIF
if(mime == "image/png" | mime == "image/jpeg" | mime == "image/jpg" | mime == "image/gif") {
// DIFF: SHOWS ALL VERSIONS OF ONE PICTURE ////////////////////////////////////
const file_commits_url = "https://gitlab.constantvzw.org/api/v4/projects/" + repoID + "/repository/commits?path=" + 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/" + repoID + "/repository/files/" + path.replace(/\//g, "%2F") + "?ref=" + blob_id;
fetch(commit_url)
.then((resp) => resp.json())
.then(function(data){
img = 'data:image/jpeg;base64,' + data['content'];
blobHistory.push(img);
});
console.log(blobHistory)
});
});
vm.blobItem = h4 + a + "<img src='" + blobURL+ "'i>";
}
// if TXT, SVG, code...
else if (mime == "text/plain" | mime == "image/svg+xml") {
var reader = new FileReader();
reader.readAsText(data);
reader.onloadend=function(){
vm.blobItem = h4 + a + reader.result;
};
}
else {
vm.blobItem = h4 + a;
}
})
}
},
}
})
// I M A G E S
var icebergList = [];
var processusList = [];
let icebergURL = "https://gitlab.constantvzw.org/api/v4/projects/" + repoID + "/repository/tree?path=iceberg";
let processusURL = "https://gitlab.constantvzw.org/api/v4/projects/" + repoID + "/repository/tree?path=processus";
getImages(repoID, icebergURL, icebergList);
getImages(repoID, processusURL, processusList);
var icebergApp = new Vue({
el: '#iceberg',
data: {
icebergList
}
})
var processusApp = new Vue({
el: '#processus',
data: {
processusList
}
})
function getImages(repoID, apiURL, imageList){
fetch(apiURL).then(function(resp){ return resp.json(); })
.then(function(data){
return data.map(function(image) {
item = {};
item.name = image.name;
project_path = [gitlabURL, user_name, "{{ project.name }}"].join('/');
item.src = project_path + "/raw/{{ project.default_branch }}/" + image.path;
imageList.push(item);
})
});
}
var projectName = "{{ project.name }}";
var projectBranch = "{{ project.default_branch }}";
</script>
<script src="/static/js/project.js" type="text/javascript" charset="utf-8"></script>
{% endblock script %}
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