From 925f643cd8f992f580a9bde3d4c0cf61b59340aa Mon Sep 17 00:00:00 2001 From: Marvin Zhang Date: Wed, 29 May 2019 17:51:44 +0800 Subject: [PATCH] added extracting list fields functionality --- frontend/src/components/Config/ConfigList.vue | 25 ++++++++++++++++--- frontend/src/store/modules/spider.js | 3 +++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/Config/ConfigList.vue b/frontend/src/components/Config/ConfigList.vue index 5b7e3d3d..b3d4c39d 100644 --- a/frontend/src/components/Config/ConfigList.vue +++ b/frontend/src/components/Config/ConfigList.vue @@ -34,14 +34,14 @@ - + - + @@ -82,7 +82,8 @@
{{$t('Run')}} - {{$t('Extract Fields')}} + {{$t('Extract Fields')}} + {{$t('Preview')}} {{$t('Save')}}
@@ -217,6 +218,24 @@ export default { }) }, onExtractFields () { + this.onSave() + .then(() => { + this.extractFieldsLoading = true + this.$store.dispatch('spider/extractFields') + .then(response => { + if (response.data.item_selector) { + this.$set(this.spiderForm, 'item_selector', response.data.item_selector) + this.$set(this.spiderForm, 'item_selector_type', 'css') + } + + if (response.data.fields && response.data.fields.length) { + this.spiderForm.fields = response.data.fields + } + }) + .finally(() => { + this.extractFieldsLoading = false + }) + }) } }, created () { diff --git a/frontend/src/store/modules/spider.js b/frontend/src/store/modules/spider.js index 18fcce2a..831c0d0e 100644 --- a/frontend/src/store/modules/spider.js +++ b/frontend/src/store/modules/spider.js @@ -208,6 +208,9 @@ const actions = { .then(response => { commit('SET_PREVIEW_CRAWL_DATA', response.data.items) }) + }, + extractFields ({ state, commit }) { + return request.post(`/spiders/${state.spiderForm._id}/extract_fields`) } }