|
|
@@ -274,7 +274,16 @@ func ReferenceDatasetDelete(ctx *context.Context) { |
|
|
repoID := ctx.Repo.Repository.ID |
|
|
repoID := ctx.Repo.Repository.ID |
|
|
datasetId, _ := strconv.ParseInt(ctx.Params(":id"), 10, 64) |
|
|
datasetId, _ := strconv.ParseInt(ctx.Params(":id"), 10, 64) |
|
|
|
|
|
|
|
|
err := models.DeleteDatasetIdsByRepoID(repoID, []int64{datasetId}) |
|
|
|
|
|
|
|
|
oldDatasetIds := models.GetDatasetIdsByRepoID(repoID) |
|
|
|
|
|
|
|
|
|
|
|
var newDatasetIds []int64 |
|
|
|
|
|
|
|
|
|
|
|
for _, tempDatasetId := range oldDatasetIds { |
|
|
|
|
|
if datasetId != tempDatasetId { |
|
|
|
|
|
newDatasetIds = append(newDatasetIds, datasetId) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
err := models.NewDatasetIdsByRepoID(repoID, newDatasetIds) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
ctx.JSON(http.StatusOK, models.BaseErrorMessage("dataset.cancel_reference_dataset_fail")) |
|
|
ctx.JSON(http.StatusOK, models.BaseErrorMessage("dataset.cancel_reference_dataset_fail")) |
|
|
} |
|
|
} |
|
|
@@ -284,29 +293,7 @@ func ReferenceDatasetDelete(ctx *context.Context) { |
|
|
|
|
|
|
|
|
func ReferenceDatasetPost(ctx *context.Context, form auth.ReferenceDatasetForm) { |
|
|
func ReferenceDatasetPost(ctx *context.Context, form auth.ReferenceDatasetForm) { |
|
|
repoID := ctx.Repo.Repository.ID |
|
|
repoID := ctx.Repo.Repository.ID |
|
|
datasetsID := models.GetDatasetIdsByRepoID(repoID) |
|
|
|
|
|
|
|
|
|
|
|
var newDataset []int64 |
|
|
|
|
|
var deletedDataset []int64 |
|
|
|
|
|
|
|
|
|
|
|
for _, id := range datasetsID { |
|
|
|
|
|
if !contains(form.DatasetID, id) { |
|
|
|
|
|
deletedDataset = append(deletedDataset, id) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for _, id := range form.DatasetID { |
|
|
|
|
|
if !contains(datasetsID, id) { |
|
|
|
|
|
newDataset = append(newDataset, id) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
err := models.DeleteDatasetIdsByRepoID(repoID, deletedDataset) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("dataset.reference_dataset_fail"))) |
|
|
|
|
|
} |
|
|
|
|
|
err = models.NewDatasetIdsByRepoID(repoID, newDataset) |
|
|
|
|
|
|
|
|
err := models.NewDatasetIdsByRepoID(repoID, form.DatasetID) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
ctx.JSON(http.StatusOK, models.BaseErrorMessage("dataset.reference_dataset_fail")) |
|
|
ctx.JSON(http.StatusOK, models.BaseErrorMessage("dataset.reference_dataset_fail")) |
|
|
} |
|
|
} |
|
|
@@ -315,15 +302,6 @@ func ReferenceDatasetPost(ctx *context.Context, form auth.ReferenceDatasetForm) |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func contains(s []int64, e int64) bool { |
|
|
|
|
|
for _, a := range s { |
|
|
|
|
|
if a == e { |
|
|
|
|
|
return true |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return false |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func EditDatasetPost(ctx *context.Context, form auth.EditDatasetForm) { |
|
|
func EditDatasetPost(ctx *context.Context, form auth.EditDatasetForm) { |
|
|
ctx.Data["PageIsDataset"] = true |
|
|
ctx.Data["PageIsDataset"] = true |
|
|
|
|
|
|
|
|
@@ -467,13 +445,23 @@ func MyDatasets(ctx *context.Context) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func datasetMultiple(ctx *context.Context, opts *models.SearchDatasetOptions) { |
|
|
func datasetMultiple(ctx *context.Context, opts *models.SearchDatasetOptions) { |
|
|
datasets, count, err := datasetMultipleGet(ctx, opts) |
|
|
|
|
|
|
|
|
page := ctx.QueryInt("page") |
|
|
|
|
|
keyword := strings.Trim(ctx.Query("q"), " ") |
|
|
|
|
|
opts.Keyword = keyword |
|
|
|
|
|
if opts.SearchOrderBy.String() == "" { |
|
|
|
|
|
opts.SearchOrderBy = models.SearchOrderByRecentUpdated |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
datasetMultipleResult(ctx, err, datasets, count) |
|
|
|
|
|
|
|
|
opts.RecommendOnly = ctx.QueryBool("recommend") |
|
|
|
|
|
opts.ListOptions = models.ListOptions{ |
|
|
|
|
|
Page: page, |
|
|
|
|
|
PageSize: setting.UI.DatasetPagingNum, |
|
|
|
|
|
} |
|
|
|
|
|
opts.JustNeedZipFile = true |
|
|
|
|
|
opts.User = ctx.User |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
datasets, count, err := models.SearchDataset(opts) |
|
|
|
|
|
|
|
|
func datasetMultipleResult(ctx *context.Context, err error, datasets models.DatasetList, count int64) { |
|
|
|
|
|
if err != nil { |
|
|
if err != nil { |
|
|
ctx.ServerError("datasets", err) |
|
|
ctx.ServerError("datasets", err) |
|
|
return |
|
|
return |
|
|
@@ -496,52 +484,31 @@ func datasetMultipleResult(ctx *context.Context, err error, datasets models.Data |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func datasetMultipleGet(ctx *context.Context, opts *models.SearchDatasetOptions) (models.DatasetList, int64, error) { |
|
|
|
|
|
page := ctx.QueryInt("page") |
|
|
|
|
|
keyword := strings.Trim(ctx.Query("q"), " ") |
|
|
|
|
|
orderBy := models.SearchOrderByRecentUpdated |
|
|
|
|
|
opts.Keyword = keyword |
|
|
|
|
|
opts.SearchOrderBy = orderBy |
|
|
|
|
|
opts.RecommendOnly = ctx.QueryBool("recommend") |
|
|
|
|
|
opts.ListOptions = models.ListOptions{ |
|
|
|
|
|
Page: page, |
|
|
|
|
|
PageSize: setting.UI.DatasetPagingNum, |
|
|
|
|
|
} |
|
|
|
|
|
opts.JustNeedZipFile = true |
|
|
|
|
|
opts.User = ctx.User |
|
|
|
|
|
|
|
|
|
|
|
datasets, count, err := models.SearchDataset(opts) |
|
|
|
|
|
return datasets, count, err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func CurrentRepoDatasetMultiple(ctx *context.Context) { |
|
|
func CurrentRepoDatasetMultiple(ctx *context.Context) { |
|
|
|
|
|
|
|
|
|
|
|
datasetIds := models.GetDatasetIdsByRepoID(ctx.Repo.Repository.ID) |
|
|
|
|
|
searchOrderBy := getSearchOrderByInValues(datasetIds) |
|
|
opts := &models.SearchDatasetOptions{ |
|
|
opts := &models.SearchDatasetOptions{ |
|
|
RepoID: ctx.Repo.Repository.ID, |
|
|
RepoID: ctx.Repo.Repository.ID, |
|
|
NeedAttachment: true, |
|
|
NeedAttachment: true, |
|
|
CloudBrainType: ctx.QueryInt("type"), |
|
|
CloudBrainType: ctx.QueryInt("type"), |
|
|
DatasetIDs: models.GetDatasetIdsByRepoID(ctx.Repo.Repository.ID), |
|
|
|
|
|
|
|
|
DatasetIDs: datasetIds, |
|
|
|
|
|
SearchOrderBy: searchOrderBy, |
|
|
} |
|
|
} |
|
|
datasetList, count, err := datasetMultipleGet(ctx, opts) |
|
|
|
|
|
|
|
|
|
|
|
if len(datasetList) > 0 { |
|
|
|
|
|
var convertDatasetList models.DatasetList |
|
|
|
|
|
|
|
|
datasetMultiple(ctx, opts) |
|
|
|
|
|
|
|
|
for _, dataset := range datasetList { |
|
|
|
|
|
if dataset.RepoID == ctx.Repo.Repository.ID && len(convertDatasetList) == 0 { |
|
|
|
|
|
convertDatasetList = append(convertDatasetList, dataset) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
for _, dataset := range datasetList { |
|
|
|
|
|
if dataset.RepoID != ctx.Repo.Repository.ID { |
|
|
|
|
|
convertDatasetList = append(convertDatasetList, dataset) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
datasetMultipleResult(ctx, err, convertDatasetList, count) |
|
|
|
|
|
} else { |
|
|
|
|
|
datasetMultipleResult(ctx, err, datasetList, count) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func getSearchOrderByInValues(datasetIds []int64) models.SearchOrderBy { |
|
|
|
|
|
if len(datasetIds) == 0 { |
|
|
|
|
|
return "" |
|
|
|
|
|
} |
|
|
|
|
|
searchOrderBy := "CASE id " |
|
|
|
|
|
for i, id := range datasetIds { |
|
|
|
|
|
searchOrderBy += fmt.Sprintf(" WHEN %d THEN %d", id, i+1) |
|
|
|
|
|
} |
|
|
|
|
|
searchOrderBy += " ELSE 0 END" |
|
|
|
|
|
return models.SearchOrderBy(searchOrderBy) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func MyDatasetsMultiple(ctx *context.Context) { |
|
|
func MyDatasetsMultiple(ctx *context.Context) { |
|
|
@@ -589,17 +556,18 @@ func MyFavoriteDatasetMultiple(ctx *context.Context) { |
|
|
} |
|
|
} |
|
|
func ReferenceDataset(ctx *context.Context) { |
|
|
func ReferenceDataset(ctx *context.Context) { |
|
|
MustEnableDataset(ctx) |
|
|
MustEnableDataset(ctx) |
|
|
|
|
|
datasetIds := models.GetDatasetIdsByRepoID(ctx.Repo.Repository.ID) |
|
|
opts := &models.SearchDatasetOptions{ |
|
|
opts := &models.SearchDatasetOptions{ |
|
|
DatasetIDs: models.GetDatasetIdsByRepoID(ctx.Repo.Repository.ID), |
|
|
|
|
|
|
|
|
DatasetIDs: datasetIds, |
|
|
NeedAttachment: false, |
|
|
NeedAttachment: false, |
|
|
CloudBrainType: models.TypeCloudBrainAll, |
|
|
CloudBrainType: models.TypeCloudBrainAll, |
|
|
ListOptions: models.ListOptions{ |
|
|
ListOptions: models.ListOptions{ |
|
|
Page: 1, |
|
|
Page: 1, |
|
|
PageSize: setting.RepoMaxReferenceDatasetNum, |
|
|
PageSize: setting.RepoMaxReferenceDatasetNum, |
|
|
}, |
|
|
}, |
|
|
SearchOrderBy: models.SearchOrderByRecentUpdated, |
|
|
|
|
|
|
|
|
SearchOrderBy: getSearchOrderByInValues(datasetIds), |
|
|
} |
|
|
} |
|
|
datasets, count, err := models.SearchDataset(opts) |
|
|
|
|
|
|
|
|
datasets, _, err := models.SearchDataset(opts) |
|
|
|
|
|
|
|
|
if err != nil { |
|
|
if err != nil { |
|
|
ctx.ServerError("SearchDatasets", err) |
|
|
ctx.ServerError("SearchDatasets", err) |
|
|
@@ -608,7 +576,7 @@ func ReferenceDataset(ctx *context.Context) { |
|
|
|
|
|
|
|
|
ctx.Data["Datasets"] = repository.ConvertToDatasetWithStar(ctx, datasets) |
|
|
ctx.Data["Datasets"] = repository.ConvertToDatasetWithStar(ctx, datasets) |
|
|
ctx.Data["PageIsDataset"] = true |
|
|
ctx.Data["PageIsDataset"] = true |
|
|
ctx.Data["Total"] = count |
|
|
|
|
|
|
|
|
ctx.Data["MaxReferenceDatasetNum"] = setting.RepoMaxReferenceDatasetNum |
|
|
ctx.HTML(200, tplReference) |
|
|
ctx.HTML(200, tplReference) |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|