mirror of
https://github.com/go-gitea/gitea.git
synced 2024-09-06 23:44:20 -04:00
Use struct for UI settings
This commit is contained in:
parent
256cd6374a
commit
46e96c008c
@ -44,6 +44,10 @@ NOTICE_PAGING_NUM = 25
|
|||||||
; Number of organization that are showed in one page
|
; Number of organization that are showed in one page
|
||||||
ORG_PAGING_NUM = 50
|
ORG_PAGING_NUM = 50
|
||||||
|
|
||||||
|
[ui.user]
|
||||||
|
; Number of repos that are showed in one page
|
||||||
|
REPO_PAGING_NUM = 15
|
||||||
|
|
||||||
[markdown]
|
[markdown]
|
||||||
; Enable hard line break extension
|
; Enable hard line break extension
|
||||||
ENABLE_HARD_LINE_BREAK = false
|
ENABLE_HARD_LINE_BREAK = false
|
||||||
|
@ -470,8 +470,8 @@ func CommitRepoAction(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(commit.Commits) > setting.FeedMaxCommitNum {
|
if len(commit.Commits) > setting.UI.FeedMaxCommitNum {
|
||||||
commit.Commits = commit.Commits[:setting.FeedMaxCommitNum]
|
commit.Commits = commit.Commits[:setting.UI.FeedMaxCommitNum]
|
||||||
}
|
}
|
||||||
|
|
||||||
bs, err := json.Marshal(commit)
|
bs, err := json.Marshal(commit)
|
||||||
|
@ -521,7 +521,7 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) {
|
|||||||
opts.Page = 1
|
opts.Page = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
sess := x.Limit(setting.IssuePagingNum, (opts.Page-1)*setting.IssuePagingNum)
|
sess := x.Limit(setting.UI.IssuePagingNum, (opts.Page-1)*setting.UI.IssuePagingNum)
|
||||||
|
|
||||||
if opts.RepoID > 0 {
|
if opts.RepoID > 0 {
|
||||||
sess.Where("issue.repo_id=?", opts.RepoID).And("issue.is_closed=?", opts.IsClosed)
|
sess.Where("issue.repo_id=?", opts.RepoID).And("issue.is_closed=?", opts.IsClosed)
|
||||||
@ -579,7 +579,7 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
issues := make([]*Issue, 0, setting.IssuePagingNum)
|
issues := make([]*Issue, 0, setting.UI.IssuePagingNum)
|
||||||
return issues, sess.Find(&issues)
|
return issues, sess.Find(&issues)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1143,10 +1143,10 @@ func GetAllRepoMilestones(repoID int64) ([]*Milestone, error) {
|
|||||||
|
|
||||||
// GetMilestones returns a list of milestones of given repository and status.
|
// GetMilestones returns a list of milestones of given repository and status.
|
||||||
func GetMilestones(repoID int64, page int, isClosed bool) ([]*Milestone, error) {
|
func GetMilestones(repoID int64, page int, isClosed bool) ([]*Milestone, error) {
|
||||||
miles := make([]*Milestone, 0, setting.IssuePagingNum)
|
miles := make([]*Milestone, 0, setting.UI.IssuePagingNum)
|
||||||
sess := x.Where("repo_id=? AND is_closed=?", repoID, isClosed)
|
sess := x.Where("repo_id=? AND is_closed=?", repoID, isClosed)
|
||||||
if page > 0 {
|
if page > 0 {
|
||||||
sess = sess.Limit(setting.IssuePagingNum, (page-1)*setting.IssuePagingNum)
|
sess = sess.Limit(setting.UI.IssuePagingNum, (page-1)*setting.UI.IssuePagingNum)
|
||||||
}
|
}
|
||||||
return miles, sess.Find(&miles)
|
return miles, sess.Find(&miles)
|
||||||
}
|
}
|
||||||
|
@ -988,7 +988,7 @@ type SearchUserOptions struct {
|
|||||||
Type UserType
|
Type UserType
|
||||||
OrderBy string
|
OrderBy string
|
||||||
Page int
|
Page int
|
||||||
PageSize int // Can be smaller than or equal to setting.ExplorePagingNum
|
PageSize int // Can be smaller than or equal to setting.UI.ExplorePagingNum
|
||||||
}
|
}
|
||||||
|
|
||||||
// SearchUserByName takes keyword and part of user name to search,
|
// SearchUserByName takes keyword and part of user name to search,
|
||||||
@ -999,8 +999,8 @@ func SearchUserByName(opts *SearchUserOptions) (users []*User, _ int64, _ error)
|
|||||||
}
|
}
|
||||||
opts.Keyword = strings.ToLower(opts.Keyword)
|
opts.Keyword = strings.ToLower(opts.Keyword)
|
||||||
|
|
||||||
if opts.PageSize <= 0 || opts.PageSize > setting.ExplorePagingNum {
|
if opts.PageSize <= 0 || opts.PageSize > setting.UI.ExplorePagingNum {
|
||||||
opts.PageSize = setting.ExplorePagingNum
|
opts.PageSize = setting.UI.ExplorePagingNum
|
||||||
}
|
}
|
||||||
if opts.Page <= 0 {
|
if opts.Page <= 0 {
|
||||||
opts.Page = 1
|
opts.Page = 1
|
||||||
|
File diff suppressed because one or more lines are too long
@ -115,15 +115,23 @@ var (
|
|||||||
ScriptType string
|
ScriptType string
|
||||||
|
|
||||||
// UI settings
|
// UI settings
|
||||||
ExplorePagingNum int
|
UI struct {
|
||||||
IssuePagingNum int
|
ExplorePagingNum int
|
||||||
FeedMaxCommitNum int
|
IssuePagingNum int
|
||||||
AdminUserPagingNum int
|
FeedMaxCommitNum int
|
||||||
AdminRepoPagingNum int
|
ThemeColorMetaTag string
|
||||||
AdminNoticePagingNum int
|
MaxDisplayFileSize int64
|
||||||
AdminOrgPagingNum int
|
|
||||||
ThemeColorMetaTag string
|
Admin struct {
|
||||||
MaxDisplayFileSize int64
|
UserPagingNum int
|
||||||
|
RepoPagingNum int
|
||||||
|
NoticePagingNum int
|
||||||
|
OrgPagingNum int
|
||||||
|
} `ini:"ui.admin"`
|
||||||
|
User struct {
|
||||||
|
RepoPagingNum int
|
||||||
|
} `ini:"ui.user"`
|
||||||
|
}
|
||||||
|
|
||||||
// Markdown sttings
|
// Markdown sttings
|
||||||
Markdown struct {
|
Markdown struct {
|
||||||
@ -437,20 +445,6 @@ func NewContext() {
|
|||||||
log.Fatal(4, "Fail to map Repository settings: %v", err)
|
log.Fatal(4, "Fail to map Repository settings: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UI settings.
|
|
||||||
sec = Cfg.Section("ui")
|
|
||||||
ExplorePagingNum = sec.Key("EXPLORE_PAGING_NUM").MustInt(20)
|
|
||||||
IssuePagingNum = sec.Key("ISSUE_PAGING_NUM").MustInt(10)
|
|
||||||
FeedMaxCommitNum = sec.Key("FEED_MAX_COMMIT_NUM").MustInt(5)
|
|
||||||
MaxDisplayFileSize = sec.Key("MAX_DISPLAY_FILE_SIZE").MustInt64(8388608)
|
|
||||||
|
|
||||||
sec = Cfg.Section("ui.admin")
|
|
||||||
AdminUserPagingNum = sec.Key("USER_PAGING_NUM").MustInt(50)
|
|
||||||
AdminRepoPagingNum = sec.Key("REPO_PAGING_NUM").MustInt(50)
|
|
||||||
AdminNoticePagingNum = sec.Key("NOTICE_PAGING_NUM").MustInt(50)
|
|
||||||
AdminOrgPagingNum = sec.Key("ORG_PAGING_NUM").MustInt(50)
|
|
||||||
ThemeColorMetaTag = sec.Key("THEME_COLOR_META_TAG").MustString("#ff5343")
|
|
||||||
|
|
||||||
sec = Cfg.Section("picture")
|
sec = Cfg.Section("picture")
|
||||||
AvatarUploadPath = sec.Key("AVATAR_UPLOAD_PATH").MustString(path.Join(AppDataPath, "avatars"))
|
AvatarUploadPath = sec.Key("AVATAR_UPLOAD_PATH").MustString(path.Join(AppDataPath, "avatars"))
|
||||||
forcePathSeparator(AvatarUploadPath)
|
forcePathSeparator(AvatarUploadPath)
|
||||||
@ -470,7 +464,9 @@ func NewContext() {
|
|||||||
DisableGravatar = true
|
DisableGravatar = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = Cfg.Section("markdown").MapTo(&Markdown); err != nil {
|
if err = Cfg.Section("ui").MapTo(&UI); err != nil {
|
||||||
|
log.Fatal(4, "Fail to map UI settings: %v", err)
|
||||||
|
} else if err = Cfg.Section("markdown").MapTo(&Markdown); err != nil {
|
||||||
log.Fatal(4, "Fail to map Markdown settings: %v", err)
|
log.Fatal(4, "Fail to map Markdown settings: %v", err)
|
||||||
} else if err = Cfg.Section("cron").MapTo(&Cron); err != nil {
|
} else if err = Cfg.Section("cron").MapTo(&Cron); err != nil {
|
||||||
log.Fatal(4, "Fail to map Cron settings: %v", err)
|
log.Fatal(4, "Fail to map Cron settings: %v", err)
|
||||||
|
@ -102,7 +102,7 @@ func NewFuncMap() []template.FuncMap {
|
|||||||
},
|
},
|
||||||
"RenderCommitMessage": RenderCommitMessage,
|
"RenderCommitMessage": RenderCommitMessage,
|
||||||
"ThemeColorMetaTag": func() string {
|
"ThemeColorMetaTag": func() string {
|
||||||
return setting.ThemeColorMetaTag
|
return setting.UI.ThemeColorMetaTag
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
@ -29,9 +29,9 @@ func Notices(ctx *context.Context) {
|
|||||||
if page <= 1 {
|
if page <= 1 {
|
||||||
page = 1
|
page = 1
|
||||||
}
|
}
|
||||||
ctx.Data["Page"] = paginater.New(int(total), setting.AdminNoticePagingNum, page, 5)
|
ctx.Data["Page"] = paginater.New(int(total), setting.UI.Admin.NoticePagingNum, page, 5)
|
||||||
|
|
||||||
notices, err := models.Notices(page, setting.AdminNoticePagingNum)
|
notices, err := models.Notices(page, setting.UI.Admin.NoticePagingNum)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "Notices", err)
|
ctx.Handle(500, "Notices", err)
|
||||||
return
|
return
|
||||||
|
@ -25,7 +25,7 @@ func Organizations(ctx *context.Context) {
|
|||||||
Type: models.USER_TYPE_ORGANIZATION,
|
Type: models.USER_TYPE_ORGANIZATION,
|
||||||
Counter: models.CountOrganizations,
|
Counter: models.CountOrganizations,
|
||||||
Ranger: models.Organizations,
|
Ranger: models.Organizations,
|
||||||
PageSize: setting.AdminOrgPagingNum,
|
PageSize: setting.UI.Admin.OrgPagingNum,
|
||||||
OrderBy: "id ASC",
|
OrderBy: "id ASC",
|
||||||
TplName: ORGS,
|
TplName: ORGS,
|
||||||
})
|
})
|
||||||
|
@ -26,7 +26,7 @@ func Repos(ctx *context.Context) {
|
|||||||
Counter: models.CountRepositories,
|
Counter: models.CountRepositories,
|
||||||
Ranger: models.Repositories,
|
Ranger: models.Repositories,
|
||||||
Private: true,
|
Private: true,
|
||||||
PageSize: setting.AdminRepoPagingNum,
|
PageSize: setting.UI.Admin.RepoPagingNum,
|
||||||
OrderBy: "id ASC",
|
OrderBy: "id ASC",
|
||||||
TplName: REPOS,
|
TplName: REPOS,
|
||||||
})
|
})
|
||||||
|
@ -33,7 +33,7 @@ func Users(ctx *context.Context) {
|
|||||||
Type: models.USER_TYPE_INDIVIDUAL,
|
Type: models.USER_TYPE_INDIVIDUAL,
|
||||||
Counter: models.CountUsers,
|
Counter: models.CountUsers,
|
||||||
Ranger: models.Users,
|
Ranger: models.Users,
|
||||||
PageSize: setting.AdminUserPagingNum,
|
PageSize: setting.UI.Admin.UserPagingNum,
|
||||||
OrderBy: "id ASC",
|
OrderBy: "id ASC",
|
||||||
TplName: USERS,
|
TplName: USERS,
|
||||||
})
|
})
|
||||||
|
@ -31,7 +31,7 @@ func ListIssues(ctx *context.APIContext) {
|
|||||||
apiIssues[i] = convert.ToIssue(issues[i])
|
apiIssues[i] = convert.ToIssue(issues[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.SetLinkHeader(ctx.Repo.Repository.NumIssues, setting.IssuePagingNum)
|
ctx.SetLinkHeader(ctx.Repo.Repository.NumIssues, setting.UI.IssuePagingNum)
|
||||||
ctx.JSON(200, &apiIssues)
|
ctx.JSON(200, &apiIssues)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ func ExploreRepos(ctx *context.Context) {
|
|||||||
RenderRepoSearch(ctx, &RepoSearchOptions{
|
RenderRepoSearch(ctx, &RepoSearchOptions{
|
||||||
Counter: models.CountPublicRepositories,
|
Counter: models.CountPublicRepositories,
|
||||||
Ranger: models.GetRecentUpdatedRepositories,
|
Ranger: models.GetRecentUpdatedRepositories,
|
||||||
PageSize: setting.ExplorePagingNum,
|
PageSize: setting.UI.ExplorePagingNum,
|
||||||
OrderBy: "updated_unix DESC",
|
OrderBy: "updated_unix DESC",
|
||||||
TplName: EXPLORE_REPOS,
|
TplName: EXPLORE_REPOS,
|
||||||
})
|
})
|
||||||
@ -174,7 +174,7 @@ func ExploreUsers(ctx *context.Context) {
|
|||||||
Type: models.USER_TYPE_INDIVIDUAL,
|
Type: models.USER_TYPE_INDIVIDUAL,
|
||||||
Counter: models.CountUsers,
|
Counter: models.CountUsers,
|
||||||
Ranger: models.Users,
|
Ranger: models.Users,
|
||||||
PageSize: setting.ExplorePagingNum,
|
PageSize: setting.UI.ExplorePagingNum,
|
||||||
OrderBy: "updated_unix DESC",
|
OrderBy: "updated_unix DESC",
|
||||||
TplName: EXPLORE_USERS,
|
TplName: EXPLORE_USERS,
|
||||||
})
|
})
|
||||||
|
@ -163,7 +163,7 @@ func Issues(ctx *context.Context) {
|
|||||||
} else {
|
} else {
|
||||||
total = int(issueStats.ClosedCount)
|
total = int(issueStats.ClosedCount)
|
||||||
}
|
}
|
||||||
pager := paginater.New(total, setting.IssuePagingNum, page, 5)
|
pager := paginater.New(total, setting.UI.IssuePagingNum, page, 5)
|
||||||
ctx.Data["Page"] = pager
|
ctx.Data["Page"] = pager
|
||||||
|
|
||||||
// Get issues.
|
// Get issues.
|
||||||
@ -1017,7 +1017,7 @@ func Milestones(ctx *context.Context) {
|
|||||||
} else {
|
} else {
|
||||||
total = int(closedCount)
|
total = int(closedCount)
|
||||||
}
|
}
|
||||||
ctx.Data["Page"] = paginater.New(total, setting.IssuePagingNum, page, 5)
|
ctx.Data["Page"] = paginater.New(total, setting.UI.IssuePagingNum, page, 5)
|
||||||
|
|
||||||
miles, err := models.GetMilestones(ctx.Repo.Repository.ID, page, isShowClosed)
|
miles, err := models.GetMilestones(ctx.Repo.Repository.ID, page, isShowClosed)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -105,7 +105,7 @@ func Home(ctx *context.Context) {
|
|||||||
case isImageFile:
|
case isImageFile:
|
||||||
ctx.Data["IsImageFile"] = true
|
ctx.Data["IsImageFile"] = true
|
||||||
case isTextFile:
|
case isTextFile:
|
||||||
if blob.Size() >= setting.MaxDisplayFileSize {
|
if blob.Size() >= setting.UI.MaxDisplayFileSize {
|
||||||
ctx.Data["IsFileTooLarge"] = true
|
ctx.Data["IsFileTooLarge"] = true
|
||||||
} else {
|
} else {
|
||||||
ctx.Data["IsFileTooLarge"] = false
|
ctx.Data["IsFileTooLarge"] = false
|
||||||
|
@ -253,7 +253,7 @@ func Issues(ctx *context.Context) {
|
|||||||
} else {
|
} else {
|
||||||
total = int(issueStats.ClosedCount)
|
total = int(issueStats.ClosedCount)
|
||||||
}
|
}
|
||||||
ctx.Data["Page"] = paginater.New(total, setting.IssuePagingNum, page, 5)
|
ctx.Data["Page"] = paginater.New(total, setting.UI.IssuePagingNum, page, 5)
|
||||||
|
|
||||||
// Get issues.
|
// Get issues.
|
||||||
issues, err := models.Issues(&models.IssuesOptions{
|
issues, err := models.Issues(&models.IssuesOptions{
|
||||||
|
Loading…
Reference in New Issue
Block a user