| @@ -11,7 +11,7 @@ watch_dirs = [ | |||||
| "$WORKDIR/models", | "$WORKDIR/models", | ||||
| "$WORKDIR/cmd", | "$WORKDIR/cmd", | ||||
| "$WORKDIR/options", | "$WORKDIR/options", | ||||
| "$WORKDIR/web_src", | |||||
| "$WORKDIR/public", | |||||
| ] # Directories to watch | ] # Directories to watch | ||||
| watch_exts = [".go", ".ini", ".less"] # Extensions to watch | watch_exts = [".go", ".ini", ".less"] # Extensions to watch | ||||
| env_files = [] # Load env vars from files | env_files = [] # Load env vars from files | ||||
| @@ -4,13 +4,27 @@ import ( | |||||
| "fmt" | "fmt" | ||||
| "code.gitea.io/gitea/modules/timeutil" | "code.gitea.io/gitea/modules/timeutil" | ||||
| "xorm.io/builder" | |||||
| ) | ) | ||||
| // Issue represents an issue or pull request of repository. | |||||
| const ( | |||||
| DatasetStatusPrivate int = iota | |||||
| DatasetStatusPublic | |||||
| DatasetStatusDeleted | |||||
| ) | |||||
| type DatasetList []*Dataset | |||||
| type SearchDatasetOptions struct { | |||||
| ListOptions | |||||
| Keyword string | |||||
| OwnerID int64 | |||||
| IsPublic bool | |||||
| } | |||||
| type Dataset struct { | type Dataset struct { | ||||
| ID int64 `xorm:"pk autoincr"` | ID int64 `xorm:"pk autoincr"` | ||||
| Title string `xorm:"INDEX NOT NULL"` | Title string `xorm:"INDEX NOT NULL"` | ||||
| Status int32 `xorm:"INDEX"` | |||||
| Status int32 `xorm:"INDEX"` // normal_private: 0, pulbic: 1, is_delete: 2 | |||||
| Category string | Category string | ||||
| Description string `xorm:"TEXT"` | Description string `xorm:"TEXT"` | ||||
| DownloadTimes int64 | DownloadTimes int64 | ||||
| @@ -50,3 +64,48 @@ func AddDatasetAttachments(DatasetID int64, attachmentUUIDs []string) (err error | |||||
| return | return | ||||
| } | } | ||||
| func SearchDataset(opts *SearchDatasetOptions) (DatasetList, int64, error) { | |||||
| cond := SearchDatasetCondition(opts) | |||||
| return SearchDatasetByCondition(opts, cond) | |||||
| } | |||||
| func SearchDatasetCondition(opts *SearchDatasetOptions) builder.Cond { | |||||
| var cond = builder.NewCond() | |||||
| cond = cond.And(builder.Eq{"user_id": opts.OwnerID}) | |||||
| if opts.IsPublic { | |||||
| cond = cond.And(builder.Eq{"status": DatasetStatusPublic}) | |||||
| } else { | |||||
| cond = cond.And(builder.Neq{"status": DatasetStatusDeleted}) | |||||
| } | |||||
| return cond | |||||
| } | |||||
| func SearchDatasetByCondition(opts *SearchDatasetOptions, cond builder.Cond) (DatasetList, int64, error) { | |||||
| if opts.Page <= 0 { | |||||
| opts.Page = 1 | |||||
| } | |||||
| var err error | |||||
| sess := x.NewSession() | |||||
| defer sess.Close() | |||||
| // count, err := sess.Where(cond).Count(new(DatasetList)) | |||||
| // if err != nil { | |||||
| // return nil, 0, fmt.Errorf("Count: %v", err) | |||||
| // } | |||||
| repos := make(DatasetList, 0, opts.PageSize) | |||||
| sess.Where(cond) | |||||
| if opts.PageSize > 0 { | |||||
| sess.Limit(opts.PageSize, (opts.Page-1)*opts.PageSize) | |||||
| } | |||||
| if err = sess.Find(&repos); err != nil { | |||||
| return nil, 0, fmt.Errorf("Dataset: %v", err) | |||||
| } | |||||
| return repos, 0, nil | |||||
| } | |||||
| @@ -14,7 +14,40 @@ const ( | |||||
| tplCreate base.TplName = "datasets/create" | tplCreate base.TplName = "datasets/create" | ||||
| ) | ) | ||||
| type ListOptions struct { | |||||
| PageSize int | |||||
| Page int // start from 1 | |||||
| } | |||||
| func MyList(ctx *context.Context) { | func MyList(ctx *context.Context) { | ||||
| ctxUser := ctx.User | |||||
| page := ctx.QueryInt("page") | |||||
| if page <= 0 { | |||||
| page = 1 | |||||
| } | |||||
| datasetSearchOptions := &models.SearchDatasetOptions{ | |||||
| OwnerID: ctxUser.ID, | |||||
| } | |||||
| var ( | |||||
| datasets []*models.Dataset | |||||
| count int64 | |||||
| err error | |||||
| ) | |||||
| datasets, count, err = models.SearchDataset(datasetSearchOptions) | |||||
| if err != nil { | |||||
| ctx.ServerError("SearchDatasets", err) | |||||
| return | |||||
| } | |||||
| // pager := context.NewPagination(int(count), opts.PageSize, page, 5) | |||||
| // pager.SetDefaultParams(ctx) | |||||
| // pager.AddParam(ctx, "topic", "TopicOnly") | |||||
| // ctx.Data["Page"] = pager | |||||
| ctx.Data["datasets"] = datasets | |||||
| ctx.Data["datasetsCount"] = count | |||||
| log.Debug("[dataset] mylist...\n") | log.Debug("[dataset] mylist...\n") | ||||
| ctx.HTML(200, tplDataSet) | ctx.HTML(200, tplDataSet) | ||||
| } | } | ||||
| @@ -1,4 +1,21 @@ | |||||
| <div class="ui repository list"> | <div class="ui repository list"> | ||||
| {{range .datasets}} | |||||
| <div class="item"> | |||||
| <div class="ui header"> | |||||
| <a class="name" href=""> | |||||
| {{.Title}} | |||||
| </a> | |||||
| <div class="ui right metas"> | |||||
| <span class="text grey">{{svg "octicon-flame" 16}} 24</span> | |||||
| </div> | |||||
| </div> | |||||
| <div class="description"> | |||||
| <a><div class="ui small label topic">{{.Description}}</div></a> | |||||
| <p class="time">{{$.i18n.Tr "org.repo_updated"}} {{TimeSinceUnix .UpdatedUnix $.i18n.Lang}}</p> | |||||
| </div> | |||||
| </div> | |||||
| {{end}} | |||||
| <div class="item"> | <div class="item"> | ||||
| <div class="ui header"> | <div class="ui header"> | ||||
| <a class="name" href="{{.Link}}"> | <a class="name" href="{{.Link}}"> | ||||