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.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.util.CollectionUtils;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import javax.net.ssl.SSLContext;
@ -348,4 +349,18 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform {
.andIssuesIdEqualTo(id);
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);
} else if (StringUtils.isNotBlank(item.getType()) &&
StringUtils.equalsAny(item.getType(), "multipleInput") && StringUtils.isNotBlank(item.getValue())) {
fields.put(fieldName, JSONArray.parseArray(item.getValue()));
} else {
fields.put(fieldName, item.getValue());
}

View File

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

View File

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

View File

@ -57,9 +57,9 @@ public class TapdClient extends BaseClient {
return (TapdGetIssueResponse) getResultForObject(TapdGetIssueResponse.class, response);
}
public TapdBug addIssue(MultiValueMap<String, String> paramMap) {
public TapdBug addIssue(MultiValueMap<String, Object> paramMap) {
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;
try {
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();
}
public TapdBug updateIssue(MultiValueMap<String, String> paramMap) {
public TapdBug updateIssue(MultiValueMap<String, Object> paramMap) {
// 带id为更新
return addIssue(paramMap);
}

View File

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

View File

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

View File

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