refactor: 自定义字段添加多值输入框

This commit is contained in:
chenjianxing 2021-09-24 14:52:46 +08:00 committed by jianxing
parent 2faae8df24
commit 2bcfbd5a4d
8 changed files with 46 additions and 28 deletions

View File

@ -34,6 +34,7 @@ import org.jsoup.safety.Whitelist;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
@ -348,4 +349,18 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform {
.andIssuesIdEqualTo(id); .andIssuesIdEqualTo(id);
testCaseIssuesMapper.deleteByExample(example); testCaseIssuesMapper.deleteByExample(example);
} }
protected void addCustomFields(IssuesUpdateRequest issuesRequest, MultiValueMap<String, Object> paramMap) {
List<CustomFieldItemDTO> customFields = getCustomFields(issuesRequest.getCustomFields());
customFields.forEach(item -> {
if (StringUtils.isNotBlank(item.getCustomData())) {
if (StringUtils.isNotBlank(item.getType()) &&
StringUtils.equalsAny(item.getType(), "multipleInput") && StringUtils.isNotBlank(item.getValue())) {
paramMap.put(item.getCustomData(), JSONArray.parseArray(item.getValue()));
} else {
paramMap.add(item.getCustomData(), item.getValue());
}
}
});
}
} }

View File

@ -275,6 +275,9 @@ public class JiraPlatform extends AbstractIssuePlatform {
}); });
} }
fields.put(fieldName, attrs); fields.put(fieldName, attrs);
} else if (StringUtils.isNotBlank(item.getType()) &&
StringUtils.equalsAny(item.getType(), "multipleInput") && StringUtils.isNotBlank(item.getValue())) {
fields.put(fieldName, JSONArray.parseArray(item.getValue()));
} else { } else {
fields.put(fieldName, item.getValue()); fields.put(fieldName, item.getValue());
} }

View File

