-
Notifications
You must be signed in to change notification settings - Fork 54
/
template.go
129 lines (123 loc) · 4.64 KB
/
template.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package apitest
const reportTemplate = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/raphael/2.2.7/raphael.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.4/clipboard.min.js"></script>
<script src="https://bramp.github.io/js-sequence-diagrams/js/sequence-diagram-min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/js/bootstrap.min.js"></script>
<style>
body {
padding-top: 2rem;
padding-bottom: 2rem;
}
#scroll-to-top-button {
background-color: #555;
border: none;
border-radius: 4px;
bottom: 20px;
color: white;
cursor: pointer;
display: none;
font-size: 18px;
outline: none;
position: fixed;
right: 30px;
z-index: 99;
}
.copy-to-clipboard-button {
background-color: #fff;
border: 1px solid #eee;
cursor: pointer;
font-size: 12px;
outline: none;
padding: 5px;
}
</style>
</head>
<body>
<!-- THIS CODE IS AUTOGENERATED. DO NOT EDIT -->
<div class="container-fluid">
<h2>{{printf "%.100s" .Title }}</h2>
<span class="{{ .BadgeClass }}">{{ .StatusCode }}</span>
<p class="lead">{{ .SubTitle }}</p>
<div class="card text-center">
<div class="card-body">
<div id="d" class="justify-content-center"></div>
</div>
</div>
<br><br>
<p class="lead">Event Log</p>
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Payload</th>
</tr>
</thead>
<tbody>
{{ range $i, $e := .LogEntries }}
<tr id="log-{{$i}}">
<th scope="row">{{ inc $i }}</th>
<td>
<pre>{{ $e.Header }}</pre>
{{if $e.Body }}
<pre style="max-height: 1000px; margin-bottom: 0; border: 1px solid #eee;"><code id="event-message-{{$i}}">{{ $e.Body }}</code></pre>
<button class="copy-to-clipboard-button" data-clipboard-target="#event-message-{{$i}}">copy to clipboard</button>
{{end}}
</td>
</tr>
{{ end }}
</tbody>
</table>
</div>
<button onclick="topFunction()" id="scroll-to-top-button" title="Go to top">Back to top</button>
<script>
Diagram.parse("{{ .WebSequenceDSL }}").drawSVG("d", {theme: 'simple', 'font-size': 14});
</script>
<style>
</style>
{{if $.MetaJSON }}<script type="application/json" id="metaJson">{{$.MetaJSON}}</script>{{end}}
<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.13.1/build/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script>new ClipboardJS('.copy-to-clipboard-button');</script>
<script>
var elements = document.getElementsByTagName('text')
var regex = /\((\d{1,3})\)/ // match elements containing (0), (1), etc.
for (var i = 0; i < elements.length; i++) {
if (elements[i].innerHTML) {
var found = elements[i].innerHTML.match(regex);
if (found && found.length > 0) {
const logIndex = parseInt(found[1], 10) - 1;
elements[i].style.cursor = 'pointer';
elements[i].addEventListener('click', function (e) {
e.preventDefault();
document.getElementById("log-" + logIndex).scrollIntoView();
}, false);
}
}
}
var scrollToTopBtn = document.getElementById("scroll-to-top-button");
window.onscroll = function () {
scrollFunction()
};
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
scrollToTopBtn.style.display = "block";
} else {
scrollToTopBtn.style.display = "none";
}
}
function topFunction() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
</script>
</body>
</html>`