fix(测试跟踪): 修改执行测试计划时报告里运行环境的查询方式

--bug=1021786 --user=宋天阳 【测试跟踪】历史数据运行环境显示不对
https://www.tapd.cn/55049933/s/1339992
This commit is contained in:
song-tianyang 2023-02-21 17:58:16 +08:00 committed by 建国
parent 6944ccba05
commit fe109ddda7
7 changed files with 298 additions and 156 deletions

View File

@ -41,6 +41,7 @@ import io.metersphere.service.plan.remote.TestPlanService;
import io.metersphere.service.scenario.ApiScenarioModuleService; import io.metersphere.service.scenario.ApiScenarioModuleService;
import io.metersphere.service.scenario.ApiScenarioReportService; import io.metersphere.service.scenario.ApiScenarioReportService;
import io.metersphere.service.scenario.ApiScenarioService; import io.metersphere.service.scenario.ApiScenarioService;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -52,7 +53,6 @@ import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import jakarta.annotation.Resource;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -351,12 +351,11 @@ public class TestPlanScenarioCaseService {
map.put(s, envMap.get(s)); map.put(s, envMap.get(s));
} }
} }
String envJsonStr = JSON.toJSONString(map);
if (!StringUtils.equals(envJsonStr, testPlanApiScenario.getEnvironment())) { testPlanApiScenario.setEnvironmentType(runModeConfig.getEnvironmentType());
testPlanApiScenario.setEnvironmentType(EnvironmentType.JSON.toString()); testPlanApiScenario.setEnvironmentGroupId(runModeConfig.getEnvironmentGroupId());
testPlanApiScenario.setEnvironment(JSON.toJSONString(map)); testPlanApiScenario.setEnvironment(JSON.toJSONString(map));
mapper.updateByPrimaryKeyWithBLOBs(testPlanApiScenario); mapper.updateByPrimaryKeyWithBLOBs(testPlanApiScenario);
}
} }
sqlSession.flushStatements(); sqlSession.flushStatements();
if (sqlSession != null && sqlSessionFactory != null) { if (sqlSession != null && sqlSessionFactory != null) {

View File

@ -40,7 +40,7 @@
AND t.user_id = #{request.executor} AND t.user_id = #{request.executor}
</if> </if>
AND (t.integrated_report_id IS NULL OR t.integrated_report_id = 'null') AND (t.integrated_report_id IS NULL OR t.integrated_report_id = 'null')
ORDER BY t.create_time DESC ORDER BY t.create_time,t.end_time DESC
</select> </select>
<select id="getScenarioTasks" resultType="io.metersphere.task.dto.TaskCenterDTO" parameterType="java.lang.String"> <select id="getScenarioTasks" resultType="io.metersphere.task.dto.TaskCenterDTO" parameterType="java.lang.String">
@ -70,7 +70,7 @@
<if test="request.executor != null and request.executor != ''"> <if test="request.executor != null and request.executor != ''">
AND t.user_id = #{request.executor} AND t.user_id = #{request.executor}
</if> </if>
ORDER BY t.create_time DESC ORDER BY t.create_time,t.end_time DESC
</select> </select>
<select id="getPerfTasks" resultType="io.metersphere.task.dto.TaskCenterDTO" parameterType="java.lang.String"> <select id="getPerfTasks" resultType="io.metersphere.task.dto.TaskCenterDTO" parameterType="java.lang.String">

View File

@ -5,11 +5,13 @@ import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import io.metersphere.base.domain.*; import io.metersphere.base.domain.*;
import io.metersphere.commons.constants.*; import io.metersphere.commons.constants.*;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.PageUtils; import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager; import io.metersphere.commons.utils.Pager;
import io.metersphere.dto.ScheduleDTO; import io.metersphere.dto.ScheduleDTO;
import io.metersphere.dto.TestPlanDTOWithMetric; import io.metersphere.dto.TestPlanDTOWithMetric;
import io.metersphere.dto.TestPlanRerunParametersDTO; import io.metersphere.dto.TestPlanRerunParametersDTO;
import io.metersphere.i18n.Translator;
import io.metersphere.log.annotation.MsAuditLog; import io.metersphere.log.annotation.MsAuditLog;
import io.metersphere.notice.annotation.SendNotice; import io.metersphere.notice.annotation.SendNotice;
import io.metersphere.plan.dto.TestCaseReportStatusResultDTO; import io.metersphere.plan.dto.TestCaseReportStatusResultDTO;
@ -26,15 +28,15 @@ import io.metersphere.plan.request.function.TestCaseRelevanceRequest;
import io.metersphere.plan.service.TestPlanProjectService; import io.metersphere.plan.service.TestPlanProjectService;
import io.metersphere.plan.service.TestPlanRerunService; import io.metersphere.plan.service.TestPlanRerunService;
import io.metersphere.plan.service.TestPlanService; import io.metersphere.plan.service.TestPlanService;
import io.metersphere.plan.service.remote.api.PlanApiAutomationService;
import io.metersphere.request.ScheduleRequest; import io.metersphere.request.ScheduleRequest;
import io.metersphere.service.BaseScheduleService; import io.metersphere.service.BaseScheduleService;
import io.metersphere.service.BaseUserService;
import io.metersphere.service.wapper.CheckPermissionService; import io.metersphere.service.wapper.CheckPermissionService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -53,7 +55,7 @@ public class TestPlanController {
@Resource @Resource
private BaseScheduleService baseScheduleService; private BaseScheduleService baseScheduleService;
@Resource @Resource
private PlanApiAutomationService planApiAutomationService; private BaseUserService baseUserService;
@Resource @Resource
private TestPlanRerunService testPlanRerunService; private TestPlanRerunService testPlanRerunService;
@ -240,6 +242,9 @@ public class TestPlanController {
@PostMapping("/run") @PostMapping("/run")
public String run(@RequestBody TestPlanRunRequest testplanRunRequest) { public String run(@RequestBody TestPlanRunRequest testplanRunRequest) {
if (baseUserService.getUserDTO(testplanRunRequest.getUserId()) == null) {
MSException.throwException(Translator.get("user_not_exist"));
}
return testPlanService.runPlan(testplanRunRequest); return testPlanService.runPlan(testplanRunRequest);
} }

View File

@ -15,6 +15,8 @@ public class TestPlanReportRunInfoDTO {
private String envGroupId; private String envGroupId;
private String runMode; private String runMode;
private Map<String, String> requestEnvMap;
// <测试计划场景关联表ID, <项目ID环境ID>> // <测试计划场景关联表ID, <项目ID环境ID>>
private Map<String, Map<String, List<String>>> scenarioRunInfo; private Map<String, Map<String, List<String>>> scenarioRunInfo;
// <测试计划场景关联表ID, <项目ID环境ID>> // <测试计划场景关联表ID, <项目ID环境ID>>

View File

@ -10,7 +10,9 @@ import io.metersphere.commons.utils.*;
import io.metersphere.constants.RunModeConstants; import io.metersphere.constants.RunModeConstants;
import io.metersphere.dto.*; import io.metersphere.dto.*;
import io.metersphere.environment.service.BaseEnvGroupProjectService; import io.metersphere.environment.service.BaseEnvGroupProjectService;
import io.metersphere.environment.service.BaseEnvironmentService;
import io.metersphere.excel.constants.TestPlanTestCaseStatus; import io.metersphere.excel.constants.TestPlanTestCaseStatus;
import io.metersphere.i18n.Translator;
import io.metersphere.log.vo.OperatingLogDetails; import io.metersphere.log.vo.OperatingLogDetails;
import io.metersphere.plan.constant.ApiReportStatus; import io.metersphere.plan.constant.ApiReportStatus;
import io.metersphere.plan.dto.*; import io.metersphere.plan.dto.*;
@ -24,6 +26,7 @@ import io.metersphere.plan.service.remote.ui.PlanTestPlanUiScenarioCaseService;
import io.metersphere.plan.utils.TestPlanRequestUtil; import io.metersphere.plan.utils.TestPlanRequestUtil;
import io.metersphere.plan.utils.TestPlanStatusCalculator; import io.metersphere.plan.utils.TestPlanStatusCalculator;
import io.metersphere.request.report.QueryTestPlanReportRequest; import io.metersphere.request.report.QueryTestPlanReportRequest;
import io.metersphere.service.BaseProjectService;
import io.metersphere.service.BaseUserService; import io.metersphere.service.BaseUserService;
import io.metersphere.service.ServiceUtils; import io.metersphere.service.ServiceUtils;
import io.metersphere.utils.DiscoveryUtil; import io.metersphere.utils.DiscoveryUtil;
@ -105,6 +108,10 @@ public class TestPlanReportService {
private PlanTestPlanScenarioCaseService planTestPlanScenarioCaseService; private PlanTestPlanScenarioCaseService planTestPlanScenarioCaseService;
@Resource @Resource
private BaseUserService baseUserService; private BaseUserService baseUserService;
@Resource
private BaseEnvironmentService apiTestEnvironmentService;
@Resource
private BaseProjectService baseProjectService;
private final String GROUP = "GROUP"; private final String GROUP = "GROUP";
@ -264,6 +271,8 @@ public class TestPlanReportService {
List<TestPlanApiScenarioInfoDTO> scenarios) { List<TestPlanApiScenarioInfoDTO> scenarios) {
TestPlanReportRunInfoDTO runInfoDTO = new TestPlanReportRunInfoDTO(); TestPlanReportRunInfoDTO runInfoDTO = new TestPlanReportRunInfoDTO();
runInfoDTO.setRequestEnvMap(config.getEnvMap());
final Map<String, String> runEnvMap = MapUtils.isNotEmpty(config.getEnvMap()) ? config.getEnvMap() : new HashMap<>(); final Map<String, String> runEnvMap = MapUtils.isNotEmpty(config.getEnvMap()) ? config.getEnvMap() : new HashMap<>();
runInfoDTO.setRunMode(config.getMode()); runInfoDTO.setRunMode(config.getMode());
@ -1129,7 +1138,8 @@ public class TestPlanReportService {
} }
TestPlanSimpleReportDTO testPlanReportDTO = new TestPlanSimpleReportDTO(); TestPlanSimpleReportDTO testPlanReportDTO = new TestPlanSimpleReportDTO();
BeanUtils.copyBean(testPlanReportDTO, testPlanReportContent); BeanUtils.copyBean(testPlanReportDTO, testPlanReportContent);
this.generateEnvironmentInfo(testPlanReportDTO, reportId); TestPlanReport testPlanReport = testPlanReportMapper.selectByPrimaryKey(reportId);
this.initTestPlanReportEnv(testPlanReportDTO, testPlanReport);
testPlanReportDTO.setFunctionResult( testPlanReportDTO.setFunctionResult(
getReportContentResultObject(testPlanReportContent.getFunctionResult(), TestPlanFunctionResultReportDTO.class) getReportContentResultObject(testPlanReportContent.getFunctionResult(), TestPlanFunctionResultReportDTO.class)
@ -1204,7 +1214,6 @@ public class TestPlanReportService {
); );
testPlanReportDTO.setId(reportId); testPlanReportDTO.setId(reportId);
TestPlanReport testPlanReport = testPlanReportMapper.selectByPrimaryKey(testPlanReportContent.getTestPlanReportId());
testPlanReportDTO.setName(testPlanReport.getName()); testPlanReportDTO.setName(testPlanReport.getName());
TestPlanService testPlanService = CommonBeanFactory.getBean(TestPlanService.class); TestPlanService testPlanService = CommonBeanFactory.getBean(TestPlanService.class);
TestPlanExtReportDTO extReport = null; TestPlanExtReportDTO extReport = null;
@ -1253,6 +1262,46 @@ public class TestPlanReportService {
} }
} }
public void initTestPlanReportEnv(TestPlanSimpleReportDTO testPlanReportDTO, TestPlanReport testPlanReport) {
TestPlanReportRunInfoDTO runInfoDTO = null;
if (StringUtils.isNotEmpty(testPlanReport.getRunInfo())) {
try {
runInfoDTO = JSON.parseObject(testPlanReport.getRunInfo(), TestPlanReportRunInfoDTO.class);
} catch (Exception e) {
LogUtil.error("解析测试计划报告记录的运行环境信息[" + testPlanReport.getRunInfo() + "]时出错!", e);
}
}
if (runInfoDTO != null) {
if (StringUtils.isNotEmpty(runInfoDTO.getEnvGroupId())) {
EnvironmentGroup environmentGroup = apiTestEnvironmentService.selectById(runInfoDTO.getEnvGroupId());
if (StringUtils.isNotEmpty(environmentGroup.getName())) {
testPlanReportDTO.setEnvGroupName(environmentGroup.getName());
}
} else {
if (MapUtils.isNotEmpty(runInfoDTO.getRequestEnvMap())) {
Map<String, List<String>> projectEnvMap = new HashMap<>();
for (Map.Entry<String, String> entry : runInfoDTO.getRequestEnvMap().entrySet()) {
String projectId = entry.getKey();
String envId = entry.getValue();
Project project = baseProjectService.getProjectById(projectId);
String projectName = project == null ? null : project.getName();
String envNames = apiTestEnvironmentService.selectNameById(envId);
if (StringUtils.isNotEmpty(projectName) && StringUtils.isNotEmpty(envNames)) {
projectEnvMap.put(projectName, new ArrayList<>() {{
this.add(envNames);
}});
}
}
if (MapUtils.isNotEmpty(projectEnvMap)) {
testPlanReportDTO.setProjectEnvMap(projectEnvMap);
}
}
}
testPlanReportDTO.setRunMode(StringUtils.equalsIgnoreCase(runInfoDTO.getRunMode(), "serial") ? Translator.get("serial") : Translator.get("parallel"));
}
}
private boolean isDynamicallyGenerateReports(TestPlanReportContentWithBLOBs testPlanReportContent) { private boolean isDynamicallyGenerateReports(TestPlanReportContentWithBLOBs testPlanReportContent) {
return testPlanReportContent != null && return testPlanReportContent != null &&
(StringUtils.isNotEmpty(testPlanReportContent.getPlanApiCaseReportStruct()) || StringUtils.isNotEmpty(testPlanReportContent.getPlanScenarioReportStruct()) || StringUtils.isNotEmpty(testPlanReportContent.getPlanLoadCaseReportStruct()) || StringUtils.isNotEmpty(testPlanReportContent.getPlanUiScenarioReportStruct())); (StringUtils.isNotEmpty(testPlanReportContent.getPlanApiCaseReportStruct()) || StringUtils.isNotEmpty(testPlanReportContent.getPlanScenarioReportStruct()) || StringUtils.isNotEmpty(testPlanReportContent.getPlanLoadCaseReportStruct()) || StringUtils.isNotEmpty(testPlanReportContent.getPlanUiScenarioReportStruct()));

View File

@ -1332,6 +1332,7 @@ public class TestPlanService {
config = JSON.parseMap(reportConfig); config = JSON.parseMap(reportConfig);
} }
TestPlanExecuteReportDTO testPlanExecuteReportDTO = testPlanReportService.genTestPlanExecuteReportDTOByTestPlanReportContent(testPlanReportContentWithBLOBs); TestPlanExecuteReportDTO testPlanExecuteReportDTO = testPlanReportService.genTestPlanExecuteReportDTOByTestPlanReportContent(testPlanReportContentWithBLOBs);
TestPlanSimpleReportDTO report = null; TestPlanSimpleReportDTO report = null;
boolean apiBaseInfoChanged = false; boolean apiBaseInfoChanged = false;
if (StringUtils.isEmpty(testPlanReportContentWithBLOBs.getApiBaseCount())) { if (StringUtils.isEmpty(testPlanReportContentWithBLOBs.getApiBaseCount())) {

View File

@ -1,66 +1,138 @@
<template> <template>
<div> <div>
<el-radio-group v-model="radio" style="width: 100%" @change="radioChange" class="radio-change"> <el-radio-group
<el-radio :label="ENV_TYPE.JSON">{{ $t('workspace.env_group.env_list') }}</el-radio> v-model="radio"
<el-radio :label="ENV_TYPE.GROUP" v-if="showEnvGroup">{{ $t('workspace.env_group.name') }}<i class="el-icon-tickets mode-span" @click="viewGroup"></i></el-radio> style="width: 100%"
@change="radioChange"
class="radio-change"
>
<el-radio :label="ENV_TYPE.JSON">{{
$t("workspace.env_group.env_list")
}}</el-radio>
<el-radio :label="ENV_TYPE.GROUP" v-if="showEnvGroup"
>{{ $t("workspace.env_group.name")
}}<i class="el-icon-tickets mode-span" @click="viewGroup"></i
></el-radio>
</el-radio-group> </el-radio-group>
<div v-for="(pe, pIndex) in eventData" :key="pe.id" v-show="radio === ENV_TYPE.JSON"> <div
<el-card shadow="never" style="margin-top: 8px;background: #F5F6F7;border-radius: 4px;"> v-for="(pe, pIndex) in eventData"
<i @click="expandCard(pIndex)" v-if="pe.expendStatus==='close'" class="el-icon-caret-right" style="color: var(--primary_color)"/> :key="pe.id"
<i @click="expandCard(pIndex)" v-else class="el-icon-caret-bottom" style="color: var(--primary_color)"/> v-show="radio === ENV_TYPE.JSON"
>
<el-card
shadow="never"
style="margin-top: 8px; background: #f5f6f7; border-radius: 4px"
>
<i
@click="expandCard(pIndex)"
v-if="pe.expendStatus === 'close'"
class="el-icon-caret-right"
style="color: var(--primary_color)"
/>
<i
@click="expandCard(pIndex)"
v-else
class="el-icon-caret-bottom"
style="color: var(--primary_color)"
/>
<span class="project-name" :title="getProjectName(pe.id)"> <span class="project-name" :title="getProjectName(pe.id)">
{{ getProjectName(pe.id) }} {{ getProjectName(pe.id) }} </span
</span><br/> ><br />
<div v-if="pe.expendStatus==='open'"> <div v-if="pe.expendStatus === 'open'">
<el-radio-group v-model="pe.envRadio" style="width: 100%;" @change="envRadioChange(pe.envRadio,pIndex)" class="radio-change"> <el-radio-group
<el-radio label="DEFAULT_ENV" style="margin-top: 7px">{{$t('api_test.environment.default_environment') }}</el-radio> v-model="pe.envRadio"
<el-radio label="CUSTOMIZE_ENV" style="margin-top: 7px">{{$t('api_test.environment.choose_new_environment')}}</el-radio> style="width: 100%"
@change="envRadioChange(pe.envRadio, pIndex)"
class="radio-change"
>
<el-radio label="DEFAULT_ENV" style="margin-top: 7px">{{
$t("api_test.environment.default_environment")
}}</el-radio>
<el-radio label="CUSTOMIZE_ENV" style="margin-top: 7px">{{
$t("api_test.environment.choose_new_environment")
}}</el-radio>
</el-radio-group> </el-radio-group>
<el-tag v-show="!pe.showEnvSelect" v-for="(itemName,index) in selectedEnvName.get(pe.id)" :key="index" size="mini" <el-tag
style="margin-left: 0; margin-right: 2px;margin-top: 8px">{{ itemName }}</el-tag> v-show="!pe.showEnvSelect"
<el-select v-show="pe.showEnvSelect" v-model="pe['selectEnv']" filterable v-for="(itemName, index) in selectedEnvName.get(pe.id)"
:placeholder="$t('api_test.environment.select_environment')" :key="index"
style="margin-top: 8px;width: 100%;" size="small" @change="chooseEnv"> size="mini"
<el-option v-for="(environment, index) in pe.envs" :key="index" style="margin-left: 0; margin-right: 2px; margin-top: 8px"
:label="environment.name" >{{ itemName }}</el-tag
:value="environment.id"/> >
<el-select
v-show="pe.showEnvSelect"
v-model="pe['selectEnv']"
filterable
:placeholder="$t('api_test.environment.select_environment')"
style="margin-top: 8px; width: 100%"
size="small"
@change="chooseEnv"
>
<el-option
v-for="(environment, index) in pe.envs"
:key="index"
:label="environment.name"
:value="environment.id"
/>
</el-select> </el-select>
</div> </div>
</el-card> </el-card>
</div> </div>
<div v-show="radio === ENV_TYPE.GROUP"> <div v-show="radio === ENV_TYPE.GROUP">
<div> <div>
<el-select v-show="!hasOptionGroup" v-model="envGroupId" :placeholder="$t('workspace.env_group.select')" @change="chooseEnvGroup" <el-select
style="margin-top: 8px;width: 100%;" size="small"> v-show="!hasOptionGroup"
<el-option v-for="(group, index) in groups" :key="index" v-model="envGroupId"
:label="group.name" :placeholder="$t('workspace.env_group.select')"
:value="group.id"/> @change="chooseEnvGroup"
style="margin-top: 8px; width: 100%"
size="small"
>
<el-option
v-for="(group, index) in groups"
:key="index"
:label="group.name"
:value="group.id"
/>
</el-select> </el-select>
<el-select v-show="hasOptionGroup" v-model="envGroupId" :placeholder="$t('workspace.env_group.select')" <el-select
style="margin-top: 8px;width: 100%;" @change="chooseEnvGroup" size="small" clearable> v-show="hasOptionGroup"
v-model="envGroupId"
:placeholder="$t('workspace.env_group.select')"
style="margin-top: 8px; width: 100%"
@change="chooseEnvGroup"
size="small"
clearable
>
<el-option-group <el-option-group
v-for="group in groups" v-for="group in groups"
:key="group.label" :key="group.label"
:label="group.label"> :label="group.label"
>
<el-option <el-option
v-for="item in group.options" v-for="item in group.options"
:key="item.name" :key="item.name"
:label="item.name" :label="item.name"
:disabled="item.disabled" :disabled="item.disabled"
:value="item.id"> :value="item.id"
>
</el-option> </el-option>
</el-option-group> </el-option-group>
</el-select> </el-select>
</div> </div>
<el-dialog :visible="visible" append-to-body :title="$t('workspace.env_group.name')" @close="visible = false" <el-dialog
style="height: 800px;"> :visible="visible"
append-to-body
:title="$t('workspace.env_group.name')"
@close="visible = false"
style="height: 800px"
>
<template> <template>
<environment-group style="overflow-y: auto;" <environment-group
:screen-height="'350px'" style="overflow-y: auto"
:read-only="true" :screen-height="'350px'"
:read-only="true"
></environment-group> ></environment-group>
</template> </template>
</el-dialog> </el-dialog>
@ -68,33 +140,34 @@
</div> </div>
</template> </template>
<script> <script>
import { ENV_TYPE } from "metersphere-frontend/src/utils/constants";
import {ENV_TYPE} from "metersphere-frontend/src/utils/constants"; import {
import {environmentGetALL,getEnvironmentOptions} from "metersphere-frontend/src/api/environment"; environmentGetALL,
getEnvironmentOptions,
} from "metersphere-frontend/src/api/environment";
import MsTag from "metersphere-frontend/src/components/MsTag"; import MsTag from "metersphere-frontend/src/components/MsTag";
import EnvironmentGroup from "@/business/plan/env/EnvironmentGroupList"; import EnvironmentGroup from "@/business/plan/env/EnvironmentGroupList";
import {getEnvironmentByProjectId} from "@/api/remote/api/api-environment"; import { getEnvironmentByProjectId } from "@/api/remote/api/api-environment";
import {parseEnvironment} from "metersphere-frontend/src/model/EnvironmentModel"; import { parseEnvironment } from "metersphere-frontend/src/model/EnvironmentModel";
export default { export default {
name: "EnvSelectPopover", name: "EnvSelectPopover",
components: {MsTag,EnvironmentGroup}, components: { MsTag, EnvironmentGroup },
data(){ data() {
return { return {
radio: this.environmentType, radio: this.environmentType,
visible: false, visible: false,
groups:[], groups: [],
disabledGroups: [], disabledGroups: [],
notDisabledGroups: [], notDisabledGroups: [],
selectedEnvName:new Map(), selectedEnvName: new Map(),
showEnvName:false, showEnvName: false,
eventData:[], eventData: [],
evnList:[], evnList: [],
selectEnvMap:new Map(), selectEnvMap: new Map(),
envGroupId: this.groupId, envGroupId: this.groupId,
} };
}, },
watch: { watch: {
groupId(val) { groupId(val) {
@ -102,150 +175,163 @@ export default {
}, },
environmentType(val) { environmentType(val) {
this.radio = val; this.radio = val;
} },
}, },
computed: { computed: {
ENV_TYPE() { ENV_TYPE() {
return ENV_TYPE; return ENV_TYPE;
} },
}, },
props:{ props: {
showEnvGroup: { showEnvGroup: {
type : Boolean, type: Boolean,
default: true default: true,
}, },
projectIds: Set, projectIds: Set,
projectList:Array, projectList: Array,
projectEnvMap:Object, projectEnvMap: Object,
envMap: Map, envMap: Map,
environmentType: String, environmentType: String,
groupId: { groupId: {
type: String, type: String,
default() { default() {
return ""; return "";
} },
}, },
hasOptionGroup: { hasOptionGroup: {
type: Boolean, type: Boolean,
default() { default() {
return false; return false;
} },
}, },
}, },
methods: { methods: {
open(){ open() {
this.envGroupId = this.groupId; this.envGroupId = this.groupId;
this.initDefaultEnv(); this.initDefaultEnv();
this.getgroups(); this.getgroups();
}, },
radioChange(val){ radioChange(val) {
this.$emit("update:environmentType", val); this.$emit("update:environmentType", val);
}, },
getProjectName(id) { getProjectName(id) {
const project = this.projectList.find(p => p.id === id); const project = this.projectList.find((p) => p.id === id);
return project ? project.name : ""; return project ? project.name : "";
}, },
envRadioChange(val,index){ envRadioChange(val, index) {
this.eventData[index].envRadio = val this.eventData[index].envRadio = val;
this.eventData[index].showEnvSelect = this.eventData[index].envRadio === "CUSTOMIZE_ENV"; this.eventData[index].showEnvSelect =
this.eventData[index].envRadio === "CUSTOMIZE_ENV";
}, },
viewGroup() { viewGroup() {
this.visible = true; this.visible = true;
}, },
getgroups(){ getgroups() {
if (!this.hasOptionGroup){ if (!this.hasOptionGroup) {
environmentGetALL().then(res => { environmentGetALL().then((res) => {
let data = res.data; let data = res.data;
this.groups = data ? data : []; this.groups = data ? data : [];
}) });
} else { } else {
getEnvironmentOptions({projectIds: [...this.projectIds]}).then(res => { getEnvironmentOptions({ projectIds: [...this.projectIds] }).then(
let groups = res.data; (res) => {
this.disabledGroups = groups.filter(group => group.disabled === true); let groups = res.data;
this.notDisabledGroups = groups.filter(group => group.disabled === false); this.disabledGroups = groups.filter(
this.$set(this.groups, 0, { (group) => group.disabled === true
label: this.$t('workspace.env_group.available_group'), );
options: this.notDisabledGroups this.notDisabledGroups = groups.filter(
}); (group) => group.disabled === false
this.$set(this.groups, 1, { );
label: this.$t('workspace.env_group.not_available_group'), this.$set(this.groups, 0, {
options: this.disabledGroups label: this.$t("workspace.env_group.available_group"),
}); options: this.notDisabledGroups,
}) });
this.$set(this.groups, 1, {
label: this.$t("workspace.env_group.not_available_group"),
options: this.disabledGroups,
});
}
);
} }
}, },
chooseEnv(val){ chooseEnv(val) {
let filter = this.evnList.filter(e => e.id === val); let filter = this.evnList.filter((e) => e.id === val);
this.selectEnvMap.set(filter[0].projectId,val); this.selectEnvMap.set(filter[0].projectId, val);
this.$emit('setProjectEnvMap', this.selectEnvMap); this.$emit("setProjectEnvMap", this.selectEnvMap);
}, },
chooseEnvGroup(envGroupId){ chooseEnvGroup(envGroupId) {
this.$emit("setEnvGroup", envGroupId); this.$emit("setEnvGroup", envGroupId);
}, },
initDefaultEnv(){ initDefaultEnv() {
this.selectedEnvName = new Map(); this.selectedEnvName = new Map();
this.evnList = []; this.evnList = [];
this.projectIds.forEach(d => { this.projectIds.forEach((d) => {
let item = {id: d, envs: [], selectEnv: "",envRadio:"DEFAULT_ENV",showEnvSelect:false,expendStatus:"open"}; let item = {
id: d,
envs: [],
selectEnv: "",
envRadio: "DEFAULT_ENV",
showEnvSelect: false,
expendStatus: "open",
};
this.eventData.push(item); this.eventData.push(item);
getEnvironmentByProjectId(d) getEnvironmentByProjectId(d).then((res) => {
.then(res => { let envs = res.data;
let envs = res.data; envs.forEach((environment) => {
envs.forEach(environment => { parseEnvironment(environment);
parseEnvironment(environment);
});
//
let temp = this.eventData.find(dt => dt.id === d);
temp.envs = envs;
envs.forEach(t=>{
this.evnList.push(t);
})
if (this.envMap && this.envMap.size > 0) {
let envId = this.envMap.get(id);
//
temp.selectEnv = envs.filter(e => e.id === envId).length === 0 ? null : envId;
}
if (this.projectEnvMap && Object.keys(this.projectEnvMap).length > 0) {
let projectEnvMapElement = this.projectEnvMap[d];
if (projectEnvMapElement.length>0) {
projectEnvMapElement.forEach(envId => {
let filter = envs.filter(e => e.id === envId);
if (!this.selectedEnvName.has(d)) {
let name = [];
name.push(filter[0].name)
this.selectedEnvName.set(d,name);
} else {
this.selectedEnvName.get(d).push(filter[0].name);
}
});
}
}
}); });
}) //
let temp = this.eventData.find((dt) => dt.id === d);
temp.envs = envs;
envs.forEach((t) => {
this.evnList.push(t);
});
if (this.envMap && this.envMap.size > 0) {
let envId = this.envMap.get(id);
//
temp.selectEnv =
envs.filter((e) => e.id === envId).length === 0 ? null : envId;
}
if (
this.projectEnvMap &&
Object.keys(this.projectEnvMap).length > 0
) {
let projectEnvMapElement = this.projectEnvMap[d];
if (projectEnvMapElement.length > 0) {
projectEnvMapElement.forEach((envId) => {
let filter = envs.filter((e) => e.id === envId);
if (!this.selectedEnvName.has(d)) {
let name = [];
name.push(filter[0].name);
this.selectedEnvName.set(d, name);
} else {
this.selectedEnvName.get(d).push(filter[0].name);
}
this.chooseEnv(filter[0].id);
});
}
}
});
});
}, },
expandCard(index){ expandCard(index) {
if (this.eventData[index].expendStatus === "open") { if (this.eventData[index].expendStatus === "open") {
this.eventData[index].expendStatus = "close" this.eventData[index].expendStatus = "close";
}else { } else {
this.eventData[index].expendStatus = "open" this.eventData[index].expendStatus = "open";
} }
} },
} },
};
}
</script> </script>
<style scoped> <style scoped>
.mode-span{ .mode-span {
margin-left: 6px; margin-left: 6px;
} }
</style> </style>
<style lang="scss" scoped> <style lang="scss" scoped>
.radio-change:deep(.el-radio__input.is-checked + .el-radio__label) { .radio-change:deep(.el-radio__input.is-checked + .el-radio__label) {
color: #606266 !important; color: #606266 !important;
} }
</style> </style>