@ -87,7 +87,7 @@ public class TapdPlatform extends AbstractIssuePlatform {
@Override @Override
public void addIssue(IssuesUpdateRequest issuesRequest) { public void addIssue(IssuesUpdateRequest issuesRequest) {
MultiValueMap<String, String> param = buildUpdateParam(issuesRequest); MultiValueMap<String, Object> param = buildUpdateParam(issuesRequest);
TapdBug bug = tapdClient.addIssue(param); TapdBug bug = tapdClient.addIssue(param);
Map<String, String> statusMap = tapdClient.getStatusMap(getProjectId(this.projectId)); Map<String, String> statusMap = tapdClient.getStatusMap(getProjectId(this.projectId));
issuesRequest.setPlatformStatus(statusMap.get(bug.getStatus())); issuesRequest.setPlatformStatus(statusMap.get(bug.getStatus()));
@ -102,18 +102,16 @@ public class TapdPlatform extends AbstractIssuePlatform {
@Override @Override
public void updateIssue(IssuesUpdateRequest request) { public void updateIssue(IssuesUpdateRequest request) {
MultiValueMap<String, String> param = buildUpdateParam(request); MultiValueMap<String, Object> param = buildUpdateParam(request);
param.add("id", request.getId()); param.add("id", request.getId());
handleIssueUpdate(request); handleIssueUpdate(request);
tapdClient.updateIssue(param); tapdClient.updateIssue(param);
} }
private MultiValueMap<String, String> buildUpdateParam(IssuesUpdateRequest issuesRequest) { private MultiValueMap<String, Object> buildUpdateParam(IssuesUpdateRequest issuesRequest) {
issuesRequest.setPlatform(IssuesManagePlatform.Tapd.toString()); issuesRequest.setPlatform(IssuesManagePlatform.Tapd.toString());
setConfig(); setConfig();
List<CustomFieldItemDTO> customFields = getCustomFields(issuesRequest.getCustomFields());
String tapdId = getProjectId(issuesRequest.getProjectId()); String tapdId = getProjectId(issuesRequest.getProjectId());
if (StringUtils.isBlank(tapdId)) { if (StringUtils.isBlank(tapdId)) {
@ -131,17 +129,14 @@ public class TapdPlatform extends AbstractIssuePlatform {
reporter = SessionUtils.getUser().getName(); reporter = SessionUtils.getUser().getName();
} }
MultiValueMap<String, String> paramMap = new LinkedMultiValueMap<>(); MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
paramMap.add("title", issuesRequest.getTitle()); paramMap.add("title", issuesRequest.getTitle());
paramMap.add("workspace_id", tapdId); paramMap.add("workspace_id", tapdId);
paramMap.add("description", msDescription2Tapd(issuesRequest.getDescription())); paramMap.add("description", msDescription2Tapd(issuesRequest.getDescription()));
paramMap.add("current_owner", usersStr); paramMap.add("current_owner", usersStr);
customFields.forEach(item -> { addCustomFields(issuesRequest, paramMap);
if (StringUtils.isNotBlank(item.getCustomData())) {
paramMap.add(item.getCustomData(), item.getValue());
}
});
paramMap.add("reporter", reporter); paramMap.add("reporter", reporter);
return paramMap; return paramMap;
} }

View File

@ -204,7 +204,6 @@ public class ZentaoPlatform extends AbstractIssuePlatform {
private MultiValueMap<String, Object> buildUpdateParam(IssuesUpdateRequest issuesRequest) { private MultiValueMap<String, Object> buildUpdateParam(IssuesUpdateRequest issuesRequest) {
issuesRequest.setPlatform(IssuesManagePlatform.Zentao.toString()); issuesRequest.setPlatform(IssuesManagePlatform.Zentao.toString());
List<CustomFieldItemDTO> customFields = getCustomFields(issuesRequest.getCustomFields());
zentaoClient.setConfig(getUserConfig()); zentaoClient.setConfig(getUserConfig());
String projectId = getProjectId(issuesRequest.getProjectId()); String projectId = getProjectId(issuesRequest.getProjectId());
if (StringUtils.isBlank(projectId)) { if (StringUtils.isBlank(projectId)) {
@ -214,11 +213,7 @@ public class ZentaoPlatform extends AbstractIssuePlatform {
paramMap.add("product", projectId); paramMap.add("product", projectId);
paramMap.add("title", issuesRequest.getTitle()); paramMap.add("title", issuesRequest.getTitle());
customFields.forEach(item -> { addCustomFields(issuesRequest, paramMap);
if (StringUtils.isNotBlank(item.getCustomData())) {
paramMap.add(item.getCustomData(), item.getValue());
}
});
String description = issuesRequest.getDescription(); String description = issuesRequest.getDescription();
String zentaoSteps = description; String zentaoSteps = description;

View File

@ -57,9 +57,9 @@ public class TapdClient extends BaseClient {
return (TapdGetIssueResponse) getResultForObject(TapdGetIssueResponse.class, response); return (TapdGetIssueResponse) getResultForObject(TapdGetIssueResponse.class, response);
} }
public TapdBug addIssue(MultiValueMap<String, String> paramMap) { public TapdBug addIssue(MultiValueMap<String, Object> paramMap) {
String url = getBaseUrl() + "/bugs"; String url = getBaseUrl() + "/bugs";
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(paramMap, getAuthHeader()); HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(paramMap, getAuthHeader());
ResponseEntity<String> response = null; ResponseEntity<String> response = null;
try { try {
response = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class); response = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
@ -70,7 +70,7 @@ public class TapdClient extends BaseClient {
return ((AddTapdIssueResponse) getResultForObject(AddTapdIssueResponse.class, response)).getData().getBug(); return ((AddTapdIssueResponse) getResultForObject(AddTapdIssueResponse.class, response)).getData().getBug();
} }
public TapdBug updateIssue(MultiValueMap<String, String> paramMap) { public TapdBug updateIssue(MultiValueMap<String, Object> paramMap) {
// 带id为更新 // 带id为更新
return addIssue(paramMap); return addIssue(paramMap);
} }

View File

@ -41,22 +41,26 @@
type: Boolean, type: Boolean,
default: false default: false
}, },
size: {type: String, default: "small"} size: {type: String, default: "small"},
prop: {
type: String,
default: "tags"
}
}, },
created() { created() {
if (!this.currentScenario.tags) { if (!this.currentScenario[this.prop]) {
this.currentScenario.tags = []; this.currentScenario[this.prop] = [];
} }
}, },
data() { data() {
return { return {
newTag: '', newTag: '',
innerTags: this.currentScenario.tags ? [...this.currentScenario.tags] : [] innerTags: this.currentScenario[this.prop] ? [...this.currentScenario[this.prop]] : []
} }
}, },
watch: { watch: {
innerTags() { innerTags() {
this.currentScenario.tags = this.innerTags; this.currentScenario[this.prop] = this.innerTags;
} }
}, },
methods: { methods: {

View File

@ -83,6 +83,9 @@
</el-option> </el-option>
</el-select> </el-select>
<ms-input-tag v-else-if="data.type === 'multipleInput'"
:read-only="disabled" :currentScenario="data" :prop="prop"/>
<el-input class="custom-with" <el-input class="custom-with"
@change="handleChange" @change="handleChange"
:disabled="disabled" :disabled="disabled"
@ -95,9 +98,10 @@
<script> <script>
import MsTableColumn from "@/business/components/common/components/table/MsTableColumn"; import MsTableColumn from "@/business/components/common/components/table/MsTableColumn";
import {getCurrentProjectID, getCurrentWorkspaceId} from "@/common/js/utils"; import {getCurrentProjectID, getCurrentWorkspaceId} from "@/common/js/utils";
import MsInputTag from "@/business/components/api/automation/scenario/MsInputTag";
export default { export default {
name: "CustomFiledComponent", name: "CustomFiledComponent",
components: {MsTableColumn}, components: {MsInputTag, MsTableColumn},
props: [ props: [
'data', 'data',
'prop', 'prop',

View File

@ -12,7 +12,8 @@ export const CUSTOM_FIELD_TYPE_OPTION = [
{value: 'multipleMember',text: '多选成员'}, {value: 'multipleMember',text: '多选成员'},
{value: 'data',text: '日期'}, {value: 'data',text: '日期'},
{value: 'int',text: '整型'}, {value: 'int',text: '整型'},
{value: 'float',text: '浮点型'} {value: 'float',text: '浮点型'},
{value: 'multipleInput',text: '多值输入框'}
]; ];
export const CUSTOM_FIELD_SCENE_OPTION = [ export const CUSTOM_FIELD_SCENE_OPTION = [
@ -43,7 +44,8 @@ export const FIELD_TYPE_MAP = {
multipleMember: '多选成员', multipleMember: '多选成员',
data: '日期', data: '日期',
int: '整型', int: '整型',
float: '浮点型' float: '浮点型',
multipleInput: '多值输入框'
}; };
export const SCENE_MAP = { export const SCENE_MAP = {