| 1 | <!DOCTYPE html> |
| 2 | <html lang="en"><head><meta charset="utf-8"> |
| 3 | <meta name="viewport" content="width=device-width,initial-scale=1"> |
| 4 | <title>git</title> |
| 5 | <!--TOKENS--> |
| 6 | <style> |
| 7 | *{box-sizing:border-box} |
| 8 | html,body{margin:0;min-height:100%} |
| 9 | body{background:var(--bg);color:var(--tx,var(--text));font-family:var(--font); |
| 10 | font-size:14px;line-height:1.5;-webkit-font-smoothing:antialiased} |
| 11 | .wrap{max-width:1200px;margin:0 auto;padding:18px 18px 40px} |
| 12 | .top{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin-bottom:14px} |
| 13 | .brand{font-size:11px;font-weight:700;letter-spacing:.09em;text-transform:uppercase; |
| 14 | color:var(--mu,var(--text-2))} |
| 15 | .title{font-size:19px;font-weight:680;margin:0;letter-spacing:-.01em} |
| 16 | .sp{flex:1 1 auto} |
| 17 | .pill{font-size:11px;font-weight:600;padding:3px 9px;border-radius:999px; |
| 18 | background:var(--sf2,var(--surface-2));color:var(--mu,var(--text-2)); |
| 19 | border:1px solid var(--ln,var(--line));white-space:nowrap} |
| 20 | .icon-btn{display:inline-flex;align-items:center;justify-content:center;gap:6px; |
| 21 | background:var(--sf2,var(--surface-2));border:1px solid var(--ln,var(--line)); |
| 22 | color:var(--text);border-radius:9px;height:30px;padding:0 11px;cursor:pointer; |
| 23 | font-family:inherit;font-size:12px;font-weight:600} |
| 24 | .icon-btn:hover{background:var(--surface-hover);border-color:var(--line-2)} |
| 25 | .icon-btn:active{transform:scale(.97)} |
| 26 | .icon-btn svg{width:14px;height:14px;fill:none;stroke:currentColor;stroke-width:1.9; |
| 27 | stroke-linecap:round;stroke-linejoin:round} |
| 28 | .icon-btn[disabled]{opacity:.5;cursor:default} |
| 29 | |
| 30 | .chips{display:grid;grid-template-columns:repeat(auto-fit,minmax(126px,1fr));gap:10px; |
| 31 | margin-bottom:14px} |
| 32 | .chip{background:var(--sf,var(--bg-card));border:1px solid var(--ln,var(--line)); |
| 33 | border-radius:12px;padding:11px 13px;cursor:pointer;font-family:inherit; |
| 34 | text-align:left;color:var(--text)} |
| 35 | .chip:hover{border-color:var(--line-2)} |
| 36 | .chip.sel{box-shadow:inset 0 0 0 1.5px var(--ac,var(--blue))} |
| 37 | .chip .k{display:flex;align-items:center;gap:6px;font-size:10.5px;font-weight:700; |
| 38 | letter-spacing:.07em;text-transform:uppercase;color:var(--mu,var(--text-2))} |
| 39 | .chip .k svg{width:12px;height:12px;fill:none;stroke:currentColor;stroke-width:2; |
| 40 | stroke-linecap:round;stroke-linejoin:round} |
| 41 | .chip .v{font-family:var(--mono);font-size:23px;font-weight:700;margin-top:3px; |
| 42 | letter-spacing:-.02em} |
| 43 | .chip.ok .v{color:var(--green)} |
| 44 | .chip.bad .v{color:var(--red)} |
| 45 | .chip.warn .v{color:var(--orange)} |
| 46 | .chip.none .v{color:var(--mu,var(--text-2))} |
| 47 | |
| 48 | .bar{display:flex;gap:8px;align-items:center;flex-wrap:wrap;margin-bottom:10px} |
| 49 | .search{flex:1 1 240px;min-width:0;padding:9px 12px;border-radius:10px; |
| 50 | border:1px solid var(--ln,var(--line));background:var(--input-bg);color:var(--text); |
| 51 | font-family:inherit;font-size:13px} |
| 52 | .search:focus{outline:2px solid var(--ac,var(--blue));outline-offset:-1px} |
| 53 | select{padding:9px 11px;border-radius:10px;border:1px solid var(--ln,var(--line)); |
| 54 | background:var(--input-bg);color:var(--text);font-family:inherit;font-size:13px} |
| 55 | |
| 56 | .panel{background:var(--sf,var(--bg-card));border:1px solid var(--ln,var(--line)); |
| 57 | border-radius:14px;overflow:hidden} |
| 58 | .tb{width:100%;overflow-x:auto} |
| 59 | table{width:100%;border-collapse:collapse;font-size:13px} |
| 60 | th{text-align:left;font-size:10.5px;letter-spacing:.07em;text-transform:uppercase; |
| 61 | color:var(--mu,var(--text-2));font-weight:700;padding:9px 12px; |
| 62 | border-bottom:1px solid var(--ln,var(--line));white-space:nowrap; |
| 63 | background:var(--sf2,var(--surface-2))} |
| 64 | td{padding:9px 12px;border-bottom:1px solid var(--ln,var(--line)); |
| 65 | vertical-align:middle;white-space:nowrap} |
| 66 | tr.row{cursor:pointer} |
| 67 | tr.row:hover td{background:var(--surface-hover)} |
| 68 | tr.row:last-child td{border-bottom:0} |
| 69 | tr.row.sel td{background:var(--sf2,var(--surface-2))} |
| 70 | .mo{font-family:var(--mono);font-size:12.5px} |
| 71 | .name{font-weight:600;max-width:300px;overflow:hidden;text-overflow:ellipsis} |
| 72 | .sub{font-size:11.5px;color:var(--mu,var(--text-2));max-width:300px; |
| 73 | overflow:hidden;text-overflow:ellipsis;margin-top:1px} |
| 74 | .subtext{color:var(--text);font-size:12.5px;max-width:340px} |
| 75 | td.c-last{max-width:360px;overflow:hidden} |
| 76 | .subtext{white-space:normal;display:-webkit-box;-webkit-line-clamp:2; |
| 77 | -webkit-box-orient:vertical;overflow:hidden} |
| 78 | .hash{font-family:var(--mono);font-size:11.5px;color:var(--mu,var(--text-2))} |
| 79 | .tag{font-size:10px;font-weight:700;padding:2px 8px;border-radius:6px; |
| 80 | white-space:nowrap;letter-spacing:.03em;display:inline-block;margin:1px 3px 1px 0} |
| 81 | .t-dirty{background:rgba(255,159,10,.16);color:var(--orange)} |
| 82 | .t-ahead{background:rgba(48,209,88,.16);color:var(--green)} |
| 83 | .t-behind{background:rgba(255,69,58,.16);color:var(--red)} |
| 84 | .t-det{background:rgba(191,90,242,.16);color:var(--purple)} |
| 85 | .t-noup{background:rgba(142,142,147,.16);color:var(--gray)} |
| 86 | .t-stash{background:rgba(94,92,230,.16);color:var(--indigo)} |
| 87 | .t-clean{background:rgba(48,209,88,.12);color:var(--green)} |
| 88 | .t-unborn{background:rgba(255,214,10,.16);color:var(--yellow)} |
| 89 | .muted{color:var(--mu,var(--text-2))} |
| 90 | .empty{padding:28px 16px;text-align:center;color:var(--mu,var(--text-2));font-size:13px} |
| 91 | .hide{display:none!important} |
| 92 | |
| 93 | .drawer{position:fixed;top:0;right:0;bottom:0;width:min(560px,100%);z-index:60; |
| 94 | background:var(--modal-bg,var(--bg-card));border-left:1px solid var(--ln,var(--line)); |
| 95 | box-shadow:var(--shadow-lg);transform:translateX(102%);transition:transform .22s var(--ease); |
| 96 | display:flex;flex-direction:column} |
| 97 | .drawer.open{transform:none} |
| 98 | .dh{display:flex;align-items:center;gap:10px;padding:14px 16px; |
| 99 | border-bottom:1px solid var(--ln,var(--line))} |
| 100 | .dh .t{font-size:15px;font-weight:680;overflow:hidden;text-overflow:ellipsis;white-space:nowrap} |
| 101 | .db{overflow:auto;padding:14px 16px 28px;flex:1 1 auto} |
| 102 | .dsec{font-size:10.5px;letter-spacing:.07em;text-transform:uppercase;font-weight:700; |
| 103 | color:var(--mu,var(--text-2));margin:16px 0 8px} |
| 104 | .dsec:first-child{margin-top:0} |
| 105 | .flist{list-style:none;margin:0;padding:0;font-size:12.5px} |
| 106 | .flist li{display:flex;gap:9px;align-items:baseline;padding:4px 0; |
| 107 | border-bottom:1px solid var(--ln,var(--line))} |
| 108 | .flist li:last-child{border-bottom:0} |
| 109 | .flist .c{font-family:var(--mono);font-size:11px;font-weight:700;width:26px;flex:0 0 26px} |
| 110 | .flist .p{font-family:var(--mono);overflow:hidden;text-overflow:ellipsis;white-space:nowrap} |
| 111 | .c-mod{color:var(--orange)}.c-add{color:var(--green)}.c-del{color:var(--red)} |
| 112 | .c-unt{color:var(--gray)}.c-con{color:var(--purple)} |
| 113 | .clist{list-style:none;margin:0;padding:0;font-size:12.5px} |
| 114 | .clist li{padding:5px 0;border-bottom:1px solid var(--ln,var(--line))} |
| 115 | .clist li:last-child{border-bottom:0} |
| 116 | .clist .s{overflow:hidden;text-overflow:ellipsis;white-space:nowrap} |
| 117 | .clist .m{font-size:11px;color:var(--mu,var(--text-2));display:flex;gap:8px} |
| 118 | .scrim{position:fixed;inset:0;background:rgba(0,0,0,.35);z-index:55} |
| 119 | .scrim.hide{display:none} |
| 120 | .note{font-size:11.5px;color:var(--mu,var(--text-2));margin-top:8px} |
| 121 | .err{color:var(--red);font-size:12.5px;margin-top:8px} |
| 122 | |
| 123 | @media(max-width:760px){ |
| 124 | .wrap{padding:12px 12px 28px} |
| 125 | .drawer{width:100%;border-left:0} |
| 126 | col.c-root,th.c-root,td.c-root{display:none} |
| 127 | } |
| 128 | @media(max-width:760px){ |
| 129 | /* Two fixed columns: the repo block and the commit block. The commit subject |
| 130 | * is allowed to wrap onto a second line, which is the only way it fits at |
| 131 | * 390 px without a mid-word cut at the panel edge. */ |
| 132 | table{table-layout:fixed;width:100%} |
| 133 | td.c-repo{white-space:normal} |
| 134 | td.c-repo .sub{overflow:visible;text-overflow:clip;line-height:1.6} |
| 135 | td.c-last{max-width:none;white-space:normal} |
| 136 | td .sub,.subtext{max-width:none} |
| 137 | col.c-repo{width:48%} |
| 138 | col.c-last{width:52%} |
| 139 | .name{max-width:none} |
| 140 | } |
| 141 | @media(max-width:560px){ |
| 142 | .chips{grid-template-columns:repeat(auto-fit,minmax(104px,1fr));gap:8px} |
| 143 | .chip .v{font-size:19px} |
| 144 | col.c-sync,th.c-sync,td.c-sync{display:none} |
| 145 | th,td{padding:8px 9px} |
| 146 | .name,td .sub,.subtext{max-width:none} |
| 147 | } |
| 148 | </style></head> |
| 149 | <body> |
| 150 | <div class="wrap"> |
| 151 | <div class="top"> |
| 152 | <div> |
| 153 | <div class="brand">SCORPIOX BOT</div> |
| 154 | <h1 class="title">git</h1> |
| 155 | </div> |
| 156 | <span class="pill" id="rootPill">local</span> |
| 157 | <span class="sp"></span> |
| 158 | <button class="icon-btn embed-hide" id="thBtn" type="button" title="Toggle appearance"> |
| 159 | <svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="4"/><path d="M12 2v3M12 19v3M2 12h3M19 12h3M4.9 4.9l2.1 2.1M17 17l2.1 2.1M19.1 4.9L17 7M7 17l-2.1 2.1"/></svg> |
| 160 | Theme |
| 161 | </button> |
| 162 | <button class="icon-btn" id="rfBtn" type="button"> |
| 163 | <svg viewBox="0 0 24 24"><path d="M21 12a9 9 0 1 1-2.6-6.4"/><path d="M21 3v6h-6"/></svg> |
| 164 | Rescan |
| 165 | </button> |
| 166 | </div> |
| 167 | |
| 168 | <div class="chips" id="chips"> |
| 169 | <button class="chip none" data-filter="all" id="vAllChip" type="button"> |
| 170 | <div class="k"><svg viewBox="0 0 24 24"><path d="M3 7h18M3 12h18M3 17h18"/></svg>All repos</div> |
| 171 | <div class="v" id="vAll">0</div> |
| 172 | </button> |
| 173 | <button class="chip warn" data-filter="dirty" type="button"> |
| 174 | <div class="k"><svg viewBox="0 0 24 24"><path d="M12 8v5M12 16h.01"/><circle cx="12" cy="12" r="9"/></svg>Dirty</div> |
| 175 | <div class="v" id="vDirty">0</div> |
| 176 | </button> |
| 177 | <button class="chip ok" data-filter="ahead" type="button"> |
| 178 | <div class="k"><svg viewBox="0 0 24 24"><path d="M12 19V5M6 11l6-6 6 6"/></svg>Ahead</div> |
| 179 | <div class="v" id="vAhead">0</div> |
| 180 | </button> |
| 181 | <button class="chip bad" data-filter="behind" type="button"> |
| 182 | <div class="k"><svg viewBox="0 0 24 24"><path d="M12 5v14M6 13l6 6 6-6"/></svg>Behind</div> |
| 183 | <div class="v" id="vBehind">0</div> |
| 184 | </button> |
| 185 | <button class="chip none" data-filter="stash" type="button"> |
| 186 | <div class="k"><svg viewBox="0 0 24 24"><path d="M4 7h16M4 12h16M4 17h10"/></svg>Stashes</div> |
| 187 | <div class="v" id="vStash">0</div> |
| 188 | </button> |
| 189 | </div> |
| 190 | |
| 191 | <div class="bar"> |
| 192 | <input class="search" id="q" type="search" placeholder="Filter by repo, branch, or last commit" autocomplete="off"> |
| 193 | <select id="sc" aria-label="Filter by state"> |
| 194 | <option value="">All states</option> |
| 195 | <option value="dirty">Dirty</option> |
| 196 | <option value="clean">Clean</option> |
| 197 | <option value="ahead">Ahead</option> |
| 198 | <option value="behind">Behind</option> |
| 199 | <option value="detached">Detached</option> |
| 200 | <option value="noup">No upstream</option> |
| 201 | </select> |
| 202 | </div> |
| 203 | |
| 204 | <div class="panel"> |
| 205 | <div class="tb"> |
| 206 | <table> |
| 207 | <colgroup> |
| 208 | <col class="c-repo"><col class="c-root"><col class="c-sync"><col class="c-sync"><col class="c-last"> |
| 209 | </colgroup> |
| 210 | <thead><tr> |
| 211 | <th>Repository</th> |
| 212 | <th class="c-root">Root</th> |
| 213 | <th class="c-sync">Sync</th> |
| 214 | <th class="c-sync">Stash</th> |
| 215 | <th>Last commit</th> |
| 216 | </tr></thead> |
| 217 | <tbody id="rows"></tbody> |
| 218 | </table> |
| 219 | </div> |
| 220 | <div class="empty hide" id="empty">No repositories found under the allowlisted roots.</div> |
| 221 | </div> |
| 222 | <div class="note" id="footNote">Read-only. Fetching from a remote stays off unless the node operator enables it.</div> |
| 223 | </div> |
| 224 | |
| 225 | <div class="scrim hide" id="scrim"></div> |
| 226 | <aside class="drawer" id="drawer" aria-hidden="true"> |
| 227 | <div class="dh"> |
| 228 | <div class="t" id="dName">Repository</div> |
| 229 | <span class="sp"></span> |
| 230 | <button class="icon-btn" id="dClose" type="button" title="Close"> |
| 231 | <svg viewBox="0 0 24 24"><path d="M18 6 6 18M6 6l12 12"/></svg> |
| 232 | </button> |
| 233 | </div> |
| 234 | <div class="db" id="dBody"></div> |
| 235 | </aside> |
| 236 | |
| 237 | <script> |
| 238 | (function(){ |
| 239 | var q = new URLSearchParams(location.search); |
| 240 | var node = q.get('node') || ''; |
| 241 | var sid = q.get('id') || ''; |
| 242 | var pwd = q.get('pwd') || (node && localStorage.getItem('bot_pwd_' + node)) || |
| 243 | localStorage.getItem('bot_active_pwd') || ''; |
| 244 | /* When the bot serves this page through its proxy, ?plugin= is the route back. |
| 245 | * Opened directly on the node, the plugin itself is the route. */ |
| 246 | var HUB = q.get('plugin') || ''; |
| 247 | |
| 248 | function api(action, extra){ |
| 249 | var u = (HUB ? '/plugins?plugin=' + encodeURIComponent(HUB) : '/plugin_gitstat') + |
| 250 | '?action=' + encodeURIComponent(action) + |
| 251 | (extra ? ('&' + extra) : '') + |
| 252 | (node ? '&node=' + encodeURIComponent(node) : '') + |
| 253 | (sid ? '&id=' + encodeURIComponent(sid) : '') + |
| 254 | (pwd ? '&pwd=' + encodeURIComponent(pwd) : ''); |
| 255 | return fetch(u, {headers: pwd ? {'X-Bot-Password': pwd} : {}}).then(function(r){ |
| 256 | if (!r.ok) throw new Error('HTTP ' + r.status); |
| 257 | return r.json(); |
| 258 | }); |
| 259 | } |
| 260 | |
| 261 | var DATA = []; |
| 262 | var ROOTS = []; |
| 263 | var FILTER = 'all'; |
| 264 | var SEL = ''; |
| 265 | |
| 266 | function esc(v){ |
| 267 | return String(v == null ? '' : v).replace(/[&<>"']/g, function(c){ |
| 268 | return {'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]; |
| 269 | }); |
| 270 | } |
| 271 | function txt(id, v){ var e = document.getElementById(id); if (e) e.textContent = v; } |
| 272 | |
| 273 | function ago(ct){ |
| 274 | if (!ct) return '-'; |
| 275 | var s = Math.max(0, Math.floor(Date.now()/1000) - ct); |
| 276 | if (s < 60) return s + 's ago'; |
| 277 | if (s < 3600) return Math.floor(s/60) + 'm ago'; |
| 278 | if (s < 86400) return Math.floor(s/3600) + 'h ago'; |
| 279 | if (s < 2592000) return Math.floor(s/86400) + 'd ago'; |
| 280 | if (s < 31536000) return Math.floor(s/2592000) + 'mo ago'; |
| 281 | return Math.floor(s/31536000) + 'y ago'; |
| 282 | } |
| 283 | |
| 284 | function badges(r){ |
| 285 | var h = ''; |
| 286 | if (r.dirty > 0) h += '<span class="tag t-dirty">' + r.dirty + ' changed</span>'; |
| 287 | if (r.ahead > 0) h += '<span class="tag t-ahead">+' + r.ahead + '</span>'; |
| 288 | if (r.behind > 0) h += '<span class="tag t-behind">-' + r.behind + '</span>'; |
| 289 | if (r.detached) h += '<span class="tag t-det">detached</span>'; |
| 290 | if (r.no_upstream && !r.detached) h += '<span class="tag t-noup">no upstream</span>'; |
| 291 | if (r.unborn) h += '<span class="tag t-unborn">unborn</span>'; |
| 292 | if (r.stash > 0) h += '<span class="tag t-stash">' + r.stash + ' stash</span>'; |
| 293 | if (r.dirty === 0 && !r.detached && !r.unborn) h += '<span class="tag t-clean">clean</span>'; |
| 294 | return h; |
| 295 | } |
| 296 | |
| 297 | function matches(r){ |
| 298 | if (FILTER === 'dirty' && !(r.dirty > 0)) return false; |
| 299 | if (FILTER === 'ahead' && !(r.ahead > 0)) return false; |
| 300 | if (FILTER === 'behind' && !(r.behind > 0)) return false; |
| 301 | if (FILTER === 'stash' && !(r.stash > 0)) return false; |
| 302 | |
| 303 | var sc = document.getElementById('sc').value; |
| 304 | if (sc === 'dirty' && !(r.dirty > 0)) return false; |
| 305 | if (sc === 'clean' && (r.dirty > 0)) return false; |
| 306 | if (sc === 'ahead' && !(r.ahead > 0)) return false; |
| 307 | if (sc === 'behind' && !(r.behind > 0)) return false; |
| 308 | if (sc === 'detached' && !r.detached) return false; |
| 309 | if (sc === 'noup' && !r.no_upstream) return false; |
| 310 | |
| 311 | var f = (document.getElementById('q').value || '').toLowerCase(); |
| 312 | if (!f) return true; |
| 313 | var hay = (r.name + ' ' + r.path + ' ' + r.branch + ' ' + r.upstream + ' ' + |
| 314 | (r.last_commit ? r.last_commit.subject : '')).toLowerCase(); |
| 315 | return hay.indexOf(f) >= 0; |
| 316 | } |
| 317 | |
| 318 | function render(){ |
| 319 | var out = DUPS(DATA), rows = document.getElementById('rows'), h = ''; |
| 320 | for (var i = 0; i < out.length; i++) { |
| 321 | var r = out[i], lc = r.last_commit || {}; |
| 322 | h += '<tr class="row' + (SEL === r.path ? ' sel' : '') + '" data-p="' + esc(r.path) + '">' + |
| 323 | '<td class="c-repo"><div class="name">' + esc(r.name) + '</div>' + |
| 324 | '<div class="sub"><span class="mo">' + esc(r.branch || '-') + '</span> ' + badges(r) + '</div></td>' + |
| 325 | '<td class="c-root muted mo">' + esc(r.root || '-') + '</td>' + |
| 326 | '<td class="c-sync mo">' + (r.ahead || r.behind ? ('+' + r.ahead + ' -' + r.behind) : '<span class="muted">-</span>') + '</td>' + |
| 327 | '<td class="c-sync mo">' + (r.stash ? r.stash : '<span class="muted">-</span>') + '</td>' + |
| 328 | '<td class="c-last"><div class="sub subtext">' + esc(lc.subject || '-') + '</div>' + |
| 329 | '<div class="hash">' + esc((lc.short || '').slice(0, 8)) + ' · ' + ago(lc.ct) + '</div></td>' + |
| 330 | '</tr>'; |
| 331 | } |
| 332 | rows.innerHTML = h; |
| 333 | document.getElementById('empty').className = out.length ? 'empty hide' : 'empty'; |
| 334 | |
| 335 | var b = rows.querySelectorAll('tr.row'); |
| 336 | for (var k = 0; k < b.length; k++) { |
| 337 | b[k].onclick = function(){ |
| 338 | openDetail(this.getAttribute('data-p')); |
| 339 | }; |
| 340 | } |
| 341 | } |
| 342 | function DUPS(a){ var o = []; for (var i=0;i<a.length;i++) if (matches(a[i])) o.push(a[i]); return o; } |
| 343 | |
| 344 | function setCounts(s, n){ |
| 345 | s = s || {}; |
| 346 | txt('vAll', n || 0); |
| 347 | txt('vDirty', s.dirty || 0); |
| 348 | txt('vAhead', s.ahead || 0); |
| 349 | txt('vBehind', s.behind || 0); |
| 350 | txt('vStash', s.stashes || 0); |
| 351 | } |
| 352 | |
| 353 | function load(){ |
| 354 | var btn = document.getElementById('rfBtn'); |
| 355 | btn.disabled = true; |
| 356 | return api('repos').then(function(d){ |
| 357 | DATA = d.repos || []; |
| 358 | ROOTS = d.roots || []; |
| 359 | setCounts(d.summary, d.count); |
| 360 | var ex = []; |
| 361 | for (var i = 0; i < ROOTS.length; i++) if (ROOTS[i].exists) ex.push(ROOTS[i].root); |
| 362 | txt('rootPill', ex.length ? (ex.length + ' root' + (ex.length === 1 ? '' : 's')) : 'no roots'); |
| 363 | render(); |
| 364 | }).catch(function(e){ |
| 365 | txt('rootPill', 'error'); |
| 366 | document.getElementById('empty').className = 'empty'; |
| 367 | document.getElementById('empty').textContent = 'Load failed: ' + e.message; |
| 368 | }).then(function(){ btn.disabled = false; }); |
| 369 | } |
| 370 | |
| 371 | function codeClass(c){ |
| 372 | if (c === '\?\?' || c === '!!') return 'c-unt'; |
| 373 | if (c === 'UU' || c === 'AA' || c === 'DD') return 'c-con'; |
| 374 | if (c.indexOf('A') >= 0) return 'c-add'; |
| 375 | if (c.indexOf('D') >= 0) return 'c-del'; |
| 376 | return 'c-mod'; |
| 377 | } |
| 378 | |
| 379 | function openDetail(path){ |
| 380 | SEL = path; |
| 381 | var d = document.getElementById('drawer'); |
| 382 | var s = document.getElementById('scrim'); |
| 383 | d.classList.add('open'); |
| 384 | d.setAttribute('aria-hidden', 'false'); |
| 385 | s.classList.remove('hide'); |
| 386 | document.getElementById('dName').textContent = path.split(/[\\/]/).pop() || path; |
| 387 | document.getElementById('dBody').innerHTML = '<div class="muted">Loading…</div>'; |
| 388 | |
| 389 | api('repo', 'path=' + encodeURIComponent(path)).then(function(j){ |
| 390 | if (!j.ok) throw new Error(j.error || 'failed'); |
| 391 | var r = j.repo || {}, lc = r.last_commit || {}; |
| 392 | var h = ''; |
| 393 | h += '<div class="dsec">Repository</div>'; |
| 394 | h += '<div class="mo" style="font-size:12px;word-break:break-all">' + esc(r.path) + '</div>'; |
| 395 | h += '<div style="margin-top:8px">' + badges(r) + '</div>'; |
| 396 | h += '<div class="note">branch <span class="mo">' + esc(r.branch || '-') + '</span>' + |
| 397 | (r.upstream ? ' → <span class="mo">' + esc(r.upstream) + '</span>' : '') + '</div>'; |
| 398 | |
| 399 | h += '<div class="dsec">Last commit</div>'; |
| 400 | h += '<div class="clist"><li><div class="s">' + esc(lc.subject || '-') + '</div>' + |
| 401 | '<div class="m"><span class="mo">' + esc((lc.short || '').slice(0, 8)) + '</span>' + |
| 402 | '<span>' + ago(lc.ct) + '</span></div></li></div>'; |
| 403 | |
| 404 | var ch = j.changed || []; |
| 405 | h += '<div class="dsec">Changed files (' + (j.changed_count || 0) + ')</div>'; |
| 406 | if (!ch.length) { |
| 407 | h += '<div class="muted">Working tree is clean.</div>'; |
| 408 | } else { |
| 409 | h += '<ul class="flist">'; |
| 410 | for (var i = 0; i < ch.length; i++) { |
| 411 | h += '<li><span class="c ' + codeClass(ch[i].code) + '">' + esc(ch[i].code) + '</span>' + |
| 412 | '<span class="p">' + esc(ch[i].path) + '</span></li>'; |
| 413 | } |
| 414 | h += '</ul>'; |
| 415 | if (j.changed_truncated) h += '<div class="note">Showing the first 500 entries.</div>'; |
| 416 | } |
| 417 | |
| 418 | var cm = j.commits || []; |
| 419 | h += '<div class="dsec">Recent commits (' + cm.length + ')</div>'; |
| 420 | if (!cm.length) { |
| 421 | h += '<div class="muted">No commits yet.</div>'; |
| 422 | } else { |
| 423 | h += '<ul class="clist">'; |
| 424 | for (var k = 0; k < cm.length; k++) { |
| 425 | h += '<li><div class="s">' + esc(cm[k].subject || '') + '</div>' + |
| 426 | '<div class="m"><span class="mo">' + esc((cm[k].hash || '').slice(0, 8)) + '</span>' + |
| 427 | '<span>' + esc(cm[k].author || '') + '</span>' + |
| 428 | '<span>' + ago(cm[k].ct) + '</span></div></li>'; |
| 429 | } |
| 430 | h += '</ul>'; |
| 431 | } |
| 432 | document.getElementById('dBody').innerHTML = h; |
| 433 | }).catch(function(e){ |
| 434 | document.getElementById('dBody').innerHTML = |
| 435 | '<div class="err">Could not read this repository: ' + esc(e.message) + '</div>'; |
| 436 | }); |
| 437 | } |
| 438 | |
| 439 | function closeDetail(){ |
| 440 | SEL = ''; |
| 441 | document.getElementById('drawer').classList.remove('open'); |
| 442 | document.getElementById('drawer').setAttribute('aria-hidden', 'true'); |
| 443 | document.getElementById('scrim').classList.add('hide'); |
| 444 | render(); |
| 445 | } |
| 446 | |
| 447 | document.getElementById('dClose').onclick = closeDetail; |
| 448 | document.getElementById('scrim').onclick = closeDetail; |
| 449 | document.addEventListener('keydown', function(e){ if (e.key === 'Escape') closeDetail(); }); |
| 450 | document.getElementById('rfBtn').onclick = load; |
| 451 | document.getElementById('q').oninput = render; |
| 452 | document.getElementById('sc').onchange = render; |
| 453 | document.getElementById('thBtn').onclick = function(){ |
| 454 | if (window.sxApplyTheme) window.sxApplyTheme(window.sxTheme() === 'dark' ? 'light' : 'dark'); |
| 455 | }; |
| 456 | |
| 457 | var chips = document.querySelectorAll('.chip'); |
| 458 | for (var ci = 0; ci < chips.length; ci++) { |
| 459 | chips[ci].onclick = function(){ |
| 460 | FILTER = this.getAttribute('data-filter'); |
| 461 | for (var j = 0; j < chips.length; j++) chips[j].classList.remove('sel'); |
| 462 | this.classList.add('sel'); |
| 463 | render(); |
| 464 | }; |
| 465 | } |
| 466 | |
| 467 | load(); |
| 468 | })(); |
| 469 | </script> |
| 470 | </body></html> |