mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-22 13:25:36 +03:00
Use struct for UI settings
This commit is contained in:
parent
256cd6374a
commit
46e96c008c
16 changed files with 48 additions and 48 deletions
|
@ -44,6 +44,10 @@ NOTICE_PAGING_NUM = 25
|
|||
; Number of organization that are showed in one page
|
||||
ORG_PAGING_NUM = 50
|
||||
|
||||
[ui.user]
|
||||
; Number of repos that are showed in one page
|
||||
REPO_PAGING_NUM = 15
|
||||
|
||||
[markdown]
|
||||
; Enable hard line break extension
|
||||
ENABLE_HARD_LINE_BREAK = false
|
||||
|
|
|
@ -470,8 +470,8 @@ func CommitRepoAction(
|
|||
}
|
||||
}
|
||||
|
||||
if len(commit.Commits) > setting.FeedMaxCommitNum {
|
||||
commit.Commits = commit.Commits[:setting.FeedMaxCommitNum]
|
||||
if len(commit.Commits) > setting.UI.FeedMaxCommitNum {
|
||||
commit.Commits = commit.Commits[:setting.UI.FeedMaxCommitNum]
|
||||
}
|
||||
|
||||
bs, err := json.Marshal(commit)
|
||||
|
|
|
@ -521,7 +521,7 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) {
|
|||
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 {
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -1143,10 +1143,10 @@ func GetAllRepoMilestones(repoID int64) ([]*Milestone, error) {
|
|||
|
||||
// GetMilestones returns a list of milestones of given repository and status.
|
||||
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)
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -988,7 +988,7 @@ type SearchUserOptions struct {
|
|||
Type UserType
|
||||
OrderBy string
|
||||
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,
|
||||
|
@ -999,8 +999,8 @@ func SearchUserByName(opts *SearchUserOptions) (users []*User, _ int64, _ error)
|
|||
}
|
||||
opts.Keyword = strings.ToLower(opts.Keyword)
|
||||
|
||||
if opts.PageSize <= 0 || opts.PageSize > setting.ExplorePagingNum {
|
||||
opts.PageSize = setting.ExplorePagingNum
|
||||
if opts.PageSize <= 0 || opts.PageSize > setting.UI.ExplorePagingNum {
|
||||
opts.PageSize = setting.UI.ExplorePagingNum
|
||||
}
|
||||
if opts.Page <= 0 {
|
||||
opts.Page = 1
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -115,15 +115,23 @@ var (
|
|||
ScriptType string
|
||||
|
||||
// UI settings
|
||||
ExplorePagingNum int
|
||||
IssuePagingNum int
|
||||
FeedMaxCommitNum int
|
||||
AdminUserPagingNum int
|
||||
AdminRepoPagingNum int
|
||||
AdminNoticePagingNum int
|
||||
AdminOrgPagingNum int
|
||||
ThemeColorMetaTag string
|
||||
MaxDisplayFileSize int64
|
||||
UI struct {
|
||||
ExplorePagingNum int
|
||||
IssuePagingNum int
|
||||
FeedMaxCommitNum int
|
||||
ThemeColorMetaTag string
|
||||
MaxDisplayFileSize int64
|
||||
|
||||
Admin struct {
|
||||
UserPagingNum int
|
||||
RepoPagingNum int
|
||||
NoticePagingNum int
|
||||
OrgPagingNum int
|
||||
} `ini:"ui.admin"`
|
||||
User struct {
|
||||
RepoPagingNum int
|
||||
} `ini:"ui.user"`
|
||||
}
|
||||
|
||||
// Markdown sttings
|
||||
Markdown struct {
|
||||
|
@ -437,20 +445,6 @@ func NewContext() {
|
|||
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")
|
||||
AvatarUploadPath = sec.Key("AVATAR_UPLOAD_PATH").MustString(path.Join(AppDataPath, "avatars"))
|
||||
forcePathSeparator(AvatarUploadPath)
|
||||
|
@ -470,7 +464,9 @@ func NewContext() {
|
|||
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)
|
||||
} else if err = Cfg.Section("cron").MapTo(&Cron); err != nil {
|
||||
log.Fatal(4, "Fail to map Cron settings: %v", err)
|
||||
|
|
|
@ -102,7 +102,7 @@ func NewFuncMap() []template.FuncMap {
|
|||
},
|
||||
"RenderCommitMessage": RenderCommitMessage,
|
||||
"ThemeColorMetaTag": func() string {
|
||||
return setting.ThemeColorMetaTag
|
||||
return setting.UI.ThemeColorMetaTag
|
||||
},
|
||||
}}
|
||||
}
|
||||
|
|
|
@ -29,9 +29,9 @@ func Notices(ctx *context.Context) {
|
|||
if 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 {
|
||||
ctx.Handle(500, "Notices", err)
|
||||
return
|
||||
|
|
|
@ -25,7 +25,7 @@ func Organizations(ctx *context.Context) {
|
|||
Type: models.USER_TYPE_ORGANIZATION,
|
||||
Counter: models.CountOrganizations,
|
||||
Ranger: models.Organizations,
|
||||
PageSize: setting.AdminOrgPagingNum,
|
||||
PageSize: setting.UI.Admin.OrgPagingNum,
|
||||
OrderBy: "id ASC",
|
||||
TplName: ORGS,
|
||||
})
|
||||
|
|
|
@ -26,7 +26,7 @@ func Repos(ctx *context.Context) {
|
|||
Counter: models.CountRepositories,
|
||||
Ranger: models.Repositories,
|
||||
Private: true,
|
||||
PageSize: setting.AdminRepoPagingNum,
|
||||
PageSize: setting.UI.Admin.RepoPagingNum,
|
||||
OrderBy: "id ASC",
|
||||
TplName: REPOS,
|
||||
})
|
||||
|
|
|
@ -33,7 +33,7 @@ func Users(ctx *context.Context) {
|
|||
Type: models.USER_TYPE_INDIVIDUAL,
|
||||
Counter: models.CountUsers,
|
||||
Ranger: models.Users,
|
||||
PageSize: setting.AdminUserPagingNum,
|
||||
PageSize: setting.UI.Admin.UserPagingNum,
|
||||
OrderBy: "id ASC",
|
||||
TplName: USERS,
|
||||
})
|
||||
|
|
|
@ -31,7 +31,7 @@ func ListIssues(ctx *context.APIContext) {
|
|||
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)
|
||||
}
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ func ExploreRepos(ctx *context.Context) {
|
|||
RenderRepoSearch(ctx, &RepoSearchOptions{
|
||||
Counter: models.CountPublicRepositories,
|
||||
Ranger: models.GetRecentUpdatedRepositories,
|
||||
PageSize: setting.ExplorePagingNum,
|
||||
PageSize: setting.UI.ExplorePagingNum,
|
||||
OrderBy: "updated_unix DESC",
|
||||
TplName: EXPLORE_REPOS,
|
||||
})
|
||||
|
@ -174,7 +174,7 @@ func ExploreUsers(ctx *context.Context) {
|
|||
Type: models.USER_TYPE_INDIVIDUAL,
|
||||
Counter: models.CountUsers,
|
||||
Ranger: models.Users,
|
||||
PageSize: setting.ExplorePagingNum,
|
||||
PageSize: setting.UI.ExplorePagingNum,
|
||||
OrderBy: "updated_unix DESC",
|
||||
TplName: EXPLORE_USERS,
|
||||
})
|
||||
|
|
|
@ -163,7 +163,7 @@ func Issues(ctx *context.Context) {
|
|||
} else {
|
||||
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
|
||||
|
||||
// Get issues.
|
||||
|
@ -1017,7 +1017,7 @@ func Milestones(ctx *context.Context) {
|
|||
} else {
|
||||
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)
|
||||
if err != nil {
|
||||
|
|
|
@ -105,7 +105,7 @@ func Home(ctx *context.Context) {
|
|||
case isImageFile:
|
||||
ctx.Data["IsImageFile"] = true
|
||||
case isTextFile:
|
||||
if blob.Size() >= setting.MaxDisplayFileSize {
|
||||
if blob.Size() >= setting.UI.MaxDisplayFileSize {
|
||||
ctx.Data["IsFileTooLarge"] = true
|
||||
} else {
|
||||
ctx.Data["IsFileTooLarge"] = false
|
||||
|
|
|
@ -253,7 +253,7 @@ func Issues(ctx *context.Context) {
|
|||
} else {
|
||||
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.
|
||||
issues, err := models.Issues(&models.IssuesOptions{
|
||||
|
|
Loading…
Reference in a new issue