╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Issues.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
325 const thread_comments_start = if (empty.comment_id.len == 0) comments_start else 0; 326 const open_window = try thread.loadWindow(Self, .issue, repo_opts.hash, arena, admin_moment, haxy_moment, event_id_to_issue, open_set, open_root, conflict_set, empty.selected_id, thread_comments_start, empty.search); 327 const closed_window = try thread.loadWindow(Self, .issue, repo_opts.hash, arena, admin_moment, haxy_moment, event_id_to_issue, closed_set, closed_root, conflict_set, empty.selected_id, thread_comments_start, empty.search); 328 const conflicts_window = try thread.loadWindow(Self, .issue, repo_opts.hash, arena, admin_moment, haxy_moment, event_id_to_issue, conflict_set, conflicts_root, conflict_set, empty.selected_id, thread_comments_start, null); 329 if (view == .conflicts and conflicts_window.count > 0) resolved_view = .conflicts; 330 331 const comment_page = if (empty.comment_id.len == 0) 332 null 333 else 334 try Comment.init(repo_opts.hash, arena, admin_moment, haxy_moment, empty.selected_id, empty.comment_id, comments_start); 335 336 const labels = try thread.loadLabels(Self, repo_opts.hash, arena, haxy_moment); 337 338 return .{ 339 .identity = empty.identity, 340 .label = empty.label, 341 .search = empty.search, 342 .selected_id = empty.selected_id, 343 .comment_id = empty.comment_id, 344 .comments_start = comments_start, 345 .comment_page = comment_page, 346 .open = open_window, 347 .closed = closed_window, 348 .conflicts = conflicts_window, 349 .conflict = conflict_data, 350 .theirs_picks = empty.theirs_picks, 351 .view = resolved_view, 352 .description_page = empty.description_page, 353 .labels = labels, 354 }; 355 } 356 357 pub const View = thread.View(.issue, Self); 358 pub const Detail = thread.Detail(.issue, Self); 359 pub const detail_widget_name = "repo_issue_detail"; 360 361 pub const Header = thread.Header; 362 363 const open_tab_label = "open"; 364 const closed_tab_label = "closed"; 365 const labels_tab_label = "labels"; 366 const edit_tab_label = "edit"; 367 const reply_tab_label = "reply"; 368 const remove_tab_label = "remove"; 369 const resolve_tab_label = "resolve"; 370 const new_tab_label = "new"; 371 const conflicts_tab_label = "conflicts"; 372 373 // tabs switching between the issues page's views 374 pub fn initHeader(allocator: std.mem.Allocator, session: *ui.Session, data: *const Self) !Header { 375 var header = try Header.init(allocator, session, data.search); 376 errdefer header.deinit(allocator); 377 const aa = session.page_arena.allocator(); 378 const selected_index = View.viewIndex(data.view); 379 const page_selected = std.meta.activeTag(session.data.current_page) == .repo_issues; 380 381 // a list tab per status, labeled with its listing's issue count 382 const status_labels = [_][]const u8{ open_tab_label, closed_tab_label }; 383 for ([_]evt.Issue.Status{ .open, .closed }, status_labels, 0..) |status, status_label, index| { 384 const route = try thread.searchRoute(ui.RoutablePage.repoIssuesRoute(data.identity, status, data.label, ""), data.search); 385 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == index); 386 var label_buf: [64]u8 = undefined; 387 const label = try thread.countLabel(&label_buf, status_label, data.window(status).*); 388 try header.addTab(allocator, label, link, index); 389 } 390 391 // labels tab, showing the active label filter 392 { 393 const labels_route = try thread.searchRoute(ui.RoutablePage.repoThreadLabelsRoute(.issue, data.identity, data.label), data.search); 394 const labels_link = try ui.inPageTabLink(session, labels_route, page_selected and selected_index == View.viewIndex(.labels)); 395 const label = if (data.label.len == 0) labels_tab_label else blk: { 396 const decoded = std.Uri.percentDecodeInPlace(try aa.dupe(u8, data.label)); 397 break :blk try std.fmt.allocPrint(aa, labels_tab_label ++ " ({s})", .{decoded}); 398 }; 399 try header.addTab(allocator, label, labels_link, View.viewIndex(.labels)); 400 } 401 402 // new-issue tab; an edit or resolve url shows its tab in this place 403 { 404 const route = switch (data.view) { 405 .edit => ui.RoutablePage.repoThreadEditRoute(.issue, data.identity, data.selected_id) orelse return error.RouteTooLong, 406 .new_comment => ui.RoutablePage.repoThreadCommentNewRoute(.issue, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 407 .edit_comment => ui.RoutablePage.repoThreadCommentEditRoute(.issue, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 408 .remove => ui.RoutablePage.repoThreadRemoveRoute(.issue, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 409 .resolve => ui.RoutablePage.repoIssuesResolveRoute(data.identity, data.selected_id, data.theirs_picks) orelse return error.RouteTooLong, 410 else => ui.RoutablePage.repoThreadNewRoute(.issue, data.identity) orelse return error.RouteTooLong, 411 }; 412 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.new)); 413 const label: []const u8 = switch (data.view) { 414 .edit => edit_tab_label, 415 .new_comment => reply_tab_label, 416 .edit_comment => edit_tab_label, 417 .remove => remove_tab_label, 418 .resolve => resolve_tab_label, 419 else => new_tab_label, 420 }; 421 try header.addTab(allocator, label, link, View.viewIndex(.new)); 422 } 423 424 // conflicts tab, labeled with the conflict count 425 if (data.conflicts.count > 0) { 426 const route = ui.RoutablePage.repoIssuesConflictsRoute(data.identity, "") orelse return error.RouteTooLong; 427 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.conflicts)); 428 var label_buf: [64]u8 = undefined; 429 const label = try std.fmt.bufPrint(&label_buf, conflicts_tab_label ++ " ({d})", .{data.conflicts.count}); 430 try header.addTab(allocator, label, link, View.viewIndex(.conflicts)); 431 } 432 433 header.select(View.viewIndex(data.view)); 434 return header; 435 } 436