fix(功能用例): 批量更新用例自定义字段

--bug=1008538 --user=lyh
【github#7696】在功能用例模块批量更新用例的输入框类型自定义字段时,“更新后属性值为”为空下拉框,也无法编辑
https://www.tapd.cn/55049933/s/1079744
This commit is contained in:
shiziyuan9527 2021-12-10 16:44:33 +08:00 committed by shiziyuan9527
parent 84425adcf1
commit d230853e86
8 changed files with 64 additions and 17 deletions

View File

@ -1,12 +1,10 @@
package io.metersphere.controller;
import io.metersphere.base.domain.CustomField;
import io.metersphere.base.domain.CustomFieldTemplate;
import io.metersphere.dto.CustomFieldTemplateDao;
import io.metersphere.service.CustomFieldTemplateService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@ -27,4 +25,10 @@ public class CustomFieldTemplateController {
public void update(@RequestBody CustomFieldTemplate request) {
customFieldTemplateService.update(request);
}
@GetMapping("/{id}")
public CustomField get(@PathVariable String id) {
return customFieldTemplateService.getCustomField(id);
}
}

View File

@ -4,6 +4,7 @@ package io.metersphere.service;
import io.metersphere.base.domain.CustomField;
import io.metersphere.base.domain.CustomFieldTemplate;
import io.metersphere.base.domain.CustomFieldTemplateExample;
import io.metersphere.base.mapper.CustomFieldMapper;
import io.metersphere.base.mapper.CustomFieldTemplateMapper;
import io.metersphere.base.mapper.ext.ExtCustomFieldTemplateMapper;
import io.metersphere.dto.CustomFieldTemplateDao;
@ -33,6 +34,8 @@ public class CustomFieldTemplateService {
SqlSessionFactory sqlSessionFactory;
@Resource
CustomFieldService customFieldService;
@Resource
private CustomFieldMapper customFieldMapper;
public List<String> getCustomFieldIds(String templateId) {
return extCustomFieldTemplateMapper.getCustomFieldIds(templateId);
@ -121,4 +124,10 @@ public class CustomFieldTemplateService {
public void update(CustomFieldTemplate request) {
customFieldTemplateMapper.updateByPrimaryKeySelective(request);
}
public CustomField getCustomField(String id) {
CustomFieldTemplate customFieldTemplate = customFieldTemplateMapper.selectByPrimaryKey(id);
String fieldId = customFieldTemplate.getFieldId();
return customFieldMapper.selectByPrimaryKey(fieldId);
}
}

View File

@ -15,6 +15,7 @@ public class TestCaseBatchRequest extends TestCaseWithBLOBs {
private String projectId;
private CustomFiledRequest customField;
private QueryTestCaseRequest condition;
private String customTemplateFieldId;
@Getter
@Setter

View File

@ -1268,15 +1268,18 @@ public class TestCaseService {
}
boolean hasField = false;
for (int i = 0; i < fields.size(); i++) {
TestCaseBatchRequest.CustomFiledRequest field = fields.get(i);
if (StringUtils.equals(request.getCustomField().getName(), field.getName())) {
for (TestCaseBatchRequest.CustomFiledRequest field : fields) {
if (StringUtils.equals(request.getCustomTemplateFieldId(), field.getId())) {
field.setValue(request.getCustomField().getValue());
hasField = true;
break;
}
}
if (!hasField) {
TestCaseBatchRequest.CustomFiledRequest customField = request.getCustomField();
customField.setId(request.getCustomTemplateFieldId());
customField.setName(request.getCustomField().getName());
customField.setValue(request.getCustomField().getValue());
fields.add(request.getCustomField());
}
if (StringUtils.equals(request.getCustomField().getName(), "用例等级")) {

View File

@ -114,11 +114,9 @@ export default {
};
},
mounted() {
if (this.data.type === 'member' || this.data.type === 'multipleMember') {
this.$post('/user/project/member/tester/list', {projectId: getCurrentProjectID()}, response => {
this.memberOptions = response.data;
});
}
this.$post('/user/project/member/tester/list', {projectId: getCurrentProjectID()}, response => {
this.memberOptions = response.data;
});
},
methods: {
getTranslateOption(item) {

View File

@ -12,7 +12,7 @@
<el-form :model="form" label-position="right" label-width="150px" size="medium" ref="form" :rules="rules">
<el-form-item :label="$t('test_track.case.batch_update', [size])" prop="type">
<el-select v-model="form.type" style="width: 80%" @change="changeType">
<el-option v-for="(type, index) in typeArr" :key="index" :value="type.id" :label="type.name"/>
<el-option v-for="(type, index) in typeArr" :key="index" :value="type.custom ? type.custom : type.id" :label="type.name"/>
</el-select>
</el-form-item>
<el-form-item v-if="form.type === 'projectEnv'" :label="$t('test_track.case.updated_attr_value')">
@ -27,6 +27,9 @@
@setEnvGroup="setEnvGroup"
ref="envPopover"/>
</el-form-item>
<el-form-item v-else-if="fieldType === 'custom'" :label="$t('test_track.case.updated_attr_value')">
<custom-filed-component :data="customField" prop="defaultValue"/>
</el-form-item>
<el-form-item v-else :label="$t('test_track.case.updated_attr_value')" prop="value">
<el-select v-model="form.value" style="width: 80%" :filterable="filterable">
<el-option v-for="(option, index) in options" :key="index" :value="option.id" :label="option.name">
@ -51,9 +54,11 @@
import {listenGoBack, removeGoBackListener} from "@/common/js/utils";
import EnvPopover from "@/business/components/api/automation/scenario/EnvPopover";
import {ENV_TYPE} from "@/common/js/constants";
import CustomFiledComponent from "@/business/components/settings/workspace/template/CustomFiledComponent";
export default {
name: "BatchEdit",
components: {
CustomFiledComponent,
EnvPopover,
MsDialogFooter
},
@ -88,7 +93,9 @@
isScenario: '',
result: {},
environmentType: ENV_TYPE.JSON,
envGroupId: ""
envGroupId: "",
customField: {},
fieldType: ""
}
},
computed: {
@ -107,6 +114,10 @@
}
this.form.map = this.map;
}
//
if (this.form.type.startsWith("custom")) {
this.form.customField = this.customField;
}
this.form.environmentType = this.environmentType;
this.form.envGroupId = this.envGroupId;
this.$emit("batchEdit", this.form);
@ -150,9 +161,25 @@
handleClose() {
this.form = {};
this.options = [];
this.fieldType = "";
removeGoBackListener(this.handleClose);
},
_handleCustomField(val) {
// custom template field id
let id = val.slice(6);
this.fieldType = "custom";
this.$get("/custom/field/template/" + id, res => {
this.customField = res ? res.data : {};
this.customField.options = JSON.parse(this.customField.options);
if (this.customField.type === 'checkbox' || this.customField.type === 'multipleMember') {
this.customField.defaultValue = [];
}
})
},
changeType(val) {
if (val && val.startsWith("custom")) {
this._handleCustomField(val);
}
this.$set(this.form, "value", "");
if (val === 'projectEnv' && this.isScenario !== '') {
this.projectIds.clear();

View File

@ -866,10 +866,14 @@ export default {
batchEdit(form) {
let ids = this.$refs.table.selectIds;
let param = {};
param.customField = form;
param.customField.name = form.type;
param.ids = ids;
param.customTemplateFieldId = form.type.slice(6);
param.condition = this.condition;
param.customField = {
id: form.customField.id,
name: form.customField.name,
value: form.customField.defaultValue
};
this.$post('/test/case/batch/edit', param, () => {
this.$success(this.$t('commons.save_success'));
this.refresh();

View File

@ -511,7 +511,8 @@ export function getCustomFieldBatchEditOption(customFields, typeArr, valueArr, m
typeArr.push({
id: item.name,
name: item.name,
uuid: item.id
uuid: item.id,
custom: "custom" + item.id
});
let options = [];