Browse Source

fix-2208

tags/v1.22.6.1^2
liuzx 3 years ago
parent
commit
beb3646f2a
2 changed files with 25 additions and 23 deletions
  1. +0
    -10
      models/attachment.go
  2. +25
    -13
      routers/repo/dataset.go

+ 0
- 10
models/attachment.go View File

@@ -723,16 +723,6 @@ func MyFvAttachments(opts *AttachmentsOptions) ([]*AttachmentInfo, int64, error)
return nil, 0, fmt.Errorf("Count: %v", err)
}

// if opts.Page >= 0 && opts.PageSize > 0 {
// var start int
// if opts.Page == 0 {
// start = 0
// } else {
// start = (opts.Page - 1) * opts.PageSize
// }
// sess.Limit(opts.PageSize, start)
// }

sess.OrderBy("attachment.created_unix DESC")
attachments := make([]*AttachmentInfo, 0)
if err := sess.Table(&Attachment{}).Where(cond).


+ 25
- 13
routers/repo/dataset.go View File

@@ -521,19 +521,17 @@ func MyFavoriteDataset(ctx *context.Context) {
datasets := merge(IsColDatasets, NotColDatasets)
count := NotColcount + IsColcount

pager := context.NewPagination(int(count), setting.UI.IssuePagingNum, page, getTotalPage(count, setting.UI.IssuePagingNum))
pager.SetDefaultParams(ctx)

data, err := json.Marshal(datasets)
if err != nil {
log.Error("json.Marshal failed:", err.Error())
ctx.JSON(200, map[string]string{
"result_code": "-1",
"error_msg": err.Error(),
"data": "",
})
return
// page := ctx.QueryInt("page")
if page <= 0 {
page = 1
}
pagesize := ctx.QueryInt("pagesize")
if pagesize <= 0 {
pagesize = 5
}
pageDatasetsInfo := getPageDatasets(datasets, page, pagesize)

data, err := json.Marshal(pageDatasetsInfo)
ctx.JSON(200, map[string]string{
"result_code": "0",
"data": string(data),
@@ -541,7 +539,21 @@ func MyFavoriteDataset(ctx *context.Context) {
})

}
func merge(a, b interface{}) interface{} {
func getPageDatasets(datasets []*models.AttachmentInfo, page int, pagesize int) []*models.AttachmentInfo {
begin := (page - 1) * pagesize
end := (page) * pagesize

if begin > len(datasets)-1 {
return nil
}
if end > len(datasets)-1 {
return datasets[begin:]
} else {
return datasets[begin:end]
}

}
func merge(a, b []*models.AttachmentInfo) []*models.AttachmentInfo {

jb, err := json.Marshal(b)
if err != nil {


Loading…
Cancel
Save