╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Issues.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1360 const cid = self.toolRow(index).getFocus().child_id orelse return self.focusHeader(root_focus); 1361 root_focus.setFocus(cid); 1362 } 1363 1364 // enter the detail pane. an empty pane (no issues) can't be entered. 1365 fn focusDetail(self: *View, index: usize, root_focus: *Focus) !void { 1366 if (self.detailInner(index).children.count() == 0) return; 1367 root_focus.setFocus(self.detailOuter(index).getFocus().id); 1368 } 1369 1370 // return to the list. 1371 fn focusList(self: *View, index: usize, root_focus: *Focus) !void { 1372 root_focus.setFocus(self.listScroll(index).getFocus().id); 1373 } 1374 1375 // cross to the header tabs above the stack. 1376 fn focusHeader(self: *View, root_focus: *Focus) void { 1377 root_focus.setFocus(self.box.children.keys()[header_index]); 1378 } 1379 1380 pub fn clearGrid(self: *View) void { 1381 self.box.clearGrid(); 1382 } 1383 1384 pub fn getGrid(self: View) ?Grid { 1385 return self.box.getGrid(); 1386 } 1387 1388 pub fn getFocus(self: *View) *Focus { 1389 return self.box.getFocus(); 1390 } 1391 1392 // for the parent's "scroll up at the top jumps to the header" check: at the 1393 // top only while the header tabs hold focus, so up from the split 1394 // crosses into the tabs first. 1395 pub fn getSelectedIndex(self: *View) ?usize { 1396 return if (self.headerActive()) 0 else 1; 1397 } 1398 }; 1399 1400 // the "a:" navigation link for `status`'s issues page filtered to the 1401 // url-encoded `tag` and rooted at issue `id` within `identity` ("owner/name"). 1402 // a rooted url ignores `status` (it derives its view from the issue's own); 1403 // with an empty `id` this is the bare list link. 1404 fn issuesLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, status: evt.Issue.Status, tag: []const u8, id: []const u8) ![]const u8 { 1405 const route = ui.RoutablePage.repoIssuesRoute(identity, status, tag, id) orelse return error.RouteTooLong; 1406 const url = try route.toUrl(page_arena); 1407 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 1408 } 1409 1410 // the in-page "ai:" anchor for selecting issue `id` in `identity`'s list; the 1411 // href is only followed with js off. 1412 fn issueRowLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, id: []const u8) ![]const u8 { 1413 const route = ui.RoutablePage.repoIssuesRoute(identity, .open, "", id) orelse return error.RouteTooLong; 1414 const url = try route.toUrl(page_arena); 1415 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{url}); 1416 } 1417 1418 // the "a:" link to the whole-description page of issue `id` within `identity`. 1419 fn descriptionLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, id: []const u8) ![]const u8 { 1420 const route = ui.RoutablePage.repoIssuesDescriptionRoute(identity, id) orelse return error.RouteTooLong; 1421 const url = try route.toUrl(page_arena); 1422 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 1423 } 1424 1425 // the "a:" link to `status`'s issues list filtered to `tag` (raw; encoded here). 1426 fn tagLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, status: evt.Issue.Status, tag: []const u8) ![]const u8 { 1427 const encoded = try ui.urlEncodeRef(page_arena.allocator(), tag); 1428 const route = ui.RoutablePage.repoIssuesRoute(identity, status, encoded, "") orelse return error.RouteTooLong; 1429 const url = try route.toUrl(page_arena); 1430 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 1431 } 1432 1433 // tabs switching between the issues page's views. 1434 pub const Header = struct { 1435 box: wgt.Box(ui.Widget), 1436 tab_ids: std.AutoArrayHashMapUnmanaged(usize, void), 1437 1438 pub fn init(allocator: std.mem.Allocator, session: *ui.Session, data: *const Self) !Header { 1439 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 1440 errdefer box.deinit(allocator); 1441 1442 var tab_ids: std.AutoArrayHashMapUnmanaged(usize, void) = .empty; 1443 errdefer tab_ids.deinit(allocator); 1444 1445 const aa = session.page_arena.allocator(); 1446 1447 // a list tab per status, labeled with its listing's issue count 1448 for ([_]evt.Issue.Status{ .open, .closed }) |status| { 1449 const route = ui.RoutablePage.repoIssuesRoute(data.identity, status, data.tag, "") orelse return error.RouteTooLong; 1450 const link = try std.fmt.allocPrint(aa, "ai:{s}", .{try route.toUrl(session.page_arena)}); 1451 const label = try std.fmt.allocPrint(aa, "{s} ({d})", .{ @tagName(status), data.window(status).count }); 1452 var text_box = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 1453 errdefer text_box.deinit(allocator); 1454 text_box.getFocus().focusable = true; 1455 text_box.getFocus().kind = .{ .custom = link }; 1456 try tab_ids.put(allocator, text_box.getFocus().id, {}); 1457 try box.children.put(allocator, text_box.getFocus().id, .{ 1458 .widget = .{ .text_box = text_box }, 1459 .rect = null, 1460 .min_size = .{ .width = label.len + 2, .height = null }, 1461 }); 1462 } 1463 1464 // tags tab, labeled with the active tag filter 1465 { 1466 const tags_route = ui.RoutablePage.repoIssuesTagsRoute(data.identity, data.tag) orelse return error.RouteTooLong; 1467 const tags_link = try std.fmt.allocPrint(aa, "ai:{s}", .{try tags_route.toUrl(session.page_arena)}); 1468 const label = if (data.tag.len == 0) "tags" else blk: { 1469 const decoded = std.Uri.percentDecodeInPlace(try aa.dupe(u8, data.tag)); 1470 break :blk try std.fmt.allocPrint(aa, "tags ({s})", .{decoded}); 1471 }; 1472 var text_box = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 1473 errdefer text_box.deinit(allocator); 1474 text_box.getFocus().focusable = true; 1475 text_box.getFocus().kind = .{ .custom = tags_link }; 1476 try tab_ids.put(allocator, text_box.getFocus().id, {}); 1477 try box.children.put(allocator, text_box.getFocus().id, .{ 1478 .widget = .{ .text_box = text_box }, 1479 .rect = null, 1480 .min_size = .{ .width = label.len + 2, .height = null }, 1481 }); 1482 } 1483 1484 // new-issue tab; an edit url shows the edit tab in its place 1485 { 1486 const route = if (data.view == .edit) 1487 ui.RoutablePage.repoIssuesEditRoute(data.identity, data.selected_id) orelse return error.RouteTooLong 1488 else 1489 ui.RoutablePage.repoIssuesNewRoute(data.identity) orelse return error.RouteTooLong; 1490 const link = try std.fmt.allocPrint(aa, "ai:{s}", .{try route.toUrl(session.page_arena)}); 1491 const label: []const u8 = if (data.view == .edit) "edit" else "new"; 1492 var text_box = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 1493 errdefer text_box.deinit(allocator); 1494 text_box.getFocus().focusable = true; 1495 text_box.getFocus().kind = .{ .custom = link }; 1496 try tab_ids.put(allocator, text_box.getFocus().id, {}); 1497 try box.children.put(allocator, text_box.getFocus().id, .{ 1498 .widget = .{ .text_box = text_box }, 1499 .rect = null, 1500 .min_size = .{ .width = label.len + 2, .height = null }, 1501 }); 1502 } 1503 1504 var self = Header{ .box = box, .tab_ids = tab_ids }; 1505 // the tab matching the page's view is selected initially. 1506 self.getFocus().child_id = self.tab_ids.keys()[View.viewIndex(data.view)]; 1507 return self; 1508 } 1509 1510 pub fn deinit(self: *Header, allocator: std.mem.Allocator) void { 1511 self.box.deinit(allocator); 1512 self.tab_ids.deinit(allocator); 1513 } 1514 1515 pub fn build(self: *Header, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 1516 self.clearGrid(); 1517 // only the selected tab shows its border 1518 for (self.box.children.keys(), self.box.children.values()) |id, *child| { 1519 switch (child.widget) { 1520 .text_box => |*tb| tb.options.border_style = if (self.getFocus().child_id == id) .single else .hidden, 1521 else => {}, 1522 } 1523 } 1524 try self.box.build(allocator, constraint, root_focus); 1525 } 1526 1527 pub fn input(self: *Header, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 1528 _ = allocator; 1529 const current_tab = self.currentTabIndex() orelse return; 1530 if (inp.moveTab(key, current_tab, self.tab_ids.count())) |new_tab| { 1531 root_focus.setFocus(self.tab_ids.keys()[new_tab]); 1532 } 1533 } 1534 1535 pub fn clearGrid(self: *Header) void { 1536 self.box.clearGrid(); 1537 } 1538 1539 pub fn getGrid(self: Header) ?Grid { 1540 return self.box.getGrid(); 1541 } 1542 1543 pub fn getFocus(self: *Header) *Focus { 1544 return self.box.getFocus(); 1545 } 1546 1547 pub fn getSelectedIndex(self: Header) ?usize { 1548 return self.currentTabIndex(); 1549 } 1550 1551 fn currentTabIndex(self: Header) ?usize { 1552 const child_id = self.box.focus.child_id orelse return null; 1553 return self.tab_ids.getIndex(child_id); 1554 } 1555 }; 1556