mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
chore: show warning message when data about to expire
This commit is contained in:
parent
934178412e
commit
8ccfcef8e3
File diff suppressed because it is too large
Load Diff
2
main.go
2
main.go
@ -214,7 +214,7 @@ func main() {
|
||||
shieldV1BadgeHandler := shieldsV1Routes.NewBadgeHandler(summaryService, userService)
|
||||
|
||||
// MVC Handlers
|
||||
summaryHandler := routes.NewSummaryHandler(summaryService, userService)
|
||||
summaryHandler := routes.NewSummaryHandler(summaryService, userService, keyValueService)
|
||||
settingsHandler := routes.NewSettingsHandler(userService, heartbeatService, summaryService, aliasService, aggregationService, languageMappingService, projectLabelService, keyValueService, mailService)
|
||||
subscriptionHandler := routes.NewSubscriptionHandler(userService, mailService, keyValueService)
|
||||
leaderboardHandler := routes.NewLeaderboardHandler(userService, leaderboardService)
|
||||
|
@ -1,6 +1,10 @@
|
||||
package view
|
||||
|
||||
import "github.com/muety/wakapi/models"
|
||||
import (
|
||||
conf "github.com/muety/wakapi/config"
|
||||
"github.com/muety/wakapi/models"
|
||||
"time"
|
||||
)
|
||||
|
||||
type SummaryViewModel struct {
|
||||
Messages
|
||||
@ -13,6 +17,16 @@ type SummaryViewModel struct {
|
||||
OSColors map[string]string
|
||||
ApiKey string
|
||||
RawQuery string
|
||||
UserFirstData time.Time
|
||||
}
|
||||
|
||||
func (s SummaryViewModel) UserDataExpiring() bool {
|
||||
cfg := conf.Get()
|
||||
return cfg.Subscriptions.Enabled &&
|
||||
cfg.App.DataRetentionMonths > 0 &&
|
||||
!s.UserFirstData.IsZero() &&
|
||||
!s.User.HasActiveSubscription() &&
|
||||
time.Now().AddDate(0, -cfg.App.DataRetentionMonths, 0).After(s.UserFirstData)
|
||||
}
|
||||
|
||||
func (s *SummaryViewModel) WithSuccess(m string) *SummaryViewModel {
|
||||
|
@ -11,19 +11,22 @@ import (
|
||||
su "github.com/muety/wakapi/routes/utils"
|
||||
"github.com/muety/wakapi/services"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
type SummaryHandler struct {
|
||||
config *conf.Config
|
||||
userSrvc services.IUserService
|
||||
summarySrvc services.ISummaryService
|
||||
config *conf.Config
|
||||
userSrvc services.IUserService
|
||||
summarySrvc services.ISummaryService
|
||||
keyValueSrvc services.IKeyValueService
|
||||
}
|
||||
|
||||
func NewSummaryHandler(summaryService services.ISummaryService, userService services.IUserService) *SummaryHandler {
|
||||
func NewSummaryHandler(summaryService services.ISummaryService, userService services.IUserService, keyValueService services.IKeyValueService) *SummaryHandler {
|
||||
return &SummaryHandler{
|
||||
summarySrvc: summaryService,
|
||||
userSrvc: userService,
|
||||
config: conf.Get(),
|
||||
summarySrvc: summaryService,
|
||||
userSrvc: userService,
|
||||
keyValueSrvc: keyValueService,
|
||||
config: conf.Get(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,6 +84,13 @@ func (h *SummaryHandler) GetIndex(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// user first data
|
||||
var firstData time.Time
|
||||
firstDataKv := h.keyValueSrvc.MustGetString(fmt.Sprintf("%s_%s", conf.KeyFirstHeartbeat, user.ID))
|
||||
if firstDataKv.Value != "" {
|
||||
firstData, _ = time.Parse(time.RFC822Z, firstDataKv.Value)
|
||||
}
|
||||
|
||||
vm := view.SummaryViewModel{
|
||||
Summary: summary,
|
||||
SummaryParams: summaryParams,
|
||||
@ -90,6 +100,7 @@ func (h *SummaryHandler) GetIndex(w http.ResponseWriter, r *http.Request) {
|
||||
OSColors: su.FilterColors(h.config.App.GetOSColors(), summary.OperatingSystems),
|
||||
ApiKey: user.ApiKey,
|
||||
RawQuery: rawQuery,
|
||||
UserFirstData: firstData,
|
||||
}
|
||||
|
||||
templates[conf.SummaryTemplate].Execute(w, vm)
|
||||
|
File diff suppressed because one or more lines are too long
Binary file not shown.
@ -17,8 +17,17 @@
|
||||
{{ if .User.HasData }}
|
||||
|
||||
<div id="summary-page" class="grow" v-scope>
|
||||
<div class="flex justify-end mt-12 relative">
|
||||
<div v-scope="TimePicker({
|
||||
<div class="flex justify-end md:space-x-8 mt-12 flex-wrap md:flex-nowrap relative items-center">
|
||||
{{ if $.UserDataExpiring }}
|
||||
<div class="flex-grow justify-start">
|
||||
<div class="flex-grow p-4 text-sm border-2 border-orange-500 rounded shadow text-gray-300 align-middle mb-4 md:mb-0">
|
||||
<span class="iconify inline mr-1" data-icon="emojione-v1:warning"></span>
|
||||
Some of your data is older than this instance's data retention period. This will cause old data to be deleted, unless you opt for a subscription. Go to <a class="font-semibold text-green-700" href="settings#subscription">Settings → Subscription</a> for more details.
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
<div class="flex-shrink-0" v-scope="TimePicker({
|
||||
fromDate: '{{ .From | simpledate }}',
|
||||
toDate: '{{ .To | ceildate | simpledate }}',
|
||||
timeSelection: '{{ .From | datetime }} - {{ .To | ceildate | datetime }}'
|
||||
|
Loading…
Reference in New Issue
Block a user