From cf46e16df56906c6e727e1e7514754faa906ec83 Mon Sep 17 00:00:00 2001 From: Asaf Gartner Date: Sat, 4 Dec 2021 16:55:45 +0200 Subject: [PATCH] Edit project --- src/templates/mapping.go | 36 ++ src/templates/src/include/header.html | 22 +- src/templates/src/project_edit.html | 15 +- src/templates/src/project_index.html | 6 +- src/templates/types.go | 2 + src/website/api.go | 1 + src/website/base_data.go | 2 + src/website/projects.go | 476 ++++++++++++++++++-------- src/website/requesthandling.go | 2 + src/website/routes.go | 18 + 10 files changed, 428 insertions(+), 152 deletions(-) diff --git a/src/templates/mapping.go b/src/templates/mapping.go index fe681e6e..087ece76 100644 --- a/src/templates/mapping.go +++ b/src/templates/mapping.go @@ -99,6 +99,42 @@ func ProjectToTemplate(p *models.ProjectWithLogos, url string, theme string) Pro } } +var ProjectLifecycleValues = map[models.ProjectLifecycle]string{ + models.ProjectLifecycleActive: "active", + models.ProjectLifecycleHiatus: "hiatus", + models.ProjectLifecycleDead: "dead", + models.ProjectLifecycleLTS: "done", +} + +func ProjectLifecycleFromValue(value string) (models.ProjectLifecycle, bool) { + for k, v := range ProjectLifecycleValues { + if v == value { + return k, true + } + } + return models.ProjectLifecycleUnapproved, false +} + +func ProjectToProjectSettings(p *models.ProjectWithLogos, owners []*models.User, currentTheme string) ProjectSettings { + ownerUsers := make([]User, 0, len(owners)) + for _, owner := range owners { + ownerUsers = append(ownerUsers, UserToTemplate(owner, currentTheme)) + } + return ProjectSettings{ + Name: p.Name, + Slug: p.Slug, + Hidden: p.Hidden, + Featured: p.Featured, + Personal: p.Personal, + Lifecycle: ProjectLifecycleValues[p.Lifecycle], + Blurb: p.Blurb, + Description: p.Description, + Owners: ownerUsers, + LightLogo: ProjectLogoUrl(p, "light"), + DarkLogo: ProjectLogoUrl(p, "dark"), + } +} + func SessionToTemplate(s *models.Session) Session { return Session{ CSRFToken: s.CSRFToken, diff --git a/src/templates/src/include/header.html b/src/templates/src/include/header.html index 76626860..6d59df41 100644 --- a/src/templates/src/include/header.html +++ b/src/templates/src/include/header.html @@ -25,34 +25,40 @@ {{ end }} -