fix(缺陷管理): 缺陷内置字段展示国际化问题
--bug=1049213 --user=宋昌昌 【缺陷管理】LOCAL平台-新建缺陷-处理人、状态展示为英文 https://www.tapd.cn/55049933/s/1615277
This commit is contained in:
parent
a355557115
commit
8d8c568503
|
@ -133,7 +133,7 @@ public class BugController {
|
|||
@Operation(summary = "缺陷管理-列表-查看缺陷(详情&&编辑&&复制)")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_BUG_READ)
|
||||
public BugDetailDTO get(@PathVariable String id) {
|
||||
return bugService.get(id, SessionUtils.getUserId());
|
||||
return bugService.get(id, SessionUtils.getUserId(), Objects.requireNonNull(SessionUtils.getUser()).getLanguage());
|
||||
}
|
||||
|
||||
@GetMapping("/delete/{id}")
|
||||
|
@ -229,7 +229,7 @@ public class BugController {
|
|||
@RequiresPermissions(PermissionConstants.PROJECT_BUG_READ)
|
||||
@CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project")
|
||||
public TemplateDTO getTemplateDetail(@RequestBody BugTemplateRequest request) {
|
||||
return bugService.getTemplate(request.getId(), request.getProjectId(), request.getFromStatusId(), request.getPlatformBugKey(), request.getShowLocal());
|
||||
return bugService.getTemplate(request.getId(), request.getProjectId(), request.getFromStatusId(), request.getPlatformBugKey(), request.getShowLocal(), Objects.requireNonNull(SessionUtils.getUser()).getLanguage());
|
||||
}
|
||||
|
||||
@GetMapping("/follow/{id}")
|
||||
|
|
|
@ -3,19 +3,19 @@ package io.metersphere.bug.enums;
|
|||
import io.metersphere.sdk.util.Translator;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum BugTemplateCustomField {
|
||||
|
||||
/**
|
||||
* 处理人
|
||||
*/
|
||||
HANDLE_USER("handleUser", Translator.get("bug.handle_user")),
|
||||
HANDLE_USER("handleUser", "bug.handle_user"),
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
STATUS("status", Translator.get("bug.status"));
|
||||
STATUS("status", "bug.status");
|
||||
|
||||
|
||||
@Getter
|
||||
private final String id;
|
||||
|
||||
private final String name;
|
||||
|
@ -24,4 +24,8 @@ public enum BugTemplateCustomField {
|
|||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName(String language) {
|
||||
return Translator.get(name, language);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -252,9 +252,9 @@ public class BugService {
|
|||
* @param id 缺陷ID
|
||||
* @return 缺陷详情
|
||||
*/
|
||||
public BugDetailDTO get(String id, String currentUser) {
|
||||
public BugDetailDTO get(String id, String currentUser, String language) {
|
||||
Bug bug = checkBugExist(id);
|
||||
TemplateDTO template = getTemplate(bug.getTemplateId(), bug.getProjectId(), null, null, StringUtils.equals(bug.getPlatform(), BugPlatform.LOCAL.getName()));
|
||||
TemplateDTO template = getTemplate(bug.getTemplateId(), bug.getProjectId(), null, null, StringUtils.equals(bug.getPlatform(), BugPlatform.LOCAL.getName()), language);
|
||||
List<BugCustomFieldDTO> allCustomFields = extBugCustomFieldMapper.getBugAllCustomFields(List.of(id), bug.getProjectId());
|
||||
BugDetailDTO detail = new BugDetailDTO();
|
||||
detail.setId(id);
|
||||
|
@ -381,21 +381,21 @@ public class BugService {
|
|||
* @param platformBugKey 平台缺陷key
|
||||
* @return 模板详情
|
||||
*/
|
||||
public TemplateDTO getTemplate(String templateId, String projectId, String fromStatusId, String platformBugKey, Boolean showLocal) {
|
||||
public TemplateDTO getTemplate(String templateId, String projectId, String fromStatusId, String platformBugKey, Boolean showLocal, String language) {
|
||||
Template template = templateMapper.selectByPrimaryKey(templateId);
|
||||
if (template != null) {
|
||||
// 属于系统模板
|
||||
return injectPlatformTemplateBugField(baseTemplateService.getTemplateDTO(template), projectId, fromStatusId, platformBugKey, showLocal);
|
||||
return injectPlatformTemplateBugField(baseTemplateService.getTemplateDTO(template), projectId, fromStatusId, platformBugKey, showLocal, language);
|
||||
} else {
|
||||
// 不属于系统模板
|
||||
List<ProjectTemplateOptionDTO> option = projectTemplateService.getOption(projectId, TemplateScene.BUG.name());
|
||||
Optional<ProjectTemplateOptionDTO> isThirdPartyDefaultTemplate = option.stream().filter(projectTemplateOptionDTO -> StringUtils.equals(projectTemplateOptionDTO.getId(), templateId)).findFirst();
|
||||
if (isThirdPartyDefaultTemplate.isPresent()) {
|
||||
// 属于第三方平台默认模板(平台生成的默认模板无需注入配置中的字段)
|
||||
return attachTemplateStatusField(getPluginBugDefaultTemplate(projectId, true), projectId, fromStatusId, platformBugKey, false);
|
||||
return attachTemplateStatusField(getPluginBugDefaultTemplate(projectId, true), projectId, fromStatusId, platformBugKey, false, language);
|
||||
} else {
|
||||
// 不属于系统模板&&不属于第三方平台默认模板, 则该模板已被删除
|
||||
return injectPlatformTemplateBugField(projectTemplateService.getDefaultTemplateDTO(projectId, TemplateScene.BUG.name()), projectId, fromStatusId, platformBugKey, showLocal);
|
||||
return injectPlatformTemplateBugField(projectTemplateService.getDefaultTemplateDTO(projectId, TemplateScene.BUG.name()), projectId, fromStatusId, platformBugKey, showLocal, language);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -883,20 +883,21 @@ public class BugService {
|
|||
* @param platformBugKey 平台缺陷key
|
||||
* @return 模板
|
||||
*/
|
||||
private TemplateDTO injectPlatformTemplateBugField(TemplateDTO templateDTO, String projectId, String fromStatusId, String platformBugKey, Boolean showLocal) {
|
||||
private TemplateDTO injectPlatformTemplateBugField(TemplateDTO templateDTO, String projectId, String fromStatusId, String platformBugKey,
|
||||
Boolean showLocal, String language) {
|
||||
// 来自平台模板
|
||||
templateDTO.setPlatformDefault(false);
|
||||
String platformName = projectApplicationService.getPlatformName(projectId);
|
||||
|
||||
// 状态字段
|
||||
attachTemplateStatusField(templateDTO, projectId, fromStatusId, platformBugKey, showLocal);
|
||||
attachTemplateStatusField(templateDTO, projectId, fromStatusId, platformBugKey, showLocal, language);
|
||||
|
||||
// 内置字段(处理人字段)
|
||||
if (StringUtils.equals(platformName, BugPlatform.LOCAL.getName()) || BooleanUtils.isTrue(showLocal)) {
|
||||
// Local(处理人)
|
||||
TemplateCustomFieldDTO handleUserField = new TemplateCustomFieldDTO();
|
||||
handleUserField.setFieldId(BugTemplateCustomField.HANDLE_USER.getId());
|
||||
handleUserField.setFieldName(BugTemplateCustomField.HANDLE_USER.getName());
|
||||
handleUserField.setFieldName(BugTemplateCustomField.HANDLE_USER.getName(language));
|
||||
handleUserField.setFieldKey(BugTemplateCustomField.HANDLE_USER.getId());
|
||||
handleUserField.setType(CustomFieldType.SELECT.name());
|
||||
handleUserField.setOptions(getMemberOption(projectId));
|
||||
|
@ -952,13 +953,14 @@ public class BugService {
|
|||
* @param platformBugKey 平台缺陷key
|
||||
* @return 模板
|
||||
*/
|
||||
public TemplateDTO attachTemplateStatusField(TemplateDTO templateDTO, String projectId, String fromStatusId, String platformBugKey, Boolean showLocal) {
|
||||
public TemplateDTO attachTemplateStatusField(TemplateDTO templateDTO, String projectId, String fromStatusId, String platformBugKey,
|
||||
Boolean showLocal, String language) {
|
||||
if (templateDTO == null) {
|
||||
return null;
|
||||
}
|
||||
TemplateCustomFieldDTO statusField = new TemplateCustomFieldDTO();
|
||||
statusField.setFieldId(BugTemplateCustomField.STATUS.getId());
|
||||
statusField.setFieldName(BugTemplateCustomField.STATUS.getName());
|
||||
statusField.setFieldName(BugTemplateCustomField.STATUS.getName(language));
|
||||
statusField.setFieldKey(BugTemplateCustomField.STATUS.getId());
|
||||
statusField.setType(CustomFieldType.SELECT.name());
|
||||
List<SelectOption> statusOption = bugStatusService.getToStatusItemOption(projectId, fromStatusId, platformBugKey, showLocal);
|
||||
|
|
|
@ -960,17 +960,19 @@ export interface CascaderOption {
|
|||
|
||||
/**
|
||||
* 解析级联选择器的值
|
||||
* @param value
|
||||
* @param arr 值
|
||||
* @param options 级联选项 (默认层级2)
|
||||
*/
|
||||
export function cascaderValueToLabel(value: string, options: CascaderOption[]) {
|
||||
if (!value || !options) return '';
|
||||
export function cascaderValueToLabel(arr: string[], options: CascaderOption[]) {
|
||||
if (!arr || !options || arr.length === 0) return '';
|
||||
let targetLabel = '';
|
||||
options.forEach((option) => {
|
||||
if (option.children) {
|
||||
option.children.forEach((child) => {
|
||||
if (child.value === value) {
|
||||
targetLabel = child.text;
|
||||
if (option.value === arr[0]) {
|
||||
targetLabel += option.text;
|
||||
if (arr.length === 1) return;
|
||||
option.children?.forEach((child) => {
|
||||
if (child.value === arr[1]) {
|
||||
targetLabel += `/${child.text}`;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1009,11 +1011,20 @@ export function customFieldDataToTableData(customFieldData: Record<string, any>[
|
|||
.map((val: string) => field.options.find((option: { value: string }) => option.value === val)?.text)
|
||||
.join(',');
|
||||
} catch (e) {
|
||||
console.log('自定义字段值不是数组');
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('multiple field value is not array!');
|
||||
}
|
||||
} else if (field.type === 'CASCADER') {
|
||||
} else if (field.type === 'CASCADER' && field.value) {
|
||||
try {
|
||||
const arr = JSON.parse(field.value);
|
||||
if (arr.length > 1) {
|
||||
// 特殊的三方字段-级联选择器
|
||||
tableData[field.id] = cascaderValueToLabel(JSON.parse(field.value)[1], field.options);
|
||||
tableData[field.id] = cascaderValueToLabel(arr, field.options);
|
||||
}
|
||||
} catch (e) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('cascader field value is nor array!');
|
||||
}
|
||||
} else {
|
||||
tableData[field.id] = field.value;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue