BlueGit

timfa bluegit

Files

bluegit / internal / server / static / pipeline.js

pipeline.js

feat: pipelines-tab en jobconsole
timfa project_87923614_bot_3aff574f6f98414b945a8799374f9092 · pushed by timfa · 3 weeks ago
Failed 5d0db17c History
pipeline.js 7.9 KiB Download Raw
1(function () {
2 function closeStages(except) {
3 document.querySelectorAll(".stage.open").forEach(function (stage) {
4 if (stage === except) {
5 return;
6 }
7 stage.classList.remove("open");
8 var pop = stage.querySelector(".stage-pop");
9 if (pop) {
10 pop.hidden = true;
11 }
12 });
13 }
14
15 document.querySelectorAll(".stage-dot[data-tip]").forEach(function (btn) {
16 btn.addEventListener("click", function (ev) {
17 ev.stopPropagation();
18 var stage = btn.parentElement;
19 var pop = stage.querySelector(".stage-pop");
20 var open = stage.classList.contains("open");
21 closeStages(null);
22 if (!open && pop) {
23 stage.classList.add("open");
24 pop.hidden = false;
25 }
26 });
27 });
28
29 document.addEventListener("click", function () {
30 closeStages(null);
31 });
32 document.addEventListener("keydown", function (ev) {
33 if (ev.key === "Escape") {
34 closeStages(null);
35 }
36 });
37
38 document.querySelectorAll(".section-toggle").forEach(function (btn) {
39 btn.addEventListener("click", function () {
40 var sec = btn.parentElement;
41 sec.classList.toggle("open");
42 });
43 });
44
45 var log = document.querySelector("[data-log]");
46 var hits = [];
47 var hitAt = -1;
48
49 function clearHits() {
50 if (!log) {
51 return;
52 }
53 log.querySelectorAll(".hit").forEach(function (el) {
54 el.classList.remove("hit", "on");
55 });
56 hits = [];
57 hitAt = -1;
58 }
59
60 function showHit(i) {
61 if (!hits.length) {
62 return;
63 }
64 hitAt = (i + hits.length) % hits.length;
65 hits.forEach(function (el, n) {
66 el.classList.toggle("on", n === hitAt);
67 });
68 var current = hits[hitAt];
69 var sec = current.closest(".logsec");
70 if (sec) {
71 sec.classList.add("open");
72 }
73 current.scrollIntoView({ block: "center" });
74 }
75
76 var search = document.querySelector("[data-log-search]");
77 if (search && log) {
78 search.addEventListener("submit", function (ev) {
79 ev.preventDefault();
80 var q = (search.querySelector("input").value || "").toLowerCase();
81 clearHits();
82 if (!q) {
83 return;
84 }
85 log.querySelectorAll("[data-line]").forEach(function (row) {
86 var code = row.querySelector("code");
87 var text = code ? code.textContent.toLowerCase() : "";
88 if (text.indexOf(q) >= 0) {
89 row.classList.add("hit");
90 hits.push(row);
91 }
92 });
93 showHit(0);
94 });
95 }
96 var prev = document.querySelector("[data-log-prev]");
97 var next = document.querySelector("[data-log-next]");
98 if (prev) {
99 prev.addEventListener("click", function () { showHit(hitAt - 1); });
100 }
101 if (next) {
102 next.addEventListener("click", function () { showHit(hitAt + 1); });
103 }
104 var wrapBtn = document.querySelector("[data-log-wrap]");
105 if (wrapBtn && log) {
106 wrapBtn.addEventListener("click", function () {
107 log.classList.toggle("wrap");
108 });
109 }
110 var topBtn = document.querySelector("[data-log-top]");
111 var bottomBtn = document.querySelector("[data-log-bottom]");
112 if (topBtn && log) {
113 topBtn.addEventListener("click", function () { log.scrollTop = 0; });
114 }
115 if (bottomBtn && log) {
116 bottomBtn.addEventListener("click", function () { log.scrollTop = log.scrollHeight; });
117 }
118 var fullBtn = document.querySelector("[data-log-full]");
119 var wrapBox = document.querySelector("[data-console]");
120 if (fullBtn && wrapBox) {
121 fullBtn.addEventListener("click", function () {
122 if (document.fullscreenElement) {
123 document.exitFullscreen();
124 return;
125 }
126 if (wrapBox.requestFullscreen) {
127 wrapBox.requestFullscreen().catch(function () {
128 wrapBox.classList.toggle("full");
129 });
130 return;
131 }
132 wrapBox.classList.toggle("full");
133 });
134 }
135
136 var stageSelect = document.querySelector("[data-stage-select]");
137 if (stageSelect) {
138 stageSelect.addEventListener("change", function () {
139 var want = stageSelect.value;
140 document.querySelectorAll(".related li").forEach(function (li) {
141 li.hidden = li.getAttribute("data-stage") !== want;
142 });
143 });
144 }
145
146 if (!wrapBox || wrapBox.getAttribute("data-running") !== "1" || !log) {
147 return;
148 }
149 var offset = parseInt(wrapBox.getAttribute("data-offset") || "0", 10);
150 var url = wrapBox.getAttribute("data-log-url");
151 var pending = "";
152 var lineNo = 0;
153 log.querySelectorAll("[data-line]").forEach(function (row) {
154 var n = parseInt(row.getAttribute("data-line") || "0", 10);
155 if (n > lineNo) {
156 lineNo = n;
157 }
158 });
159 var currentSec = log.querySelector(".logsec.open:last-of-type");
160
161 function addLine(ts, text) {
162 lineNo += 1;
163 var row = document.createElement("div");
164 row.className = "logline";
165 row.setAttribute("data-line", String(lineNo));
166 var ln = document.createElement("span");
167 ln.className = "ln";
168 ln.textContent = String(lineNo);
169 var time = document.createElement("span");
170 time.className = "ts";
171 time.textContent = ts;
172 var code = document.createElement("code");
173 code.textContent = text;
174 row.appendChild(ln);
175 row.appendChild(time);
176 row.appendChild(code);
177 if (currentSec) {
178 var list = currentSec.querySelector("ol");
179 var li = document.createElement("li");
180 li.className = "logline";
181 li.setAttribute("data-line", String(lineNo));
182 li.appendChild(ln);
183 li.appendChild(time);
184 li.appendChild(code);
185 list.appendChild(li);
186 row = li;
187 } else {
188 log.appendChild(row);
189 }
190 log.scrollTop = log.scrollHeight;
191 }
192
193 function openSection(title) {
194 var sec = document.createElement("section");
195 sec.className = "logsec open";
196 var btn = document.createElement("button");
197 btn.type = "button";
198 btn.className = "section-toggle";
199 var chev = document.createElement("span");
200 chev.className = "chev";
201 var label = document.createElement("span");
202 label.className = "sectitle";
203 label.textContent = title;
204 btn.appendChild(chev);
205 btn.appendChild(label);
206 btn.addEventListener("click", function () { sec.classList.toggle("open"); });
207 var ol = document.createElement("ol");
208 sec.appendChild(btn);
209 sec.appendChild(ol);
210 log.appendChild(sec);
211 currentSec = sec;
212 }
213
214 function closeSection(dur) {
215 if (!currentSec) {
216 return;
217 }
218 if (dur) {
219 var pill = document.createElement("span");
220 pill.className = "pill";
221 pill.textContent = dur;
222 currentSec.querySelector("button").appendChild(pill);
223 }
224 currentSec = null;
225 }
226
227 function take(line) {
228 var tab = line.indexOf("\t");
229 var ts = "";
230 var text = line;
231 if (tab >= 0) {
232 ts = line.slice(0, tab);
233 text = line.slice(tab + 1);
234 }
235 if (ts.length >= 19 && ts.indexOf("T") === 10) {
236 ts = ts.slice(11, 19);
237 }
238 if (text.indexOf("section_start:") === 0) {
239 var body = text.slice("section_start:".length);
240 var colon = body.indexOf(":");
241 openSection(colon >= 0 ? body.slice(colon + 1) : body);
242 return;
243 }
244 if (text.indexOf("section_end:") === 0) {
245 var end = text.slice("section_end:".length);
246 var dtab = end.indexOf("\t");
247 closeSection(dtab >= 0 ? end.slice(dtab + 1) : "");
248 return;
249 }
250 addLine(ts, text);
251 }
252
253 function poll() {
254 fetch(url + "?offset=" + offset, { headers: { Accept: "application/json" } })
255 .then(function (res) { return res.json(); })
256 .then(function (data) {
257 var chunk = pending + (data.text || "");
258 var rows = chunk.split("\n");
259 pending = rows.pop();
260 rows.forEach(function (row) {
261 if (row) {
262 take(row);
263 }
264 });
265 offset = data.offset || offset;
266 if (data.status === "running" || data.status === "queued") {
267 setTimeout(poll, 1500);
268 return;
269 }
270 if (pending) {
271 take(pending);
272 pending = "";
273 }
274 window.location.reload();
275 })
276 .catch(function () {
277 setTimeout(poll, 3000);
278 });
279 }
280 setTimeout(poll, 1500);
281})();