mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
chore: invert visualization of project labels (resolve #263)
This commit is contained in:
parent
782da0b49e
commit
2c7977cf63
@ -354,27 +354,23 @@ func (h *SettingsHandler) actionDeleteLabel(w http.ResponseWriter, r *http.Reque
|
|||||||
}
|
}
|
||||||
|
|
||||||
user := middlewares.GetPrincipal(r)
|
user := middlewares.GetPrincipal(r)
|
||||||
labelKey := r.PostFormValue("key")
|
labelKey := r.PostFormValue("key") // label key
|
||||||
labelValue := r.PostFormValue("value")
|
labelValue := r.PostFormValue("value") // project key
|
||||||
|
|
||||||
labelMap, err := h.projectLabelSrvc.GetByUserGrouped(user.ID)
|
labels, err := h.projectLabelSrvc.GetByUser(user.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return http.StatusInternalServerError, "", "could not delete label"
|
return http.StatusInternalServerError, "", "could not delete label"
|
||||||
}
|
}
|
||||||
|
|
||||||
if projectLabels, ok := labelMap[labelKey]; ok {
|
for _, l := range labels {
|
||||||
for _, l := range projectLabels {
|
if l.Label == labelKey && l.ProjectKey == labelValue {
|
||||||
if l.Label == labelValue {
|
if err := h.projectLabelSrvc.Delete(l); err != nil {
|
||||||
if err := h.projectLabelSrvc.Delete(l); err != nil {
|
return http.StatusInternalServerError, "", "could not delete label"
|
||||||
return http.StatusInternalServerError, "", "could not delete label"
|
|
||||||
}
|
|
||||||
return http.StatusOK, "label deleted successfully", ""
|
|
||||||
}
|
}
|
||||||
|
return http.StatusOK, "label deleted successfully", ""
|
||||||
}
|
}
|
||||||
return http.StatusNotFound, "", "label not found"
|
|
||||||
} else {
|
|
||||||
return http.StatusNotFound, "", "project not found"
|
|
||||||
}
|
}
|
||||||
|
return http.StatusNotFound, "", "label not found"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *SettingsHandler) actionDeleteLanguageMapping(w http.ResponseWriter, r *http.Request) (int, string, string) {
|
func (h *SettingsHandler) actionDeleteLanguageMapping(w http.ResponseWriter, r *http.Request) (int, string, string) {
|
||||||
@ -651,7 +647,7 @@ func (h *SettingsHandler) buildViewModel(r *http.Request) *view.SettingsViewMode
|
|||||||
}
|
}
|
||||||
|
|
||||||
// labels
|
// labels
|
||||||
labelMap, err := h.projectLabelSrvc.GetByUserGrouped(user.ID)
|
labelMap, err := h.projectLabelSrvc.GetByUserGroupedInverted(user.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
conf.Log().Request(r).Error("error while building settings project label map - %v", err)
|
conf.Log().Request(r).Error("error while building settings project label map - %v", err)
|
||||||
return &view.SettingsViewModel{Error: criticalError}
|
return &view.SettingsViewModel{Error: criticalError}
|
||||||
@ -660,11 +656,11 @@ func (h *SettingsHandler) buildViewModel(r *http.Request) *view.SettingsViewMode
|
|||||||
combinedLabels := make([]*view.SettingsVMCombinedLabel, 0)
|
combinedLabels := make([]*view.SettingsVMCombinedLabel, 0)
|
||||||
for _, l := range labelMap {
|
for _, l := range labelMap {
|
||||||
cl := &view.SettingsVMCombinedLabel{
|
cl := &view.SettingsVMCombinedLabel{
|
||||||
Key: l[0].ProjectKey,
|
Key: l[0].Label,
|
||||||
Values: make([]string, len(l)),
|
Values: make([]string, len(l)),
|
||||||
}
|
}
|
||||||
for i, l1 := range l {
|
for i, l1 := range l {
|
||||||
cl.Values[i] = l1.Label
|
cl.Values[i] = l1.ProjectKey
|
||||||
}
|
}
|
||||||
combinedLabels = append(combinedLabels, cl)
|
combinedLabels = append(combinedLabels, cl)
|
||||||
}
|
}
|
||||||
|
@ -44,21 +44,37 @@ func (srv *ProjectLabelService) GetByUser(userId string) ([]*models.ProjectLabel
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (srv *ProjectLabelService) GetByUserGrouped(userId string) (map[string][]*models.ProjectLabel, error) {
|
func (srv *ProjectLabelService) GetByUserGrouped(userId string) (map[string][]*models.ProjectLabel, error) {
|
||||||
labels := make(map[string][]*models.ProjectLabel)
|
labelsByProject := make(map[string][]*models.ProjectLabel)
|
||||||
userLabels, err := srv.GetByUser(userId)
|
userLabels, err := srv.GetByUser(userId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, l := range userLabels {
|
for _, l := range userLabels {
|
||||||
if _, ok := labels[l.ProjectKey]; !ok {
|
if _, ok := labelsByProject[l.ProjectKey]; !ok {
|
||||||
labels[l.ProjectKey] = []*models.ProjectLabel{l}
|
labelsByProject[l.ProjectKey] = []*models.ProjectLabel{l}
|
||||||
} else {
|
} else {
|
||||||
labels[l.ProjectKey] = append(labels[l.ProjectKey], l)
|
labelsByProject[l.ProjectKey] = append(labelsByProject[l.ProjectKey], l)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return labelsByProject, nil
|
||||||
|
}
|
||||||
|
|
||||||
return labels, nil
|
func (srv *ProjectLabelService) GetByUserGroupedInverted(userId string) (map[string][]*models.ProjectLabel, error) {
|
||||||
|
projectsByLabel := make(map[string][]*models.ProjectLabel)
|
||||||
|
userLabels, err := srv.GetByUser(userId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, l := range userLabels {
|
||||||
|
if _, ok := projectsByLabel[l.Label]; !ok {
|
||||||
|
projectsByLabel[l.Label] = []*models.ProjectLabel{l}
|
||||||
|
} else {
|
||||||
|
projectsByLabel[l.Label] = append(projectsByLabel[l.Label], l)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return projectsByLabel, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *ProjectLabelService) Create(label *models.ProjectLabel) (*models.ProjectLabel, error) {
|
func (srv *ProjectLabelService) Create(label *models.ProjectLabel) (*models.ProjectLabel, error) {
|
||||||
|
@ -62,6 +62,7 @@ type IProjectLabelService interface {
|
|||||||
GetById(uint) (*models.ProjectLabel, error)
|
GetById(uint) (*models.ProjectLabel, error)
|
||||||
GetByUser(string) ([]*models.ProjectLabel, error)
|
GetByUser(string) ([]*models.ProjectLabel, error)
|
||||||
GetByUserGrouped(string) (map[string][]*models.ProjectLabel, error)
|
GetByUserGrouped(string) (map[string][]*models.ProjectLabel, error)
|
||||||
|
GetByUserGroupedInverted(string) (map[string][]*models.ProjectLabel, error)
|
||||||
Create(*models.ProjectLabel) (*models.ProjectLabel, error)
|
Create(*models.ProjectLabel) (*models.ProjectLabel, error)
|
||||||
Delete(*models.ProjectLabel) error
|
Delete(*models.ProjectLabel) error
|
||||||
}
|
}
|
||||||
|
@ -221,9 +221,9 @@
|
|||||||
<div class="flex items-center" action="" method="post">
|
<div class="flex items-center" action="" method="post">
|
||||||
<div class="text-gray-500 border-1 w-full border-green-700 inline-block my-1 py-1 text-align text-sm"
|
<div class="text-gray-500 border-1 w-full border-green-700 inline-block my-1 py-1 text-align text-sm"
|
||||||
style="line-height: 1.8">
|
style="line-height: 1.8">
|
||||||
▸ <span class="font-semibold text-white">{{ $label.Key }}:</span>
|
▸ <span class="font-semibold text-white font-mono">{{ $label.Key }}:</span>
|
||||||
{{ range $j, $value := $label.Values }}
|
{{ range $j, $value := $label.Values }}
|
||||||
<form action="" method="post" class="text-white text-xs bg-gray-900 rounded-full py-1 px-2 font-mono inline-flex justify-between items-center space-x-2">
|
<form action="" method="post" class="text-white text-xs bg-gray-900 rounded-full py-1 px-2 my-1 inline-flex justify-between items-center space-x-2">
|
||||||
<input type="hidden" name="action" value="delete_label">
|
<input type="hidden" name="action" value="delete_label">
|
||||||
<input type="hidden" name="key" value="{{ $label.Key }}">
|
<input type="hidden" name="key" value="{{ $label.Key }}">
|
||||||
<input type="hidden" name="value" value="{{ $value }}">
|
<input type="hidden" name="value" value="{{ $value }}">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user