╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Patches.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
986 len += 1; 987 } 988 name[len] = std.ascii.toLower(char); 989 len += 1; 990 pending = null; 991 } else if (char == ' ') { 992 if (len != 0) pending = '-'; 993 } else if (char == '.') { 994 if (len != 0 and pending != '-') pending = '.'; 995 } 996 } 997 if (len == 0) return ""; 998 return allocator.dupe(u8, name[0..len]); 999 } 1000 1001 // tabs switching between the patches page's views 1002 pub fn initHeader(allocator: std.mem.Allocator, session: *ui.Session, data: *const Self) !Header { 1003 var header = try Header.init(allocator, session, data.search); 1004 errdefer header.deinit(allocator); 1005 const aa = session.page_arena.allocator(); 1006 const selected_index = View.viewIndex(data.view); 1007 const page_selected = std.meta.activeTag(session.data.current_page) == .repo_patches; 1008 1009 // a list tab per status, labeled with its listing's patch count 1010 const status_labels = [_][]const u8{ open_tab_label, closed_tab_label, merged_tab_label }; 1011 for ([_]Status{ .open, .closed, .merged }, status_labels, 0..) |status, status_label, index| { 1012 const route = try thread.searchRoute(ui.RoutablePage.repoPatchesRoute(data.identity, status, data.label, ""), data.search); 1013 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == index); 1014 var label_buf: [64]u8 = undefined; 1015 const label = try thread.countLabel(&label_buf, status_label, data.window(status).*); 1016 try header.addTab(allocator, label, link, index); 1017 } 1018 1019 // labels tab, showing the active label filter 1020 { 1021 const labels_route = try thread.searchRoute(ui.RoutablePage.repoThreadLabelsRoute(.patch, data.identity, data.label), data.search); 1022 const labels_link = try ui.inPageTabLink(session, labels_route, page_selected and selected_index == View.viewIndex(.labels)); 1023 const label = if (data.label.len == 0) labels_tab_label else blk: { 1024 const decoded = std.Uri.percentDecodeInPlace(try aa.dupe(u8, data.label)); 1025 break :blk try std.fmt.allocPrint(aa, labels_tab_label ++ " ({s})", .{decoded}); 1026 }; 1027 try header.addTab(allocator, label, labels_link, View.viewIndex(.labels)); 1028 } 1029 1030 // new-patch tab; an edit or resolve url shows its tab in this place 1031 { 1032 const route = switch (data.view) { 1033 .edit => ui.RoutablePage.repoThreadEditRoute(.patch, data.identity, data.selected_id) orelse return error.RouteTooLong, 1034 .publish => ui.RoutablePage.repoPatchPublishRoute(data.identity, data.selected_id) orelse return error.RouteTooLong, 1035 .merge => ui.RoutablePage.repoPatchMergeRoute(data.identity, data.selected_id) orelse return error.RouteTooLong, 1036 .new_comment => ui.RoutablePage.repoThreadCommentNewRoute(.patch, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 1037 .edit_comment => ui.RoutablePage.repoThreadCommentEditRoute(.patch, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 1038 .remove => ui.RoutablePage.repoThreadRemoveRoute(.patch, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 1039 .resolve => ui.RoutablePage.repoPatchesResolveRoute(data.identity, data.selected_id, data.theirs_picks) orelse return error.RouteTooLong, 1040 else => ui.RoutablePage.repoThreadNewRoute(.patch, data.identity) orelse return error.RouteTooLong, 1041 }; 1042 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.new)); 1043 const label: []const u8 = switch (data.view) { 1044 .edit => edit_tab_label, 1045 .publish => publish_tab_label, 1046 .merge => merge_tab_label, 1047 .new_comment => reply_tab_label, 1048 .edit_comment => edit_tab_label, 1049 .remove => remove_tab_label, 1050 .resolve => resolve_tab_label, 1051 else => new_tab_label, 1052 }; 1053 try header.addTab(allocator, label, link, View.viewIndex(.new)); 1054 } 1055 1056 // drafts belong to the logged-in user and are not available locally 1057 if (session.data.host_kind != .local) { 1058 const route = ui.RoutablePage.repoPatchesDraftsRoute(data.identity) orelse return error.RouteTooLong; 1059 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.drafts)); 1060 var label_buf: [64]u8 = undefined; 1061 const label = try std.fmt.bufPrint(&label_buf, drafts_tab_label ++ " ({d})", .{data.drafts.count}); 1062 try header.addTab(allocator, label, link, View.viewIndex(.drafts)); 1063 } 1064 1065 // conflicts tab, labeled with the conflict count 1066 if (data.conflicts.count > 0) { 1067 const route = ui.RoutablePage.repoPatchesConflictsRoute(data.identity, "") orelse return error.RouteTooLong; 1068 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.conflicts)); 1069 var label_buf: [64]u8 = undefined; 1070 const label = try std.fmt.bufPrint(&label_buf, conflicts_tab_label ++ " ({d})", .{data.conflicts.count}); 1071 try header.addTab(allocator, label, link, View.viewIndex(.conflicts)); 1072 } 1073 1074 header.select(View.viewIndex(data.view)); 1075 return header; 1076 } 1077