added github import

This commit is contained in:
Marvin Zhang
2019-03-04 12:07:14 +08:00
parent e3287ab593
commit 95cf526013
8 changed files with 112 additions and 34 deletions

View File

@@ -12,7 +12,10 @@ const state = {
activeNode: {},
// upload form for importing spiders
importForm: {}
importForm: {
url: '',
type: 'github'
}
}
const getters = {}
@@ -114,8 +117,14 @@ const actions = {
}).sort((a, b) => a.create_ts < b.create_ts ? 1 : -1),
{ root: true })
})
},
importGithub ({ state }) {
const url = state.importForm.url
return request.post('/spiders/import/github', { url })
.then(response => {
console.log(response)
})
}
}
export default {

View File

@@ -8,22 +8,22 @@
:before-close="onDialogClose">
<el-form label-width="150px"
:model="importForm"
ref="spiderForm"
ref="importForm"
label-position="right">
<el-form-item label="Source URL" prop="url" required>
<el-input v-model="importForm.url" placeholder="Source URL"></el-input>
</el-form-item>
<el-form-item label="Source Type" prop="type" required>
<el-select v-model="importForm.type" placeholder="Source Type">
<el-option value="github"></el-option>
<el-option value="gitlab"></el-option>
<el-option value="svn"></el-option>
<el-option value="github" label="Github"></el-option>
<el-option value="gitlab" label="Gitlab"></el-option>
<el-option value="svn" label="SVN" disabled></el-option>
</el-select>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="onCancel">Cancel</el-button>
<el-button type="primary" @click="onImport">Import</el-button>
<el-button v-loading="importLoading" type="primary" @click="onImport">Import</el-button>
</span>
</el-dialog>
@@ -36,23 +36,9 @@
@change="onSearch">
</el-input>
<div class="right">
<el-dropdown class="btn">
<el-button type="primary" icon="el-icon-upload">
Import Spiders
<i class="el-icon-arrow-down el-icon--right"></i>
</el-button>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item>
<div @click="openImportDialog('github')">Github</div>
</el-dropdown-item>
<el-dropdown-item disabled>
<span @click="openImportDialog('gitlab')">Gitlab</span>
</el-dropdown-item>
<el-dropdown-item disabled>
<span @click="openImportDialog('svn')">SVN</span>
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
<el-button type="primary" icon="el-icon-upload" @click="openImportDialog">
Import Spiders
</el-button>
<el-button type="success"
icon="el-icon-refresh"
class="btn refresh"
@@ -158,6 +144,7 @@ export default {
pageNum: 0,
pageSize: 10
},
importLoading: false,
isEditMode: false,
dialogVisible: false,
filter: {
@@ -231,7 +218,6 @@ export default {
this.dialogVisible = false
},
onEdit (row) {
console.log(row)
this.isEditMode = true
this.$store.commit('spider/SET_SPIDER_FORM', row)
this.dialogVisible = true
@@ -268,10 +254,25 @@ export default {
this.$store.dispatch('spider/getSpiderList')
},
onImport () {
this.dialogVisible = false
this.$refs.importForm.validate(valid => {
if (valid) {
this.importLoading = true
this.$store.dispatch('spider/importGithub')
.then(response => {
this.$message.success('Import repo sucessfully')
this.$store.dispatch('spider/getSpiderList')
})
.catch(response => {
this.$message.error(response.data.error)
})
.finally(() => {
this.dialogVisible = false
this.importLoading = false
})
}
})
},
openImportDialog (type) {
this.$store.commit('spider/SET_IMPORT_FORM', { type })
openImportDialog () {
this.dialogVisible = true
}
},