From e4dcf3d2e0b96c024036bea3aa4c531fc8434dfb Mon Sep 17 00:00:00 2001 From: calvin Date: Tue, 15 Mar 2022 09:35:14 +0800 Subject: [PATCH] [Fix-8836][UI Next][V1.0.0-Alpha] Rectify this issue about creating a file or directory with a wrong path. (#8880) * fix this issue * fix this issue --- .../api/controller/ResourcesController.java | 22 ++++++++++ .../api/service/ResourcesService.java | 7 +++ .../service/impl/ResourcesServiceImpl.java | 18 ++++++++ .../components/timezone/index.module.scss | 2 +- .../src/service/modules/resources/index.ts | 7 +++ .../src/service/modules/resources/types.ts | 3 +- .../definition/components/use-modal.ts | 44 +++++++++---------- .../views/resource/file/folder/use-folder.ts | 6 +-- .../src/views/resource/file/index.tsx | 19 +++++++- 9 files changed, 100 insertions(+), 28 deletions(-) diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ResourcesController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ResourcesController.java index 0073ad0048..2ba0bc97fd 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ResourcesController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ResourcesController.java @@ -748,4 +748,26 @@ public class ResourcesController extends BaseController { Map result = resourceService.authorizedUDFFunction(loginUser, userId); return returnDataList(result); } + + /** + * query resource by resource id + * + * @param loginUser login user + * @param id resource id + * @return resource + */ + @ApiOperation(value = "queryResourceById", notes = "QUERY_BY_RESOURCE_NAME") + @ApiImplicitParams({ + @ApiImplicitParam(name = "id", value = "RESOURCE_ID", required = true, dataType = "Int", example = "10") + }) + @GetMapping(value = "/{id}/query") + @ResponseStatus(HttpStatus.OK) + @ApiException(RESOURCE_NOT_EXIST) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") + public Result queryResourceById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @PathVariable(value = "id", required = true) Integer id + ) { + + return resourceService.queryResourceById(id); + } } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ResourcesService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ResourcesService.java index 25a5af24b1..2433e34a08 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ResourcesService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ResourcesService.java @@ -231,4 +231,11 @@ public interface ResourcesService { */ Map authorizedFile(User loginUser, Integer userId); + /** + * get resource by id + * @param resourceId resource id + * @return resource + */ + Result queryResourceById(Integer resourceId); + } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java index 22621a50b2..398d182adf 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java @@ -815,6 +815,24 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe return result; } + /** + * get resource by id + * @param id resource id + * @return resource + */ + @Override + public Result queryResourceById(Integer id) { + Result result = new Result<>(); + Resource resource = resourcesMapper.selectById(id); + if (resource == null) { + putMsg(result, Status.RESOURCE_NOT_EXIST); + return result; + } + putMsg(result, Status.SUCCESS); + result.setData(resource); + return result; + } + /** * view resource file online * diff --git a/dolphinscheduler-ui-next/src/layouts/content/components/timezone/index.module.scss b/dolphinscheduler-ui-next/src/layouts/content/components/timezone/index.module.scss index ec3fa47c2b..f81bc9d1f6 100644 --- a/dolphinscheduler-ui-next/src/layouts/content/components/timezone/index.module.scss +++ b/dolphinscheduler-ui-next/src/layouts/content/components/timezone/index.module.scss @@ -15,7 +15,7 @@ * limitations under the License. */ - .icon { +.icon { margin: 0 12px; } diff --git a/dolphinscheduler-ui-next/src/service/modules/resources/index.ts b/dolphinscheduler-ui-next/src/service/modules/resources/index.ts index b4a32bf5fd..28f395f2b0 100644 --- a/dolphinscheduler-ui-next/src/service/modules/resources/index.ts +++ b/dolphinscheduler-ui-next/src/service/modules/resources/index.ts @@ -55,6 +55,13 @@ export function queryResourceById( }) } +export function queryCurrentResourceById(id: number): any { + return axios({ + url: `/resources/${id}/query`, + method: 'get' + }) +} + export function createResource( data: CreateReq & FileNameReq & NameReq & ResourceTypeReq ): any { diff --git a/dolphinscheduler-ui-next/src/service/modules/resources/types.ts b/dolphinscheduler-ui-next/src/service/modules/resources/types.ts index 70d7752f87..43a532d4e7 100644 --- a/dolphinscheduler-ui-next/src/service/modules/resources/types.ts +++ b/dolphinscheduler-ui-next/src/service/modules/resources/types.ts @@ -137,5 +137,6 @@ export { ResourceIdReq, UdfFuncReq, ResourceListRes, - ResourceViewRes + ResourceViewRes, + ResourceFile } diff --git a/dolphinscheduler-ui-next/src/views/projects/workflow/definition/components/use-modal.ts b/dolphinscheduler-ui-next/src/views/projects/workflow/definition/components/use-modal.ts index 9787a0868b..46b0a17c52 100644 --- a/dolphinscheduler-ui-next/src/views/projects/workflow/definition/components/use-modal.ts +++ b/dolphinscheduler-ui-next/src/views/projects/workflow/definition/components/use-modal.ts @@ -37,8 +37,8 @@ import { import { parseTime } from '@/utils/common' export function useModal( - state: any, - ctx: SetupContext<('update:show' | 'update:row' | 'updateList')[]> + state: any, + ctx: SetupContext<('update:show' | 'update:row' | 'updateList')[]> ) { const { t } = useI18n() const router: Router = useRouter() @@ -87,12 +87,12 @@ export function useModal( state.startForm.processDefinitionCode = code if (state.startForm.startEndTime) { const start = format( - new Date(state.startForm.startEndTime[0]), - 'yyyy-MM-dd hh:mm:ss' + new Date(state.startForm.startEndTime[0]), + 'yyyy-MM-dd hh:mm:ss' ) const end = format( - new Date(state.startForm.startEndTime[1]), - 'yyyy-MM-dd hh:mm:ss' + new Date(state.startForm.startEndTime[1]), + 'yyyy-MM-dd hh:mm:ss' ) state.startForm.scheduleTime = `${start},${end}` } @@ -104,8 +104,8 @@ export function useModal( } } state.startForm.startParams = !_.isEmpty(startParams) - ? JSON.stringify(startParams) - : '' + ? JSON.stringify(startParams) + : '' await startProcessInstance(state.startForm, variables.projectCode) window.$message.success(t('project.workflow.success')) @@ -157,12 +157,12 @@ export function useModal( const getTimingData = () => { const start = format( - parseTime(state.timingForm.startEndTime[0]), - 'yyyy-MM-dd hh:mm:ss' + parseTime(state.timingForm.startEndTime[0]), + 'yyyy-MM-dd hh:mm:ss' ) const end = format( - parseTime(state.timingForm.startEndTime[1]), - 'yyyy-MM-dd hh:mm:ss' + parseTime(state.timingForm.startEndTime[1]), + 'yyyy-MM-dd hh:mm:ss' ) const data = { @@ -176,9 +176,9 @@ export function useModal( warningType: state.timingForm.warningType, processInstancePriority: state.timingForm.processInstancePriority, warningGroupId: - state.timingForm.warningGroupId === '' - ? 0 - : state.timingForm.warningGroupId, + state.timingForm.warningGroupId === '' + ? 0 + : state.timingForm.warningGroupId, workerGroup: state.timingForm.workerGroup, environmentCode: state.timingForm.environmentCode } @@ -215,9 +215,9 @@ export function useModal( const getStartParamsList = (code: number) => { queryProcessDefinitionByCode(code, variables.projectCode).then( - (res: any) => { - variables.startParamsList = res.processDefinition.globalParamList - } + (res: any) => { + variables.startParamsList = res.processDefinition.globalParamList + } ) } @@ -227,12 +227,12 @@ export function useModal( const projectCode = Number(router.currentRoute.value.params.projectCode) const start = format( - new Date(state.timingForm.startEndTime[0]), - 'yyyy-MM-dd hh:mm:ss' + new Date(state.timingForm.startEndTime[0]), + 'yyyy-MM-dd hh:mm:ss' ) const end = format( - new Date(state.timingForm.startEndTime[1]), - 'yyyy-MM-dd hh:mm:ss' + new Date(state.timingForm.startEndTime[1]), + 'yyyy-MM-dd hh:mm:ss' ) const schedule = JSON.stringify({ diff --git a/dolphinscheduler-ui-next/src/views/resource/file/folder/use-folder.ts b/dolphinscheduler-ui-next/src/views/resource/file/folder/use-folder.ts index d662360c83..e18c61f10b 100644 --- a/dolphinscheduler-ui-next/src/views/resource/file/folder/use-folder.ts +++ b/dolphinscheduler-ui-next/src/views/resource/file/folder/use-folder.ts @@ -28,9 +28,9 @@ export function useFolder(state: any) { const fileStore = useFileStore() const handleCreateFolder = async ( - emit: IEmit, - hideModal: () => void, - resetForm: () => void + emit: IEmit, + hideModal: () => void, + resetForm: () => void ) => { await state.folderFormRef.validate() diff --git a/dolphinscheduler-ui-next/src/views/resource/file/index.tsx b/dolphinscheduler-ui-next/src/views/resource/file/index.tsx index 842f481747..3b758bfe5a 100644 --- a/dolphinscheduler-ui-next/src/views/resource/file/index.tsx +++ b/dolphinscheduler-ui-next/src/views/resource/file/index.tsx @@ -45,6 +45,9 @@ import ResourceRenameModal from './rename' import { IRenameFile } from './types' import type { Router } from 'vue-router' import styles from './index.module.scss' +import { useFileStore } from '@/store/file/file' +import { queryCurrentResourceById } from '@/service/modules/resources' +import { ResourceFile } from '@/service/modules/resources/types' export default defineComponent({ name: 'File', @@ -142,6 +145,7 @@ export default defineComponent({ serachRef.value ) } + const fileStore = useFileStore() onMounted(() => { resourceListRef.value = getResourceListState(fileId.value) @@ -150,7 +154,20 @@ export default defineComponent({ watch( () => router.currentRoute.value.params.id, // @ts-ignore - () => reload() + () => { + reload() + const currFileId = Number(router.currentRoute.value.params.id) || -1 + + if (currFileId === -1) { + fileStore.setCurrentDir('/') + } else { + queryCurrentResourceById(currFileId).then((res: ResourceFile) => { + if (res.fullName) { + fileStore.setCurrentDir(res.fullName) + } + }) + } + } ) return {