gitlabculture
clone your own copy | download snapshot

Snapshots | iceberg

No images in this repository’s iceberg at this time

Inside this repository

contour.html
text/html

Download raw (7.9 KB)

<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">

    <title>Contour</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>BLOB</h2>
	<div id="blob"></div>

	<h2>ICEBERG</h2>
	<div id="iceberg"></div>

	<h2>Commits</h2>
	<ul id="commits"></ul>


    <script type="text/javascript" charset="utf-8">
        var gitlab_url = "http://gitlab.constantvzw.org";
        var user_name = "osp";
        var project_name = "work.contour";

        var this_url = new URL(window.location.href);

        // 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;
        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);
                });
            });
        });

        // 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";
            const blob_elt = document.querySelector('#blob');
            fetch(blob_url)
            .then((resp) => resp.blob())
            .then(function(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);
                } 
                // if TXT, SVG, code...
                else if (mime == "text/plain" | mime == "image/svg+xml") {
                    var reader = new FileReader();
                    reader.onloadend=function(){
                        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;
                raw.innerHTML = 'Download raw file.';
                raw.download = name;
                raw.target = '_blank';
                blob_elt.appendChild(raw);
            })
        } 

        // 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('/');
        } else {
            var path = this_url.searchParams.get("path");
        }
        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;
            // 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);
        }
        // IF ROOT FOLDER
        else {
            var tree_url = "https://gitlab.constantvzw.org/api/v4/projects/456/repository/tree";
        }

        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);
                if (file.type == 'tree') {
                    li.innerHTML = "<a href='?path=" + file.path + "' >" + file.name + "</a>";
                } else {
                    li.innerHTML = "<a href='?path=" + file.path + "&blob=" + file.id + "' >" + file.name + "</a>";
                }
                tree_elt.appendChild(li);


                // ICEBERG
                //if (file.name == "iceberg"){
                //    iceberg = fil4.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
          
        // 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>