Update the group promotion UI.

Invert the direction of the query to make promotions a little less exacting.
Make sure admins can't set the from group as the to group in a group promotion.
Shorten a field name in the word filter manager.

Add panel_group_promotions_level_prefix phrase.
Add panel_group_promotions_posts_prefix phrase.
Add panel_group_promotions_delete_button phrase.
This commit is contained in:
Azareal 2019-10-07 08:54:09 +10:00
parent 2e28ae39f3
commit 3798838ece
6 changed files with 18 additions and 12 deletions

View File

@ -45,7 +45,7 @@ func NewDefaultGroupPromotionStore(acc *qgen.Accumulator) (*DefaultGroupPromotio
delete: acc.Delete(ugp).Where("pid = ?").Prepare(),
create: acc.Insert(ugp).Columns("from_gid, to_gid, two_way, level, posts, minTime").Fields("?,?,?,?,?,?").Prepare(),
getByUser: acc.Select(ugp).Columns("pid, to_gid, two_way, level, posts, minTime").Where("from_gid=? AND level>=? AND posts>=?").Orderby("level DESC").Limit("1").Prepare(),
getByUser: acc.Select(ugp).Columns("pid, to_gid, two_way, level, posts, minTime").Where("from_gid=? AND level<=? AND posts<=?").Orderby("level DESC").Limit("1").Prepare(),
updateUser: acc.Update("users").Set("group = ?").Where("level >= ? AND posts >= ?").Prepare(),
}, acc.FirstError()
}

View File

@ -884,6 +884,9 @@
"panel_group_update_button":"Update Group",
"panel_group_extended_permissions":"Extended Permissions",
"panel_group_promotions_level_prefix":"level ",
"panel_group_promotions_posts_prefix":"posts ",
"panel_group_promotions_delete_button":"Delete",
"panel_group_promotions_create_head":"Add Promotion",
"panel_group_promotions_from":"From",
"panel_group_promotions_to":"To",

View File

@ -197,11 +197,13 @@ func GroupsPromotionsCreateSubmit(w http.ResponseWriter, r *http.Request, user c
if err != nil {
return c.LocalError("from must be integer", w, r, user)
}
to, err := strconv.Atoi(r.FormValue("to"))
if err != nil {
return c.LocalError("to must be integer", w, r, user)
}
if from == to {
return c.LocalError("the from group and to group cannot be the same",w,r,user)
}
twoWay := r.FormValue("two-way") == "1"
level, err := strconv.Atoi(r.FormValue("level"))

View File

@ -19,12 +19,12 @@ func WordFilters(w http.ResponseWriter, r *http.Request, user c.User) c.RouteErr
}
// TODO: What if this list gets too long?
filterList, err := c.WordFilters.GetAll()
filters, err := c.WordFilters.GetAll()
if err != nil {
return c.InternalError(err, w, r)
}
pi := c.PanelPage{basePage, tList, filterList}
pi := c.PanelPage{basePage, tList, filters}
return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "", "", "panel_word_filters", &pi})
}
@ -36,7 +36,7 @@ func WordFiltersCreateSubmit(w http.ResponseWriter, r *http.Request, user c.User
if !user.Perms.EditSettings {
return c.NoPermissions(w, r, user)
}
js := (r.PostFormValue("js") == "1")
js := r.PostFormValue("js") == "1"
// ? - We're not doing a full sanitise here, as it would be useful if admins were able to put down rules for replacing things with HTML, etc.
find := strings.TrimSpace(r.PostFormValue("find"))
@ -45,7 +45,7 @@ func WordFiltersCreateSubmit(w http.ResponseWriter, r *http.Request, user c.User
}
// Unlike with find, it's okay if we leave this blank, as this means that the admin wants to remove the word entirely with no replacement
replace := strings.TrimSpace(r.PostFormValue("replacement"))
replace := strings.TrimSpace(r.PostFormValue("replace"))
err := c.WordFilters.Create(find, replace)
if err != nil {
@ -75,7 +75,7 @@ func WordFiltersEditSubmit(w http.ResponseWriter, r *http.Request, user c.User,
if ferr != nil {
return ferr
}
js := (r.PostFormValue("js") == "1")
js := r.PostFormValue("js") == "1"
if !user.Perms.EditSettings {
return c.NoPermissionsJSQ(w, r, user, js)
}
@ -90,7 +90,7 @@ func WordFiltersEditSubmit(w http.ResponseWriter, r *http.Request, user c.User,
return c.LocalErrorJSQ("You need to specify what word you want to match", w, r, user, js)
}
// Unlike with find, it's okay if we leave this blank, as this means that the admin wants to remove the word entirely with no replacement
replace := strings.TrimSpace(r.PostFormValue("replacement"))
replace := strings.TrimSpace(r.PostFormValue("replace"))
err = c.WordFilters.Update(id, find, replace)
if err != nil {

View File

@ -11,9 +11,10 @@
{{range .Promotions}}
<div class="rowitem">
<a href="#p-{{.ID}}">{{.FromGroup.Name}} -> {{.ToGroup.Name}}{{if .TwoWay}} (two way){{end}}</a>
<span>&nbsp;-&nbsp;level {{.Level}}</span>
{{if .Level}}<span>&nbsp;-&nbsp;{{lang "panel_group_promotions_level_prefix"}}{{.Level}}</span>{{end}}
{{if .Posts}}<span>&nbsp;-&nbsp;{{lang "panel_group_promotions_posts_prefix"}}{{.Posts}}</span>{{end}}
<div class="to_right">
<a href="/panel/groups/promotions/delete/submit/{{$.ID}}-{{.ID}}?s={{$.CurrentUser.Session}}"><button form="nn">Delete</button></a>
<a href="/panel/groups/promotions/delete/submit/{{$.ID}}-{{.ID}}?s={{$.CurrentUser.Session}}"><button form="nn">{{lang "panel_group_promotions_delete_button"}}</button></a>
</div>
</div>{{end}}
<div class="rowitem">

View File

@ -6,7 +6,7 @@
<div class="rowitem panel_compactrow editable_parent">
<a data-field="find" data-type="text" href="/panel/settings/word-filters/edit/{{.ID}}" class="editable_block panel_upshift edit_fields filter_find">{{.Find}}</a>
<span class="itemSeparator"></span>
<a data-field="replacement" data-type="text" class="editable_block panel_compacttext filter_replace">{{.Replacement}}</a>
<a data-field="replace" data-type="text" class="editable_block panel_compacttext filter_replace">{{.Replacement}}</a>
<span class="panel_buttons">
<a class="panel_tag edit_fields hide_on_edit panel_right_button edit_button" aria-label="{{lang "panel_word_filters_edit_button_aria"}}"></a>
<a class="panel_right_button show_on_edit" href="/panel/settings/word-filters/edit/submit/{{.ID}}"><button class='panel_tag submit_edit' type='submit'>{{lang "panel_word_filters_update_button"}}</button></a>
@ -31,7 +31,7 @@
</div>
<div class="formrow">
<div class="formitem formlabel"><a>{{lang "panel_word_filters_create_replacement"}}</a></div>
<div class="formitem"><input name="replacement" type="text" placeholder="{{lang "panel_word_filters_create_replacement_placeholder"}}" /></div>
<div class="formitem"><input name="replace" type="text" placeholder="{{lang "panel_word_filters_create_replacement_placeholder"}}" /></div>
</div>
<div class="formrow">
<div class="formitem"><button name="panel-button" class="formbutton form_middle_button">{{lang "panel_word_filters_create_button"}}</button></div>