diff --git a/crawlab/routes/base.py b/crawlab/routes/base.py
index 689b8f6a..8a3d6709 100644
--- a/crawlab/routes/base.py
+++ b/crawlab/routes/base.py
@@ -38,8 +38,8 @@ class BaseApi(Resource):
:param action:
:return:
"""
- import pdb
- pdb.set_trace()
+ # import pdb
+ # pdb.set_trace()
args = self.parser.parse_args()
# action by id
@@ -85,13 +85,13 @@ class BaseApi(Resource):
# TODO: getting status for node
- return jsonify({
+ return {
'status': 'ok',
'total_count': total_count,
'page_num': page,
'page_size': page_size,
- 'items': items
- })
+ 'items': jsonify(items)
+ }
# get item by id
else:
@@ -108,6 +108,9 @@ class BaseApi(Resource):
if k not in DEFAULT_ARGS:
item[k] = args.get(k)
item = db_manager.save(col_name=self.col_name, item=item)
+
+ self.after_update(item._id)
+
return item
def update(self, id: str = None) -> (dict, tuple):
diff --git a/crawlab/routes/schedules.py b/crawlab/routes/schedules.py
index 1eceabde..f966e2cb 100644
--- a/crawlab/routes/schedules.py
+++ b/crawlab/routes/schedules.py
@@ -13,6 +13,8 @@ class ScheduleApi(BaseApi):
col_name = 'schedules'
arguments = (
+ ('name', str),
+ ('description', str),
('cron', str),
('spider_id', str)
)
diff --git a/frontend/src/views/schedule/ScheduleList.vue b/frontend/src/views/schedule/ScheduleList.vue
index b0dbb209..c6359733 100644
--- a/frontend/src/views/schedule/ScheduleList.vue
+++ b/frontend/src/views/schedule/ScheduleList.vue
@@ -2,7 +2,7 @@
@@ -11,19 +11,34 @@
:inline-message="true"
ref="scheduleForm"
label-position="right">
-
+
-
+
+
+
+
+
+
+
+
+
+ {{$t('Cron')}}
+
+
+
+
-
+
@@ -55,8 +70,8 @@
-
-
+
+
@@ -78,13 +93,30 @@ import {
export default {
name: 'ScheduleList',
data () {
+ const cronValidator = (rule, value, callback) => {
+ let patArr = []
+ for (let i = 0; i < 6; i++) {
+ patArr.push('[/*,0-9]+')
+ }
+ const pat = '^' + patArr.join(' ') + '$'
+ if (!value) {
+ callback(new Error('cron cannot be empty'))
+ } else if (!value.match(pat)) {
+ callback(new Error('cron format is invalid'))
+ }
+ callback()
+ }
return {
columns: [
{ name: 'name', label: 'Name', width: '220' },
{ name: 'cron', label: 'Cron', width: '220' },
{ name: 'description', label: 'Description', width: 'auto' }
],
- dialogVisible: false
+ dialogTitle: '',
+ dialogVisible: false,
+ cronRules: [
+ { validator: cronValidator, trigger: 'blur' }
+ ]
}
},
computed: {
@@ -92,30 +124,68 @@ export default {
'scheduleList',
'scheduleForm'
]),
+ ...mapState('spider', [
+ 'spiderList'
+ ]),
filteredTableData () {
return this.scheduleList
}
},
methods: {
onDialogClose () {
+ this.dialogVisible = false
},
onCancel () {
this.dialogVisible = false
},
onAdd () {
this.dialogVisible = true
+ this.$store.commit('schedule/SET_SCHEDULE_FORM', {})
},
onAddSubmit () {
+ this.$refs.scheduleForm.validate(res => {
+ if (res) {
+ this.$store.dispatch('schedule/addSchedule')
+ .then(response => {
+ this.dialogVisible = false
+ setTimeout(() => {
+ this.$store.dispatch('schedule/getScheduleList')
+ }, 100)
+ })
+ }
+ })
+ },
+ isShowRun () {
+ },
+ onEdit (row) {
+ this.$store.commit('schedule/SET_SCHEDULE_FORM', row)
+ this.dialogVisible = true
+ },
+ onRemove (row) {
+ this.$store.dispatch('schedule/removeSchedule', row._id)
+ .then(response => {
+ setTimeout(() => {
+ this.$store.dispatch('schedule/getScheduleList')
+ this.$message.success(`Schedule "${row.name}" has been removed`)
+ }, 100)
+ })
+ },
+ onRun () {
}
},
created () {
this.$store.dispatch('schedule/getScheduleList')
+ this.$store.dispatch('spider/getSpiderList')
}
}