Browse Source

improved search options

tags/v1.21.12.1
yan 5 years ago
parent
commit
9390b75232
4 changed files with 9 additions and 28 deletions
  1. +8
    -19
      models/dataset.go
  2. +0
    -7
      routers/admin/dataset.go
  3. +1
    -1
      routers/dataset/dataset.go
  4. +0
    -1
      routers/user/profile.go

+ 8
- 19
models/dataset.go View File

@@ -76,10 +76,9 @@ func (datasets DatasetList) loadAttributes(e Engine) error {
}

type SearchDatasetOptions struct {
Keyword string
doerID int64
OwnerID int64
IsPublic bool
Keyword string
OwnerID int64
IncludePublic bool
ListOptions
SearchOrderBy
}
@@ -100,27 +99,17 @@ func SearchDataset(opts *SearchDatasetOptions) (DatasetList, int64, error) {
func SearchDatasetCondition(opts *SearchDatasetOptions) builder.Cond {
var cond = builder.NewCond()
cond = cond.And(builder.Neq{"status": DatasetStatusDeleted})

if len(opts.Keyword) > 0 {
cond = cond.And(builder.Like{"title", opts.Keyword})
}

if opts.doerID > 0 {
doer, err := GetUserByID(opts.doerID)
if err != nil {
return nil
}
if doer.IsAdmin {

if opts.IncludePublic {
cond = cond.And(builder.Eq{"status": DatasetStatusPublic})
if opts.OwnerID > 0 {
cond = cond.Or(builder.Eq{"user_id": opts.OwnerID})
}

} else {
if opts.IsPublic {
cond = cond.And(builder.Eq{"status": DatasetStatusPublic})
if opts.OwnerID > 0 {
cond = cond.Or(builder.Eq{"user_id": opts.OwnerID})
}
}

if opts.OwnerID > 0 {
cond = cond.And(builder.Eq{"user_id": opts.OwnerID})
}


+ 0
- 7
routers/admin/dataset.go View File

@@ -63,12 +63,6 @@ func Datasets(ctx *context.Context) {
}

keyword := strings.Trim(ctx.Query("q"), " ")
var uid int64
if ctx.User != nil {
uid = ctx.User.ID
} else {
uid = 0
}

datasets, count, err = models.SearchDataset(&models.SearchDatasetOptions{
ListOptions: models.ListOptions{
@@ -76,7 +70,6 @@ func Datasets(ctx *context.Context) {
PageSize: setting.UI.ExplorePagingNum,
},
Keyword: keyword,
OwnerID: uid,
SearchOrderBy: orderBy,
})
if err != nil {


+ 1
- 1
routers/dataset/dataset.go View File

@@ -74,7 +74,7 @@ func MyList(ctx *context.Context) {
}
opts := &models.SearchDatasetOptions{
Keyword: keyword,
IsPublic: true,
IncludePublic: true,
SearchOrderBy: orderBy,
OwnerID: userID,
ListOptions: models.ListOptions{


+ 0
- 1
routers/user/profile.go View File

@@ -212,7 +212,6 @@ func Profile(ctx *context.Context) {
case "datasets":
datasetSearchOptions := &models.SearchDatasetOptions{
Keyword: keyword,
IsPublic: true,
OwnerID: ctxUser.ID,
SearchOrderBy: orderBy,
ListOptions: models.ListOptions{


Loading…
Cancel
Save