mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-21 17:21:09 +01:00
finish up project
This commit is contained in:
@@ -32,6 +32,7 @@ type Spider struct {
|
||||
Envs []Env `json:"envs" bson:"envs"` // 环境变量
|
||||
Remark string `json:"remark" bson:"remark"` // 备注
|
||||
Src string `json:"src" bson:"src"` // 源码位置
|
||||
ProjectId bson.ObjectId `json:"project_id" bson:"project_id"` // 项目ID
|
||||
|
||||
// 自定义爬虫
|
||||
Cmd string `json:"cmd" bson:"cmd"` // 执行命令
|
||||
@@ -56,6 +57,11 @@ func (spider *Spider) Save() error {
|
||||
|
||||
spider.UpdateTs = time.Now()
|
||||
|
||||
// 兼容没有项目ID的爬虫
|
||||
if spider.ProjectId.Hex() == "" {
|
||||
spider.ProjectId = bson.ObjectIdHex(constants.ObjectIdNull)
|
||||
}
|
||||
|
||||
if err := c.UpdateId(spider.Id, spider); err != nil {
|
||||
debug.PrintStack()
|
||||
return err
|
||||
|
||||
@@ -30,6 +30,7 @@ func GetSpiderList(c *gin.Context) {
|
||||
pageNum, _ := c.GetQuery("page_num")
|
||||
pageSize, _ := c.GetQuery("page_size")
|
||||
keyword, _ := c.GetQuery("keyword")
|
||||
pid, _ := c.GetQuery("project_id")
|
||||
t, _ := c.GetQuery("type")
|
||||
sortKey, _ := c.GetQuery("sort_key")
|
||||
sortDirection, _ := c.GetQuery("sort_direction")
|
||||
@@ -41,6 +42,16 @@ func GetSpiderList(c *gin.Context) {
|
||||
if t != "" && t != "all" {
|
||||
filter["type"] = t
|
||||
}
|
||||
if pid == "" {
|
||||
// do nothing
|
||||
} else if pid == constants.ObjectIdNull {
|
||||
filter["$or"] = []bson.M{
|
||||
{"project_id": bson.ObjectIdHex(pid)},
|
||||
{"project_id": bson.M{"$exists": false}},
|
||||
}
|
||||
} else {
|
||||
filter["project_id"] = bson.ObjectIdHex(pid)
|
||||
}
|
||||
|
||||
// 排序
|
||||
sortStr := "-_id"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
// 新增
|
||||
func PostVariable(c *gin.Context) {
|
||||
func PutVariable(c *gin.Context) {
|
||||
var variable model.Variable
|
||||
if err := c.ShouldBindJSON(&variable); err != nil {
|
||||
HandleError(http.StatusBadRequest, c, err)
|
||||
@@ -22,7 +22,7 @@ func PostVariable(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 修改
|
||||
func PutVariable(c *gin.Context) {
|
||||
func PostVariable(c *gin.Context) {
|
||||
var id = c.Param("id")
|
||||
var variable model.Variable
|
||||
if err := c.ShouldBindJSON(&variable); err != nil {
|
||||
|
||||
@@ -571,8 +571,12 @@ export default {
|
||||
this.getList()
|
||||
},
|
||||
onAdd () {
|
||||
let projectId = '000000000000000000000000'
|
||||
if (this.filter.project_id) {
|
||||
projectId = this.filter.project_id
|
||||
}
|
||||
this.$store.commit('spider/SET_SPIDER_FORM', {
|
||||
project_id: '000000000000000000000000',
|
||||
project_id: projectId,
|
||||
template: this.templateList[0]
|
||||
})
|
||||
this.addDialogVisible = true
|
||||
@@ -812,7 +816,6 @@ export default {
|
||||
|
||||
// fetch template list
|
||||
await this.$store.dispatch('spider/getTemplateList')
|
||||
|
||||
},
|
||||
mounted () {
|
||||
const vm = this
|
||||
|
||||
Reference in New Issue
Block a user