╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Issues.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1311 const cid = tf.focus.child_id orelse tf.text_boxes.items[0].getFocus().id; 1312 const item = tf.indexOfFocusId(cid) orelse 0; 1313 self.focusTag(index, tf, root_focus, item); 1314 } 1315 1316 fn focusDescription(self: *View, index: usize, root_focus: *Focus) !void { 1317 if (self.description_id[index]) |id| root_focus.setFocus(id); 1318 } 1319 1320 // return to the tool row's last-focused button. 1321 fn focusToolRow(self: *View, index: usize, root_focus: *Focus) void { 1322 const cid = self.toolRow(index).getFocus().child_id orelse return; 1323 root_focus.setFocus(cid); 1324 } 1325 1326 // enter the detail pane. an empty pane (no issues) can't be entered. 1327 fn focusDetail(self: *View, index: usize, root_focus: *Focus) !void { 1328 if (self.detailInner(index).children.count() == 0) return; 1329 root_focus.setFocus(self.detailOuter(index).getFocus().id); 1330 } 1331 1332 // return to the list. 1333 fn focusList(self: *View, index: usize, root_focus: *Focus) !void { 1334 root_focus.setFocus(self.listScroll(index).getFocus().id); 1335 } 1336 1337 // cross to the header tabs above the stack. 1338 fn focusHeader(self: *View, root_focus: *Focus) void { 1339 root_focus.setFocus(self.box.children.keys()[header_index]); 1340 } 1341 1342 pub fn clearGrid(self: *View) void { 1343 self.box.clearGrid(); 1344 } 1345 1346 pub fn getGrid(self: View) ?Grid { 1347 return self.box.getGrid(); 1348 } 1349 1350 pub fn getFocus(self: *View) *Focus { 1351 return self.box.getFocus(); 1352 } 1353 1354 // for the parent's "scroll up at the top jumps to the header" check: at the 1355 // top only while the header tabs hold focus, so up from the split 1356 // crosses into the tabs first. 1357 pub fn getSelectedIndex(self: *View) ?usize { 1358 return if (self.headerActive()) 0 else 1; 1359 } 1360 }; 1361 1362 // the "a:" navigation link for `status`'s issues page filtered to the 1363 // url-encoded `tag` and rooted at issue `id` within `identity` ("owner/name"). 1364 // a rooted url ignores `status` (it derives its view from the issue's own); 1365 // with an empty `id` this is the bare list link. 1366 fn issuesLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, status: evt.Issue.Status, tag: []const u8, id: []const u8) ![]const u8 { 1367 const route = ui.RoutablePage.repoIssuesRoute(identity, status, tag, id) orelse return error.RouteTooLong; 1368 const url = try route.toUrl(page_arena); 1369 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 1370 } 1371 1372 // the in-page "ai:" anchor for selecting issue `id` in `identity`'s list; the 1373 // href is only followed with js off. 1374 fn issueRowLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, id: []const u8) ![]const u8 { 1375 const route = ui.RoutablePage.repoIssuesRoute(identity, .open, "", id) orelse return error.RouteTooLong; 1376 const url = try route.toUrl(page_arena); 1377 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{url}); 1378 } 1379 1380 // the "a:" link to `status`'s issues list filtered to `tag` (raw; encoded here). 1381 fn tagLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, status: evt.Issue.Status, tag: []const u8) ![]const u8 { 1382 const encoded = try ui.urlEncodeRef(page_arena.allocator(), tag); 1383 const route = ui.RoutablePage.repoIssuesRoute(identity, status, encoded, "") orelse return error.RouteTooLong; 1384 const url = try route.toUrl(page_arena); 1385 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 1386 } 1387 1388 // tabs switching between the issues page's views. 1389 pub const Header = struct { 1390 box: wgt.Box(ui.Widget), 1391 tab_ids: std.AutoArrayHashMapUnmanaged(usize, void), 1392 1393 pub fn init(allocator: std.mem.Allocator, session: *ui.Session, data: *const Self) !Header { 1394 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 1395 errdefer box.deinit(allocator); 1396 1397 var tab_ids: std.AutoArrayHashMapUnmanaged(usize, void) = .empty; 1398 errdefer tab_ids.deinit(allocator); 1399 1400 const aa = session.page_arena.allocator(); 1401 1402 // a list tab per status, labeled with its listing's issue count 1403 for ([_]evt.Issue.Status{ .open, .closed }) |status| { 1404 const route = ui.RoutablePage.repoIssuesRoute(data.identity, status, data.tag, "") orelse return error.RouteTooLong; 1405 const link = try std.fmt.allocPrint(aa, "ai:{s}", .{try route.toUrl(session.page_arena)}); 1406 const label = try std.fmt.allocPrint(aa, "{s} ({d})", .{ @tagName(status), data.window(status).count }); 1407 var text_box = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 1408 errdefer text_box.deinit(allocator); 1409 text_box.getFocus().focusable = true; 1410 text_box.getFocus().kind = .{ .custom = link }; 1411 try tab_ids.put(allocator, text_box.getFocus().id, {}); 1412 try box.children.put(allocator, text_box.getFocus().id, .{ 1413 .widget = .{ .text_box = text_box }, 1414 .rect = null, 1415 .min_size = .{ .width = label.len + 2, .height = null }, 1416 }); 1417 } 1418 1419 // tags tab, labeled with the active tag filter 1420 { 1421 const tags_route = ui.RoutablePage.repoIssuesTagsRoute(data.identity, data.tag) orelse return error.RouteTooLong; 1422 const tags_link = try std.fmt.allocPrint(aa, "ai:{s}", .{try tags_route.toUrl(session.page_arena)}); 1423 const label = if (data.tag.len == 0) "tags" else blk: { 1424 const decoded = std.Uri.percentDecodeInPlace(try aa.dupe(u8, data.tag)); 1425 break :blk try std.fmt.allocPrint(aa, "tags ({s})", .{decoded}); 1426 }; 1427 var text_box = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 1428 errdefer text_box.deinit(allocator); 1429 text_box.getFocus().focusable = true; 1430 text_box.getFocus().kind = .{ .custom = tags_link }; 1431 try tab_ids.put(allocator, text_box.getFocus().id, {}); 1432 try box.children.put(allocator, text_box.getFocus().id, .{ 1433 .widget = .{ .text_box = text_box }, 1434 .rect = null, 1435 .min_size = .{ .width = label.len + 2, .height = null }, 1436 }); 1437 } 1438 1439 // new-issue tab; an edit url shows the edit tab in its place 1440 { 1441 const route = if (data.view == .edit) 1442 ui.RoutablePage.repoIssuesEditRoute(data.identity, data.selected_id) orelse return error.RouteTooLong 1443 else 1444 ui.RoutablePage.repoIssuesNewRoute(data.identity) orelse return error.RouteTooLong; 1445 const link = try std.fmt.allocPrint(aa, "ai:{s}", .{try route.toUrl(session.page_arena)}); 1446 const label: []const u8 = if (data.view == .edit) "edit" else "new"; 1447 var text_box = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 1448 errdefer text_box.deinit(allocator); 1449 text_box.getFocus().focusable = true; 1450 text_box.getFocus().kind = .{ .custom = link }; 1451 try tab_ids.put(allocator, text_box.getFocus().id, {}); 1452 try box.children.put(allocator, text_box.getFocus().id, .{ 1453 .widget = .{ .text_box = text_box }, 1454 .rect = null, 1455 .min_size = .{ .width = label.len + 2, .height = null }, 1456 }); 1457 } 1458 1459 var self = Header{ .box = box, .tab_ids = tab_ids }; 1460 // the tab matching the page's view is selected initially. 1461 self.getFocus().child_id = self.tab_ids.keys()[View.viewIndex(data.view)]; 1462 return self; 1463 } 1464 1465 pub fn deinit(self: *Header, allocator: std.mem.Allocator) void { 1466 self.box.deinit(allocator); 1467 self.tab_ids.deinit(allocator); 1468 } 1469 1470 pub fn build(self: *Header, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 1471 self.clearGrid(); 1472 // only the selected tab shows its border 1473 for (self.box.children.keys(), self.box.children.values()) |id, *child| { 1474 switch (child.widget) { 1475 .text_box => |*tb| tb.options.border_style = if (self.getFocus().child_id == id) .single else .hidden, 1476 else => {}, 1477 } 1478 } 1479 try self.box.build(allocator, constraint, root_focus); 1480 } 1481 1482 pub fn input(self: *Header, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 1483 _ = allocator; 1484 const current_tab = self.currentTabIndex() orelse return; 1485 if (inp.moveTab(key, current_tab, self.tab_ids.count())) |new_tab| { 1486 root_focus.setFocus(self.tab_ids.keys()[new_tab]); 1487 } 1488 } 1489 1490 pub fn clearGrid(self: *Header) void { 1491 self.box.clearGrid(); 1492 } 1493 1494 pub fn getGrid(self: Header) ?Grid { 1495 return self.box.getGrid(); 1496 } 1497 1498 pub fn getFocus(self: *Header) *Focus { 1499 return self.box.getFocus(); 1500 } 1501 1502 pub fn getSelectedIndex(self: Header) ?usize { 1503 return self.currentTabIndex(); 1504 } 1505 1506 fn currentTabIndex(self: Header) ?usize { 1507 const child_id = self.box.focus.child_id orelse return null; 1508 return self.tab_ids.getIndex(child_id); 1509 } 1510 }; 1511