workspace delete

This commit is contained in:
Captain.B 2020-02-11 17:34:03 +08:00
parent 7ca97ac14a
commit 3982976042
3 changed files with 60 additions and 26 deletions

View File

@ -2,10 +2,7 @@ package io.metersphere.controller;
import io.metersphere.base.domain.Workspace; import io.metersphere.base.domain.Workspace;
import io.metersphere.service.WorkspaceService; import io.metersphere.service.WorkspaceService;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
@ -16,9 +13,14 @@ public class WorkspaceController {
@Resource @Resource
private WorkspaceService workspaceService; private WorkspaceService workspaceService;
@PostMapping("add") @PostMapping("save")
public Workspace addWorkspace(@RequestBody Workspace workspace) { public Workspace saveWorkspace(@RequestBody Workspace workspace) {
return workspaceService.add(workspace); return workspaceService.saveWorkspace(workspace);
}
@GetMapping("delete/{workspaceId}")
public void saveWorkspace(@PathVariable String workspaceId) {
workspaceService.deleteWorkspace(workspaceId);
} }
@PostMapping("list") @PostMapping("list")

View File

@ -17,7 +17,7 @@ public class WorkspaceService {
@Resource @Resource
private WorkspaceMapper workspaceMapper; private WorkspaceMapper workspaceMapper;
public Workspace add(Workspace workspace) { public Workspace saveWorkspace(Workspace workspace) {
if (StringUtils.isBlank(workspace.getName())) { if (StringUtils.isBlank(workspace.getName())) {
MSException.throwException("Workspace name cannot be null."); MSException.throwException("Workspace name cannot be null.");
} }
@ -25,15 +25,24 @@ public class WorkspaceService {
if (StringUtils.isBlank(workspace.getOrganizationId())) { if (StringUtils.isBlank(workspace.getOrganizationId())) {
workspace.setOrganizationId("root"); workspace.setOrganizationId("root");
} }
long createTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();
workspace.setCreateTime(createTime); if (StringUtils.isBlank(workspace.getId())) {
workspace.setUpdateTime(createTime); // 首次 update time workspace.setId(UUID.randomUUID().toString()); // 设置ID
workspace.setId(UUID.randomUUID().toString()); // 设置ID workspace.setCreateTime(currentTime);
workspaceMapper.insertSelective(workspace); workspace.setUpdateTime(currentTime); // 首次 update time
workspaceMapper.insertSelective(workspace);
} else {
workspace.setUpdateTime(currentTime);
workspaceMapper.updateByPrimaryKeySelective(workspace);
}
return workspace; return workspace;
} }
public List<Workspace> getWorkspaceList() { public List<Workspace> getWorkspaceList() {
return workspaceMapper.selectByExample(null); return workspaceMapper.selectByExample(null);
} }
public void deleteWorkspace(String workspaceId) {
workspaceMapper.deleteByPrimaryKey(workspaceId);
}
} }

View File

@ -13,10 +13,15 @@
<el-table :data="items" style="width: 100%"> <el-table :data="items" style="width: 100%">
<el-table-column prop="name" label="名称"/> <el-table-column prop="name" label="名称"/>
<el-table-column prop="description" label="描述"/> <el-table-column prop="description" label="描述"/>
<el-table-column width="50"> <el-table-column width="100">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button @click="edit(scope.row)" type="primary" icon="el-icon-edit" size="mini" circle <el-button @click="edit(scope.row)" type="primary" icon="el-icon-edit" size="mini" circle
class="edit"/> class="edit"/>
<el-popconfirm title="这个工作空间确定要删除吗?" @onConfirm="del(scope.row)">
<el-button slot="reference" type="primary" icon="el-icon-delete" size="mini"
circle
class="edit"/>
</el-popconfirm>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
@ -40,25 +45,28 @@
<script> <script>
import MsCreateBox from "./CreateBox"; import MsCreateBox from "./CreateBox";
import {Message} from "element-ui";
export default { export default {
name: "MsWorkspace", name: "MsWorkspace",
components: {MsCreateBox}, components: {MsCreateBox},
mounted() { mounted() {
this.$post('/workspace/list', {}, response => { this.list();
this.items = response.data;
})
}, },
methods: { methods: {
create() { create() {
this.createVisible = true; this.createVisible = true;
this.form = {};
}, },
submit(formName) { submit(formName) {
this.$refs[formName].validate((valid) => { this.$refs[formName].validate((valid) => {
if (valid) { if (valid) {
this.createVisible = false; this.loading = true;
this.$post("/workspace/add", this.form, () => { this.$post("/workspace/save", this.form, () => {
this.$message({message: '保存成功', type: 'success'}); this.createVisible = false;
this.loading = false;
this.list();
Message.success('保存成功');
}) })
} else { } else {
return false; return false;
@ -66,15 +74,30 @@
}); });
}, },
edit(row) { edit(row) {
this.createVisible = true;
window.console.log(row); window.console.log(row);
this.loading = true; this.loading = true;
let self = this; this.form = row;
let getUser1 = this.$get("/test/user");
let getUser2 = this.$get("/test/sleep"); // let self = this;
this.$all([getUser1, getUser2], function (r1, r2) { // let getUser1 = this.$get("/test/user");
window.console.log(r1.data.data, r2.data.data); // let getUser2 = this.$get("/test/sleep");
self.loading = false; // this.$all([getUser1, getUser2], function (r1, r2) {
// window.console.log(r1.data.data, r2.data.data);
// self.loading = false;
// });
},
del(row) {
this.$get('/workspace/delete/' + row.id, () => {
Message.success('删除成功');
this.list();
}); });
window.console.log(row);
},
list() {
this.$post('/workspace/list', {}, response => {
this.items = response.data;
})
} }
}, },
data() { data() {