Browse Source

Initial commit: Working status monitor archive

2xB 2 years ago
commit
ebf8099c53
3 changed files with 191 additions and 0 deletions
  1. 41 0
      index.css
  2. 35 0
      index.html
  3. 115 0
      index.js

+ 41 - 0
index.css

@@ -0,0 +1,41 @@
+body {
+  position: absolute;
+  height: 100%;
+  width: 100%;
+  display: grid;
+  grid-template-rows: auto 1fr auto;
+  margin: 0;
+}
+
+/*
+header, footer {
+  background: #c4d8ff;
+  color: #032363;
+}
+*/
+
+header {
+  border-bottom: 4px solid;
+}
+
+footer {
+  border-top: 4px solid;
+}
+
+header h1 {
+    margin: 0;
+}
+
+body div, body footer, body header {
+  padding: 10px;
+}
+
+.archive.main {
+  display: grid;
+  grid-template-rows: auto 1fr;
+}
+
+.archive.content {
+    width: 100%;
+    hegiht: 100%;
+}

+ 35 - 0
index.html

@@ -0,0 +1,35 @@
+<!doctype html>
+<html>
+  <head>
+    <title>(New) Status Monitor Archive</title>
+    <link rel="stylesheet" href="index.css"/>
+    <script src="index.js"></script>
+  </head>
+  <body>
+    <header>
+        <h1>(New) Status Monitor | Archive</h1>
+    </header>
+    <div class="archive main">
+        <span>
+          Date (2021-12-21 to today): <input type="date" min="2021-12-21" id="dateselector"/> | Version:
+          <select class="archive commits" id="commitSelect"></select>
+        </span>
+        <iframe class="archive content" height="100%" id="content"></iframe>
+    </div>
+    <footer>
+        <a href="https://nuserv.uni-muenster.de:8443/bbieringer/new_monitor_archive">Raw&nbsp;archive&nbsp;data</a> | <a href="https://nuserv.uni-muenster.de:8443/bbieringer/githtmlarchiveviewer">Git&nbsp;HTML&nbsp;archive&nbsp;viewer&nbsp;on&nbsp;nuserv</a> | Contact&nbsp;(Archive):&nbsp;<a href="mailto:benedikt.b@wwu.de">Benedikt&nbsp;Bieringer</a> | Contact&nbsp;(Status&nbsp;Monitor):&nbsp;<a href="mailto:thuemmler@kit.edu">Thomas&nbsp;Th&uuml;mmler</a>
+    </footer>
+    <script>
+    new ArchiveView(
+        dateselector = document.getElementById("dateselector"),
+        commitsSelect = document.getElementById("commitSelect"),
+        content = document.getElementById("content"),
+        token = "MwoSWmkk76mcyxSGR2Ci",
+        url = "nuserv.uni-muenster.de:8443",
+        id = 513,
+        branch = "main",
+        page_path = "status-sds.kaas.kit.edu"
+    );
+    </script>
+  </body>
+</html>

+ 115 - 0
index.js

@@ -0,0 +1,115 @@
+class ArchiveCommit {
+    constructor(message, time, sha) {
+        this.message = message
+        this.time = time
+        this.sha = sha
+    }
+}
+
+function replace_urls(text, url_before, url_after) {
+    for(const key of ["src=\""]) {
+        segments = text.split(key)
+        result_text = segments[0]
+        for(const segment of segments.slice(1)) {
+            var index = segment.indexOf('"')
+            var first = segment.substring(0, index)
+            var second = segment.substring(index)
+            
+            var new_url = url_before + encodeURIComponent(first) + url_after
+            
+            result_text += key + new_url + second
+        }
+        
+        text = result_text
+    }
+    
+    return text
+}
+
+class ArchiveView {
+    constructor(dateselector, commitsSelect, content, token, url, project_id, branch, page_path) {
+        this.token = token
+        this.url = url
+        this.project_id = project_id
+        this.branch = branch
+        
+        this.dateselector = dateselector
+        this.dateselector.value = ""
+        this.dateselector.max = new Date().toLocaleDateString('en-ca')
+        // Alternative, doesn't allow selecting today in first two hours of day:
+        // this.dateselector.max = new Date().toISOString().split("T")[0]
+        this.dateselector.addEventListener("input",((event) => this.on_date_selected(event)))
+        
+        this.commitsSelect = commitsSelect
+        this.commitsSelect.addEventListener("input",((event) => this.on_commit_selected(event)))
+        
+        this.content = content
+        
+        this.page_path = page_path
+    }
+    
+    add_commits(commits) {
+        commits.map(commit => {
+            var elem = document.createElement("option")
+            elem.innerHTML = commit.message
+            elem.value = commit.sha
+            this.commitsSelect.appendChild(elem)
+        })
+    }
+    
+    on_date_selected(event) {
+        if (!event.target.value)
+            return
+        var page = 1
+        var date = event.target.value
+        
+        // Clean commits list
+        this.commitsSelect.innerHTML = ""
+        this.commitsSelect.appendChild(document.createElement("option"))
+        
+        this.load_pages_recursive(page, date)
+    }
+    
+    on_commit_selected(event) {
+        var sha = event.target.value
+        var url_before = 'https://' + this.url + '/api/v4/projects/' + this.project_id + '/repository/files/' + encodeURIComponent(this.page_path + "/")
+        var url_after = '/raw?ref=' + sha + '&private_token=' + this.token
+        var url = url_before + encodeURIComponent("index.html") + url_after
+        fetch(url)
+        .then(response => response.text())
+        .then(text => {
+            console.log(text)
+            var cleaned_text = replace_urls(text, url_before, url_after)
+            console.log(cleaned_text)
+            
+            const blobContent = new Blob([cleaned_text], {type: "text/html"})
+            this.content.src = URL.createObjectURL(blobContent)
+        })
+
+    }
+    
+    load_pages_recursive(page, date) {
+        var commits_url = 'https://' + this.url + '/api/v4/projects/' + this.project_id + '/repository/commits?ref_name=' + this.branch + '&private_token=' + this.token + "&since="+date+"T00:00&until="+date+"T24:00&per_page=100&page=" + page;
+        
+        var length_promise = fetch(commits_url)
+        .then(response => response.json())
+        .then(
+            // Translate response to commits
+            json => json.map(
+                gitlab_commit => new ArchiveCommit(
+                    gitlab_commit.message,
+                    gitlab_commit.created_at,
+                    gitlab_commit.id
+                )
+            )
+        ).then((commits) => {
+                this.add_commits(commits)
+                return commits.length
+            }
+        ).then((length) => {
+            if (length > 0) {
+                this.load_pages_recursive(page+1, date)
+            }
+        })
+    }
+}