From dd6e94e8c677832f391772c8db8176509257f583 Mon Sep 17 00:00:00 2001 From: calvin Date: Tue, 11 Jul 2023 17:57:04 +0800 Subject: [PATCH 01/11] add a few codes about dao --- .../dao/entity/ProjectPreference.java | 54 +++++++++++++++ .../dao/mapper/ProjectPreferenceMapper.java | 25 +++++++ .../resources/sql/dolphinscheduler_h2.sql | 22 +++++++ .../resources/sql/dolphinscheduler_mysql.sql | 21 ++++++ .../sql/dolphinscheduler_postgresql.sql | 25 +++++++ .../mapper/ProjectPreferenceMapperTest.java | 65 +++++++++++++++++++ 6 files changed, 212 insertions(+) create mode 100644 dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProjectPreference.java create mode 100644 dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProjectPreferenceMapper.java create mode 100644 dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProjectPreferenceMapperTest.java diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProjectPreference.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProjectPreference.java new file mode 100644 index 000000000000..755d90476654 --- /dev/null +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProjectPreference.java @@ -0,0 +1,54 @@ +/* + * 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 com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import java.util.Date; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@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; +} diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProjectPreferenceMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProjectPreferenceMapper.java new file mode 100644 index 000000000000..b2d73dc358a4 --- /dev/null +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProjectPreferenceMapper.java @@ -0,0 +1,25 @@ +/* + * 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 com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.dolphinscheduler.dao.entity.ProjectPreference; + +public interface ProjectPreferenceMapper extends BaseMapper { + +} diff --git a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql index 43feaaf36910..c4468477a79b 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql @@ -681,6 +681,28 @@ CREATE TABLE t_ds_project_parameter -- Records of t_ds_project_parameter -- ---------------------------- +-- ---------------------------- +-- Table structure for t_ds_project_preference +-- ---------------------------- +DROP TABLE IF EXISTS t_ds_project_preference CASCADE; +CREATE TABLE t_ds_project_preference +( + id int(11) NOT NULL AUTO_INCREMENT, + code bigint(20) NOT NULL, + project_code bigint(20) NOT NULL, + preferences varchar(512) NOT NULL, + user_id int(11) DEFAULT NULL, + create_time datetime NOT NULL, + update_time datetime DEFAULT NULL, + PRIMARY KEY (id), + UNIQUE KEY unique_project_preference_project_code (project_code), + UNIQUE KEY unique_project_preference_code (code) +); + +-- ---------------------------- +-- Records of t_ds_project_preference +-- ---------------------------- + -- ---------------------------- -- Table structure for t_ds_queue -- ---------------------------- diff --git a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql index 8dc54779758c..537686eb6fee 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql @@ -684,6 +684,27 @@ CREATE TABLE `t_ds_project_parameter` ( -- Records of t_ds_project_parameter -- ---------------------------- +-- ---------------------------- +-- Table structure for t_ds_project_preference +-- ---------------------------- +DROP TABLE IF EXISTS `t_ds_project_preference`; +CREATE TABLE `t_ds_project_preference` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'key', + `code` bigint(20) NOT NULL COMMENT 'encoding', + `project_code` bigint(20) NOT NULL COMMENT 'project code', + `preferences` varchar(512) NOT NULL COMMENT 'project preferences', + `user_id` int(11) DEFAULT NULL COMMENT 'creator id', + `create_time` datetime NOT NULL COMMENT 'create time', + `update_time` datetime DEFAULT NULL COMMENT 'update time', + PRIMARY KEY (`id`), + UNIQUE KEY `unique_project_preference_project_code`(`project_code`), + UNIQUE KEY `unique_project_preference_code`(`code`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE = utf8_bin; + +-- ---------------------------- +-- Records of t_ds_project_preference +-- ---------------------------- + -- ---------------------------- -- Table structure for t_ds_queue -- ---------------------------- diff --git a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql index f9f6ca5391b6..90829d9e027b 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql @@ -606,6 +606,27 @@ CREATE TABLE t_ds_project_parameter ( CREATE UNIQUE INDEX unique_project_parameter_name on t_ds_project_parameter (project_code, param_name); CREATE UNIQUE INDEX unique_project_parameter_code on t_ds_project_parameter (code); + +-- +-- Table structure for table t_ds_project_preference +-- +DROP TABLE IF EXISTS t_ds_project_preference; +CREATE TABLE t_ds_project_preference +( + id int NOT NULL , + code bigint NOT NULL, + project_code bigint NOT NULL, + preferences varchar(512) NOT NULL, + user_id int DEFAULT NULL , + create_time timestamp DEFAULT CURRENT_TIMESTAMP , + update_time timestamp DEFAULT CURRENT_TIMESTAMP , + PRIMARY KEY (id) +); + +CREATE UNIQUE INDEX unique_project_preference_project_code on t_ds_project_preference (project_code); +CREATE UNIQUE INDEX unique_project_preference_code on t_ds_project_preference (code); + + -- -- Table structure for table t_ds_queue -- @@ -998,6 +1019,10 @@ DROP SEQUENCE IF EXISTS t_ds_project_parameter_id_sequence; CREATE SEQUENCE t_ds_project_parameter_id_sequence; ALTER TABLE t_ds_project_parameter ALTER COLUMN id SET DEFAULT NEXTVAL('t_ds_project_parameter_id_sequence'); +DROP SEQUENCE IF EXISTS t_ds_project_preference_id_sequence; +CREATE SEQUENCE t_ds_project_preference_id_sequence; +ALTER TABLE t_ds_project_preference ALTER COLUMN id SET DEFAULT NEXTVAL('t_ds_project_preference_id_sequence'); + -- Records of t_ds_user?user : admin , password : dolphinscheduler123 INSERT INTO t_ds_user(user_name, user_password, user_type, email, phone, tenant_id, state, create_time, update_time, time_zone) VALUES ('admin', '7ad2410b2f4c074479a8937a28a22b8f', '0', 'xxx@qq.com', '', '-1', 1, '2018-03-27 15:48:50', '2018-10-24 17:40:22', null); diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProjectPreferenceMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProjectPreferenceMapperTest.java new file mode 100644 index 000000000000..9cfbeb294e1c --- /dev/null +++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProjectPreferenceMapperTest.java @@ -0,0 +1,65 @@ +/* + * 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 com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import java.util.Date; +import org.apache.dolphinscheduler.dao.BaseDaoTest; +import org.apache.dolphinscheduler.dao.entity.ProjectPreference; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +public class ProjectPreferenceMapperTest extends BaseDaoTest { + + @Autowired + private ProjectPreferenceMapper projectPreferenceMapper; + + private ProjectPreference insertOne(long code, String name, long projectCode) { + ProjectPreference projectPreference = new ProjectPreference(); + projectPreference.setCode(code); + projectPreference.setProjectCode(projectCode); + projectPreference.setPreferences("value"); + projectPreference.setCreateTime(new Date()); + projectPreference.setUpdateTime(new Date()); + projectPreference.setUserId(1); + projectPreferenceMapper.insert(projectPreference); + return projectPreference; + } + + @Test + public void testUpdate() { + ProjectPreference projectPreference = insertOne(1, "name", 1); + projectPreference.setUpdateTime(new Date()); + + int update = projectPreferenceMapper.updateById(projectPreference); + Assertions.assertEquals(1, update); + } + + + @Test + public void testQueryByProjectCode() { + insertOne(1, "name1", 1); + insertOne(2, "name2", 2); + + ProjectPreference projectPreference = projectPreferenceMapper + .selectOne(new QueryWrapper().lambda().eq(ProjectPreference::getProjectCode, 1)); + Assertions.assertEquals(1, projectPreference); + } + +} From f7c49c804d0571830bca396a8c60e9dcf23cbc4f Mon Sep 17 00:00:00 2001 From: calvin Date: Wed, 12 Jul 2023 20:02:33 +0800 Subject: [PATCH 02/11] add a few codes about dao --- .../dolphinscheduler/api/enums/Status.java | 5 + .../api/service/ProjectPreferenceService.java | 28 ++++ .../impl/ProjectPreferenceServiceImpl.java | 139 ++++++++++++++++++ .../service/ProjectPreferenceServiceTest.java | 117 +++++++++++++++ .../mapper/ProjectPreferenceMapperTest.java | 15 +- 5 files changed, 297 insertions(+), 7 deletions(-) create mode 100644 dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectPreferenceService.java create mode 100644 dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectPreferenceServiceImpl.java create mode 100644 dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectPreferenceServiceTest.java diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java index 7cc5c22c9321..7e2afe01d2e1 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java @@ -287,6 +287,11 @@ public enum Status { PROJECT_PARAMETER_CODE_EMPTY(10220, "project parameter code empty", "项目参数code为空"), + CREATE_PROJECT_PREFERENCE_ERROR(10300, "create project preference error", "创建项目偏好设置错误"), + + UPDATE_PROJECT_PREFERENCE_ERROR(10301, "update project preference error", "更新项目偏好设置错误"), + QUERY_PROJECT_PREFERENCE_ERROR(10302, "query project preference error by project code {0}", "查询项目[{0}]偏好设置错误"), + UDF_FUNCTION_NOT_EXIST(20001, "UDF function not found", "UDF函数不存在"), UDF_FUNCTION_EXISTS(20002, "UDF function already exists", "UDF函数已存在"), RESOURCE_NOT_EXIST(20004, "resource not exist", "资源不存在"), diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectPreferenceService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectPreferenceService.java new file mode 100644 index 000000000000..90d2f2c2b738 --- /dev/null +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectPreferenceService.java @@ -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); +} diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectPreferenceServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectPreferenceServiceImpl.java new file mode 100644 index 000000000000..c29a626843d8 --- /dev/null +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectPreferenceServiceImpl.java @@ -0,0 +1,139 @@ +/* + * 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 com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.google.common.collect.Lists; +import java.util.Date; +import java.util.List; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.dolphinscheduler.api.enums.Status; +import org.apache.dolphinscheduler.api.exceptions.ServiceException; +import org.apache.dolphinscheduler.api.service.ProjectParameterService; +import org.apache.dolphinscheduler.api.service.ProjectPreferenceService; +import org.apache.dolphinscheduler.api.service.ProjectService; +import org.apache.dolphinscheduler.api.utils.PageInfo; +import org.apache.dolphinscheduler.api.utils.Result; +import org.apache.dolphinscheduler.common.constants.Constants; +import org.apache.dolphinscheduler.common.utils.CodeGenerateUtils; +import org.apache.dolphinscheduler.common.utils.DateUtils; +import org.apache.dolphinscheduler.dao.entity.Project; +import org.apache.dolphinscheduler.dao.entity.ProjectParameter; +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.ProjectParameterMapper; +import org.apache.dolphinscheduler.dao.mapper.ProjectPreferenceMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@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().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.CREATE_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().lambda().eq(ProjectPreference::getProjectCode, projectCode)); + + if (Objects.nonNull(projectPreference)) { + result.setData(projectPreference); + putMsg(result, Status.SUCCESS); + } else { + putMsg(result, Status.QUERY_PROJECT_PREFERENCE_ERROR); + } + return result; + } +} diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectPreferenceServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectPreferenceServiceTest.java new file mode 100644 index 000000000000..f2ae9661a2c5 --- /dev/null +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectPreferenceServiceTest.java @@ -0,0 +1,117 @@ +/* + * 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.QUERY_PROJECT_PREFERENCE_ERROR.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; + } +} diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProjectPreferenceMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProjectPreferenceMapperTest.java index 9cfbeb294e1c..3fe8962cb5ff 100644 --- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProjectPreferenceMapperTest.java +++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProjectPreferenceMapperTest.java @@ -30,11 +30,12 @@ public class ProjectPreferenceMapperTest extends BaseDaoTest { @Autowired private ProjectPreferenceMapper projectPreferenceMapper; - private ProjectPreference insertOne(long code, String name, long projectCode) { + + private ProjectPreference insertOne(long code, long projectCode) { ProjectPreference projectPreference = new ProjectPreference(); projectPreference.setCode(code); projectPreference.setProjectCode(projectCode); - projectPreference.setPreferences("value"); + projectPreference.setPreferences("{workerGroup:{availableOptions:[],default:1}}"); projectPreference.setCreateTime(new Date()); projectPreference.setUpdateTime(new Date()); projectPreference.setUserId(1); @@ -44,7 +45,7 @@ private ProjectPreference insertOne(long code, String name, long projectCode) { @Test public void testUpdate() { - ProjectPreference projectPreference = insertOne(1, "name", 1); + ProjectPreference projectPreference = insertOne(1, 1); projectPreference.setUpdateTime(new Date()); int update = projectPreferenceMapper.updateById(projectPreference); @@ -54,12 +55,12 @@ public void testUpdate() { @Test public void testQueryByProjectCode() { - insertOne(1, "name1", 1); - insertOne(2, "name2", 2); + long projectCode = 2; + ProjectPreference expectedProjectPreference = insertOne(2, projectCode); ProjectPreference projectPreference = projectPreferenceMapper - .selectOne(new QueryWrapper().lambda().eq(ProjectPreference::getProjectCode, 1)); - Assertions.assertEquals(1, projectPreference); + .selectOne(new QueryWrapper().lambda().eq(ProjectPreference::getProjectCode, projectCode)); + Assertions.assertEquals(expectedProjectPreference, projectPreference); } } From c066df3a265af39bb9f0d4055860ce2fa8282e53 Mon Sep 17 00:00:00 2001 From: calvin Date: Wed, 12 Jul 2023 20:14:59 +0800 Subject: [PATCH 03/11] add a few codes about dao --- .../ProjectPreferenceController.java | 79 +++++++++++++++++++ .../main/resources/i18n/messages.properties | 7 +- 2 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectPreferenceController.java diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectPreferenceController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectPreferenceController.java new file mode 100644 index 000000000000..a1b0404e6ddd --- /dev/null +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectPreferenceController.java @@ -0,0 +1,79 @@ +/* + * 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.CREATE_PROJECT_PREFERENCE_ERROR; +import static org.apache.dolphinscheduler.api.enums.Status.QUERY_PROJECT_PREFERENCE_ERROR; + +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; +import lombok.extern.slf4j.Slf4j; +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 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.PostMapping; +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; + +@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)), + }) + @PostMapping() + @ResponseStatus(HttpStatus.CREATED) + @ApiException(CREATE_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(value = "/{code}") + @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); + } + +} diff --git a/dolphinscheduler-api/src/main/resources/i18n/messages.properties b/dolphinscheduler-api/src/main/resources/i18n/messages.properties index ea97ba1ce8da..63d894d7a5b0 100644 --- a/dolphinscheduler-api/src/main/resources/i18n/messages.properties +++ b/dolphinscheduler-api/src/main/resources/i18n/messages.properties @@ -447,4 +447,9 @@ UPDATE_PROJECT_PARAMETER_NOTES=update project parameter PROJECT_PARAMETER_CODE=project parameter code DELETE_PROJECT_PARAMETER_NOTES=delete project parameter QUERY_PROJECT_PARAMETER_LIST_PAGING_NOTES=query project parameter list paging -QUERY_PROJECT_PARAMETER_NOTES=query project parameter \ No newline at end of file +QUERY_PROJECT_PARAMETER_NOTES=query project parameter + +PROJECT_PREFERENCE_TAG=project preference related operation +UPDATE_PROJECT_PREFERENCE_NOTES=update project preference +PROJECT_PREFERENCES=project preferences +QUERY_PROJECT_PREFERENCE_NOTES=query project preference \ No newline at end of file From 3301606e4ade2f9790f9be793361f664e708f7c0 Mon Sep 17 00:00:00 2001 From: calvin Date: Wed, 12 Jul 2023 20:23:00 +0800 Subject: [PATCH 04/11] add a few codes about dao --- .../ProjectPreferenceControllerTest.java | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProjectPreferenceControllerTest.java diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProjectPreferenceControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProjectPreferenceControllerTest.java new file mode 100644 index 000000000000..8e060075901b --- /dev/null +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProjectPreferenceControllerTest.java @@ -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; + } + +} From 4166775c2b92e1711ceb8ebbe76a2b8ce167c88a Mon Sep 17 00:00:00 2001 From: calvin Date: Thu, 13 Jul 2023 19:57:50 +0800 Subject: [PATCH 05/11] add a few codes about the project preferences --- .../src/layouts/content/use-dataList.ts | 5 + dolphinscheduler-ui/src/locales/en_US/menu.ts | 1 + .../src/locales/en_US/project.ts | 5 + dolphinscheduler-ui/src/locales/zh_CN/menu.ts | 1 + .../src/locales/zh_CN/project.ts | 5 + .../src/router/modules/projects.ts | 11 + .../preference/components/parameter-modal.tsx | 147 +++++++++++++ .../preference/components/use-modal.ts | 112 ++++++++++ .../src/views/projects/preference/index.tsx | 122 +++++++++++ .../views/projects/preference/use-table.ts | 195 ++++++++++++++++++ .../task/components/node/detail-modal.tsx | 8 + .../task/components/node/format-data.ts | 5 + 12 files changed, 617 insertions(+) create mode 100644 dolphinscheduler-ui/src/views/projects/preference/components/parameter-modal.tsx create mode 100644 dolphinscheduler-ui/src/views/projects/preference/components/use-modal.ts create mode 100644 dolphinscheduler-ui/src/views/projects/preference/index.tsx create mode 100644 dolphinscheduler-ui/src/views/projects/preference/use-table.ts diff --git a/dolphinscheduler-ui/src/layouts/content/use-dataList.ts b/dolphinscheduler-ui/src/layouts/content/use-dataList.ts index 379073d2a15e..0cf6bd2ea5ab 100644 --- a/dolphinscheduler-ui/src/layouts/content/use-dataList.ts +++ b/dolphinscheduler-ui/src/layouts/content/use-dataList.ts @@ -117,6 +117,11 @@ export function useDataList() { key: `/projects/${projectCode}/parameter`, payload: { projectName: projectName }, }, + { + label: t('menu.project_preferences'), + key: `/projects/${projectCode}/preferences`, + payload: { projectName: projectName }, + }, ] }, { diff --git a/dolphinscheduler-ui/src/locales/en_US/menu.ts b/dolphinscheduler-ui/src/locales/en_US/menu.ts index 30d8b6f72a09..dec594be0728 100644 --- a/dolphinscheduler-ui/src/locales/en_US/menu.ts +++ b/dolphinscheduler-ui/src/locales/en_US/menu.ts @@ -24,6 +24,7 @@ export default { security: 'Security', project_overview: 'Project Overview', project_parameter: 'Project Parameter', + project_preferences: 'Project Preferences', workflow_relation: 'Workflow Relation', workflow: 'Workflow', workflow_definition: 'Workflow Definition', diff --git a/dolphinscheduler-ui/src/locales/en_US/project.ts b/dolphinscheduler-ui/src/locales/en_US/project.ts index c3cbfd09722d..807cf9d7aa00 100644 --- a/dolphinscheduler-ui/src/locales/en_US/project.ts +++ b/dolphinscheduler-ui/src/locales/en_US/project.ts @@ -889,4 +889,9 @@ export default { delete_confirm: 'Delete?', success: 'Success', }, + preference: { + edit_preference: 'Edit Preference', + preference_manage: 'Preference Management', + success: 'Success', + }, } diff --git a/dolphinscheduler-ui/src/locales/zh_CN/menu.ts b/dolphinscheduler-ui/src/locales/zh_CN/menu.ts index 4089b0833e42..2d38fa9e41bb 100644 --- a/dolphinscheduler-ui/src/locales/zh_CN/menu.ts +++ b/dolphinscheduler-ui/src/locales/zh_CN/menu.ts @@ -25,6 +25,7 @@ export default { ui_setting: '界面设置', project_overview: '项目概览', project_parameter: '项目级别参数', + project_preferences: '项目偏好设置', workflow_relation: '工作流关系', workflow: '工作流', workflow_definition: '工作流定义', diff --git a/dolphinscheduler-ui/src/locales/zh_CN/project.ts b/dolphinscheduler-ui/src/locales/zh_CN/project.ts index fca300a90373..8fdb1b9bae72 100644 --- a/dolphinscheduler-ui/src/locales/zh_CN/project.ts +++ b/dolphinscheduler-ui/src/locales/zh_CN/project.ts @@ -863,4 +863,9 @@ export default { delete_confirm: '确定删除吗?', success: '成功', }, + preference: { + edit_preference: '修改项目偏好设置', + preference_manage: '偏好管理', + success: '成功', + }, } diff --git a/dolphinscheduler-ui/src/router/modules/projects.ts b/dolphinscheduler-ui/src/router/modules/projects.ts index 471b6df481b0..8412f5904f0f 100644 --- a/dolphinscheduler-ui/src/router/modules/projects.ts +++ b/dolphinscheduler-ui/src/router/modules/projects.ts @@ -64,6 +64,17 @@ export default { auth: [] } }, + { + path: '/projects/:projectCode/preferences', + name: 'projects-preference', + component: components['projects-preference'], + meta: { + title: '项目偏好设置', + activeMenu: 'projects', + showSide: true, + auth: [] + } + }, { path: '/projects/:projectCode/workflow/relation', name: 'workflow-relation', diff --git a/dolphinscheduler-ui/src/views/projects/preference/components/parameter-modal.tsx b/dolphinscheduler-ui/src/views/projects/preference/components/parameter-modal.tsx new file mode 100644 index 000000000000..c69ae864b209 --- /dev/null +++ b/dolphinscheduler-ui/src/views/projects/preference/components/parameter-modal.tsx @@ -0,0 +1,147 @@ +/* + * 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, + getCurrentInstance, + PropType, + toRefs, + watch +} from 'vue' +import Modal from '@/components/modal' +import { NForm, NFormItem, NInput } from 'naive-ui' +import { useModal } from './use-modal' +import { useI18n } from 'vue-i18n' + +const ParameterModal = defineComponent({ + name: 'ParameterModal', + props: { + showModalRef: { + type: Boolean as PropType, + default: false + }, + statusRef: { + type: Number as PropType, + default: 0 + }, + row: { + type: Object as PropType, + default: {} + } + }, + emits: ['cancelModal', 'confirmModal'], + setup(props, ctx) { + const { variables, handleValidate } = useModal(props, ctx) + const { t } = useI18n() + + const cancelModal = () => { + if (props.statusRef === 0) { + variables.model.projectParameterName = '' + variables.model.projectParameterValue = '' + } else { + variables.model.projectParameterName = props.row.paramName + variables.model.projectParameterValue = props.row.paramValue + } + ctx.emit('cancelModal', props.showModalRef) + } + + const confirmModal = () => { + handleValidate(props.statusRef) + } + + const trim = getCurrentInstance()?.appContext.config.globalProperties.trim + + watch( + () => props.showModalRef, + () => { + props.showModalRef + } + ) + + watch( + () => props.statusRef, + () => { + if (props.statusRef === 0) { + variables.model.projectParameterName = '' + variables.model.projectParameterValue = '' + } else { + variables.model.code = props.row.code + variables.model.projectParameterName = props.row.paramName + variables.model.projectParameterValue = props.row.paramValue + } + } + ) + + watch( + () => props.row, + () => { + variables.model.code = props.row.code + variables.model.projectParameterName = props.row.paramName + variables.model.projectParameterValue = props.row.paramValue + } + ) + + return { t, ...toRefs(variables), cancelModal, confirmModal, trim } + }, + render() { + const { t } = this + return ( +
+ + {{ + default: () => ( + + + + + + + + + ) + }} + +
+ ) + } +}) + +export default ParameterModal diff --git a/dolphinscheduler-ui/src/views/projects/preference/components/use-modal.ts b/dolphinscheduler-ui/src/views/projects/preference/components/use-modal.ts new file mode 100644 index 000000000000..56b51868460b --- /dev/null +++ b/dolphinscheduler-ui/src/views/projects/preference/components/use-modal.ts @@ -0,0 +1,112 @@ +/* + * 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 { reactive, ref, SetupContext } from 'vue' +import { useI18n } from 'vue-i18n' +import type { Router } from 'vue-router' +import { + createProjectParameter, + updateProjectParameter +} from '@/service/modules/projects-parameter' +import { + ProjectParameterReq, + UpdateProjectParameterReq +} from '@/service/modules/projects-parameter/types' +import { useRouter } from 'vue-router' + +export function useModal( + props: any, + ctx: SetupContext<('cancelModal' | 'confirmModal')[]> +) { + const { t } = useI18n() + const router: Router = useRouter() + + const variables = reactive({ + formRef: ref(), + projectCode: ref(Number(router.currentRoute.value.params.projectCode)), + model: { + code: ref(-1), + projectParameterName: ref(''), + projectParameterValue: ref('') + }, + saving: false, + rules: { + name: { + required: true, + trigger: ['input', 'blur'], + validator() { + if (variables.model.projectParameterName === '') { + return new Error(t('project.parameter.name_tips')) + } + } + }, + value: { + required: true, + trigger: ['input', 'blur'], + validator() { + if (variables.model.projectParameterValue === '') { + return new Error(t('project.parameter.value_tips')) + } + } + } + } + }) + + const handleValidate = async (statusRef: number) => { + // await variables.formRef.validate() + + if (variables.saving) return + variables.saving = true + + try { + statusRef === 0 ? await submitModal() : await updateModal() + variables.saving = false + } catch (err) { + variables.saving = false + } + } + + const submitModal = () => { + const data: ProjectParameterReq = { + projectParameterName: variables.model.projectParameterName, + projectParameterValue: variables.model.projectParameterValue + } + + createProjectParameter(data, variables.projectCode).then(() => { + variables.model.projectParameterName = '' + variables.model.projectParameterValue = '' + ctx.emit('confirmModal', props.showModalRef) + }) + } + + const updateModal = () => { + const data: UpdateProjectParameterReq = { + code: variables.model.code, + projectParameterName: variables.model.projectParameterName, + projectParameterValue: variables.model.projectParameterValue + } + + updateProjectParameter(data, variables.projectCode).then(() => { + ctx.emit('confirmModal', props.showModalRef) + }) + } + + return { + variables, + handleValidate + } +} diff --git a/dolphinscheduler-ui/src/views/projects/preference/index.tsx b/dolphinscheduler-ui/src/views/projects/preference/index.tsx new file mode 100644 index 000000000000..2a9c8f28f175 --- /dev/null +++ b/dolphinscheduler-ui/src/views/projects/preference/index.tsx @@ -0,0 +1,122 @@ +/* + * 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 { + NDataTable, + NIcon, + NInput, + NPagination, + NSpace, + NButton +} from 'naive-ui' +import { defineComponent, onMounted, toRefs, watch } from 'vue' +import { useI18n } from 'vue-i18n' +import { useTable } from '@/views/projects/parameter/use-table' +import Card from '@/components/card' +import ParameterModal from '@/views/projects/parameter/components/parameter-modal' +import { SearchOutlined } from '@vicons/antd' + +export default defineComponent({ + name: 'ProjectPreferenceList', + setup() { + const { variables, createColumns, getTableData } = useTable() + + const requestData = () => { + getTableData({ + pageSize: variables.pageSize, + pageNo: variables.page, + searchVal: variables.searchVal, + projectCode: variables.projectCode + }) + } + + const handleUpdateList = () => { + requestData() + } + + const handleSearch = () => { + variables.page = 1 + requestData() + } + + const handleChangePageSize = () => { + variables.page = 1 + requestData() + } + + const onCancelModal = () => { + variables.showRef = false + } + + const onConfirmModal = () => { + variables.showRef = false + requestData() + } + + const onCreateParameter = () => { + variables.showRef = true + variables.statusRef = 0 + } + + onMounted(() => { + createColumns(variables) + requestData() + }) + + watch(useI18n().locale, () => { + createColumns(variables) + }) + + return { + requestData, + handleSearch, + handleUpdateList, + handleChangePageSize, + onCreateParameter, + onCancelModal, + onConfirmModal, + ...toRefs(variables) + } + }, + render() { + const { t } = useI18n() + const { + loadingRef, + handleSearch, + onCreateParameter, + onConfirmModal, + onCancelModal + } = this + + return ( + + + + + + + + ) + } +}) diff --git a/dolphinscheduler-ui/src/views/projects/preference/use-table.ts b/dolphinscheduler-ui/src/views/projects/preference/use-table.ts new file mode 100644 index 000000000000..e0d4b940cf13 --- /dev/null +++ b/dolphinscheduler-ui/src/views/projects/preference/use-table.ts @@ -0,0 +1,195 @@ +/* + * 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 { h, ref, reactive } from 'vue' +import { useI18n } from 'vue-i18n' +import { useRouter } from 'vue-router' +import { NSpace, NTooltip, NButton, NPopconfirm } from 'naive-ui' +import { + deleteProjectParameterByCode, + queryProjectParameterListPaging +} from '@/service/modules/projects-parameter' +import { ProjectParameterCodeReq } from '@/service/modules/projects-parameter/types' +import { DeleteOutlined, EditOutlined } from '@vicons/antd' +import { + COLUMN_WIDTH_CONFIG, + calculateTableWidth, + DefaultTableWidth +} from '@/common/column-width-config' +import type { Router } from 'vue-router' + +export function useTable() { + const { t } = useI18n() + const router: Router = useRouter() + + const variables = reactive({ + columns: [], + tableWidth: DefaultTableWidth, + row: {}, + tableData: [], + projectCode: ref(Number(router.currentRoute.value.params.projectCode)), + page: ref(1), + pageSize: ref(10), + searchVal: ref(), + totalPage: ref(1), + showRef: ref(false), + statusRef: ref(0), + loadingRef: ref(false) + }) + + const createColumns = (variables: any) => { + variables.columns = [ + { + title: '#', + key: 'id', + ...COLUMN_WIDTH_CONFIG['index'], + render: (row: any, index: number) => index + 1 + }, + { + title: t('project.parameter.name'), + key: 'paramName', + ...COLUMN_WIDTH_CONFIG['name'] + }, + { + title: t('project.parameter.value'), + key: 'paramValue', + ...COLUMN_WIDTH_CONFIG['name'] + }, + { + title: t('project.parameter.create_time'), + key: 'createTime', + ...COLUMN_WIDTH_CONFIG['time'] + }, + { + title: t('project.parameter.update_time'), + key: 'updateTime', + ...COLUMN_WIDTH_CONFIG['time'] + }, + { + title: t('project.parameter.operation'), + key: 'operation', + ...COLUMN_WIDTH_CONFIG['operation'](3), + render: (row: any) => { + return h(NSpace, null, { + default: () => [ + h( + NTooltip, + {}, + { + trigger: () => + h( + NButton, + { + circle: true, + type: 'info', + size: 'small', + onClick: () => { + handleEdit(row) + } + }, + { + icon: () => h(EditOutlined) + } + ), + default: () => t('project.parameter.edit') + } + ), + h( + NPopconfirm, + { + onPositiveClick: () => { + handleDelete(row.code) + } + }, + { + trigger: () => + h( + NTooltip, + {}, + { + trigger: () => + h( + NButton, + { + circle: true, + type: 'error', + size: 'small' + }, + { + icon: () => h(DeleteOutlined) + } + ), + default: () => t('project.parameter.delete') + } + ), + default: () => t('project.parameter.delete_confirm') + } + ) + ] + }) + } + } + ] + if (variables.tableWidth) { + variables.tableWidth = calculateTableWidth(variables.columns) + } + } + + const handleEdit = (row: any) => { + variables.showRef = true + variables.statusRef = 1 + variables.row = row + } + + const getTableData = (params: any) => { + if (variables.loadingRef) return + variables.loadingRef = true + + queryProjectParameterListPaging({ ...params }, variables.projectCode).then( + (res: any) => { + variables.totalPage = res.totalPage + variables.tableData = res.totalList.map((item: any) => { + return { ...item } + }) + variables.loadingRef = false + } + ) + } + + const handleDelete = (code: number) => { + if (variables.tableData.length === 1 && variables.page > 1) { + variables.page -= 1 + } + const data: ProjectParameterCodeReq = { + code: code + } + deleteProjectParameterByCode(data, variables.projectCode).then(() => { + window.$message.success(t('project.parameter.success')) + getTableData({ + pageSize: variables.pageSize, + pageNo: variables.page, + searchVal: variables.searchVal + }) + }) + } + + return { + variables, + createColumns, + getTableData + } +} diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/detail-modal.tsx b/dolphinscheduler-ui/src/views/projects/task/components/node/detail-modal.tsx index 390968b2c51e..6067f531d7c4 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/detail-modal.tsx +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/detail-modal.tsx @@ -116,6 +116,13 @@ const NodeDetailModal = defineComponent({ } } + const initProjectPreferences = (projectCode: number, data: ITaskData) => { + console.log('initProjectPreferences') + console.log(projectCode) + console.log(data) + } + + const initHeaderLinks = (processInstance: any, taskType?: ITaskType) => { headerLinks.value = [ { @@ -211,6 +218,7 @@ const NodeDetailModal = defineComponent({ initHeaderLinks(props.processInstance, props.data.taskType) taskStore.init() await nextTick() + initProjectPreferences(props.projectCode, props.data) detailRef.value.value.setValues(formatModel(props.data)) } ) diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/format-data.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/format-data.ts index e6d87298d0b2..e7e1ef95e632 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/format-data.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/format-data.ts @@ -31,6 +31,7 @@ export function formatParams(data: INodeData): { upstreamCodes: string taskDefinitionJsonObj: object } { + const taskParams: ITaskParams = {} if (data.taskType === 'SUB_PROCESS' || data.taskType === 'DYNAMIC') { taskParams.processDefinitionCode = data.processDefinitionCode @@ -555,6 +556,9 @@ export function formatParams(data: INodeData): { } export function formatModel(data: ITaskData) { + + console.log('formatModel') + console.log(data) const params = { ...omit(data, [ 'environmentCode', @@ -740,5 +744,6 @@ export function formatModel(data: ITaskData) { params.isCustomTask = data.taskParams.jobType === 'CUSTOM' } + console.log(params) return params } From 71a1c3fac29f0947947ec02fdbe09776d14bac42 Mon Sep 17 00:00:00 2001 From: calvin Date: Sat, 15 Jul 2023 17:28:38 +0800 Subject: [PATCH 06/11] add a few codes about the project preferences --- .../ProjectPreferenceController.java | 9 +- .../dolphinscheduler/api/enums/Status.java | 2 +- .../impl/ProjectPreferenceServiceImpl.java | 5 +- .../src/components/form/use-form.ts | 1 + .../src/locales/en_US/project.ts | 3 +- .../src/locales/zh_CN/project.ts | 3 +- .../modules/projects-preference/index.ts | 42 ++++ .../modules/projects-preference/types.ts | 40 ++++ .../preference/components/parameter-modal.tsx | 147 ------------- .../preference/components/use-modal.ts | 112 ---------- .../src/views/projects/preference/detail.tsx | 57 +++++ .../src/views/projects/preference/index.tsx | 90 +------- .../src/views/projects/preference/use-form.ts | 107 ++++++++++ .../views/projects/preference/use-table.ts | 195 ------------------ .../task/components/node/format-data.ts | 5 - 15 files changed, 267 insertions(+), 551 deletions(-) create mode 100644 dolphinscheduler-ui/src/service/modules/projects-preference/index.ts create mode 100644 dolphinscheduler-ui/src/service/modules/projects-preference/types.ts delete mode 100644 dolphinscheduler-ui/src/views/projects/preference/components/parameter-modal.tsx delete mode 100644 dolphinscheduler-ui/src/views/projects/preference/components/use-modal.ts create mode 100644 dolphinscheduler-ui/src/views/projects/preference/detail.tsx create mode 100644 dolphinscheduler-ui/src/views/projects/preference/use-form.ts delete mode 100644 dolphinscheduler-ui/src/views/projects/preference/use-table.ts diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectPreferenceController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectPreferenceController.java index a1b0404e6ddd..093b92220f1a 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectPreferenceController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectPreferenceController.java @@ -19,6 +19,7 @@ import static org.apache.dolphinscheduler.api.enums.Status.CREATE_PROJECT_PREFERENCE_ERROR; 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 io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -36,7 +37,7 @@ 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.PostMapping; +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; @@ -56,9 +57,9 @@ public class ProjectPreferenceController extends BaseController { @Parameters({ @Parameter(name = "projectPreferences", description = "PROJECT_PREFERENCES", schema = @Schema(implementation = String.class)), }) - @PostMapping() + @PutMapping @ResponseStatus(HttpStatus.CREATED) - @ApiException(CREATE_PROJECT_PREFERENCE_ERROR) + @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, @@ -67,7 +68,7 @@ public Result updateProjectPreference(@Parameter(hidden = true) @RequestAttribut } @Operation(summary = "queryProjectPreferenceByProjectCode", description = "QUERY_PROJECT_PREFERENCE_NOTES") - @GetMapping(value = "/{code}") + @GetMapping() @ResponseStatus(HttpStatus.OK) @ApiException(QUERY_PROJECT_PREFERENCE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java index 7e2afe01d2e1..c91d15afd17e 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java @@ -290,7 +290,7 @@ public enum Status { CREATE_PROJECT_PREFERENCE_ERROR(10300, "create project preference error", "创建项目偏好设置错误"), UPDATE_PROJECT_PREFERENCE_ERROR(10301, "update project preference error", "更新项目偏好设置错误"), - QUERY_PROJECT_PREFERENCE_ERROR(10302, "query project preference error by project code {0}", "查询项目[{0}]偏好设置错误"), + QUERY_PROJECT_PREFERENCE_ERROR(10302, "query project preference error", "查询项目偏好设置错误"), UDF_FUNCTION_NOT_EXIST(20001, "UDF function not found", "UDF函数不存在"), UDF_FUNCTION_EXISTS(20002, "UDF function already exists", "UDF函数已存在"), diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectPreferenceServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectPreferenceServiceImpl.java index c29a626843d8..a204a8262294 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectPreferenceServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectPreferenceServiceImpl.java @@ -114,7 +114,6 @@ public Result updateProjectPreference(User loginUser, long projectCode, String p return result; } - @Override public Result queryProjectPreferenceByProjectCode(User loginUser, long projectCode) { Result result = new Result(); @@ -130,10 +129,8 @@ public Result queryProjectPreferenceByProjectCode(User loginUser, long projectCo if (Objects.nonNull(projectPreference)) { result.setData(projectPreference); - putMsg(result, Status.SUCCESS); - } else { - putMsg(result, Status.QUERY_PROJECT_PREFERENCE_ERROR); } + putMsg(result, Status.SUCCESS); return result; } } diff --git a/dolphinscheduler-ui/src/components/form/use-form.ts b/dolphinscheduler-ui/src/components/form/use-form.ts index 2f76a112707f..29cc5b2576ba 100644 --- a/dolphinscheduler-ui/src/components/form/use-form.ts +++ b/dolphinscheduler-ui/src/components/form/use-form.ts @@ -38,6 +38,7 @@ export function useForm() { } const setValues = (initialValues: { [field: string]: any }) => { + console.log(initialValues) for (const [key, value] of Object.entries(initialValues)) { state.formRef.model[key] = value } diff --git a/dolphinscheduler-ui/src/locales/en_US/project.ts b/dolphinscheduler-ui/src/locales/en_US/project.ts index 807cf9d7aa00..752723475322 100644 --- a/dolphinscheduler-ui/src/locales/en_US/project.ts +++ b/dolphinscheduler-ui/src/locales/en_US/project.ts @@ -891,7 +891,8 @@ export default { }, preference: { edit_preference: 'Edit Preference', - preference_manage: 'Preference Management', + preference_manage: 'Project Preference Management', success: 'Success', + submit: 'Submit' }, } diff --git a/dolphinscheduler-ui/src/locales/zh_CN/project.ts b/dolphinscheduler-ui/src/locales/zh_CN/project.ts index 8fdb1b9bae72..236935d2110d 100644 --- a/dolphinscheduler-ui/src/locales/zh_CN/project.ts +++ b/dolphinscheduler-ui/src/locales/zh_CN/project.ts @@ -865,7 +865,8 @@ export default { }, preference: { edit_preference: '修改项目偏好设置', - preference_manage: '偏好管理', + preference_manage: '项目偏好管理', success: '成功', + submit: '提交' }, } diff --git a/dolphinscheduler-ui/src/service/modules/projects-preference/index.ts b/dolphinscheduler-ui/src/service/modules/projects-preference/index.ts new file mode 100644 index 000000000000..2d2ff48bd4dd --- /dev/null +++ b/dolphinscheduler-ui/src/service/modules/projects-preference/index.ts @@ -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 + }) +} \ No newline at end of file diff --git a/dolphinscheduler-ui/src/service/modules/projects-preference/types.ts b/dolphinscheduler-ui/src/service/modules/projects-preference/types.ts new file mode 100644 index 000000000000..459ec561ecd6 --- /dev/null +++ b/dolphinscheduler-ui/src/service/modules/projects-preference/types.ts @@ -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 +} diff --git a/dolphinscheduler-ui/src/views/projects/preference/components/parameter-modal.tsx b/dolphinscheduler-ui/src/views/projects/preference/components/parameter-modal.tsx deleted file mode 100644 index c69ae864b209..000000000000 --- a/dolphinscheduler-ui/src/views/projects/preference/components/parameter-modal.tsx +++ /dev/null @@ -1,147 +0,0 @@ -/* - * 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, - getCurrentInstance, - PropType, - toRefs, - watch -} from 'vue' -import Modal from '@/components/modal' -import { NForm, NFormItem, NInput } from 'naive-ui' -import { useModal } from './use-modal' -import { useI18n } from 'vue-i18n' - -const ParameterModal = defineComponent({ - name: 'ParameterModal', - props: { - showModalRef: { - type: Boolean as PropType, - default: false - }, - statusRef: { - type: Number as PropType, - default: 0 - }, - row: { - type: Object as PropType, - default: {} - } - }, - emits: ['cancelModal', 'confirmModal'], - setup(props, ctx) { - const { variables, handleValidate } = useModal(props, ctx) - const { t } = useI18n() - - const cancelModal = () => { - if (props.statusRef === 0) { - variables.model.projectParameterName = '' - variables.model.projectParameterValue = '' - } else { - variables.model.projectParameterName = props.row.paramName - variables.model.projectParameterValue = props.row.paramValue - } - ctx.emit('cancelModal', props.showModalRef) - } - - const confirmModal = () => { - handleValidate(props.statusRef) - } - - const trim = getCurrentInstance()?.appContext.config.globalProperties.trim - - watch( - () => props.showModalRef, - () => { - props.showModalRef - } - ) - - watch( - () => props.statusRef, - () => { - if (props.statusRef === 0) { - variables.model.projectParameterName = '' - variables.model.projectParameterValue = '' - } else { - variables.model.code = props.row.code - variables.model.projectParameterName = props.row.paramName - variables.model.projectParameterValue = props.row.paramValue - } - } - ) - - watch( - () => props.row, - () => { - variables.model.code = props.row.code - variables.model.projectParameterName = props.row.paramName - variables.model.projectParameterValue = props.row.paramValue - } - ) - - return { t, ...toRefs(variables), cancelModal, confirmModal, trim } - }, - render() { - const { t } = this - return ( -
- - {{ - default: () => ( - - - - - - - - - ) - }} - -
- ) - } -}) - -export default ParameterModal diff --git a/dolphinscheduler-ui/src/views/projects/preference/components/use-modal.ts b/dolphinscheduler-ui/src/views/projects/preference/components/use-modal.ts deleted file mode 100644 index 56b51868460b..000000000000 --- a/dolphinscheduler-ui/src/views/projects/preference/components/use-modal.ts +++ /dev/null @@ -1,112 +0,0 @@ -/* - * 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 { reactive, ref, SetupContext } from 'vue' -import { useI18n } from 'vue-i18n' -import type { Router } from 'vue-router' -import { - createProjectParameter, - updateProjectParameter -} from '@/service/modules/projects-parameter' -import { - ProjectParameterReq, - UpdateProjectParameterReq -} from '@/service/modules/projects-parameter/types' -import { useRouter } from 'vue-router' - -export function useModal( - props: any, - ctx: SetupContext<('cancelModal' | 'confirmModal')[]> -) { - const { t } = useI18n() - const router: Router = useRouter() - - const variables = reactive({ - formRef: ref(), - projectCode: ref(Number(router.currentRoute.value.params.projectCode)), - model: { - code: ref(-1), - projectParameterName: ref(''), - projectParameterValue: ref('') - }, - saving: false, - rules: { - name: { - required: true, - trigger: ['input', 'blur'], - validator() { - if (variables.model.projectParameterName === '') { - return new Error(t('project.parameter.name_tips')) - } - } - }, - value: { - required: true, - trigger: ['input', 'blur'], - validator() { - if (variables.model.projectParameterValue === '') { - return new Error(t('project.parameter.value_tips')) - } - } - } - } - }) - - const handleValidate = async (statusRef: number) => { - // await variables.formRef.validate() - - if (variables.saving) return - variables.saving = true - - try { - statusRef === 0 ? await submitModal() : await updateModal() - variables.saving = false - } catch (err) { - variables.saving = false - } - } - - const submitModal = () => { - const data: ProjectParameterReq = { - projectParameterName: variables.model.projectParameterName, - projectParameterValue: variables.model.projectParameterValue - } - - createProjectParameter(data, variables.projectCode).then(() => { - variables.model.projectParameterName = '' - variables.model.projectParameterValue = '' - ctx.emit('confirmModal', props.showModalRef) - }) - } - - const updateModal = () => { - const data: UpdateProjectParameterReq = { - code: variables.model.code, - projectParameterName: variables.model.projectParameterName, - projectParameterValue: variables.model.projectParameterValue - } - - updateProjectParameter(data, variables.projectCode).then(() => { - ctx.emit('confirmModal', props.showModalRef) - }) - } - - return { - variables, - handleValidate - } -} diff --git a/dolphinscheduler-ui/src/views/projects/preference/detail.tsx b/dolphinscheduler-ui/src/views/projects/preference/detail.tsx new file mode 100644 index 000000000000..2ac2a40caf34 --- /dev/null +++ b/dolphinscheduler-ui/src/views/projects/preference/detail.tsx @@ -0,0 +1,57 @@ +/* + * 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, ref } from 'vue' +import Form from '@/components/form' +import { useForm } from './use-form' +import { NButton, NSpace } from "naive-ui"; + +const PreferenceForm = defineComponent({ + name: 'PreferenceForm', + setup() { + + const { formRef, elementsRef, rulesRef, model, formProps, t, handleUpdate } = useForm() + + return () => ( +
+
+ + + {t('project.preference.submit')} + + +
+ ) + } +}) + +export default PreferenceForm diff --git a/dolphinscheduler-ui/src/views/projects/preference/index.tsx b/dolphinscheduler-ui/src/views/projects/preference/index.tsx index 2a9c8f28f175..ae61ad8748a4 100644 --- a/dolphinscheduler-ui/src/views/projects/preference/index.tsx +++ b/dolphinscheduler-ui/src/views/projects/preference/index.tsx @@ -15,104 +15,32 @@ * limitations under the License. */ -import { - NDataTable, - NIcon, - NInput, - NPagination, - NSpace, - NButton -} from 'naive-ui' -import { defineComponent, onMounted, toRefs, watch } from 'vue' +import { NSpace } from 'naive-ui' +import { defineComponent, ref } from 'vue' import { useI18n } from 'vue-i18n' -import { useTable } from '@/views/projects/parameter/use-table' import Card from '@/components/card' -import ParameterModal from '@/views/projects/parameter/components/parameter-modal' -import { SearchOutlined } from '@vicons/antd' +import PreferenceForm from "@/views/projects/preference/detail"; export default defineComponent({ - name: 'ProjectPreferenceList', + name: 'ProjectPreference', setup() { - const { variables, createColumns, getTableData } = useTable() - const requestData = () => { - getTableData({ - pageSize: variables.pageSize, - pageNo: variables.page, - searchVal: variables.searchVal, - projectCode: variables.projectCode - }) - } - - const handleUpdateList = () => { - requestData() - } - - const handleSearch = () => { - variables.page = 1 - requestData() - } - - const handleChangePageSize = () => { - variables.page = 1 - requestData() - } - - const onCancelModal = () => { - variables.showRef = false - } - - const onConfirmModal = () => { - variables.showRef = false - requestData() - } - - const onCreateParameter = () => { - variables.showRef = true - variables.statusRef = 0 - } - - onMounted(() => { - createColumns(variables) - requestData() - }) - - watch(useI18n().locale, () => { - createColumns(variables) - }) + const detailRef = ref() return { - requestData, - handleSearch, - handleUpdateList, - handleChangePageSize, - onCreateParameter, - onCancelModal, - onConfirmModal, - ...toRefs(variables) + detailRef } }, render() { const { t } = useI18n() - const { - loadingRef, - handleSearch, - onCreateParameter, - onConfirmModal, - onCancelModal - } = this + const { detailRef } = this return ( - diff --git a/dolphinscheduler-ui/src/views/projects/preference/use-form.ts b/dolphinscheduler-ui/src/views/projects/preference/use-form.ts new file mode 100644 index 000000000000..4ea6eadb848a --- /dev/null +++ b/dolphinscheduler-ui/src/views/projects/preference/use-form.ts @@ -0,0 +1,107 @@ +/* + * 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, unref} 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, ProjectPreferenceRes } from "@/service/modules/projects-preference/types"; + +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 + const elementsRef = ref([]) as Ref + const rulesRef = ref({}) + const formProps = ref({}) + + formProps.value = { + labelPlacement: 'left', + labelWidth: 'auto', + size: 'large' + } + + const data = reactive({ + model: { + workerGroup: 'default', + environmentCode: null, + failRetryInterval: 1, + failRetryTimes: 0 + } 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) + } + + const preferencesItems: IJsonItem[] = [ + Fields.useWorkerGroup(), + ] + + jsonRef.value = preferencesItems + + const getElements = () => { + const { rules, elements } = getElementByJson(jsonRef.value, data.model) + if (rules) { + for (let key in rules) { + rules[key].required = false + } + } + elementsRef.value = elements + rulesRef.value = rules + console.log('elements') + console.log(rules) + } + + getElements() + + return { formRef, elementsRef, rulesRef, model: data.model, formProps, t, handleUpdate } +} diff --git a/dolphinscheduler-ui/src/views/projects/preference/use-table.ts b/dolphinscheduler-ui/src/views/projects/preference/use-table.ts deleted file mode 100644 index e0d4b940cf13..000000000000 --- a/dolphinscheduler-ui/src/views/projects/preference/use-table.ts +++ /dev/null @@ -1,195 +0,0 @@ -/* - * 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 { h, ref, reactive } from 'vue' -import { useI18n } from 'vue-i18n' -import { useRouter } from 'vue-router' -import { NSpace, NTooltip, NButton, NPopconfirm } from 'naive-ui' -import { - deleteProjectParameterByCode, - queryProjectParameterListPaging -} from '@/service/modules/projects-parameter' -import { ProjectParameterCodeReq } from '@/service/modules/projects-parameter/types' -import { DeleteOutlined, EditOutlined } from '@vicons/antd' -import { - COLUMN_WIDTH_CONFIG, - calculateTableWidth, - DefaultTableWidth -} from '@/common/column-width-config' -import type { Router } from 'vue-router' - -export function useTable() { - const { t } = useI18n() - const router: Router = useRouter() - - const variables = reactive({ - columns: [], - tableWidth: DefaultTableWidth, - row: {}, - tableData: [], - projectCode: ref(Number(router.currentRoute.value.params.projectCode)), - page: ref(1), - pageSize: ref(10), - searchVal: ref(), - totalPage: ref(1), - showRef: ref(false), - statusRef: ref(0), - loadingRef: ref(false) - }) - - const createColumns = (variables: any) => { - variables.columns = [ - { - title: '#', - key: 'id', - ...COLUMN_WIDTH_CONFIG['index'], - render: (row: any, index: number) => index + 1 - }, - { - title: t('project.parameter.name'), - key: 'paramName', - ...COLUMN_WIDTH_CONFIG['name'] - }, - { - title: t('project.parameter.value'), - key: 'paramValue', - ...COLUMN_WIDTH_CONFIG['name'] - }, - { - title: t('project.parameter.create_time'), - key: 'createTime', - ...COLUMN_WIDTH_CONFIG['time'] - }, - { - title: t('project.parameter.update_time'), - key: 'updateTime', - ...COLUMN_WIDTH_CONFIG['time'] - }, - { - title: t('project.parameter.operation'), - key: 'operation', - ...COLUMN_WIDTH_CONFIG['operation'](3), - render: (row: any) => { - return h(NSpace, null, { - default: () => [ - h( - NTooltip, - {}, - { - trigger: () => - h( - NButton, - { - circle: true, - type: 'info', - size: 'small', - onClick: () => { - handleEdit(row) - } - }, - { - icon: () => h(EditOutlined) - } - ), - default: () => t('project.parameter.edit') - } - ), - h( - NPopconfirm, - { - onPositiveClick: () => { - handleDelete(row.code) - } - }, - { - trigger: () => - h( - NTooltip, - {}, - { - trigger: () => - h( - NButton, - { - circle: true, - type: 'error', - size: 'small' - }, - { - icon: () => h(DeleteOutlined) - } - ), - default: () => t('project.parameter.delete') - } - ), - default: () => t('project.parameter.delete_confirm') - } - ) - ] - }) - } - } - ] - if (variables.tableWidth) { - variables.tableWidth = calculateTableWidth(variables.columns) - } - } - - const handleEdit = (row: any) => { - variables.showRef = true - variables.statusRef = 1 - variables.row = row - } - - const getTableData = (params: any) => { - if (variables.loadingRef) return - variables.loadingRef = true - - queryProjectParameterListPaging({ ...params }, variables.projectCode).then( - (res: any) => { - variables.totalPage = res.totalPage - variables.tableData = res.totalList.map((item: any) => { - return { ...item } - }) - variables.loadingRef = false - } - ) - } - - const handleDelete = (code: number) => { - if (variables.tableData.length === 1 && variables.page > 1) { - variables.page -= 1 - } - const data: ProjectParameterCodeReq = { - code: code - } - deleteProjectParameterByCode(data, variables.projectCode).then(() => { - window.$message.success(t('project.parameter.success')) - getTableData({ - pageSize: variables.pageSize, - pageNo: variables.page, - searchVal: variables.searchVal - }) - }) - } - - return { - variables, - createColumns, - getTableData - } -} diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/format-data.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/format-data.ts index e7e1ef95e632..8afb79294e34 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/format-data.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/format-data.ts @@ -556,9 +556,6 @@ export function formatParams(data: INodeData): { } export function formatModel(data: ITaskData) { - - console.log('formatModel') - console.log(data) const params = { ...omit(data, [ 'environmentCode', @@ -743,7 +740,5 @@ export function formatModel(data: ITaskData) { if (data.taskParams?.jobType) { params.isCustomTask = data.taskParams.jobType === 'CUSTOM' } - - console.log(params) return params } From 8ccfcd49959349b432731bc7b1e0c6edb9980113 Mon Sep 17 00:00:00 2001 From: calvin Date: Mon, 17 Jul 2023 20:09:50 +0800 Subject: [PATCH 07/11] add a few codes about the project preferences --- .../src/components/form/use-form.ts | 2 - .../src/locales/en_US/project.ts | 1 + .../src/locales/zh_CN/project.ts | 1 + .../preference/components/use-alert-group.ts | 47 +++++++++++++++++++ .../preference/components/use-tenant.ts | 46 ++++++++++++++++++ .../preference/components/use-warning-type.ts | 46 ++++++++++++++++++ .../src/views/projects/preference/detail.tsx | 4 +- .../src/views/projects/preference/use-form.ts | 44 ++++++++++++----- .../task/components/node/detail-modal.tsx | 26 ++++++---- .../task/components/node/format-data.ts | 1 + .../definition/components/timing-modal.tsx | 18 +++++++ 11 files changed, 214 insertions(+), 22 deletions(-) create mode 100644 dolphinscheduler-ui/src/views/projects/preference/components/use-alert-group.ts create mode 100644 dolphinscheduler-ui/src/views/projects/preference/components/use-tenant.ts create mode 100644 dolphinscheduler-ui/src/views/projects/preference/components/use-warning-type.ts diff --git a/dolphinscheduler-ui/src/components/form/use-form.ts b/dolphinscheduler-ui/src/components/form/use-form.ts index 29cc5b2576ba..c28b5963183a 100644 --- a/dolphinscheduler-ui/src/components/form/use-form.ts +++ b/dolphinscheduler-ui/src/components/form/use-form.ts @@ -33,12 +33,10 @@ export function useForm() { delete state.formRef.model[key] } } - setValues(initialValues) } const setValues = (initialValues: { [field: string]: any }) => { - console.log(initialValues) for (const [key, value] of Object.entries(initialValues)) { state.formRef.model[key] = value } diff --git a/dolphinscheduler-ui/src/locales/en_US/project.ts b/dolphinscheduler-ui/src/locales/en_US/project.ts index 752723475322..3ca1eb7c28be 100644 --- a/dolphinscheduler-ui/src/locales/en_US/project.ts +++ b/dolphinscheduler-ui/src/locales/en_US/project.ts @@ -892,6 +892,7 @@ export default { preference: { edit_preference: 'Edit Preference', preference_manage: 'Project Preference Management', + instruction_tips: 'The settings below will affect all workflows and tasks under this project.When creating the workflow or task, these preferences will be the default value of their components.', success: 'Success', submit: 'Submit' }, diff --git a/dolphinscheduler-ui/src/locales/zh_CN/project.ts b/dolphinscheduler-ui/src/locales/zh_CN/project.ts index 236935d2110d..ca4816f516d3 100644 --- a/dolphinscheduler-ui/src/locales/zh_CN/project.ts +++ b/dolphinscheduler-ui/src/locales/zh_CN/project.ts @@ -866,6 +866,7 @@ export default { preference: { edit_preference: '修改项目偏好设置', preference_manage: '项目偏好管理', + instruction_tips: '下面这些项目偏好配置将影响这个项目下的所有工作流和任务。当创建工作流和任务时,这些配置将影响组件中的默认选项', success: '成功', submit: '提交' }, diff --git a/dolphinscheduler-ui/src/views/projects/preference/components/use-alert-group.ts b/dolphinscheduler-ui/src/views/projects/preference/components/use-alert-group.ts new file mode 100644 index 000000000000..b207a0f91172 --- /dev/null +++ b/dolphinscheduler-ui/src/views/projects/preference/components/use-alert-group.ts @@ -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 { ref, onMounted } from 'vue' +import { useI18n } from 'vue-i18n' +import type { IJsonItem } from '../../task/components/node/types' +import {queryTenantList} from "@/service/modules/tenants"; +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: 8, + name: t('project.workflow.alarm_group'), + options: options, + value: 'default' + } +} diff --git a/dolphinscheduler-ui/src/views/projects/preference/components/use-tenant.ts b/dolphinscheduler-ui/src/views/projects/preference/components/use-tenant.ts new file mode 100644 index 000000000000..211dba114f5a --- /dev/null +++ b/dolphinscheduler-ui/src/views/projects/preference/components/use-tenant.ts @@ -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 { 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() + console.log(res) + options.value = res.map((item: any) => ({ label: item.tenantCode, value: item.tenantCode })) + } + + onMounted(() => { + getTenantList() + }) + + return { + type: 'select', + field: 'tenant', + span: 8, + name: t('project.workflow.tenant_code'), + options: options, + value: 'default' + } +} diff --git a/dolphinscheduler-ui/src/views/projects/preference/components/use-warning-type.ts b/dolphinscheduler-ui/src/views/projects/preference/components/use-warning-type.ts new file mode 100644 index 000000000000..7ccad2350c8c --- /dev/null +++ b/dolphinscheduler-ui/src/views/projects/preference/components/use-warning-type.ts @@ -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: 8, + options, + validate: { + required: true + }, + value: 'NONE' + } +} \ No newline at end of file diff --git a/dolphinscheduler-ui/src/views/projects/preference/detail.tsx b/dolphinscheduler-ui/src/views/projects/preference/detail.tsx index 2ac2a40caf34..064ce4f1de45 100644 --- a/dolphinscheduler-ui/src/views/projects/preference/detail.tsx +++ b/dolphinscheduler-ui/src/views/projects/preference/detail.tsx @@ -28,6 +28,7 @@ const PreferenceForm = defineComponent({ return () => (
+
{t('project.preference.instruction_tips')}
diff --git a/dolphinscheduler-ui/src/views/projects/preference/use-form.ts b/dolphinscheduler-ui/src/views/projects/preference/use-form.ts index 4ea6eadb848a..5a588eeacbac 100644 --- a/dolphinscheduler-ui/src/views/projects/preference/use-form.ts +++ b/dolphinscheduler-ui/src/views/projects/preference/use-form.ts @@ -28,7 +28,10 @@ import { updateProjectPreference } from "@/service/modules/projects-preference"; import {useI18n} from "vue-i18n"; -import { UpdateProjectPreferenceReq, ProjectPreferenceRes } from "@/service/modules/projects-preference/types"; +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() { @@ -51,10 +54,16 @@ export function useForm() { const data = reactive({ model: { + taskPriority: 'MEDIUM', workerGroup: 'default', environmentCode: null, + failRetryTimes: 0, failRetryInterval: 1, - failRetryTimes: 0 + cpuQuota: -1, + memoryMax: -1, + timeoutFlag: false, + timeoutNotifyStrategy: ['WARN'], + timeout: 30 } as INodeData }) @@ -79,26 +88,39 @@ export function useForm() { const requestData = { projectPreferences: JSON.stringify(data.model) } as UpdateProjectPreferenceReq - updateProjectPreference(requestData, projectCode) + updateProjectPreference(requestData, projectCode).then(() => { + window.$message.success(t('project.preference.success')) + }) } const preferencesItems: IJsonItem[] = [ + Fields.useTaskPriority(), Fields.useWorkerGroup(), + Fields.useEnvironmentName(data.model, true), + ...Fields.useFailed(), + ...Fields.useResourceLimit(), + Fields.useDelayTime(data.model), + ...Fields.useTimeoutAlarm(data.model), + useWarningType(), + useTenant(), + useAlertGroup(), ] - jsonRef.value = preferencesItems + const restructurePreferencesItems = (preferencesItems: any) => { + for (let item of preferencesItems) { + if (item.validate?.required) { + item.validate.required = false + } + } + return preferencesItems + } + + jsonRef.value = restructurePreferencesItems(preferencesItems) const getElements = () => { const { rules, elements } = getElementByJson(jsonRef.value, data.model) - if (rules) { - for (let key in rules) { - rules[key].required = false - } - } elementsRef.value = elements rulesRef.value = rules - console.log('elements') - console.log(rules) } getElements() diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/detail-modal.tsx b/dolphinscheduler-ui/src/views/projects/task/components/node/detail-modal.tsx index 6067f531d7c4..b8378bce5009 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/detail-modal.tsx +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/detail-modal.tsx @@ -24,7 +24,7 @@ import { provide, computed, h, - Ref + Ref, onMounted } from 'vue' import { useI18n } from 'vue-i18n' import Modal from '@/components/modal' @@ -48,6 +48,8 @@ import type { IWorkflowTaskInstance, WorkflowInstance } from './types' +import {queryProjectPreferenceByProjectCode} from "@/service/modules/projects-preference"; +import {INodeData} from "./types"; const props = { show: { @@ -109,6 +111,7 @@ const NodeDetailModal = defineComponent({ } const headerLinks = ref([] as any) + const projectPreferences = ref({} as any) const handleViewLog = () => { if (props.taskInstance) { @@ -116,13 +119,14 @@ const NodeDetailModal = defineComponent({ } } - const initProjectPreferences = (projectCode: number, data: ITaskData) => { - console.log('initProjectPreferences') - console.log(projectCode) - console.log(data) + const initProjectPreferences = (projectCode: number) => { + queryProjectPreferenceByProjectCode(projectCode).then((result: any) => { + if (result?.preferences) { + projectPreferences.value = JSON.parse(result.preferences) + } + }) } - const initHeaderLinks = (processInstance: any, taskType?: ITaskType) => { headerLinks.value = [ { @@ -211,15 +215,21 @@ const NodeDetailModal = defineComponent({ })) ) + onMounted(() => { + initProjectPreferences(props.projectCode) + }) + + watch( () => [props.show, props.data], async () => { if (!props.show) return initHeaderLinks(props.processInstance, props.data.taskType) taskStore.init() + const nodeData = formatModel(props.data) + Object.assign(nodeData, projectPreferences.value) await nextTick() - initProjectPreferences(props.projectCode, props.data) - detailRef.value.value.setValues(formatModel(props.data)) + detailRef.value.value.setValues(nodeData) } ) diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/format-data.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/format-data.ts index 8afb79294e34..6dcca179e234 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/format-data.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/format-data.ts @@ -740,5 +740,6 @@ export function formatModel(data: ITaskData) { if (data.taskParams?.jobType) { params.isCustomTask = data.taskParams.jobType === 'CUSTOM' } + return params } diff --git a/dolphinscheduler-ui/src/views/projects/workflow/definition/components/timing-modal.tsx b/dolphinscheduler-ui/src/views/projects/workflow/definition/components/timing-modal.tsx index 6a112ba5b721..c87b8b5c6c41 100644 --- a/dolphinscheduler-ui/src/views/projects/workflow/definition/components/timing-modal.tsx +++ b/dolphinscheduler-ui/src/views/projects/workflow/definition/components/timing-modal.tsx @@ -47,9 +47,11 @@ import { NThing, NPopover } from 'naive-ui' +import { Router, useRouter } from "vue-router"; import { ArrowDownOutlined, ArrowUpOutlined } from '@vicons/antd' import { timezoneList } from '@/common/timezone' import Crontab from '@/components/crontab' +import {queryProjectPreferenceByProjectCode} from "@/service/modules/projects-preference" const props = { row: { @@ -74,6 +76,8 @@ export default defineComponent({ const crontabRef = ref() const parallelismRef = ref(false) const { t } = useI18n() + const router: Router = useRouter() + const { timingState } = useForm() const { variables, @@ -86,12 +90,25 @@ export default defineComponent({ getPreviewSchedule } = useModal(timingState, ctx) + const projectCode = Number(router.currentRoute.value.params.projectCode) + const environmentOptions = computed(() => variables.environmentList.filter((item: any) => item.workerGroups?.includes(timingState.timingForm.workerGroup) ) ) + const projectPreferences = ref({} as any) + + const initProjectPreferences = (projectCode: number) => { + queryProjectPreferenceByProjectCode(projectCode).then((result: any) => { + if (result?.preferences) { + projectPreferences.value = JSON.parse(result.preferences) + } + }) + } + + const hideModal = () => { ctx.emit('update:show') } @@ -193,6 +210,7 @@ export default defineComponent({ getTenantList() getAlertGroups() getEnvironmentList() + initProjectPreferences(projectCode) }) watch( From d573f2dab827b390d201c6a7e57cb4dc0e37d07f Mon Sep 17 00:00:00 2001 From: calvin Date: Tue, 18 Jul 2023 16:19:10 +0800 Subject: [PATCH 08/11] add a few codes about the project preferences --- .../preference/components/use-alert-group.ts | 12 +- .../preference/components/use-tenant.ts | 10 +- .../preference/components/use-warning-type.ts | 10 +- .../src/views/projects/preference/detail.tsx | 61 +++++----- .../src/views/projects/preference/index.tsx | 7 +- .../src/views/projects/preference/use-form.ts | 39 ++++--- .../task/components/node/detail-modal.tsx | 20 +++- .../definition/components/timing-modal.tsx | 104 +++++++++++++++--- 8 files changed, 178 insertions(+), 85 deletions(-) diff --git a/dolphinscheduler-ui/src/views/projects/preference/components/use-alert-group.ts b/dolphinscheduler-ui/src/views/projects/preference/components/use-alert-group.ts index b207a0f91172..bf7170f5b758 100644 --- a/dolphinscheduler-ui/src/views/projects/preference/components/use-alert-group.ts +++ b/dolphinscheduler-ui/src/views/projects/preference/components/use-alert-group.ts @@ -18,8 +18,8 @@ import { ref, onMounted } from 'vue' import { useI18n } from 'vue-i18n' import type { IJsonItem } from '../../task/components/node/types' -import {queryTenantList} from "@/service/modules/tenants"; -import {listAlertGroupById} from "@/service/modules/alert-group"; +import { queryTenantList } from '@/service/modules/tenants' +import { listAlertGroupById } from '@/service/modules/alert-group' export function useAlertGroup(): IJsonItem { const { t } = useI18n() @@ -28,10 +28,12 @@ export function useAlertGroup(): IJsonItem { const getAlertGroups = async () => { const res = await listAlertGroupById() - options.value = res.map((item: any) => ({ label: item.groupName, value: item.id })) + options.value = res.map((item: any) => ({ + label: item.groupName, + value: item.id + })) } - onMounted(() => { getAlertGroups() }) @@ -39,7 +41,7 @@ export function useAlertGroup(): IJsonItem { return { type: 'select', field: 'alertGroups', - span: 8, + span: 12, name: t('project.workflow.alarm_group'), options: options, value: 'default' diff --git a/dolphinscheduler-ui/src/views/projects/preference/components/use-tenant.ts b/dolphinscheduler-ui/src/views/projects/preference/components/use-tenant.ts index 211dba114f5a..1bc2fac997e3 100644 --- a/dolphinscheduler-ui/src/views/projects/preference/components/use-tenant.ts +++ b/dolphinscheduler-ui/src/views/projects/preference/components/use-tenant.ts @@ -18,7 +18,7 @@ import { ref, onMounted } from 'vue' import { useI18n } from 'vue-i18n' import type { IJsonItem } from '../../task/components/node/types' -import {queryTenantList} from "@/service/modules/tenants"; +import { queryTenantList } from '@/service/modules/tenants' export function useTenant(): IJsonItem { const { t } = useI18n() @@ -27,8 +27,10 @@ export function useTenant(): IJsonItem { const getTenantList = async () => { const res = await queryTenantList() - console.log(res) - options.value = res.map((item: any) => ({ label: item.tenantCode, value: item.tenantCode })) + options.value = res.map((item: any) => ({ + label: item.tenantCode, + value: item.tenantCode + })) } onMounted(() => { @@ -38,7 +40,7 @@ export function useTenant(): IJsonItem { return { type: 'select', field: 'tenant', - span: 8, + span: 12, name: t('project.workflow.tenant_code'), options: options, value: 'default' diff --git a/dolphinscheduler-ui/src/views/projects/preference/components/use-warning-type.ts b/dolphinscheduler-ui/src/views/projects/preference/components/use-warning-type.ts index 7ccad2350c8c..3fe7e5903fac 100644 --- a/dolphinscheduler-ui/src/views/projects/preference/components/use-warning-type.ts +++ b/dolphinscheduler-ui/src/views/projects/preference/components/use-warning-type.ts @@ -17,7 +17,7 @@ import { useI18n } from 'vue-i18n' import type { IJsonItem } from '../../task/components/node/types' -import { warningTypeList } from "@/common/common"; +import { warningTypeList } from '@/common/common' export function useWarningType(): IJsonItem { const { t } = useI18n() @@ -25,8 +25,8 @@ export function useWarningType(): IJsonItem { const options = [] as any const initOptions = () => { - warningTypeList.forEach(item => { - options.push({label: t(item.code), value: item.id}) + warningTypeList.forEach((item) => { + options.push({ label: t(item.code), value: item.id }) }) } @@ -36,11 +36,11 @@ export function useWarningType(): IJsonItem { type: 'select', field: 'warningType', name: t('project.workflow.notification_strategy'), - span: 8, + span: 12, options, validate: { required: true }, value: 'NONE' } -} \ No newline at end of file +} diff --git a/dolphinscheduler-ui/src/views/projects/preference/detail.tsx b/dolphinscheduler-ui/src/views/projects/preference/detail.tsx index 064ce4f1de45..41eafb065f12 100644 --- a/dolphinscheduler-ui/src/views/projects/preference/detail.tsx +++ b/dolphinscheduler-ui/src/views/projects/preference/detail.tsx @@ -18,40 +18,47 @@ import { defineComponent, ref } from 'vue' import Form from '@/components/form' import { useForm } from './use-form' -import { NButton, NSpace } from "naive-ui"; +import { NButton, NDivider, NSpace } from 'naive-ui' const PreferenceForm = defineComponent({ name: 'PreferenceForm', setup() { - - const { formRef, elementsRef, rulesRef, model, formProps, t, handleUpdate } = useForm() + const { + formRef, + elementsRef, + rulesRef, + model, + formProps, + t, + handleUpdate + } = useForm() return () => ( -
-
{t('project.preference.instruction_tips')}
- - - - {t('project.preference.submit')} - - +
+
+ {t('project.preference.instruction_tips')}
+ + + + + + {t('project.preference.submit')} + + +
) } }) diff --git a/dolphinscheduler-ui/src/views/projects/preference/index.tsx b/dolphinscheduler-ui/src/views/projects/preference/index.tsx index ae61ad8748a4..e772bd95fa6b 100644 --- a/dolphinscheduler-ui/src/views/projects/preference/index.tsx +++ b/dolphinscheduler-ui/src/views/projects/preference/index.tsx @@ -19,12 +19,11 @@ 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"; +import PreferenceForm from '@/views/projects/preference/detail' export default defineComponent({ name: 'ProjectPreference', setup() { - const detailRef = ref() return { @@ -39,9 +38,7 @@ export default defineComponent({ - + diff --git a/dolphinscheduler-ui/src/views/projects/preference/use-form.ts b/dolphinscheduler-ui/src/views/projects/preference/use-form.ts index 5a588eeacbac..00c1e6a59dc6 100644 --- a/dolphinscheduler-ui/src/views/projects/preference/use-form.ts +++ b/dolphinscheduler-ui/src/views/projects/preference/use-form.ts @@ -14,27 +14,26 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {onMounted, reactive, ref, Ref, unref} from 'vue' +import { onMounted, reactive, ref, Ref, unref } from 'vue' import getElementByJson from '@/components/form/get-elements-by-json' import type { IFormItem, IJsonItem, - INodeData, + INodeData } from '../task/components/node/types' -import * as Fields from "@/views/projects/task/components/node/fields"; -import { Router, useRouter } from "vue-router"; +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"; +} 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() @@ -95,22 +94,22 @@ export function useForm() { const preferencesItems: IJsonItem[] = [ Fields.useTaskPriority(), + useTenant(), Fields.useWorkerGroup(), Fields.useEnvironmentName(data.model, true), ...Fields.useFailed(), - ...Fields.useResourceLimit(), - Fields.useDelayTime(data.model), - ...Fields.useTimeoutAlarm(data.model), useWarningType(), - useTenant(), 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 } @@ -125,5 +124,13 @@ export function useForm() { getElements() - return { formRef, elementsRef, rulesRef, model: data.model, formProps, t, handleUpdate } + return { + formRef, + elementsRef, + rulesRef, + model: data.model, + formProps, + t, + handleUpdate + } } diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/detail-modal.tsx b/dolphinscheduler-ui/src/views/projects/task/components/node/detail-modal.tsx index b8378bce5009..570b4c421183 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/detail-modal.tsx +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/detail-modal.tsx @@ -24,7 +24,8 @@ import { provide, computed, h, - Ref, onMounted + Ref, + onMounted } from 'vue' import { useI18n } from 'vue-i18n' import Modal from '@/components/modal' @@ -48,8 +49,8 @@ import type { IWorkflowTaskInstance, WorkflowInstance } from './types' -import {queryProjectPreferenceByProjectCode} from "@/service/modules/projects-preference"; -import {INodeData} from "./types"; +import { queryProjectPreferenceByProjectCode } from '@/service/modules/projects-preference' +import { INodeData } from './types' const props = { show: { @@ -127,6 +128,12 @@ const NodeDetailModal = defineComponent({ }) } + const restructureNodeData = (data: INodeData) => { + if (!data?.id) { + Object.assign(data, projectPreferences.value) + } + } + const initHeaderLinks = (processInstance: any, taskType?: ITaskType) => { headerLinks.value = [ { @@ -169,7 +176,9 @@ const NodeDetailModal = defineComponent({ }, { text: t('project.node.enter_this_child_node'), - show: props.data.taskType === 'SUB_PROCESS' || props.data.taskType === 'DYNAMIC', + show: + props.data.taskType === 'SUB_PROCESS' || + props.data.taskType === 'DYNAMIC', disabled: !props.data.id || (router.currentRoute.value.name === 'workflow-instance-detail' && @@ -219,7 +228,6 @@ const NodeDetailModal = defineComponent({ initProjectPreferences(props.projectCode) }) - watch( () => [props.show, props.data], async () => { @@ -227,8 +235,8 @@ const NodeDetailModal = defineComponent({ initHeaderLinks(props.processInstance, props.data.taskType) taskStore.init() const nodeData = formatModel(props.data) - Object.assign(nodeData, projectPreferences.value) await nextTick() + restructureNodeData(nodeData) detailRef.value.value.setValues(nodeData) } ) diff --git a/dolphinscheduler-ui/src/views/projects/workflow/definition/components/timing-modal.tsx b/dolphinscheduler-ui/src/views/projects/workflow/definition/components/timing-modal.tsx index c87b8b5c6c41..17b2dc56f720 100644 --- a/dolphinscheduler-ui/src/views/projects/workflow/definition/components/timing-modal.tsx +++ b/dolphinscheduler-ui/src/views/projects/workflow/definition/components/timing-modal.tsx @@ -47,11 +47,11 @@ import { NThing, NPopover } from 'naive-ui' -import { Router, useRouter } from "vue-router"; +import { Router, useRouter } from 'vue-router' import { ArrowDownOutlined, ArrowUpOutlined } from '@vicons/antd' import { timezoneList } from '@/common/timezone' import Crontab from '@/components/crontab' -import {queryProjectPreferenceByProjectCode} from "@/service/modules/projects-preference" +import { queryProjectPreferenceByProjectCode } from '@/service/modules/projects-preference' const props = { row: { @@ -108,7 +108,6 @@ export default defineComponent({ }) } - const hideModal = () => { ctx.emit('update:show') } @@ -203,6 +202,71 @@ export default defineComponent({ }) } + const containValueInOptions = ( + options: Array, + findingValue: string + ): boolean => { + for (let { value } of options) { + if (findingValue === value) { + return true + } + } + return false + } + + const restructureTimingForm = (timingForm: any) => { + if (projectPreferences.value?.taskPriority) { + timingForm.processInstancePriority = + projectPreferences.value.taskPriority + } + if (projectPreferences.value?.warningType) { + timingForm.warningType = projectPreferences.value.warningType + } + if (projectPreferences.value?.workerGroup) { + if ( + containValueInOptions( + variables.workerGroups, + projectPreferences.value.workerGroup + ) + ) { + timingForm.workerGroup = projectPreferences.value.workerGroup + } + } + if (projectPreferences.value?.tenant) { + if ( + containValueInOptions( + variables.tenantList, + projectPreferences.value.tenant + ) + ) { + timingForm.tenantCode = projectPreferences.value.tenant + } + } + if ( + projectPreferences.value?.environmentCode && + variables?.environmentList + ) { + if ( + containValueInOptions( + variables.environmentList, + projectPreferences.value.environmentCode + ) + ) { + timingForm.environmentCode = projectPreferences.value.environmentCode + } + } + if (projectPreferences.value?.alertGroup && variables?.alertGroups) { + if ( + containValueInOptions( + variables.alertGroups, + projectPreferences.value.alertGroup + ) + ) { + timingForm.warningGroupId = projectPreferences.value.alertGroup + } + } + } + const trim = getCurrentInstance()?.appContext.config.globalProperties.trim onMounted(() => { @@ -216,7 +280,10 @@ export default defineComponent({ watch( () => props.row, () => { - if (!props.row.crontab) return + if (!props.row.crontab) { + restructureTimingForm(timingState.timingForm) + return + } timingState.timingForm.startEndTime = [ new Date(props.row.startTime), @@ -316,19 +383,22 @@ export default defineComponent({ - {this.schedulePreviewList.length > 0 ? - - - {this.schedulePreviewList.map((item: string) => ( - - {item} -
-
- ))} -
-
: null} + {this.schedulePreviewList.length > 0 ? ( + + + {this.schedulePreviewList.map((item: string) => ( + + {item} +
+
+ ))} +
+
+ ) : null}
Date: Tue, 18 Jul 2023 17:23:45 +0800 Subject: [PATCH 09/11] use spotless --- .../ProjectPreferenceController.java | 22 ++++++----- .../impl/ProjectPreferenceServiceImpl.java | 39 +++++++------------ .../ProjectPreferenceControllerTest.java | 4 +- .../service/ProjectPreferenceServiceTest.java | 3 +- .../dao/entity/ProjectPreference.java | 10 +++-- .../dao/mapper/ProjectPreferenceMapper.java | 3 +- .../mapper/ProjectPreferenceMapperTest.java | 12 +++--- 7 files changed, 46 insertions(+), 47 deletions(-) diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectPreferenceController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectPreferenceController.java index 093b92220f1a..b5422b245597 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectPreferenceController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectPreferenceController.java @@ -17,22 +17,18 @@ package org.apache.dolphinscheduler.api.controller; -import static org.apache.dolphinscheduler.api.enums.Status.CREATE_PROJECT_PREFERENCE_ERROR; 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 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; -import lombok.extern.slf4j.Slf4j; 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; @@ -44,6 +40,12 @@ 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") @@ -62,8 +64,8 @@ public class ProjectPreferenceController extends BaseController { @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) { + @Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @RequestParam(value = "projectPreferences", required = true) String projectPreferences) { return projectPreferenceService.updateProjectPreference(loginUser, projectCode, projectPreferences); } @@ -73,7 +75,7 @@ public Result updateProjectPreference(@Parameter(hidden = true) @RequestAttribut @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) { + @Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode) { return projectPreferenceService.queryProjectPreferenceByProjectCode(loginUser, projectCode); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectPreferenceServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectPreferenceServiceImpl.java index a204a8262294..4005b8a6dc74 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectPreferenceServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectPreferenceServiceImpl.java @@ -19,43 +19,32 @@ import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.PROJECT; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.google.common.collect.Lists; -import java.util.Date; -import java.util.List; -import java.util.Objects; -import java.util.Set; -import java.util.stream.Collectors; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; import org.apache.dolphinscheduler.api.enums.Status; -import org.apache.dolphinscheduler.api.exceptions.ServiceException; -import org.apache.dolphinscheduler.api.service.ProjectParameterService; import org.apache.dolphinscheduler.api.service.ProjectPreferenceService; import org.apache.dolphinscheduler.api.service.ProjectService; -import org.apache.dolphinscheduler.api.utils.PageInfo; import org.apache.dolphinscheduler.api.utils.Result; -import org.apache.dolphinscheduler.common.constants.Constants; import org.apache.dolphinscheduler.common.utils.CodeGenerateUtils; -import org.apache.dolphinscheduler.common.utils.DateUtils; import org.apache.dolphinscheduler.dao.entity.Project; -import org.apache.dolphinscheduler.dao.entity.ProjectParameter; 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.ProjectParameterMapper; 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 org.springframework.transaction.annotation.Transactional; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @Service @Slf4j -public class ProjectPreferenceServiceImpl extends BaseServiceImpl implements - ProjectPreferenceService { +public class ProjectPreferenceServiceImpl extends BaseServiceImpl + implements + ProjectPreferenceService { @Autowired private ProjectPreferenceMapper projectPreferenceMapper; @@ -78,7 +67,8 @@ public Result updateProjectPreference(User loginUser, long projectCode, String p } ProjectPreference projectPreference = projectPreferenceMapper - .selectOne(new QueryWrapper().lambda().eq(ProjectPreference::getProjectCode, projectCode)); + .selectOne(new QueryWrapper().lambda().eq(ProjectPreference::getProjectCode, + projectCode)); Date now = new Date(); if (Objects.isNull(projectPreference)) { @@ -125,7 +115,8 @@ public Result queryProjectPreferenceByProjectCode(User loginUser, long projectCo } ProjectPreference projectPreference = projectPreferenceMapper - .selectOne(new QueryWrapper().lambda().eq(ProjectPreference::getProjectCode, projectCode)); + .selectOne(new QueryWrapper().lambda().eq(ProjectPreference::getProjectCode, + projectCode)); if (Objects.nonNull(projectPreference)) { result.setData(projectPreference); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProjectPreferenceControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProjectPreferenceControllerTest.java index 8e060075901b..65ec4b342f0a 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProjectPreferenceControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProjectPreferenceControllerTest.java @@ -22,6 +22,7 @@ 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; @@ -42,7 +43,6 @@ public class ProjectPreferenceControllerTest { @Mock private ProjectPreferenceServiceImpl projectPreferenceService; - @Test public void testUpdateProjectPreference() { User loginUser = getGeneralUser(); @@ -59,7 +59,7 @@ public void testQueryProjectPreferenceByProjectCode() { User loginUser = getGeneralUser(); Mockito.when(projectPreferenceService.queryProjectPreferenceByProjectCode(Mockito.any(), Mockito.anyLong())) - .thenReturn(getSuccessResult()); + .thenReturn(getSuccessResult()); Result result = projectPreferenceController.queryProjectPreferenceByProjectCode(loginUser, 1); Assertions.assertEquals(Status.SUCCESS.getCode(), result.getCode()); } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectPreferenceServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectPreferenceServiceTest.java index f2ae9661a2c5..7c6c4c13611d 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectPreferenceServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectPreferenceServiceTest.java @@ -27,6 +27,7 @@ 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; @@ -66,7 +67,7 @@ public void testUpdateProjectPreference() { Mockito.when(projectPreferenceMapper.selectOne(Mockito.any())).thenReturn(null); Mockito.when(projectPreferenceMapper.insert(Mockito.any())).thenReturn(1); - Result result = projectPreferenceService.updateProjectPreference(loginUser, projectCode, "value"); + Result result = projectPreferenceService.updateProjectPreference(loginUser, projectCode, "value"); Assertions.assertEquals(Status.SUCCESS.getCode(), result.getCode()); } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProjectPreference.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProjectPreference.java index 755d90476654..beddabdcc603 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProjectPreference.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProjectPreference.java @@ -17,16 +17,18 @@ package org.apache.dolphinscheduler.dao.entity; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; 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 diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProjectPreferenceMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProjectPreferenceMapper.java index b2d73dc358a4..44f5709b4698 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProjectPreferenceMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProjectPreferenceMapper.java @@ -17,9 +17,10 @@ package org.apache.dolphinscheduler.dao.mapper; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.dolphinscheduler.dao.entity.ProjectPreference; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + public interface ProjectPreferenceMapper extends BaseMapper { } diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProjectPreferenceMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProjectPreferenceMapperTest.java index 3fe8962cb5ff..eea7fa2aa811 100644 --- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProjectPreferenceMapperTest.java +++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProjectPreferenceMapperTest.java @@ -17,20 +17,22 @@ package org.apache.dolphinscheduler.dao.mapper; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import java.util.Date; 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); @@ -52,14 +54,14 @@ public void testUpdate() { Assertions.assertEquals(1, update); } - @Test public void testQueryByProjectCode() { long projectCode = 2; ProjectPreference expectedProjectPreference = insertOne(2, projectCode); ProjectPreference projectPreference = projectPreferenceMapper - .selectOne(new QueryWrapper().lambda().eq(ProjectPreference::getProjectCode, projectCode)); + .selectOne(new QueryWrapper().lambda().eq(ProjectPreference::getProjectCode, + projectCode)); Assertions.assertEquals(expectedProjectPreference, projectPreference); } From eafeccaabaa0353807cfc2391f26657f77147739 Mon Sep 17 00:00:00 2001 From: calvin Date: Tue, 18 Jul 2023 19:39:23 +0800 Subject: [PATCH 10/11] fix a few unused variables --- .../src/views/projects/preference/components/use-alert-group.ts | 1 - dolphinscheduler-ui/src/views/projects/preference/detail.tsx | 2 +- dolphinscheduler-ui/src/views/projects/preference/use-form.ts | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/dolphinscheduler-ui/src/views/projects/preference/components/use-alert-group.ts b/dolphinscheduler-ui/src/views/projects/preference/components/use-alert-group.ts index bf7170f5b758..cbe469dbf0d1 100644 --- a/dolphinscheduler-ui/src/views/projects/preference/components/use-alert-group.ts +++ b/dolphinscheduler-ui/src/views/projects/preference/components/use-alert-group.ts @@ -18,7 +18,6 @@ import { ref, onMounted } from 'vue' import { useI18n } from 'vue-i18n' import type { IJsonItem } from '../../task/components/node/types' -import { queryTenantList } from '@/service/modules/tenants' import { listAlertGroupById } from '@/service/modules/alert-group' export function useAlertGroup(): IJsonItem { diff --git a/dolphinscheduler-ui/src/views/projects/preference/detail.tsx b/dolphinscheduler-ui/src/views/projects/preference/detail.tsx index 41eafb065f12..6d2cc9b050e2 100644 --- a/dolphinscheduler-ui/src/views/projects/preference/detail.tsx +++ b/dolphinscheduler-ui/src/views/projects/preference/detail.tsx @@ -15,7 +15,7 @@ * limitations under the License. */ -import { defineComponent, ref } from 'vue' +import { defineComponent } from 'vue' import Form from '@/components/form' import { useForm } from './use-form' import { NButton, NDivider, NSpace } from 'naive-ui' diff --git a/dolphinscheduler-ui/src/views/projects/preference/use-form.ts b/dolphinscheduler-ui/src/views/projects/preference/use-form.ts index 00c1e6a59dc6..6773091ea9d4 100644 --- a/dolphinscheduler-ui/src/views/projects/preference/use-form.ts +++ b/dolphinscheduler-ui/src/views/projects/preference/use-form.ts @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { onMounted, reactive, ref, Ref, unref } from 'vue' +import { onMounted, reactive, ref, Ref } from 'vue' import getElementByJson from '@/components/form/get-elements-by-json' import type { IFormItem, From cc0687defb9724169b5674a39b7ee719d9811ede Mon Sep 17 00:00:00 2001 From: calvin Date: Wed, 19 Jul 2023 11:32:41 +0800 Subject: [PATCH 11/11] adjust a few codes --- .../api/service/impl/ProjectPreferenceServiceImpl.java | 7 +++---- .../api/service/ProjectPreferenceServiceTest.java | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectPreferenceServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectPreferenceServiceImpl.java index 4005b8a6dc74..7f4da3c8ce4f 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectPreferenceServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectPreferenceServiceImpl.java @@ -98,7 +98,7 @@ public Result updateProjectPreference(User loginUser, long projectCode, String p putMsg(result, Status.SUCCESS); } else { log.error("Project preference update error, projectCode:{}.", projectPreference.getProjectCode()); - putMsg(result, Status.CREATE_PROJECT_PREFERENCE_ERROR); + putMsg(result, Status.UPDATE_PROJECT_PREFERENCE_ERROR); } } return result; @@ -118,9 +118,8 @@ public Result queryProjectPreferenceByProjectCode(User loginUser, long projectCo .selectOne(new QueryWrapper().lambda().eq(ProjectPreference::getProjectCode, projectCode)); - if (Objects.nonNull(projectPreference)) { - result.setData(projectPreference); - } + result.setData(projectPreference); + putMsg(result, Status.SUCCESS); return result; } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectPreferenceServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectPreferenceServiceTest.java index 7c6c4c13611d..0c89e254d108 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectPreferenceServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectPreferenceServiceTest.java @@ -82,7 +82,7 @@ public void testQueryProjectPreferenceByProjectCode() { Mockito.when(projectPreferenceMapper.selectOne(Mockito.any())).thenReturn(null); Result result = projectPreferenceService.queryProjectPreferenceByProjectCode(loginUser, projectCode); - Assertions.assertEquals(Status.QUERY_PROJECT_PREFERENCE_ERROR.getCode(), result.getCode()); + Assertions.assertEquals(Status.SUCCESS.getCode(), result.getCode()); // SUCCESS Mockito.when(projectPreferenceMapper.selectOne(Mockito.any())).thenReturn(getProjectPreference());