Skip to content

Commit

Permalink
feat(system-client): impl remote deploy pages;
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow committed Sep 6, 2021
1 parent 7fbb75e commit 8dee4e5
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 220 deletions.
94 changes: 87 additions & 7 deletions packages/system-client/src/api/deploy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,57 @@
import store from '@/store'
import request from '@/utils/request'
import axios from 'axios'

/**
* Get deploy targets
* @returns
*/
export function getDeployTargets() {
const appid = store.state.app.appid
return request({
url: `/apps/${appid}/deploy/targets`,
method: 'get'
})
}

/**
* Create a deploy target
* @returns
*/
export function createDeployTarget(data) {
const appid = store.state.app.appid
return request({
url: `/apps/${appid}/deploy/targets/create`,
method: 'post',
data: data
})
}

/**
* Update a deploy target
* @returns
*/
export function updateDeployTarget(target_id, data) {
const appid = store.state.app.appid
return request({
url: `/apps/${appid}/deploy/targets/${target_id}`,
method: 'post',
data: data
})
}

/**
* Remove a deploy target
* @returns
*/
export function removeDeployTarget(target_id) {
const appid = store.state.app.appid
return request({
url: `/apps/${appid}/deploy/targets/${target_id}`,
method: 'delete'
})
}

/**
* 创建部署令牌
* @param {string[]} permissions 令牌权限: "policy" , "function"
Expand All @@ -8,8 +60,9 @@ import axios from 'axios'
* @returns
*/
export function createDeployToken({ permissions, expire, source }) {
const appid = store.state.app.appid
return request({
url: '/deploy/create-token',
url: `/apps/${appid}/deploy/create-token`,
method: 'post',
data: {
permissions,
Expand All @@ -35,16 +88,43 @@ export async function deploy2remote(deploy_url, deploy_token, { policies, functi
}

/**
* 应用部署请求
* @param {string} id 部署请求的 id
* Get deploy requests
* @returns
*/
export function applyDeployRequest(id) {
export function getDeployRequests(query, page, pageSize) {
const appid = store.state.app.appid
return request({
url: '/deploy/apply',
method: 'post',
url: `/apps/${appid}/deploy/requests`,
method: 'get',
data: {
id
...query,
page,
limit: pageSize
}
})
}

/**
* Remove a deploy request
* @returns
*/
export function removeDeployRequest(id) {
const appid = store.state.app.appid
return request({
url: `/apps/${appid}/deploy/requests/${id}`,
method: 'delete'
})
}

/**
* Apply deploy request
* @param {string} id the id of deploy request
* @returns
*/
export function applyDeployRequest(id) {
const appid = store.state.app.appid
return request({
url: `/apps/${appid}/deploy/requests/${id}/apply`,
method: 'post'
})
}
2 changes: 1 addition & 1 deletion packages/system-client/src/router/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export const asyncRoutes = [
]
},
{
path: '/deploy',
path: '/app/:appid/deploy',
component: Layout,
redirect: '/deploy/target',
meta: {
Expand Down
2 changes: 1 addition & 1 deletion packages/system-client/src/views/cloudfunction/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
</el-dialog>

<!-- 部署面板 -->
<deploy-panel v-model="deployPanelVisible" :functions="deploy_functions" />
<deploy-panel v-if="deployPanelVisible" v-model="deployPanelVisible" :functions="deploy_functions" />
</div>
</template>

Expand Down
2 changes: 1 addition & 1 deletion packages/system-client/src/views/database/policies.vue
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
</el-dialog>

<!-- 部署面板 -->
<DeployPanel v-model="deployPanelVisible" :policies="list" />
<DeployPanel v-if="deployPanelVisible" v-model="deployPanelVisible" :policies="list" />
</div>
</template>

Expand Down
49 changes: 12 additions & 37 deletions packages/system-client/src/views/deploy/components/deploy-panel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@
{{ func.name }} - {{ func.label }}
</el-tag>
</el-form-item>
<el-form-item v-if="triggers && triggers.length" label="部署触发器" size="normal">
<el-tag v-for="tri in triggers" :key="tri._id" type="default" size="mini" style="margin-right: 10px;">
{{ tri.name }} - {{ tri.event || 'timer' }}
</el-tag>
</el-form-item>
<el-form-item label="部署说明" prop="comment">
<el-input
v-model="form.comment"
Expand All @@ -57,9 +52,9 @@
</div>
</template>
<script>
import { db } from '@/api/cloud'
import { deploy2remote } from '@/api/deploy'
import { Constants } from '../../../api/constants'
// import { db } from '@/api/cloud'
import { deploy2remote, getDeployTargets } from '@/api/deploy'
// import { Constants } from '../../../api/constants'
// 表单验证规则
const formRules = {
Expand Down Expand Up @@ -89,8 +84,7 @@ export default {
// 部署目标
targets: [],
formRules,
internal_functions: [],
triggers: []
internal_functions: []
}
},
computed: {
Expand All @@ -109,7 +103,6 @@ export default {
functions() {
if (this.functions) {
this.internal_functions = [...this.functions]
this.loadTriggers()
}
}
},
Expand All @@ -121,50 +114,32 @@ export default {
},
methods: {
async load() {
const r = await db.collection(Constants.cn.deploy_targets).get()
if (!r.ok) throw new Error('get targets failed')
const r = await getDeployTargets()
this.targets = r.data
},
async loadTriggers() {
this.triggers = []
if (!this.internal_functions?.length) {
return
}
const func_ids = this.internal_functions.map(func => func._id)
const r = await db.collection(Constants.cn.triggers)
.where({
func_id: db.command.in(func_ids)
})
.get()
if (r.ok) {
this.triggers = r.data
}
},
deploy() {
if (!this.functions?.length && !this.policies?.length) {
this.$message.error('无可部署内容')
return
return this.$message.error('无可部署内容')
}
if (!this.selected_target) {
this.$message.error('无推送目标选中')
return this.$message.error('无推送目标选中')
}
this.$refs['dataForm'].validate(async(valid) => {
if (!valid) { return }
const data = {
policies: this.policies,
functions: this.functions,
triggers: this.triggers,
comment: this.form.comment
}
const target = this.selected_target
const r = await deploy2remote(target.url, target.token, data)
if (r.code === 0) {
this.$message.success('操作成功!')
}
if (r.code) { return this.$message.error('出错了') }
this.$message.success('操作成功!')
})
},
defaultForm() {
Expand Down
61 changes: 10 additions & 51 deletions packages/system-client/src/views/deploy/requests.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

<!-- 表格 -->
<el-table
:key="tableKey"
v-loading="listLoading"
:data="list"
border
Expand Down Expand Up @@ -137,9 +136,7 @@

<script>
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import { db } from '@/api/cloud'
import { applyDeployRequest, createDeployToken } from '../../api/deploy'
import { Constants } from '../../api/constants'
import { applyDeployRequest, createDeployToken, getDeployRequests, removeDeployRequest } from '../../api/deploy'
// 默认的创建部署令牌表单
function getDefaultFormValue() {
Expand Down Expand Up @@ -174,7 +171,6 @@ export default {
},
data() {
return {
tableKey: 0,
list: null,
total: 0,
listLoading: true,
Expand Down Expand Up @@ -203,45 +199,20 @@ export default {
*/
async getList() {
this.listLoading = true
// 拼装查询条件 by this.listQuery
const { limit, page, keyword } = this.listQuery
const query = {}
if (keyword) {
query['$or'] = [
{ name: db.RegExp({ regexp: `.*${keyword}.*` }) },
{ label: db.RegExp({ regexp: `.*${keyword}.*` }) },
{ description: db.RegExp({ regexp: `.*${keyword}.*` }) }
]
}
// 执行数据查询
const res = await db.collection(Constants.cn.deploy_requests)
.where(query)
.limit(limit)
.skip((page - 1) * limit)
.get()
.catch(() => { this.listLoading = false })
const query = { }
if (keyword) { query['keyword'] = keyword }
const res = await getDeployRequests(query, page, limit)
this.list = res.data
// 获取数据总数
const { total } = await db.collection(Constants.cn.deploy_requests)
.where(query)
.limit(limit)
.skip((page - 1) * limit)
.count()
.catch(() => { this.listLoading = false })
this.total = total
this.total = res.total
this.listLoading = false
},
/**
* 应用部署请求
*/
async apply(data) {
const r = await applyDeployRequest(data._id)
console.log(r)
if (r.code === 0) {
this.$message.success('应用成功!')
this.getList()
Expand Down Expand Up @@ -298,26 +269,14 @@ export default {
await this.$confirm('确认要删除此数据?', '删除确认')
// 执行删除请求
const r = await db.collection(Constants.cn.deploy_requests)
.where({ _id: row._id })
.remove()
const r = await removeDeployRequest(row._id)
if (!r.ok) {
this.$notify({
type: 'error',
title: '操作失败',
message: '删除失败!' + r.error
})
return
if (r.error) {
return this.$notify({ type: 'error', title: '操作失败', message: '删除失败!' + r.error })
}
this.$notify({
type: 'success',
title: '操作成功',
message: '删除成功!'
})
this.list.splice(index, 1)
this.$notify({ type: 'success', title: '操作成功', message: '删除成功!' })
this.getList()
},
// 查看详情
// async handleShowDetail(row) {
Expand Down
Loading

0 comments on commit 8dee4e5

Please sign in to comment.