|
|
|
@@ -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 { |
|
|
|
|