mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
feat: settings option to opt in to leaderboards
This commit is contained in:
parent
82a565738f
commit
23759d526a
@ -175,6 +175,7 @@ func (r *UserRepository) Update(user *models.User) (*models.User, error) {
|
|||||||
"reset_token": user.ResetToken,
|
"reset_token": user.ResetToken,
|
||||||
"location": user.Location,
|
"location": user.Location,
|
||||||
"reports_weekly": user.ReportsWeekly,
|
"reports_weekly": user.ReportsWeekly,
|
||||||
|
"public_leaderboard": user.PublicLeaderboard,
|
||||||
}
|
}
|
||||||
|
|
||||||
result := r.db.Model(user).Updates(updateMap)
|
result := r.db.Model(user).Updates(updateMap)
|
||||||
|
@ -146,6 +146,8 @@ func (h *SettingsHandler) dispatchAction(action string) action {
|
|||||||
return h.actionAddLanguageMapping
|
return h.actionAddLanguageMapping
|
||||||
case "update_sharing":
|
case "update_sharing":
|
||||||
return h.actionUpdateSharing
|
return h.actionUpdateSharing
|
||||||
|
case "update_leaderboard":
|
||||||
|
return h.actionUpdateLeaderboard
|
||||||
case "toggle_wakatime":
|
case "toggle_wakatime":
|
||||||
return h.actionSetWakatimeApiKey
|
return h.actionSetWakatimeApiKey
|
||||||
case "import_wakatime":
|
case "import_wakatime":
|
||||||
@ -252,6 +254,26 @@ func (h *SettingsHandler) actionResetApiKey(w http.ResponseWriter, r *http.Reque
|
|||||||
return http.StatusOK, msg, ""
|
return http.StatusOK, msg, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *SettingsHandler) actionUpdateLeaderboard(w http.ResponseWriter, r *http.Request) (int, string, string) {
|
||||||
|
if h.config.IsDev() {
|
||||||
|
loadTemplates()
|
||||||
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
user := middlewares.GetPrincipal(r)
|
||||||
|
defer h.userSrvc.FlushCache()
|
||||||
|
|
||||||
|
user.PublicLeaderboard, err = strconv.ParseBool(r.PostFormValue("enable_leaderboard"))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return http.StatusBadRequest, "", "invalid input"
|
||||||
|
}
|
||||||
|
if _, err := h.userSrvc.Update(user); err != nil {
|
||||||
|
return http.StatusInternalServerError, "", "internal sever error"
|
||||||
|
}
|
||||||
|
return http.StatusOK, "settings updated", ""
|
||||||
|
}
|
||||||
|
|
||||||
func (h *SettingsHandler) actionUpdateSharing(w http.ResponseWriter, r *http.Request) (int, string, string) {
|
func (h *SettingsHandler) actionUpdateSharing(w http.ResponseWriter, r *http.Request) (int, string, string) {
|
||||||
if h.config.IsDev() {
|
if h.config.IsDev() {
|
||||||
loadTemplates()
|
loadTemplates()
|
||||||
|
@ -380,6 +380,46 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-cloak id="permissions" class="tab flex flex-col space-y-4" v-if="isActive('permissions')">
|
<div v-cloak id="permissions" class="tab flex flex-col space-y-4" v-if="isActive('permissions')">
|
||||||
|
<!-- Public Leaderboard -->
|
||||||
|
<form action="" method="post" class="w-full lg:w-3/4">
|
||||||
|
<div class="flex flex-wrap md:flex-nowrap mb-8 gap-x-4">
|
||||||
|
<div class="w-full md:w-1/2 mb-4 md:mb-0 inline-block">
|
||||||
|
<span class="font-semibold text-gray-300 text-lg">Public Leaderboard</span>
|
||||||
|
<p class="block text-sm text-gray-600">
|
||||||
|
Opt in to get listed in the <a class="link" href="leaderboard">public leaderboard</a>. It shows aggregated statistics from the past 7 days of your coding.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex-col w-full md:w-1/2 inline-block space-y-4">
|
||||||
|
<input type="hidden" name="action" value="update_leaderboard">
|
||||||
|
|
||||||
|
<div class="flex space-x-8">
|
||||||
|
<div class="flex-grow">
|
||||||
|
<label class="font-semibold text-gray-300" for="share_projects">Participate in leaderboard</label>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<select autocomplete="off" id="enable_leaderboard" name="enable_leaderboard" class="select-default flex-grow">
|
||||||
|
<option value="false" class="cursor-pointer" {{ if not .User.PublicLeaderboard }} selected {{ end }}>No
|
||||||
|
</option>
|
||||||
|
<option value="true" class="cursor-pointer" {{ if .User.PublicLeaderboard }} selected {{ end }}>Yes
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex justify-end mt-4">
|
||||||
|
<button type="submit" class="btn-primary">
|
||||||
|
Save
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div class="w-full md:w-3/4">
|
||||||
|
<hr class="border-t border-gray-800 my-4">
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Public Data -->
|
<!-- Public Data -->
|
||||||
<form action="" method="post" class="w-full lg:w-3/4">
|
<form action="" method="post" class="w-full lg:w-3/4">
|
||||||
<div class="flex flex-wrap md:flex-nowrap mb-8 gap-x-4">
|
<div class="flex flex-wrap md:flex-nowrap mb-8 gap-x-4">
|
||||||
|
Loading…
Reference in New Issue
Block a user