calvin
1 year ago
committed by
GitHub
31 changed files with 1302 additions and 19 deletions
@ -0,0 +1,82 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.api.controller; |
||||||
|
|
||||||
|
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_PROJECT_PREFERENCE_ERROR; |
||||||
|
import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_PROJECT_PREFERENCE_ERROR; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; |
||||||
|
import org.apache.dolphinscheduler.api.exceptions.ApiException; |
||||||
|
import org.apache.dolphinscheduler.api.service.ProjectPreferenceService; |
||||||
|
import org.apache.dolphinscheduler.api.utils.Result; |
||||||
|
import org.apache.dolphinscheduler.common.constants.Constants; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.User; |
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.http.HttpStatus; |
||||||
|
import org.springframework.web.bind.annotation.GetMapping; |
||||||
|
import org.springframework.web.bind.annotation.PathVariable; |
||||||
|
import org.springframework.web.bind.annotation.PutMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestAttribute; |
||||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestParam; |
||||||
|
import org.springframework.web.bind.annotation.ResponseStatus; |
||||||
|
import org.springframework.web.bind.annotation.RestController; |
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.Operation; |
||||||
|
import io.swagger.v3.oas.annotations.Parameter; |
||||||
|
import io.swagger.v3.oas.annotations.Parameters; |
||||||
|
import io.swagger.v3.oas.annotations.media.Schema; |
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag; |
||||||
|
|
||||||
|
@Tag(name = "PROJECT_PREFERENCE_TAG") |
||||||
|
@RestController |
||||||
|
@RequestMapping("projects/{projectCode}/project-preference") |
||||||
|
@Slf4j |
||||||
|
public class ProjectPreferenceController extends BaseController { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private ProjectPreferenceService projectPreferenceService; |
||||||
|
|
||||||
|
@Operation(summary = "updateProjectPreference", description = "UPDATE_PROJECT_PREFERENCE_NOTES") |
||||||
|
@Parameters({ |
||||||
|
@Parameter(name = "projectPreferences", description = "PROJECT_PREFERENCES", schema = @Schema(implementation = String.class)), |
||||||
|
}) |
||||||
|
@PutMapping |
||||||
|
@ResponseStatus(HttpStatus.CREATED) |
||||||
|
@ApiException(UPDATE_PROJECT_PREFERENCE_ERROR) |
||||||
|
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||||
|
public Result updateProjectPreference(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode, |
||||||
|
@RequestParam(value = "projectPreferences", required = true) String projectPreferences) { |
||||||
|
return projectPreferenceService.updateProjectPreference(loginUser, projectCode, projectPreferences); |
||||||
|
} |
||||||
|
|
||||||
|
@Operation(summary = "queryProjectPreferenceByProjectCode", description = "QUERY_PROJECT_PREFERENCE_NOTES") |
||||||
|
@GetMapping() |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
@ApiException(QUERY_PROJECT_PREFERENCE_ERROR) |
||||||
|
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||||
|
public Result queryProjectPreferenceByProjectCode(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode) { |
||||||
|
return projectPreferenceService.queryProjectPreferenceByProjectCode(loginUser, projectCode); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,28 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.api.service; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.api.utils.Result; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.User; |
||||||
|
|
||||||
|
public interface ProjectPreferenceService { |
||||||
|
|
||||||
|
Result updateProjectPreference(User loginUser, long projectCode, String preferences); |
||||||
|
|
||||||
|
Result queryProjectPreferenceByProjectCode(User loginUser, long projectCode); |
||||||
|
} |
@ -0,0 +1,126 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.api.service.impl; |
||||||
|
|
||||||
|
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.PROJECT; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.api.enums.Status; |
||||||
|
import org.apache.dolphinscheduler.api.service.ProjectPreferenceService; |
||||||
|
import org.apache.dolphinscheduler.api.service.ProjectService; |
||||||
|
import org.apache.dolphinscheduler.api.utils.Result; |
||||||
|
import org.apache.dolphinscheduler.common.utils.CodeGenerateUtils; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.Project; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.ProjectPreference; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.User; |
||||||
|
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; |
||||||
|
import org.apache.dolphinscheduler.dao.mapper.ProjectPreferenceMapper; |
||||||
|
|
||||||
|
import java.util.Date; |
||||||
|
import java.util.Objects; |
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||||
|
|
||||||
|
@Service |
||||||
|
@Slf4j |
||||||
|
public class ProjectPreferenceServiceImpl extends BaseServiceImpl |
||||||
|
implements |
||||||
|
ProjectPreferenceService { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private ProjectPreferenceMapper projectPreferenceMapper; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private ProjectService projectService; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private ProjectMapper projectMapper; |
||||||
|
|
||||||
|
@Override |
||||||
|
public Result updateProjectPreference(User loginUser, long projectCode, String preferences) { |
||||||
|
Result result = new Result(); |
||||||
|
|
||||||
|
// check if the user has the writing permission for project
|
||||||
|
Project project = projectMapper.queryByCode(projectCode); |
||||||
|
boolean hasProjectAndWritePerm = projectService.hasProjectAndWritePerm(loginUser, project, result); |
||||||
|
if (!hasProjectAndWritePerm) { |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
ProjectPreference projectPreference = projectPreferenceMapper |
||||||
|
.selectOne(new QueryWrapper<ProjectPreference>().lambda().eq(ProjectPreference::getProjectCode, |
||||||
|
projectCode)); |
||||||
|
|
||||||
|
Date now = new Date(); |
||||||
|
if (Objects.isNull(projectPreference)) { |
||||||
|
projectPreference = new ProjectPreference(); |
||||||
|
projectPreference.setProjectCode(projectCode); |
||||||
|
projectPreference.setPreferences(preferences); |
||||||
|
projectPreference.setUserId(loginUser.getId()); |
||||||
|
projectPreference.setCode(CodeGenerateUtils.getInstance().genCode()); |
||||||
|
projectPreference.setCreateTime(now); |
||||||
|
projectPreference.setUpdateTime(now); |
||||||
|
if (projectPreferenceMapper.insert(projectPreference) > 0) { |
||||||
|
log.info("Project preference is created and id is :{}", projectPreference.getId()); |
||||||
|
result.setData(projectPreference); |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
} else { |
||||||
|
log.error("Project preference create error, projectCode:{}.", projectPreference.getProjectCode()); |
||||||
|
putMsg(result, Status.CREATE_PROJECT_PREFERENCE_ERROR); |
||||||
|
} |
||||||
|
} else { |
||||||
|
projectPreference.setPreferences(preferences); |
||||||
|
projectPreference.setUserId(loginUser.getId()); |
||||||
|
projectPreference.setUpdateTime(now); |
||||||
|
|
||||||
|
if (projectPreferenceMapper.updateById(projectPreference) > 0) { |
||||||
|
log.info("Project preference is updated and id is :{}", projectPreference.getId()); |
||||||
|
result.setData(projectPreference); |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
} else { |
||||||
|
log.error("Project preference update error, projectCode:{}.", projectPreference.getProjectCode()); |
||||||
|
putMsg(result, Status.UPDATE_PROJECT_PREFERENCE_ERROR); |
||||||
|
} |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Result queryProjectPreferenceByProjectCode(User loginUser, long projectCode) { |
||||||
|
Result result = new Result(); |
||||||
|
|
||||||
|
Project project = projectMapper.queryByCode(projectCode); |
||||||
|
boolean hasProjectAndPerm = projectService.hasProjectAndPerm(loginUser, project, result, PROJECT); |
||||||
|
if (!hasProjectAndPerm) { |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
ProjectPreference projectPreference = projectPreferenceMapper |
||||||
|
.selectOne(new QueryWrapper<ProjectPreference>().lambda().eq(ProjectPreference::getProjectCode, |
||||||
|
projectCode)); |
||||||
|
|
||||||
|
result.setData(projectPreference); |
||||||
|
|
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
return result; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,82 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.api.controller; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.api.enums.Status; |
||||||
|
import org.apache.dolphinscheduler.api.service.impl.ProjectPreferenceServiceImpl; |
||||||
|
import org.apache.dolphinscheduler.api.utils.Result; |
||||||
|
import org.apache.dolphinscheduler.common.enums.UserType; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.User; |
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions; |
||||||
|
import org.junit.jupiter.api.Test; |
||||||
|
import org.junit.jupiter.api.extension.ExtendWith; |
||||||
|
import org.mockito.InjectMocks; |
||||||
|
import org.mockito.Mock; |
||||||
|
import org.mockito.Mockito; |
||||||
|
import org.mockito.junit.jupiter.MockitoExtension; |
||||||
|
import org.mockito.junit.jupiter.MockitoSettings; |
||||||
|
import org.mockito.quality.Strictness; |
||||||
|
|
||||||
|
@ExtendWith(MockitoExtension.class) |
||||||
|
@MockitoSettings(strictness = Strictness.LENIENT) |
||||||
|
public class ProjectPreferenceControllerTest { |
||||||
|
|
||||||
|
@InjectMocks |
||||||
|
private ProjectPreferenceController projectPreferenceController; |
||||||
|
|
||||||
|
@Mock |
||||||
|
private ProjectPreferenceServiceImpl projectPreferenceService; |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testUpdateProjectPreference() { |
||||||
|
User loginUser = getGeneralUser(); |
||||||
|
|
||||||
|
Mockito.when(projectPreferenceService.updateProjectPreference(Mockito.any(), Mockito.anyLong(), |
||||||
|
Mockito.anyString())).thenReturn(getSuccessResult()); |
||||||
|
|
||||||
|
Result result = projectPreferenceController.updateProjectPreference(loginUser, 1, "value"); |
||||||
|
Assertions.assertEquals(Status.SUCCESS.getCode(), result.getCode()); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testQueryProjectPreferenceByProjectCode() { |
||||||
|
User loginUser = getGeneralUser(); |
||||||
|
|
||||||
|
Mockito.when(projectPreferenceService.queryProjectPreferenceByProjectCode(Mockito.any(), Mockito.anyLong())) |
||||||
|
.thenReturn(getSuccessResult()); |
||||||
|
Result result = projectPreferenceController.queryProjectPreferenceByProjectCode(loginUser, 1); |
||||||
|
Assertions.assertEquals(Status.SUCCESS.getCode(), result.getCode()); |
||||||
|
} |
||||||
|
|
||||||
|
private User getGeneralUser() { |
||||||
|
User loginUser = new User(); |
||||||
|
loginUser.setUserType(UserType.GENERAL_USER); |
||||||
|
loginUser.setUserName("userName"); |
||||||
|
loginUser.setId(1); |
||||||
|
return loginUser; |
||||||
|
} |
||||||
|
|
||||||
|
private Result getSuccessResult() { |
||||||
|
Result result = new Result(); |
||||||
|
result.setCode(Status.SUCCESS.getCode()); |
||||||
|
result.setMsg(Status.SUCCESS.getMsg()); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,118 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.api.service; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.api.enums.Status; |
||||||
|
import org.apache.dolphinscheduler.api.service.impl.ProjectPreferenceServiceImpl; |
||||||
|
import org.apache.dolphinscheduler.api.service.impl.ProjectServiceImpl; |
||||||
|
import org.apache.dolphinscheduler.api.utils.Result; |
||||||
|
import org.apache.dolphinscheduler.common.enums.UserType; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.Project; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.ProjectPreference; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.User; |
||||||
|
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; |
||||||
|
import org.apache.dolphinscheduler.dao.mapper.ProjectPreferenceMapper; |
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions; |
||||||
|
import org.junit.jupiter.api.Test; |
||||||
|
import org.junit.jupiter.api.extension.ExtendWith; |
||||||
|
import org.mockito.InjectMocks; |
||||||
|
import org.mockito.Mock; |
||||||
|
import org.mockito.Mockito; |
||||||
|
import org.mockito.junit.jupiter.MockitoExtension; |
||||||
|
import org.mockito.junit.jupiter.MockitoSettings; |
||||||
|
import org.mockito.quality.Strictness; |
||||||
|
|
||||||
|
@ExtendWith(MockitoExtension.class) |
||||||
|
@MockitoSettings(strictness = Strictness.LENIENT) |
||||||
|
public class ProjectPreferenceServiceTest { |
||||||
|
|
||||||
|
@InjectMocks |
||||||
|
private ProjectPreferenceServiceImpl projectPreferenceService; |
||||||
|
|
||||||
|
@Mock |
||||||
|
private ProjectMapper projectMapper; |
||||||
|
|
||||||
|
@Mock |
||||||
|
private ProjectPreferenceMapper projectPreferenceMapper; |
||||||
|
|
||||||
|
@Mock |
||||||
|
private ProjectServiceImpl projectService; |
||||||
|
|
||||||
|
protected final static long projectCode = 1L; |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testUpdateProjectPreference() { |
||||||
|
User loginUser = getGeneralUser(); |
||||||
|
|
||||||
|
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); |
||||||
|
Mockito.when(projectService.hasProjectAndWritePerm(Mockito.any(), Mockito.any(), Mockito.any(Result.class))) |
||||||
|
.thenReturn(true); |
||||||
|
|
||||||
|
Mockito.when(projectPreferenceMapper.selectOne(Mockito.any())).thenReturn(null); |
||||||
|
Mockito.when(projectPreferenceMapper.insert(Mockito.any())).thenReturn(1); |
||||||
|
|
||||||
|
Result result = projectPreferenceService.updateProjectPreference(loginUser, projectCode, "value"); |
||||||
|
Assertions.assertEquals(Status.SUCCESS.getCode(), result.getCode()); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testQueryProjectPreferenceByProjectCode() { |
||||||
|
User loginUser = getGeneralUser(); |
||||||
|
|
||||||
|
// PROJECT_PARAMETER_NOT_EXISTS
|
||||||
|
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); |
||||||
|
Mockito.when(projectService.hasProjectAndPerm(Mockito.any(), Mockito.any(), Mockito.any(Result.class), |
||||||
|
Mockito.any())).thenReturn(true); |
||||||
|
|
||||||
|
Mockito.when(projectPreferenceMapper.selectOne(Mockito.any())).thenReturn(null); |
||||||
|
Result result = projectPreferenceService.queryProjectPreferenceByProjectCode(loginUser, projectCode); |
||||||
|
Assertions.assertEquals(Status.SUCCESS.getCode(), result.getCode()); |
||||||
|
|
||||||
|
// SUCCESS
|
||||||
|
Mockito.when(projectPreferenceMapper.selectOne(Mockito.any())).thenReturn(getProjectPreference()); |
||||||
|
result = projectPreferenceService.queryProjectPreferenceByProjectCode(loginUser, projectCode); |
||||||
|
Assertions.assertEquals(Status.SUCCESS.getCode(), result.getCode()); |
||||||
|
} |
||||||
|
|
||||||
|
private User getGeneralUser() { |
||||||
|
User loginUser = new User(); |
||||||
|
loginUser.setUserType(UserType.GENERAL_USER); |
||||||
|
loginUser.setUserName("userName"); |
||||||
|
loginUser.setId(1); |
||||||
|
return loginUser; |
||||||
|
} |
||||||
|
|
||||||
|
private Project getProject(long projectCode) { |
||||||
|
Project project = new Project(); |
||||||
|
project.setCode(projectCode); |
||||||
|
project.setId(1); |
||||||
|
project.setName("test"); |
||||||
|
project.setUserId(1); |
||||||
|
return project; |
||||||
|
} |
||||||
|
|
||||||
|
private ProjectPreference getProjectPreference() { |
||||||
|
ProjectPreference projectPreference = new ProjectPreference(); |
||||||
|
projectPreference.setId(1); |
||||||
|
projectPreference.setCode(1); |
||||||
|
projectPreference.setProjectCode(projectCode); |
||||||
|
projectPreference.setPreferences("value"); |
||||||
|
return projectPreference; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,56 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.dao.entity; |
||||||
|
|
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.Builder; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.NoArgsConstructor; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableField; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
|
||||||
|
@Data |
||||||
|
@Builder |
||||||
|
@NoArgsConstructor |
||||||
|
@AllArgsConstructor |
||||||
|
@TableName("t_ds_project_preference") |
||||||
|
public class ProjectPreference { |
||||||
|
|
||||||
|
@TableId(value = "id", type = IdType.AUTO) |
||||||
|
private Integer id; |
||||||
|
|
||||||
|
private long code; |
||||||
|
|
||||||
|
@TableField("project_code") |
||||||
|
private long projectCode; |
||||||
|
|
||||||
|
@TableField("preferences") |
||||||
|
private String preferences; |
||||||
|
|
||||||
|
@TableField("user_id") |
||||||
|
private Integer userId; |
||||||
|
|
||||||
|
private Date createTime; |
||||||
|
|
||||||
|
private Date updateTime; |
||||||
|
} |
@ -0,0 +1,26 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.dao.mapper; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.dao.entity.ProjectPreference; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
|
||||||
|
public interface ProjectPreferenceMapper extends BaseMapper<ProjectPreference> { |
||||||
|
|
||||||
|
} |
@ -0,0 +1,68 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.dao.mapper; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.dao.BaseDaoTest; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.ProjectPreference; |
||||||
|
|
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions; |
||||||
|
import org.junit.jupiter.api.Test; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||||
|
|
||||||
|
public class ProjectPreferenceMapperTest extends BaseDaoTest { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private ProjectPreferenceMapper projectPreferenceMapper; |
||||||
|
|
||||||
|
private ProjectPreference insertOne(long code, long projectCode) { |
||||||
|
ProjectPreference projectPreference = new ProjectPreference(); |
||||||
|
projectPreference.setCode(code); |
||||||
|
projectPreference.setProjectCode(projectCode); |
||||||
|
projectPreference.setPreferences("{workerGroup:{availableOptions:[],default:1}}"); |
||||||
|
projectPreference.setCreateTime(new Date()); |
||||||
|
projectPreference.setUpdateTime(new Date()); |
||||||
|
projectPreference.setUserId(1); |
||||||
|
projectPreferenceMapper.insert(projectPreference); |
||||||
|
return projectPreference; |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testUpdate() { |
||||||
|
ProjectPreference projectPreference = insertOne(1, 1); |
||||||
|
projectPreference.setUpdateTime(new Date()); |
||||||
|
|
||||||
|
int update = projectPreferenceMapper.updateById(projectPreference); |
||||||
|
Assertions.assertEquals(1, update); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testQueryByProjectCode() { |
||||||
|
long projectCode = 2; |
||||||
|
ProjectPreference expectedProjectPreference = insertOne(2, projectCode); |
||||||
|
|
||||||
|
ProjectPreference projectPreference = projectPreferenceMapper |
||||||
|
.selectOne(new QueryWrapper<ProjectPreference>().lambda().eq(ProjectPreference::getProjectCode, |
||||||
|
projectCode)); |
||||||
|
Assertions.assertEquals(expectedProjectPreference, projectPreference); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,42 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
import { axios } from '@/service/service' |
||||||
|
|
||||||
|
import { |
||||||
|
UpdateProjectPreferenceReq |
||||||
|
} from './types' |
||||||
|
|
||||||
|
export function queryProjectPreferenceByProjectCode( |
||||||
|
projectCode: number |
||||||
|
): any { |
||||||
|
return axios({ |
||||||
|
url: `/projects/${projectCode}/project-preference`, |
||||||
|
method: 'get' |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
export function updateProjectPreference( |
||||||
|
data: UpdateProjectPreferenceReq, |
||||||
|
projectCode: number |
||||||
|
): any { |
||||||
|
return axios({ |
||||||
|
url: `/projects/${projectCode}/project-preference`, |
||||||
|
method: 'put', |
||||||
|
data |
||||||
|
}) |
||||||
|
} |
@ -0,0 +1,40 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
|
||||||
|
interface ProjectPreferenceReq { |
||||||
|
projectPreferences: string |
||||||
|
} |
||||||
|
|
||||||
|
interface UpdateProjectPreferenceReq extends ProjectPreferenceReq { |
||||||
|
code: number |
||||||
|
} |
||||||
|
|
||||||
|
interface ProjectPreferenceRes { |
||||||
|
id: number |
||||||
|
code: number |
||||||
|
projectCode: number |
||||||
|
preferences: string |
||||||
|
createTime: string |
||||||
|
updateTime: string |
||||||
|
} |
||||||
|
|
||||||
|
export { |
||||||
|
ProjectPreferenceRes, |
||||||
|
ProjectPreferenceReq, |
||||||
|
UpdateProjectPreferenceReq |
||||||
|
} |
@ -0,0 +1,48 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
import { ref, onMounted } from 'vue' |
||||||
|
import { useI18n } from 'vue-i18n' |
||||||
|
import type { IJsonItem } from '../../task/components/node/types' |
||||||
|
import { listAlertGroupById } from '@/service/modules/alert-group' |
||||||
|
|
||||||
|
export function useAlertGroup(): IJsonItem { |
||||||
|
const { t } = useI18n() |
||||||
|
|
||||||
|
const options = ref([] as { label: string; value: string }[]) |
||||||
|
|
||||||
|
const getAlertGroups = async () => { |
||||||
|
const res = await listAlertGroupById() |
||||||
|
options.value = res.map((item: any) => ({ |
||||||
|
label: item.groupName, |
||||||
|
value: item.id |
||||||
|
})) |
||||||
|
} |
||||||
|
|
||||||
|
onMounted(() => { |
||||||
|
getAlertGroups() |
||||||
|
}) |
||||||
|
|
||||||
|
return { |
||||||
|
type: 'select', |
||||||
|
field: 'alertGroups', |
||||||
|
span: 12, |
||||||
|
name: t('project.workflow.alarm_group'), |
||||||
|
options: options, |
||||||
|
value: 'default' |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,48 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
import { ref, onMounted } from 'vue' |
||||||
|
import { useI18n } from 'vue-i18n' |
||||||
|
import type { IJsonItem } from '../../task/components/node/types' |
||||||
|
import { queryTenantList } from '@/service/modules/tenants' |
||||||
|
|
||||||
|
export function useTenant(): IJsonItem { |
||||||
|
const { t } = useI18n() |
||||||
|
|
||||||
|
const options = ref([] as { label: string; value: string }[]) |
||||||
|
|
||||||
|
const getTenantList = async () => { |
||||||
|
const res = await queryTenantList() |
||||||
|
options.value = res.map((item: any) => ({ |
||||||
|
label: item.tenantCode, |
||||||
|
value: item.tenantCode |
||||||
|
})) |
||||||
|
} |
||||||
|
|
||||||
|
onMounted(() => { |
||||||
|
getTenantList() |
||||||
|
}) |
||||||
|
|
||||||
|
return { |
||||||
|
type: 'select', |
||||||
|
field: 'tenant', |
||||||
|
span: 12, |
||||||
|
name: t('project.workflow.tenant_code'), |
||||||
|
options: options, |
||||||
|
value: 'default' |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,46 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
import { useI18n } from 'vue-i18n' |
||||||
|
import type { IJsonItem } from '../../task/components/node/types' |
||||||
|
import { warningTypeList } from '@/common/common' |
||||||
|
|
||||||
|
export function useWarningType(): IJsonItem { |
||||||
|
const { t } = useI18n() |
||||||
|
|
||||||
|
const options = [] as any |
||||||
|
|
||||||
|
const initOptions = () => { |
||||||
|
warningTypeList.forEach((item) => { |
||||||
|
options.push({ label: t(item.code), value: item.id }) |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
initOptions() |
||||||
|
|
||||||
|
return { |
||||||
|
type: 'select', |
||||||
|
field: 'warningType', |
||||||
|
name: t('project.workflow.notification_strategy'), |
||||||
|
span: 12, |
||||||
|
options, |
||||||
|
validate: { |
||||||
|
required: true |
||||||
|
}, |
||||||
|
value: 'NONE' |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,66 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
import { defineComponent } from 'vue' |
||||||
|
import Form from '@/components/form' |
||||||
|
import { useForm } from './use-form' |
||||||
|
import { NButton, NDivider, NSpace } from 'naive-ui' |
||||||
|
|
||||||
|
const PreferenceForm = defineComponent({ |
||||||
|
name: 'PreferenceForm', |
||||||
|
setup() { |
||||||
|
const { |
||||||
|
formRef, |
||||||
|
elementsRef, |
||||||
|
rulesRef, |
||||||
|
model, |
||||||
|
formProps, |
||||||
|
t, |
||||||
|
handleUpdate |
||||||
|
} = useForm() |
||||||
|
|
||||||
|
return () => ( |
||||||
|
<div> |
||||||
|
<div style={{ margin: '30px' }}> |
||||||
|
{t('project.preference.instruction_tips')} |
||||||
|
</div> |
||||||
|
<NDivider /> |
||||||
|
<Form |
||||||
|
ref={formRef} |
||||||
|
meta={{ |
||||||
|
model, |
||||||
|
rules: rulesRef.value, |
||||||
|
elements: elementsRef.value, |
||||||
|
...formProps.value |
||||||
|
}} |
||||||
|
layout={{ |
||||||
|
xGap: 10 |
||||||
|
}} |
||||||
|
style={{ marginLeft: '150px' }} |
||||||
|
/> |
||||||
|
<NDivider /> |
||||||
|
<NSpace justify='end'> |
||||||
|
<NButton type='info' onClick={handleUpdate}> |
||||||
|
{t('project.preference.submit')} |
||||||
|
</NButton> |
||||||
|
</NSpace> |
||||||
|
</div> |
||||||
|
) |
||||||
|
} |
||||||
|
}) |
||||||
|
|
||||||
|
export default PreferenceForm |
@ -0,0 +1,47 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
import { NSpace } from 'naive-ui' |
||||||
|
import { defineComponent, ref } from 'vue' |
||||||
|
import { useI18n } from 'vue-i18n' |
||||||
|
import Card from '@/components/card' |
||||||
|
import PreferenceForm from '@/views/projects/preference/detail' |
||||||
|
|
||||||
|
export default defineComponent({ |
||||||
|
name: 'ProjectPreference', |
||||||
|
setup() { |
||||||
|
const detailRef = ref() |
||||||
|
|
||||||
|
return { |
||||||
|
detailRef |
||||||
|
} |
||||||
|
}, |
||||||
|
render() { |
||||||
|
const { t } = useI18n() |
||||||
|
const { detailRef } = this |
||||||
|
|
||||||
|
return ( |
||||||
|
<NSpace vertical> |
||||||
|
<Card title={t('project.preference.preference_manage')}> |
||||||
|
<NSpace vertical> |
||||||
|
<PreferenceForm ref={detailRef} /> |
||||||
|
</NSpace> |
||||||
|
</Card> |
||||||
|
</NSpace> |
||||||
|
) |
||||||
|
} |
||||||
|
}) |
@ -0,0 +1,136 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
import { onMounted, reactive, ref, Ref } from 'vue' |
||||||
|
import getElementByJson from '@/components/form/get-elements-by-json' |
||||||
|
import type { |
||||||
|
IFormItem, |
||||||
|
IJsonItem, |
||||||
|
INodeData |
||||||
|
} from '../task/components/node/types' |
||||||
|
import * as Fields from '@/views/projects/task/components/node/fields' |
||||||
|
import { Router, useRouter } from 'vue-router' |
||||||
|
import { |
||||||
|
queryProjectPreferenceByProjectCode, |
||||||
|
updateProjectPreference |
||||||
|
} from '@/service/modules/projects-preference' |
||||||
|
import { useI18n } from 'vue-i18n' |
||||||
|
import { UpdateProjectPreferenceReq } from '@/service/modules/projects-preference/types' |
||||||
|
import { useWarningType } from '@/views/projects/preference/components/use-warning-type' |
||||||
|
import { useTenant } from '@/views/projects/preference/components/use-tenant' |
||||||
|
import { useAlertGroup } from '@/views/projects/preference/components/use-alert-group' |
||||||
|
|
||||||
|
export function useForm() { |
||||||
|
const router: Router = useRouter() |
||||||
|
const { t } = useI18n() |
||||||
|
|
||||||
|
const projectCode = Number(router.currentRoute.value.params.projectCode) |
||||||
|
|
||||||
|
const formRef = ref() |
||||||
|
const jsonRef = ref([]) as Ref<IJsonItem[]> |
||||||
|
const elementsRef = ref([]) as Ref<IFormItem[]> |
||||||
|
const rulesRef = ref({}) |
||||||
|
const formProps = ref({}) |
||||||
|
|
||||||
|
formProps.value = { |
||||||
|
labelPlacement: 'left', |
||||||
|
labelWidth: 'auto', |
||||||
|
size: 'large' |
||||||
|
} |
||||||
|
|
||||||
|
const data = reactive({ |
||||||
|
model: { |
||||||
|
taskPriority: 'MEDIUM', |
||||||
|
workerGroup: 'default', |
||||||
|
environmentCode: null, |
||||||
|
failRetryTimes: 0, |
||||||
|
failRetryInterval: 1, |
||||||
|
cpuQuota: -1, |
||||||
|
memoryMax: -1, |
||||||
|
timeoutFlag: false, |
||||||
|
timeoutNotifyStrategy: ['WARN'], |
||||||
|
timeout: 30 |
||||||
|
} as INodeData |
||||||
|
}) |
||||||
|
|
||||||
|
const setValues = (initialValues: { [field: string]: any }) => { |
||||||
|
Object.assign(data.model, initialValues) |
||||||
|
} |
||||||
|
|
||||||
|
const initProjectPreference = async () => { |
||||||
|
if (projectCode) { |
||||||
|
const result = await queryProjectPreferenceByProjectCode(projectCode) |
||||||
|
if (result?.preferences) { |
||||||
|
setValues(JSON.parse(result.preferences)) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
onMounted(() => { |
||||||
|
initProjectPreference() |
||||||
|
}) |
||||||
|
|
||||||
|
const handleUpdate = () => { |
||||||
|
const requestData = { |
||||||
|
projectPreferences: JSON.stringify(data.model) |
||||||
|
} as UpdateProjectPreferenceReq |
||||||
|
updateProjectPreference(requestData, projectCode).then(() => { |
||||||
|
window.$message.success(t('project.preference.success')) |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
const preferencesItems: IJsonItem[] = [ |
||||||
|
Fields.useTaskPriority(), |
||||||
|
useTenant(), |
||||||
|
Fields.useWorkerGroup(), |
||||||
|
Fields.useEnvironmentName(data.model, true), |
||||||
|
...Fields.useFailed(), |
||||||
|
useWarningType(), |
||||||
|
useAlertGroup(), |
||||||
|
...Fields.useResourceLimit() |
||||||
|
] |
||||||
|
|
||||||
|
const restructurePreferencesItems = (preferencesItems: any) => { |
||||||
|
for (let item of preferencesItems) { |
||||||
|
if (item.validate?.required) { |
||||||
|
item.validate.required = false |
||||||
|
item.span = 12 |
||||||
|
} |
||||||
|
Object.assign(item, { props: { style: 'width: 250px' } }) |
||||||
|
} |
||||||
|
return preferencesItems |
||||||
|
} |
||||||
|
|
||||||
|
jsonRef.value = restructurePreferencesItems(preferencesItems) |
||||||
|
|
||||||
|
const getElements = () => { |
||||||
|
const { rules, elements } = getElementByJson(jsonRef.value, data.model) |
||||||
|
elementsRef.value = elements |
||||||
|
rulesRef.value = rules |
||||||
|
} |
||||||
|
|
||||||
|
getElements() |
||||||
|
|
||||||
|
return { |
||||||
|
formRef, |
||||||
|
elementsRef, |
||||||
|
rulesRef, |
||||||
|
model: data.model, |
||||||
|
formProps, |
||||||
|
t, |
||||||
|
handleUpdate |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue