aboutsummaryrefslogtreecommitdiff
blob: 10d4b9c7ed452e51b45101dc02bbd1d9b114dd6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package user

import (
	"encoding/base64"
	"encoding/json"
	"net/http"
	"slices"
	"soko/pkg/app/utils"
	"soko/pkg/database"
	"soko/pkg/models"
	"time"
)

func splitAllProjects() [][]models.Project {
	var projects []models.Project
	database.DBCon.Model(&projects).Column("name", "email").Select()
	split := (3 + len(projects)) / 4
	return [][]models.Project{projects[:split], projects[split : 2*split], projects[2*split : 3*split], projects[3*split:]}
}

templ maintainers(preferences models.MaintainersPreferences) {
	<form method="post" action="/user/preferences/maintainers/edit">
		<div class="row">
			<div class="col-12">
				<h3 class="mt-0" id="qa-report">Include Project Packages</h3>
				<div class="form-check form-check-inline" style="text-overflow: ellipsis;overflow: hidden; width: 100%;">
					<input
						type="checkbox"
						id="include-packages"
						name="include-packages"
						value="true"
						checked?={ preferences.IncludeProjectPackages }
					/>
					<label class="form-check-label ml-1" for="include-packages" style="overflow:hidden;text-overflow: ellipsis;" title="">Include packages of projects the maintainer is part of</label>
				</div>
				<i>If this option is enabled, all packages, QA reports, pull requests and bugs of projects a maintainer is part of will be displayed as well on the maintainer page. That is, if <i>Larry</i> is part of the <i>Python</i> project, all packages, QA reports, pull requests and bugs of the Python project will be displayed as well on the maintainer page of <i>Larry</i>.<br/>Below you can furthermore specify projects that will be excluded on the maintainer page. E.g. if Larry is furthermore part of the proxy-maintainers project, and the project is marked below, packages of the proxy maintainers project won't be shown on Larry's maintainer page.</i>
			</div>
			<div class="col-12">
				<h3 class="mt-4 pt-3" id="qa-report">Excluded Projects</h3>
			</div>
			for _, projects := range splitAllProjects() {
				<div class="col-3">
					for _, project := range projects {
						<li class="list-group-item">
							<div class="form-check form-check-inline" style="text-overflow: ellipsis;overflow: hidden; width: 100%;height:21px;">
								<input
									type="checkbox"
									id={ "excluded-projects-" + project.Email }
									name="excluded-projects"
									value={ project.Email }
									checked?={ slices.Contains(preferences.ExcludedProjects, project.Email) }
								/>
								<label class="form-check-label ml-1" for={ "excluded-projects-" + project.Email } style="overflow:hidden;text-overflow: ellipsis;height:21px;" title={ project.Name }>{ project.Name }</label>
							</div>
						</li>
					}
				</div>
			}
			<div class="col-12 mt-4">
				<button type="submit" class="float-right btn btn-sm btn-primary">Save</button>
				<a class="float-right btn btn-sm btn-outline-danger mr-2" href="/user/preferences/maintainers/reset">Reset to Defaults</a>
			</div>
		</div>
	</form>
}

func Maintainers(w http.ResponseWriter, r *http.Request) {
	userPreferences := utils.GetUserPreferences(r)
	r.ParseForm()
	// excluded projects
	excludedProjects := r.Form["excluded-projects"]
	userPreferences.Maintainers.ExcludedProjects = excludedProjects
	// include projects?
	includePackages := r.Form.Get("include-packages")
	userPreferences.Maintainers.IncludeProjectPackages = includePackages == "true"
	// store cookie
	encodedUserPreferences, err := json.Marshal(&userPreferences.Maintainers)
	if err == nil {
		sEnc := base64.StdEncoding.EncodeToString(encodedUserPreferences)
		addCookie(w, "userpref_maintainers", "/", sEnc, 365*24*time.Hour)
	}
	http.Redirect(w, r, "/user/preferences/maintainers", http.StatusSeeOther)
}

func ResetMaintainers(w http.ResponseWriter, r *http.Request) {
	userPreferences := utils.GetDefaultUserPreferences()
	encodedUserPreferences, err := json.Marshal(&userPreferences.Maintainers)
	if err == nil {
		sEnc := base64.StdEncoding.EncodeToString(encodedUserPreferences)
		addCookie(w, "userpref_maintainers", "/", sEnc, 365*24*time.Hour)
	}
	http.Redirect(w, r, "/user/preferences/maintainers", http.StatusSeeOther)
}