fix(测试计划): 测试计划批量开启定时任务提示优化

This commit is contained in:
limin-fit2 2022-02-14 17:04:45 +08:00 committed by 刘瑞斌
parent 9fb6d3544a
commit 0cf3f100d3
8 changed files with 102 additions and 36 deletions

View File

@ -1,5 +1,6 @@
package io.metersphere.api.dto.datacount.request;
import io.metersphere.track.request.testcase.QueryTestPlanRequest;
import lombok.Getter;
import lombok.Setter;
@ -16,4 +17,6 @@ public class ScheduleInfoRequest {
private String taskID;
private boolean enable;
private List<String> taskIds;
private boolean selectAll;
private QueryTestPlanRequest queryTestPlanRequest;
}

View File

@ -282,4 +282,9 @@ public class TestPlanController {
public void updateBatchScheduleEnable(@RequestBody ScheduleInfoRequest request) {
testPlanService.batchUpdateScheduleEnable(request);
}
@PostMapping(value = "/schedule/enable/total")
public long countByScheduleEnableTotal(@RequestBody QueryTestPlanRequest request) {
return testPlanService.countScheduleEnableTotal(request);
}
}

View File

@ -2002,13 +2002,33 @@ public class TestPlanService {
}
public void batchUpdateScheduleEnable(ScheduleInfoRequest request) {
for (String id : request.getTaskIds()) {
List<String> scheduleIds = request.getTaskIds();
if (request.isSelectAll()) {
QueryTestPlanRequest queryTestPlanRequest = request.getQueryTestPlanRequest();
request.getQueryTestPlanRequest().setOrders(ServiceUtils.getDefaultOrder(queryTestPlanRequest.getOrders()));
if (StringUtils.isNotBlank(queryTestPlanRequest.getProjectId())) {
request.getQueryTestPlanRequest().setProjectId(queryTestPlanRequest.getProjectId());
}
List<TestPlanDTOWithMetric> testPlans = extTestPlanMapper.list(queryTestPlanRequest);
scheduleIds = testPlans.stream().filter(testPlan -> testPlan.getScheduleId() != null).map(testPlan -> testPlan.getScheduleId()).collect(Collectors.toList());
}
for (String id : scheduleIds) {
Schedule schedule = scheduleService.getSchedule(id);
schedule.setEnable(request.isEnable());
apiAutomationService.updateSchedule(schedule);
}
}
public long countScheduleEnableTotal(QueryTestPlanRequest request) {
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
if (StringUtils.isNotBlank(request.getProjectId())) {
request.setProjectId(request.getProjectId());
}
List<TestPlanDTOWithMetric> testPlans = extTestPlanMapper.list(request);
return testPlans.stream().filter(testPlan -> testPlan.getScheduleId() != null).count();
}
//获取下次执行时间getFireTimeAfter也可以下下次...
private static long getNextTriggerTime(String cron) {
if (!CronExpression.isValidExpression(cron)) {

View File

@ -2,17 +2,32 @@
<el-dialog :visible.sync="dialogFormVisible"
:before-close="close"
width="14%">
:close-on-click-modal="false"
:destroy-on-close="true"
append-to-body
width="30%">
<div>
<div style="margin-bottom: 8px;">
<i class="el-icon-warning" style="color: #e6a23c;"/>
<span v-if="size > 0 " style="margin-left: 4px; font-size: 14px">
{{ $t('test_track.plan.check_schedule_enabled', [size]) }}
</span>
<span v-else style="margin-left: 4px; font-size: 14px">
{{ $t('test_track.plan.no_check_schedule_enabled') }}
</span>
</div>
<div v-if=" size > 0 ">
<el-switch
v-model="schedule.enable"
:inactive-text="$t('test_track.plan.batch_update_schedule_enable', [size])"
active-color="#783887">
</el-switch>
<p style="font-size: 10px;color: gray;margin-bottom: -10px">
{{ $t('test_track.plan.batch_update_schedule_enable_alert') }}</p>
{{ $t('test_track.plan.batch_update_schedule_enable_alert') }}
</p>
</div>
<template v-slot:footer>
</div>
<template v-slot:footer v-if="size > 0">
<ms-dialog-footer
@cancel="close"
@confirm="saveTest"/>
@ -35,13 +50,14 @@ export default {
name: "MsTestPlanScheduleBatchSwitch",
schedule: {
enable: true,
taskIds: []
taskIds: [],
selectAll: false,
queryTestPlanRequest: {}
},
size: 0,
selectRows: new Set(),
allDataRows: new Set(),
dialogFormVisible: false,
test: {}
dialogFormVisible: false
}
},
props: {
@ -53,12 +69,12 @@ export default {
}
},
methods: {
open(ids, size) {
if (size) {
this.size = size;
} else {
this.size = this.$parent.selectDataCounts;
open(ids, size, selectAll, condition) {
if (selectAll) {
this.schedule.selectAll = true;
this.schedule.queryTestPlanRequest = condition;
}
this.size = size;
this.schedule.taskIds = ids;
listenGoBack(this.close);
this.dialogFormVisible = true;
@ -66,13 +82,19 @@ export default {
saveTest() {
this.$post("/test/plan/schedule/Batch/updateEnable", this.schedule, () => {
this.$success(this.$t('commons.modify_success'));
this.dialogFormVisible = false;
this.$emit("refreshTable");
this.close();
});
},
close() {
removeGoBackListener(this.close);
this.schedule = {
enable: true,
taskIds: [],
selectAll: false,
queryTestPlanRequest: {}
};
this.dialogFormVisible = false;
removeGoBackListener(this.close);
this.$emit("refresh");
}
}
}

View File

@ -8,7 +8,7 @@
</template>
<ms-table
v-loading="result.loading"
v-loading="cardResult.loading"
operator-width="170px"
row-key="id"
:data="tableData"
@ -23,7 +23,8 @@
:field-key="tableHeaderKey"
@handlePageChange="intoPlan"
@refresh="initTableData"
ref="testPlanLitTable">
ref="testPlanLitTable"
@handleRowClick="intoPlan">
<span v-for="item in fields" :key="item.key">
@ -106,6 +107,7 @@
}}</span>
</div>
<el-switch
@click.stop.native
v-model="scope.row.scheduleOpen"
inactive-color="#DCDFE6"
@change="scheduleChange(scope.row)">
@ -114,6 +116,7 @@
</span>
<span v-else-if="scope.row.scheduleStatus === 'SHUT'">
<el-switch
@click.stop.native
v-model="scope.row.scheduleOpen"
inactive-color="#DCDFE6"
@change="scheduleChange(scope.row)">
@ -305,7 +308,7 @@
{{ $t('test_track.plan.plan_delete_tip') }}
</ms-delete-confirm>
<ms-test-plan-schedule-maintain ref="scheduleMaintain" @refreshTable="initTableData"/>
<ms-test-plan-schedule-batch-switch ref="scheduleBatchSwitch" @refreshTable="initTableData"/>
<ms-test-plan-schedule-batch-switch ref="scheduleBatchSwitch" @refresh="refresh"/>
<plan-run-mode-with-env @handleRunBatch="_handleRun" ref="runMode" :plan-case-ids="[]" :type="'plan'"
:plan-id="currentPlanId"/>
<test-plan-report-review ref="testCaseReportView"/>
@ -556,17 +559,28 @@ export default {
handleEdit(testPlan) {
this.$emit('testPlanEdit', testPlan);
},
refresh() {
this.$refs.testPlanLitTable.clear();
this.$refs.testPlanLitTable.isSelectDataAll(false);
this.initTableData();
},
handleBatchSwitch() {
let param = [];
let size = 0;
let row = this.$refs.testPlanLitTable.selectRows.size;
if (this.condition.selectAll) {
this.$post("/test/plan/schedule/enable/total", this.condition, response => {
size = response.data;
this.$refs.scheduleBatchSwitch.open(param, size, this.condition.selectAll, this.condition);
});
} else {
this.$refs.testPlanLitTable.selectRows.forEach((item) => {
if (item.scheduleStatus !== null && item.scheduleStatus !== 'NOTSET') {
param.push(item.scheduleId);
size++;
}
});
this.$refs.scheduleBatchSwitch.open(param, size);
this.$refs.scheduleBatchSwitch.open(param, size, this.condition.selectAll, this.condition);
}
},
statusChange(data) {
if (!hasPermission('PROJECT_TRACK_PLAN:READ+EDIT')) {
@ -627,10 +641,6 @@ export default {
this.$success(this.$t('commons.delete_success'));
});
},
refresh() {
this.$refs.table.clear();
this.$emit('refresh');
},
intoPlan(row, column, event) {
if (column.label !== this.$t('commons.operating')) {
this.$router.push('/track/plan/view/' + row.id);

View File

@ -2120,6 +2120,8 @@ export default {
batch_update_schedule_enable_alert: 'note: only test plans with scheduled tasks can be updated',
next_run_time: 'next running time',
schedule_enabled: 'enabled',
check_schedule_enabled: 'the data you checked has detected {0} scheduled tasks that can be modified',
no_check_schedule_enabled: 'the data you checked does not detect a scheduled task',
load_case: {
case: "Load Case",
execution_status: "Execution status",

View File

@ -2120,6 +2120,8 @@ export default {
batch_update_schedule_enable_alert: '注意:只能更新已设置了定时任务的测试计划',
next_run_time: '下次运行时间',
schedule_enabled: '已开启',
check_schedule_enabled: '您勾选的数据检测到有{0}条定时任务可以修改',
no_check_schedule_enabled: '您勾选的数据没有检测到定时任务',
load_case: {
case: "性能用例",
execution_status: "执行状态",

View File

@ -2119,6 +2119,8 @@ export default {
batch_update_schedule_enable_alert: '注意:只能更新已設定了定時任務的測試計畫',
next_run_time: '下次運行時間',
schedule_enabled: '已開啟',
check_schedule_enabled: '您勾選的數據檢測到有{0}條定時任務可以修改',
no_check_schedule_enabled: '您勾選的數據沒有檢測到定時任務',
load_case: {
case: "性能用例",
execution_status: "執行狀態",