mirror of
https://github.com/go-gitea/gitea
synced 2024-12-22 13:17:53 +01:00
Improvements for supporting UI Location (#3146)
* improvements for supporting UI Location * improved the comment
This commit is contained in:
parent
b6d2243ac0
commit
f94c1b3943
@ -18,6 +18,7 @@ import (
|
|||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/private"
|
"code.gitea.io/gitea/modules/private"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
"code.gitea.io/gitea/modules/util"
|
||||||
|
|
||||||
"github.com/Unknwon/com"
|
"github.com/Unknwon/com"
|
||||||
"github.com/dgrijalva/jwt-go"
|
"github.com/dgrijalva/jwt-go"
|
||||||
@ -219,8 +220,8 @@ func runServ(c *cli.Context) error {
|
|||||||
fail("Internal error", "GetDeployKey: %v", err)
|
fail("Internal error", "GetDeployKey: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
deployKey.Updated = time.Now()
|
deployKey.UpdatedUnix = util.TimeStampNow()
|
||||||
if err = models.UpdateDeployKey(deployKey); err != nil {
|
if err = models.UpdateDeployKeyCols(deployKey, "updated_unix"); err != nil {
|
||||||
fail("Internal error", "UpdateDeployKey: %v", err)
|
fail("Internal error", "UpdateDeployKey: %v", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -7,6 +7,7 @@ package models
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/modules/setting"
|
||||||
api "code.gitea.io/sdk/gitea"
|
api "code.gitea.io/sdk/gitea"
|
||||||
|
|
||||||
"github.com/go-xorm/builder"
|
"github.com/go-xorm/builder"
|
||||||
@ -24,7 +25,7 @@ type TrackedTime struct {
|
|||||||
|
|
||||||
// AfterLoad is invoked from XORM after setting the values of all fields of this object.
|
// AfterLoad is invoked from XORM after setting the values of all fields of this object.
|
||||||
func (t *TrackedTime) AfterLoad() {
|
func (t *TrackedTime) AfterLoad() {
|
||||||
t.Created = time.Unix(t.CreatedUnix, 0).Local()
|
t.Created = time.Unix(t.CreatedUnix, 0).In(setting.UILocation)
|
||||||
}
|
}
|
||||||
|
|
||||||
// APIFormat converts TrackedTime to API format
|
// APIFormat converts TrackedTime to API format
|
||||||
|
@ -600,20 +600,16 @@ type DeployKey struct {
|
|||||||
Fingerprint string
|
Fingerprint string
|
||||||
Content string `xorm:"-"`
|
Content string `xorm:"-"`
|
||||||
|
|
||||||
Created time.Time `xorm:"-"`
|
CreatedUnix util.TimeStamp `xorm:"created"`
|
||||||
CreatedUnix int64 `xorm:"created"`
|
UpdatedUnix util.TimeStamp `xorm:"updated"`
|
||||||
Updated time.Time `xorm:"-"`
|
HasRecentActivity bool `xorm:"-"`
|
||||||
UpdatedUnix int64 `xorm:"updated"`
|
HasUsed bool `xorm:"-"`
|
||||||
HasRecentActivity bool `xorm:"-"`
|
|
||||||
HasUsed bool `xorm:"-"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AfterLoad is invoked from XORM after setting the values of all fields of this object.
|
// AfterLoad is invoked from XORM after setting the values of all fields of this object.
|
||||||
func (key *DeployKey) AfterLoad() {
|
func (key *DeployKey) AfterLoad() {
|
||||||
key.Created = time.Unix(key.CreatedUnix, 0).Local()
|
key.HasUsed = key.UpdatedUnix > key.CreatedUnix
|
||||||
key.Updated = time.Unix(key.UpdatedUnix, 0).Local()
|
key.HasRecentActivity = key.UpdatedUnix.AddDuration(7*24*time.Hour) > util.TimeStampNow()
|
||||||
key.HasUsed = key.Updated.After(key.Created)
|
|
||||||
key.HasRecentActivity = key.Updated.Add(7 * 24 * time.Hour).After(time.Now())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetContent gets associated public key content.
|
// GetContent gets associated public key content.
|
||||||
@ -740,6 +736,12 @@ func GetDeployKeyByRepo(keyID, repoID int64) (*DeployKey, error) {
|
|||||||
return key, nil
|
return key, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateDeployKeyCols updates deploy key information in the specified columns.
|
||||||
|
func UpdateDeployKeyCols(key *DeployKey, cols ...string) error {
|
||||||
|
_, err := x.ID(key.ID).Cols(cols...).Update(key)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// UpdateDeployKey updates deploy key information.
|
// UpdateDeployKey updates deploy key information.
|
||||||
func UpdateDeployKey(key *DeployKey) error {
|
func UpdateDeployKey(key *DeployKey) error {
|
||||||
_, err := x.ID(key.ID).AllCols().Update(key)
|
_, err := x.ID(key.ID).AllCols().Update(key)
|
||||||
|
@ -151,14 +151,6 @@ func (u *User) UpdateDiffViewStyle(style string) error {
|
|||||||
return UpdateUserCols(u, "diff_view_style")
|
return UpdateUserCols(u, "diff_view_style")
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
// AfterLoad is invoked from XORM after setting the values of all fields of this object.
|
|
||||||
func (u *User) AfterLoad() {
|
|
||||||
u.Created = time.Unix(u.CreatedUnix, 0).Local()
|
|
||||||
u.Updated = time.Unix(u.UpdatedUnix, 0).Local()
|
|
||||||
u.LastLogin = time.Unix(u.LastLoginUnix, 0).Local()
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// getEmail returns an noreply email, if the user has set to keep his
|
// getEmail returns an noreply email, if the user has set to keep his
|
||||||
// email address private, otherwise the primary email address.
|
// email address private, otherwise the primary email address.
|
||||||
func (u *User) getEmail() string {
|
func (u *User) getEmail() string {
|
||||||
|
@ -531,6 +531,9 @@ var (
|
|||||||
IterateBufferSize int
|
IterateBufferSize int
|
||||||
|
|
||||||
ExternalMarkupParsers []MarkupParser
|
ExternalMarkupParsers []MarkupParser
|
||||||
|
// UILocation is the location on the UI, so that we can display the time on UI.
|
||||||
|
// Currently only show the default time.Local, it could be added to app.ini after UI is ready
|
||||||
|
UILocation = time.Local
|
||||||
)
|
)
|
||||||
|
|
||||||
// DateLang transforms standard language locale name to corresponding value in datetime plugin.
|
// DateLang transforms standard language locale name to corresponding value in datetime plugin.
|
||||||
|
@ -4,7 +4,11 @@
|
|||||||
|
|
||||||
package util
|
package util
|
||||||
|
|
||||||
import "time"
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
)
|
||||||
|
|
||||||
// TimeStamp defines a timestamp
|
// TimeStamp defines a timestamp
|
||||||
type TimeStamp int64
|
type TimeStamp int64
|
||||||
@ -31,13 +35,13 @@ func (ts TimeStamp) Year() int {
|
|||||||
|
|
||||||
// AsTime convert timestamp as time.Time in Local locale
|
// AsTime convert timestamp as time.Time in Local locale
|
||||||
func (ts TimeStamp) AsTime() (tm time.Time) {
|
func (ts TimeStamp) AsTime() (tm time.Time) {
|
||||||
tm = time.Unix(int64(ts), 0).Local()
|
tm = time.Unix(int64(ts), 0).In(setting.UILocation)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// AsTimePtr convert timestamp as *time.Time in Local locale
|
// AsTimePtr convert timestamp as *time.Time in Local locale
|
||||||
func (ts TimeStamp) AsTimePtr() *time.Time {
|
func (ts TimeStamp) AsTimePtr() *time.Time {
|
||||||
tm := time.Unix(int64(ts), 0).Local()
|
tm := time.Unix(int64(ts), 0).In(setting.UILocation)
|
||||||
return &tm
|
return &tm
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ func ToDeployKey(apiLink string, key *models.DeployKey) *api.DeployKey {
|
|||||||
Key: key.Content,
|
Key: key.Content,
|
||||||
URL: apiLink + com.ToStr(key.ID),
|
URL: apiLink + com.ToStr(key.ID),
|
||||||
Title: key.Name,
|
Title: key.Name,
|
||||||
Created: key.Created,
|
Created: key.CreatedUnix.AsTime(),
|
||||||
ReadOnly: true, // All deploy keys are read-only.
|
ReadOnly: true, // All deploy keys are read-only.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user