╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ NewRepo.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
150 // posts the form to the new-repo route. 151 fn submitForm(self: *View, allocator: std.mem.Allocator) !void { 152 if (comptime wasm) return; 153 const io = self.session.io orelse return; 154 const users_dir = self.session.users_dir orelse return; 155 const admin_repo = self.session.admin_repo orelse return; 156 const user_id = self.session.userId() orelse return; 157 const moment = try evt.currentMoment(evt.admin_repo_opts, admin_repo); 158 const user = (try ui.activeUser(moment, self.session.page_arena, user_id)) orelse return; 159 160 const name_input = try formField(&self.box, "name"); 161 const description_input = try formField(&self.box, "description"); 162 const name = try name_input.text(allocator); 163 defer allocator.free(name); 164 const description = try description_input.text(allocator); 165 defer allocator.free(description); 166 const hash_kind = std.meta.stringToEnum(hash.HashKind, (try formRadio(&self.box, "hash")).selected()) orelse unreachable; 167 const access = std.meta.stringToEnum(evt.Repo.Access, (try formRadio(&self.box, "access")).selected()) orelse unreachable; 168 169 _ = evt.createRepo(io, allocator, users_dir, &user_id, .{ .name = user.event.name, .email = user.event.email }, name, description, access, hash_kind) catch |err| { 170 const failure = ui.Session.FormFeedback.RepoFailure.fromError(err) orelse return err; 171 const aa = self.session.arena.allocator(); 172 self.session.data.form_feedback = .{ .repo = .{ .failure = failure, .fields = .{ 173 .name = try aa.dupe(u8, name), 174 .description = try aa.dupe(u8, description), 175 .hash = hash_kind, 176 .access = access, 177 } } }; 178 return; 179 }; 180 181 // wipe the form so a return visit starts fresh 182 name_input.clear(allocator); 183 description_input.clear(allocator); 184 185 const identity = try std.fmt.allocPrint(self.session.page_arena.allocator(), "{s}/{s}", .{ user.event.name, name }); 186 try self.session.navigate(ui.RoutablePage.repoFilesRoute(identity, null, "", "", 0) orelse return); 187 } 188 189 pub fn clearGrid(self: *View) void { 190 self.box.clearGrid(); 191 } 192 193 pub fn getGrid(self: View) ?Grid { 194 return self.box.getGrid(); 195 } 196 197 pub fn getFocus(self: *View) *Focus { 198 return self.box.getFocus(); 199 } 200 201 // up leaves the form from its first control 202 pub fn atTop(self: View) bool { 203 const first = self.box.children.keys()[0]; 204 return self.box.focus.child_id == first; 205 } 206 }; 207