mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-10-21 21:23:39 +00:00
Merge pull request #153 from movableink/js-in-external-files
JS in external files
This commit is contained in:
@@ -13,13 +13,14 @@
|
||||
|
||||
<!-- drone bootstrap theme -->
|
||||
<link href="/css/drone.css" rel="stylesheet" type="text/css" />
|
||||
|
||||
|
||||
<!-- fonts -->
|
||||
<link href="//fonts.googleapis.com/css?family=Orbitron" rel="stylesheet" />
|
||||
<link href="//fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet" />
|
||||
<link href="//fonts.googleapis.com/css?family=Droid+Sans+Mono" rel="stylesheet" />
|
||||
<link href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet" />
|
||||
|
||||
<script src="/js/main.js" type="text/javascript"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -59,4 +60,4 @@
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/js/bootstrap.min.js"></script>
|
||||
{{ template "script" . }}
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
@@ -52,120 +52,36 @@
|
||||
{{ define "script" }}
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-timeago/1.1.0/jquery.timeago.js"></script>
|
||||
<script>
|
||||
window.autofollow = false;
|
||||
$(document).ready(function() {
|
||||
$(".timeago").timeago();
|
||||
$("#follow").bind("click", function(ev) {
|
||||
if (window.autofollow) {
|
||||
window.autofollow = false;
|
||||
$("#follow").text("Follow");
|
||||
} else {
|
||||
window.autofollow = true;
|
||||
$("#follow").text("Stop following");
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<script>
|
||||
var re = /\u001B\[([0-9]+;?)*[Km]/g;
|
||||
|
||||
var styles = new Array();
|
||||
var formatLine = function(s) {
|
||||
// Check for newline and early exit?
|
||||
s = s.replace(/</g, "<");
|
||||
s = s.replace(/>/g, ">");
|
||||
|
||||
var final = "";
|
||||
var current = 0;
|
||||
while (m = re.exec(s)) {
|
||||
var part = s.substring(current, m.index+1);
|
||||
current = re.lastIndex;
|
||||
|
||||
var token = s.substr(m.index, re.lastIndex - m.index);
|
||||
var code = token.substr(2, token.length-2);
|
||||
|
||||
var pre = "";
|
||||
var post = "";
|
||||
|
||||
switch (code) {
|
||||
case 'm':
|
||||
case '0m':
|
||||
var len = styles.length;
|
||||
for (var i=0; i < len; i++) {
|
||||
styles.pop();
|
||||
post += "</span>"
|
||||
}
|
||||
break;
|
||||
case '30;42m': pre = '<span style="color:black;background:lime">'; break;
|
||||
case '36m':
|
||||
case '36;1m': pre = '<span style="color:cyan;">'; break;
|
||||
case '31m':
|
||||
case '31;31m': pre = '<span style="color:red;">'; break;
|
||||
case '33m':
|
||||
case '33;33m': pre = '<span style="color:yellow;">'; break;
|
||||
case '32m':
|
||||
case '0;32m': pre = '<span style="color:lime;">'; break;
|
||||
case '90m': pre = '<span style="color:gray;">'; break;
|
||||
case 'K':
|
||||
case '0K':
|
||||
case '1K':
|
||||
case '2K': break;
|
||||
}
|
||||
|
||||
if (pre !== "") {
|
||||
styles.push(pre);
|
||||
}
|
||||
|
||||
final += part + pre + post;
|
||||
}
|
||||
|
||||
var part = s.substring(current, s.length);
|
||||
final += part;
|
||||
return final;
|
||||
};
|
||||
</script>
|
||||
|
||||
<script>
|
||||
{{ if .Build.IsRunning }}
|
||||
var outputBox = document.getElementById('stdout');
|
||||
var outputWS = new WebSocket((window.location.protocol=='http:'?'ws':'wss')+'://'+window.location.host+'/feed?token='+{{ .Token }});
|
||||
outputWS.onopen = function () { console.log('output websocket open'); };
|
||||
outputWS.onerror = function (e) { console.log('websocket error: ' + e); };
|
||||
outputWS.onclose = function (e) { window.location.reload(); };
|
||||
$(document).ready(function() {
|
||||
var commitUpdates = new Drone.CommitUpdates('/feed?token='+{{ .Token }});
|
||||
var outputBox = document.getElementById('stdout');
|
||||
commitUpdates.startOutput(outputBox);
|
||||
|
||||
window.requestAnimationFrame = window.requestAnimationFrame ||
|
||||
window.webkitRequestAnimationFrame ||
|
||||
function(callback, element) {
|
||||
return window.setTimeout(function() {
|
||||
callback(+new Date());
|
||||
}, 1000 / 60);
|
||||
};
|
||||
$("#follow").on("click", function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var lineBuffer = "";
|
||||
|
||||
outputWS.onmessage = function (e) {
|
||||
lineBuffer += formatLine(e.data);
|
||||
};
|
||||
|
||||
function updateScreen() {
|
||||
if(lineBuffer.length > 0) {
|
||||
outputBox.innerHTML += lineBuffer;
|
||||
lineBuffer = '';
|
||||
|
||||
if (window.autofollow) {
|
||||
window.scrollTo(0, document.body.scrollHeight);
|
||||
if(commitUpdates.autoFollow) {
|
||||
commitUpdates.autoFollow = false;
|
||||
$(this).text("Follow");
|
||||
} else {
|
||||
commitUpdates.autoFollow = true;
|
||||
$(this).text("Stop following");
|
||||
}
|
||||
}
|
||||
requestAnimationFrame(updateScreen);
|
||||
}
|
||||
|
||||
requestAnimationFrame(updateScreen);
|
||||
});
|
||||
});
|
||||
|
||||
{{ else }}
|
||||
$.get("/{{ .Repo.Slug }}/commit/{{ .Commit.Hash }}/build/{{ .Build.Slug }}/out.txt", function( data ) {
|
||||
$( "#stdout" ).html(formatLine(data));
|
||||
var lineFormatter = new Drone.LineFormatter();
|
||||
$( "#stdout" ).html(lineFormatter.format(data));
|
||||
});
|
||||
{{ end }}
|
||||
</script>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
@@ -5,6 +5,9 @@ import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io"
|
||||
"crypto/md5"
|
||||
"strings"
|
||||
"fmt"
|
||||
|
||||
"github.com/GeertJohan/go.rice"
|
||||
)
|
||||
@@ -88,6 +91,17 @@ func init() {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
assets := rice.MustFindBox("../../cmd/droned/assets")
|
||||
mainjs, err := assets.String("js/main.js")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
h := md5.New()
|
||||
io.WriteString(h, mainjs)
|
||||
jshash := fmt.Sprintf("%x", h.Sum(nil))
|
||||
base = strings.Replace(base, "main.js", "main.js?h=" + jshash, 1)
|
||||
|
||||
// extract the base form template as a string
|
||||
form, err := box.String("form.html")
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user