╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Roles.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
262 switch (key) { 263 .arrow_left, .arrow_right => _ = ui.widget.moveInSelectedRow(rows, root_focus, key == .arrow_right), 264 else => { 265 // the previous link, when there is one, sits above the rows 266 const offset: usize = @intFromBool(self.data.start > 0); 267 if (current < offset or current - offset >= self.data.rows.len) return; 268 const row = self.data.rows[current - offset]; 269 const row_box = &rows.children.values()[current].widget.box; 270 const button_id = row_box.getFocus().child_id orelse return; 271 const pressed = switch (key) { 272 .enter => root_focus.grandchild_id == button_id, 273 .mouse => |mouse| inp.leftClickOn(root_focus, button_id, mouse), 274 else => false, 275 }; 276 if (!pressed) return; 277 const action: Action = switch (row_box.children.getIndex(button_id) orelse return) { 278 1 => .revoke, 279 2 => if (row.role == .owner) .demote else .promote, 280 else => return, 281 }; 282 try self.act(allocator, action, row.name); 283 }, 284 } 285 } 286 287 // the terminal performs the action itself; the web posts the form instead 288 fn act(self: *View, allocator: std.mem.Allocator, action: Action, name: []const u8) !void { 289 if (comptime wasm) return; 290 const io = self.session.io orelse return; 291 const users_dir = self.session.users_dir orelse return; 292 const admin_repo = self.session.admin_repo orelse return; 293 const actor = (try self.session.authorize(self.data.identity, .owner, null)) orelse return; 294 const moment = try evt.currentMoment(evt.admin_repo_opts, admin_repo); 295 const failure = perform(io, allocator, moment, users_dir, actor, self.data.identity, action, name) catch |err| switch (err) { 296 // a stale row; the refresh below shows the list as it is 297 error.EventNotFound => null, 298 else => return err, 299 }; 300 if (failure) |value| { 301 self.session.data.form_feedback = .{ .repo_roles = .{ .failure = value, .name = try self.session.arena.allocator().dupe(u8, name) } }; 302 return; 303 } 304 try self.session.navigate(landingRoute(self.data.identity, self.data.start, actor, action, name) orelse return error.RouteTooLong); 305 } 306 307 pub fn clearGrid(self: *View) void { 308 self.box.clearGrid(); 309 } 310 311 pub fn getGrid(self: View) ?Grid { 312 return self.box.getGrid(); 313 } 314 315 pub fn getFocus(self: *View) *Focus { 316 return self.box.getFocus(); 317 } 318 319 // up leaves the view from the add row 320 pub fn atTop(self: *View) bool { 321 return self.addActive(); 322 } 323 }; 324