improve the creation of custom request

pull/330/head
vapao 2021-04-26 17:51:53 +08:00
parent 0e6e618cef
commit 54d5649663
4 changed files with 16 additions and 11 deletions

View File

@ -98,6 +98,7 @@ class DeployExtend2(models.Model, ModelMixin):
deploy = models.OneToOneField(Deploy, primary_key=True, on_delete=models.CASCADE) deploy = models.OneToOneField(Deploy, primary_key=True, on_delete=models.CASCADE)
server_actions = models.TextField() server_actions = models.TextField()
host_actions = models.TextField() host_actions = models.TextField()
require_upload = models.BooleanField(default=False)
def to_dict(self, *args, **kwargs): def to_dict(self, *args, **kwargs):
tmp = super().to_dict(*args, **kwargs) tmp = super().to_dict(*args, **kwargs)

View File

@ -151,6 +151,7 @@ class DeployView(View):
return json_response(error=error) return json_response(error=error)
if len(extend_form.server_actions) + len(extend_form.host_actions) == 0: if len(extend_form.server_actions) + len(extend_form.host_actions) == 0:
return json_response(error='请至少设置一个执行的动作') return json_response(error='请至少设置一个执行的动作')
extend_form.require_upload = any(x.get('src_mode') == '1' for x in extend_form.host_actions)
extend_form.server_actions = json.dumps(extend_form.server_actions) extend_form.server_actions = json.dumps(extend_form.server_actions)
extend_form.host_actions = json.dumps(extend_form.host_actions) extend_form.host_actions = json.dumps(extend_form.host_actions)
if form.id: if form.id:

View File

@ -69,7 +69,7 @@ export default observer(function () {
return false return false
} }
const {app_host_ids, deploy_id, type} = store.record; const {app_host_ids, deploy_id, type, require_upload} = store.record;
return ( return (
<Modal <Modal
visible visible
@ -89,12 +89,14 @@ export default observer(function () {
tooltip="可以在自定义脚本中引用该变量,用于设置本次发布相关的动态变量,在脚本中通过 $SPUG_RELEASE 来使用该值。"> tooltip="可以在自定义脚本中引用该变量,用于设置本次发布相关的动态变量,在脚本中通过 $SPUG_RELEASE 来使用该值。">
<Input placeholder="请输入环境变量 SPUG_RELEASE 的值"/> <Input placeholder="请输入环境变量 SPUG_RELEASE 的值"/>
</Form.Item> </Form.Item>
<Form.Item label="上传数据" tooltip="通过数据传输动作来使用上传的文件。" className={styles.upload}> {require_upload && (
<Form.Item required label="上传数据" tooltip="通过数据传输动作来使用上传的文件。" className={styles.upload}>
<Upload name="file" fileList={fileList} headers={{'X-Token': X_TOKEN}} beforeUpload={handleUpload} <Upload name="file" fileList={fileList} headers={{'X-Token': X_TOKEN}} beforeUpload={handleUpload}
data={{deploy_id}} onChange={handleUploadChange}> data={{deploy_id}} onChange={handleUploadChange}>
{fileList.length === 0 ? <Button loading={uploading} icon={<UploadOutlined/>}>点击上传</Button> : null} {fileList.length === 0 ? <Button loading={uploading} icon={<UploadOutlined/>}>点击上传</Button> : null}
</Upload> </Upload>
</Form.Item> </Form.Item>
)}
<Form.Item required label="目标主机" tooltip="可以通过创建多个发布申请单,选择主机分批发布。"> <Form.Item required label="目标主机" tooltip="可以通过创建多个发布申请单,选择主机分批发布。">
{host_ids.length > 0 && `已选择 ${host_ids.length} 台(可选${app_host_ids.length}`} {host_ids.length > 0 && `已选择 ${host_ids.length} 台(可选${app_host_ids.length}`}
<Button type="link" onClick={() => setVisible(true)}>选择主机</Button> <Button type="link" onClick={() => setVisible(true)}>选择主机</Button>

View File

@ -84,7 +84,8 @@ class Store {
}; };
confirmAdd = (deploy) => { confirmAdd = (deploy) => {
this.record = {deploy_id: deploy.id, app_host_ids: deploy.host_ids}; const {id, host_ids, require_upload} = deploy;
this.record = {deploy_id: id, app_host_ids: host_ids, require_upload};
if (deploy.extend === '1') { if (deploy.extend === '1') {
this.ext1Visible = true this.ext1Visible = true
} else { } else {