Unverified Commit 12989375 authored by zhu-mingye's avatar zhu-mingye Committed by GitHub

[Refactor][web] refactor system center's system info (#1957)

* refactor system center's system info * refactor system center's system info
parent e8db2094
...@@ -22,7 +22,7 @@ package org.dinky.controller; ...@@ -22,7 +22,7 @@ package org.dinky.controller;
import org.dinky.common.result.ProTableResult; import org.dinky.common.result.ProTableResult;
import org.dinky.common.result.Result; import org.dinky.common.result.Result;
import org.dinky.dto.GitProjectDTO; import org.dinky.dto.GitProjectDTO;
import org.dinky.dto.GitProjectTreeNodeDTO; import org.dinky.dto.TreeNodeDTO;
import org.dinky.model.GitProject; import org.dinky.model.GitProject;
import org.dinky.service.GitProjectService; import org.dinky.service.GitProjectService;
import org.dinky.utils.GitProjectStepSseFactory; import org.dinky.utils.GitProjectStepSseFactory;
...@@ -189,9 +189,9 @@ public class GitController { ...@@ -189,9 +189,9 @@ public class GitController {
* @return {@link Result} of {@link Void} * @return {@link Result} of {@link Void}
*/ */
@GetMapping("/getProjectCode") @GetMapping("/getProjectCode")
public Result<List<GitProjectTreeNodeDTO>> getProjectCode(@RequestParam("id") Integer id) { public Result<List<TreeNodeDTO>> getProjectCode(@RequestParam("id") Integer id) {
List<GitProjectTreeNodeDTO> projectCode = gitProjectService.getProjectCode(id); List<TreeNodeDTO> projectCode = gitProjectService.getProjectCode(id);
if (projectCode == null) { if (projectCode == null) {
return Result.failed(MessageResolverUtils.getMessage("response.get.failed")); return Result.failed(MessageResolverUtils.getMessage("response.get.failed"));
} }
......
...@@ -21,7 +21,7 @@ package org.dinky.controller; ...@@ -21,7 +21,7 @@ package org.dinky.controller;
import org.dinky.common.result.Result; import org.dinky.common.result.Result;
import org.dinky.constant.DirConstant; import org.dinky.constant.DirConstant;
import org.dinky.model.FileNode; import org.dinky.dto.TreeNodeDTO;
import org.dinky.service.SystemService; import org.dinky.service.SystemService;
import java.util.List; import java.util.List;
...@@ -33,11 +33,7 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -33,11 +33,7 @@ import org.springframework.web.bind.annotation.RestController;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
/** /** SystemController */
* SystemController
*
* @since 2022/10/15 19:20
*/
@RestController @RestController
@RequestMapping("/api/system") @RequestMapping("/api/system")
@RequiredArgsConstructor @RequiredArgsConstructor
...@@ -45,21 +41,32 @@ public class SystemController { ...@@ -45,21 +41,32 @@ public class SystemController {
private final SystemService systemService; private final SystemService systemService;
/**
* All log files for this project
*
* @return {@link Result} <{@link List}<{@link TreeNodeDTO}>>
*/
@GetMapping("/listLogDir") @GetMapping("/listLogDir")
public Result<List<FileNode>> listLogDir() { public Result<List<TreeNodeDTO>> listLogDir() {
return Result.data(systemService.listLogDir()); return Result.data(systemService.listLogDir());
} }
/**
* get root log file content
*
* @return {@link Result} <{@link String}>
*/
@GetMapping("/getRootLog") @GetMapping("/getRootLog")
public Result<String> getRootLog() { public Result<String> getRootLog() {
return Result.data(systemService.readFile(DirConstant.ROOT_LOG_PATH)); return Result.data(systemService.readFile(DirConstant.ROOT_LOG_PATH));
} }
@GetMapping("/listDirByPath") /**
public Result<List<FileNode>> listDirByPath(@RequestParam String path) { * readFile by path
return Result.data(systemService.listDirByPath(path)); *
} * @param path {@link String}
* @return {@link Result} <{@link String}>
*/
@GetMapping("/readFile") @GetMapping("/readFile")
public Result<String> readFile(@RequestParam String path) { public Result<String> readFile(@RequestParam String path) {
return Result.data(systemService.readFile(path)); return Result.data(systemService.readFile(path));
......
...@@ -35,20 +35,16 @@ import lombok.ToString; ...@@ -35,20 +35,16 @@ import lombok.ToString;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@ToString @ToString
public class GitProjectTreeNodeDTO { public class TreeNodeDTO {
private String name; private String name;
private String path; private String path;
private String content; private String content;
private Long size; private Long size;
private boolean isLeaf; private boolean isLeaf;
private List<GitProjectTreeNodeDTO> children; private List<TreeNodeDTO> children;
public GitProjectTreeNodeDTO( public TreeNodeDTO(
String name, String name, String path, boolean isLeaf, List<TreeNodeDTO> children, Long size) {
String path,
boolean isLeaf,
List<GitProjectTreeNodeDTO> children,
Long size) {
this.name = name; this.name = name;
this.path = path; this.path = path;
this.isLeaf = isLeaf; this.isLeaf = isLeaf;
......
...@@ -21,7 +21,7 @@ package org.dinky.service; ...@@ -21,7 +21,7 @@ package org.dinky.service;
import org.dinky.db.service.ISuperService; import org.dinky.db.service.ISuperService;
import org.dinky.dto.GitProjectDTO; import org.dinky.dto.GitProjectDTO;
import org.dinky.dto.GitProjectTreeNodeDTO; import org.dinky.dto.TreeNodeDTO;
import org.dinky.model.GitProject; import org.dinky.model.GitProject;
import java.util.List; import java.util.List;
...@@ -49,9 +49,9 @@ public interface GitProjectService extends ISuperService<GitProject> { ...@@ -49,9 +49,9 @@ public interface GitProjectService extends ISuperService<GitProject> {
* get project code tree * get project code tree
* *
* @param id {@link Integer} * @param id {@link Integer}
* @return {@link List< GitProjectTreeNodeDTO >} * @return {@link List< TreeNodeDTO >}
*/ */
List<GitProjectTreeNodeDTO> getProjectCode(Integer id); List<TreeNodeDTO> getProjectCode(Integer id);
/** /**
* remove project and code cascade by id * remove project and code cascade by id
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
package org.dinky.service; package org.dinky.service;
import org.dinky.dto.TreeNodeDTO;
import org.dinky.model.FileNode; import org.dinky.model.FileNode;
import java.util.List; import java.util.List;
...@@ -30,20 +31,12 @@ import java.util.List; ...@@ -30,20 +31,12 @@ import java.util.List;
*/ */
public interface SystemService { public interface SystemService {
/**
* list all dir and file by dir path
*
* @param path
* @return {@link List<FileNode>}
*/
List<FileNode> listDirByPath(String path);
/** /**
* List log root dir. * List log root dir.
* *
* @return {@link List<FileNode>} * @return {@link List<FileNode>}
*/ */
List<FileNode> listLogDir(); List<TreeNodeDTO> listLogDir();
/** /**
* readFile * readFile
......
...@@ -21,18 +21,18 @@ package org.dinky.service.impl; ...@@ -21,18 +21,18 @@ package org.dinky.service.impl;
import org.dinky.db.service.impl.SuperServiceImpl; import org.dinky.db.service.impl.SuperServiceImpl;
import org.dinky.dto.GitProjectDTO; import org.dinky.dto.GitProjectDTO;
import org.dinky.dto.GitProjectTreeNodeDTO;
import org.dinky.dto.JarClassesDTO; import org.dinky.dto.JarClassesDTO;
import org.dinky.dto.TreeNodeDTO;
import org.dinky.mapper.GitProjectMapper; import org.dinky.mapper.GitProjectMapper;
import org.dinky.model.GitProject; import org.dinky.model.GitProject;
import org.dinky.process.exception.DinkyException; import org.dinky.process.exception.DinkyException;
import org.dinky.service.GitProjectService; import org.dinky.service.GitProjectService;
import org.dinky.utils.GitProjectStepSseFactory; import org.dinky.utils.GitProjectStepSseFactory;
import org.dinky.utils.GitRepository; import org.dinky.utils.GitRepository;
import org.dinky.utils.TreeUtil;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
...@@ -85,10 +85,10 @@ public class GitProjectServiceImpl extends SuperServiceImpl<GitProjectMapper, Gi ...@@ -85,10 +85,10 @@ public class GitProjectServiceImpl extends SuperServiceImpl<GitProjectMapper, Gi
* @return {@link List < GitProjectCodeTreeDTO >} * @return {@link List < GitProjectCodeTreeDTO >}
*/ */
@Override @Override
public List<GitProjectTreeNodeDTO> getProjectCode(Integer id) { public List<TreeNodeDTO> getProjectCode(Integer id) {
GitProject gitProject = getById(id); GitProject gitProject = getById(id);
File projectDir = GitRepository.getProjectDir(gitProject.getName()); File projectDir = GitRepository.getProjectDir(gitProject.getName());
return treeNodeData(projectDir); return TreeUtil.treeNodeData(projectDir, true);
} }
/** /**
...@@ -159,79 +159,11 @@ public class GitProjectServiceImpl extends SuperServiceImpl<GitProjectMapper, Gi ...@@ -159,79 +159,11 @@ public class GitProjectServiceImpl extends SuperServiceImpl<GitProjectMapper, Gi
buildStep5Logs(file, sb); buildStep5Logs(file, sb);
sb.append("\n\n\n\n"); sb.append("\n\n\n\n");
} else { } else {
sb.append(readFile(file)); sb.append(FileUtil.readUtf8String(file));
sb.append("\n\n\n\n"); sb.append("\n\n\n\n");
} }
} }
/**
* build tree node data
*
* @param projectDir {@link File}
* @return {@link List < GitProjectTreeNodeDTO >}
*/
private static List<GitProjectTreeNodeDTO> treeNodeData(File projectDir) {
List<GitProjectTreeNodeDTO> nodes = new ArrayList<>();
if (projectDir.exists() && projectDir.isDirectory()) {
GitProjectTreeNodeDTO rootNode =
new GitProjectTreeNodeDTO(
projectDir.getName(),
projectDir.getAbsolutePath(),
true,
new ArrayList<>(),
0L);
buildTree(projectDir, rootNode);
nodes.add(rootNode);
}
return nodes;
}
/**
* build tree
*
* @param file {@link File}
* @param parentNode {@link GitProjectTreeNodeDTO}
*/
private static void buildTree(File file, GitProjectTreeNodeDTO parentNode) {
if (file.isDirectory()) {
File[] children = file.listFiles();
if (children != null) {
for (File child : children) {
GitProjectTreeNodeDTO childNode =
new GitProjectTreeNodeDTO(
child.getName(),
child.getAbsolutePath(),
child.isDirectory(),
new ArrayList<>(),
child.length());
parentNode.getChildren().add(childNode);
buildTree(child, childNode);
}
}
} else {
try {
String content = readFile(file);
parentNode.setLeaf(file.isDirectory());
parentNode.setContent(content);
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* read file
*
* @param file {@link File}
* @return {@link String}
* @throws IOException
*/
private static String readFile(File file) throws IOException {
return FileUtil.readUtf8String(file);
}
/** /**
* match step by code type * match step by code type
* *
...@@ -295,7 +227,7 @@ public class GitProjectServiceImpl extends SuperServiceImpl<GitProjectMapper, Gi ...@@ -295,7 +227,7 @@ public class GitProjectServiceImpl extends SuperServiceImpl<GitProjectMapper, Gi
* @throws IOException * @throws IOException
*/ */
private void buildStep5Logs(File file, StringBuilder sb) throws IOException { private void buildStep5Logs(File file, StringBuilder sb) throws IOException {
String step5Log = readFile(file); String step5Log = FileUtil.readUtf8String(file);
sb.append("Jar And UDF Class List:\n"); sb.append("Jar And UDF Class List:\n");
List<JarClassesDTO> jarClassesDTOList = JSONUtil.toList(step5Log, JarClassesDTO.class); List<JarClassesDTO> jarClassesDTOList = JSONUtil.toList(step5Log, JarClassesDTO.class);
jarClassesDTOList.stream() jarClassesDTOList.stream()
......
...@@ -20,10 +20,12 @@ ...@@ -20,10 +20,12 @@
package org.dinky.service.impl; package org.dinky.service.impl;
import org.dinky.constant.DirConstant; import org.dinky.constant.DirConstant;
import org.dinky.model.FileNode; import org.dinky.dto.TreeNodeDTO;
import org.dinky.service.SystemService; import org.dinky.service.SystemService;
import org.dinky.utils.DirUtil; import org.dinky.utils.DirUtil;
import org.dinky.utils.TreeUtil;
import java.io.File;
import java.util.List; import java.util.List;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -37,13 +39,9 @@ import org.springframework.stereotype.Service; ...@@ -37,13 +39,9 @@ import org.springframework.stereotype.Service;
public class SystemServiceImpl implements SystemService { public class SystemServiceImpl implements SystemService {
@Override @Override
public List<FileNode> listDirByPath(String path) { public List<TreeNodeDTO> listLogDir() {
return DirUtil.listDirByPath(path); File systemLogFiles = TreeUtil.getFilesOfDir(DirConstant.LOG_DIR_PATH);
} return TreeUtil.treeNodeData(systemLogFiles, false);
@Override
public List<FileNode> listLogDir() {
return DirUtil.listDirByPath(DirConstant.LOG_DIR_PATH);
} }
@Override @Override
......
/*
*
* 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.dinky.utils;
import org.dinky.dto.TreeNodeDTO;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import cn.hutool.core.io.FileUtil;
/** the tree util , is use build tree , and show tree view */
public class TreeUtil {
/**
* build tree node data
*
* @param dir {@link File}
* @return {@link List < GitProjectTreeNodeDTO >}
*/
public static List<TreeNodeDTO> treeNodeData(File dir, Boolean readContent) {
List<TreeNodeDTO> nodes = new ArrayList<>();
if (dir.exists() && dir.isDirectory()) {
TreeNodeDTO rootNode =
new TreeNodeDTO(
dir.getName(), dir.getAbsolutePath(), true, new ArrayList<>(), 0L);
buildTree(dir, rootNode, readContent);
nodes.add(rootNode);
}
return nodes;
}
/**
* build tree, if readContent is true , read file content to set {@link TreeNodeDTO#content}
*
* @param file {@link File}
* @param parentNode {@link TreeNodeDTO}
* @param readContent {@link Boolean}
*/
private static void buildTree(File file, TreeNodeDTO parentNode, Boolean readContent) {
if (file.isDirectory()) {
File[] children = file.listFiles();
if (children != null) {
for (File child : children) {
TreeNodeDTO childNode =
new TreeNodeDTO(
child.getName(),
child.getAbsolutePath(),
child.isDirectory(),
new ArrayList<>(),
child.length());
parentNode.getChildren().add(childNode);
buildTree(child, childNode, readContent);
}
}
} else {
try {
if (readContent) {
String content = readFiles(file);
parentNode.setContent(content);
}
parentNode.setLeaf(file.isDirectory());
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* read file
*
* @param file {@link File}
* @return {@link String}
* @throws IOException
*/
public static String readFiles(File file) throws IOException {
return FileUtil.readUtf8String(file);
}
/**
* get files of dir
*
* @param path {@link String}
* @return {@File}
*/
public static File getFilesOfDir(String path) {
return FileUtil.file(path);
}
}
...@@ -219,7 +219,7 @@ export default [ ...@@ -219,7 +219,7 @@ export default [
path: '/settings/system', path: '/settings/system',
name: 'system', name: 'system',
icon: 'InfoCircleOutlined', icon: 'InfoCircleOutlined',
// component: './SettingCenter/SystemInfo', component: './SettingCenter/SystemInfo',
}, },
{ {
path: '/settings/process', path: '/settings/process',
......
...@@ -46,14 +46,14 @@ ...@@ -46,14 +46,14 @@
], ],
"dependencies": { "dependencies": {
"@ant-design/icons": "^5.0.1", "@ant-design/icons": "^5.0.1",
"@ant-design/pro-components": "^2.3.57", "@ant-design/pro-components": "^2.4.14",
"@ant-design/pro-layout": "^7.8.2", "@ant-design/pro-layout": "^7.13.3",
"@ant-design/pro-table": "^3.3.1", "@ant-design/pro-table": "^3.6.9",
"@ant-design/use-emotion-css": "^1.0.4", "@ant-design/use-emotion-css": "^1.0.4",
"@umijs/route-utils": "^4.0.1", "@umijs/route-utils": "^4.0.1",
"antd": "^5.4.5", "antd": "^5.4.7",
"classnames": "^2.3.2", "classnames": "^2.3.2",
"js-cookie": "^3.0.4", "js-cookie": "^3.0.5",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"moment": "^2.29.4", "moment": "^2.29.4",
"omit.js": "^2.0.2", "omit.js": "^2.0.2",
...@@ -63,7 +63,6 @@ ...@@ -63,7 +63,6 @@
"react-dev-inspector": "^1.8.1", "react-dev-inspector": "^1.8.1",
"react-monaco-editor": "^0.52.0", "react-monaco-editor": "^0.52.0",
"react-dom": "^18.0.0", "react-dom": "^18.0.0",
"react-draggable": "^4.4.5",
"react-helmet-async": "^1.3.0", "react-helmet-async": "^1.3.0",
"screenfull": "^6.0.2", "screenfull": "^6.0.2",
"use-sse": "^2.0.1" "use-sse": "^2.0.1"
......
...@@ -184,7 +184,7 @@ const CodeShow = (props: CodeShowFormProps) => { ...@@ -184,7 +184,7 @@ const CodeShow = (props: CodeShowFormProps) => {
* render * render
*/ */
return (<> return (<>
<div id={"monaco"} className={"monaco-float"}> <div className={"monaco-float"}>
<MonacoEditor <MonacoEditor
width={width} width={width}
height={height} height={height}
......
/*
* 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 React from "react";
import {FloatButton, Space} from "antd";
import {l} from "@/utils/intl";
import {DownCircleFilled, StopFilled, SyncOutlined, UpCircleFilled} from "@ant-design/icons";
import {PlayCircleFilled} from "@ant-design/icons/lib/icons";
/**
* props
*/
type EditFloatBtnProps = {
refreshLogCallback?: () => void; // refresh log callback
autoRefresh?: boolean; // auto refresh flag
stopping?: boolean; // stop auto refresh flag
loading?: boolean; // loading flag
handleSyncLog?: () => void; // sync log callback
handleStopAutoRefresh?: () => void; // stop auto refresh callback
handleStartAutoRefresh?: () => void; // start auto refresh callback
handleBackTop?: () => void; // back to top callback
handleBackBottom?: () => void; // back to bottom callback
handleUpScroll?: () => void; // up scroll callback
handleDownScroll?: () => void; // down scroll callback
}
const EditFloatBtn: React.FC<EditFloatBtnProps> = (props) => {
/**
* init props
*/
const {
refreshLogCallback,
autoRefresh,
stopping,
loading,
handleSyncLog,
handleStopAutoRefresh,
handleStartAutoRefresh,
handleBackTop,
handleBackBottom,
handleUpScroll,
handleDownScroll
} = props;
/**
* render
*/
return <>
<FloatButton.Group
shape="circle"
className={"float-button"}
>
<Space direction={"vertical"}>
{/* if refreshLogCallback is not null, then show sync button , auto refresh button and stop auto refresh button */}
{refreshLogCallback &&
<>
<FloatButton tooltip={l("button.refresh")} icon={<SyncOutlined spin={loading}/>} onClick={handleSyncLog}/>
{autoRefresh ?
<FloatButton icon={<StopFilled spin={stopping}/>} tooltip={l("button.stopRefresh")} onClick={handleStopAutoRefresh}/> :
<FloatButton icon={<PlayCircleFilled/>} tooltip={l("button.startRefresh")} onClick={handleStartAutoRefresh}/>
}
</>
}
{/* back top */}
<FloatButton.BackTop tooltip={l("button.backTop")} onClick={handleBackTop} visibilityHeight={0}/>
{/* go bottom */}
<FloatButton.BackTop className={"back-bottom"} tooltip={l("button.backBottom")} onClick={handleBackBottom}
visibilityHeight={0}/>
{/* scroll up */}
<FloatButton icon={<UpCircleFilled/>} tooltip={l("button.upScroll")} onClick={handleUpScroll}/>
{/* scroll down */}
<FloatButton icon={<DownCircleFilled/>} tooltip={l("button.downScroll")} onClick={handleDownScroll}/>
</Space>
</FloatButton.Group>
</>;
};
export default EditFloatBtn;
...@@ -26,6 +26,32 @@ body, ...@@ -26,6 +26,32 @@ body,
'Noto Color Emoji'; 'Noto Color Emoji';
} }
// scrollbar style --- start ----
::-webkit-scrollbar {
width: 0.5vw;
height: 1vh;
background-color: #f5f5f5;
}
::-webkit-scrollbar-thumb {
background-color: #ccc;
border-radius: 6px;
box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
}
::-webkit-scrollbar-thumb:hover {
background-color: #aaa;
}
::-webkit-scrollbar-thumb:active {
background-color: #999;
}
::-webkit-scrollbar-corner {
background-color: #f5f5f5;
}
// scrollbar style --- end ----
.colorWeak { .colorWeak {
filter: invert(80%); filter: invert(80%);
} }
......
...@@ -793,6 +793,7 @@ export default { ...@@ -793,6 +793,7 @@ export default {
'sys.process.endtime': 'End Time', 'sys.process.endtime': 'End Time',
'sys.process.duration': 'Duration', 'sys.process.duration': 'Duration',
'sys.process.operator': 'Operator', 'sys.process.operator': 'Operator',
'sys.info.logList.tips': 'Click left log file to viewing',
'devops.jobinfo.alert.title': 'Title', 'devops.jobinfo.alert.title': 'Title',
'devops.jobinfo.alert.content':'Body', 'devops.jobinfo.alert.content':'Body',
......
...@@ -787,6 +787,7 @@ export default { ...@@ -787,6 +787,7 @@ export default {
'sys.process.endtime':'结束时间', 'sys.process.endtime':'结束时间',
'sys.process.duration':'耗时', 'sys.process.duration':'耗时',
'sys.process.operator':'操作人', 'sys.process.operator':'操作人',
'sys.info.logList.tips': '点击左侧日志文件查看',
'devops.jobinfo.alert.title':'标题', 'devops.jobinfo.alert.title':'标题',
'devops.jobinfo.alert.content':'正文', 'devops.jobinfo.alert.content':'正文',
......
...@@ -92,7 +92,9 @@ export const BuildSteps: React.FC<BuildStepsProps> = (props) => { ...@@ -92,7 +92,9 @@ export const BuildSteps: React.FC<BuildStepsProps> = (props) => {
return l("rc.gp.build.step." + step); return l("rc.gp.build.step." + step);
} }
// const [data, error] = useSSE(() => {
// return fetch("https://myapi.example.com").then((res) => res.json());
// }, []);
useEffect(() => { useEffect(() => {
if (values.buildStep === 0) { if (values.buildStep === 0) {
...@@ -100,6 +102,7 @@ export const BuildSteps: React.FC<BuildStepsProps> = (props) => { ...@@ -100,6 +102,7 @@ export const BuildSteps: React.FC<BuildStepsProps> = (props) => {
setCurrentStep(0); setCurrentStep(0);
} }
const eventSource = new EventSource(API_CONSTANTS.GIT_PROJECT_BUILD_STEP_LOGS + "?id=" + values.id); const eventSource = new EventSource(API_CONSTANTS.GIT_PROJECT_BUILD_STEP_LOGS + "?id=" + values.id);
setEventSource(eventSource); setEventSource(eventSource);
buildStepList(); buildStepList();
......
...@@ -65,7 +65,7 @@ export const ShowLog: React.FC<ShowLogProps> = (props) => { ...@@ -65,7 +65,7 @@ export const ShowLog: React.FC<ShowLogProps> = (props) => {
*/ */
useEffect(() => { useEffect(() => {
queryAllStepLogs(); queryAllStepLogs();
}, [modalVisible]); }, []);
/** /**
......
/*
* 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.
*/
/*
* 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 CodeShow from "@/components/CustomEditor/CodeShow";
import React from "react";
import {l} from "@/utils/intl";
import {Empty} from "antd";
const CodeEditProps = {
height: "70vh",
width: "100%",
lineNumbers: "on",
language: "java",
};
type LogsShowProps = {
code: string;
refreshLogCallback: () => void;
}
// todo:
// If the log is too large and there are too many contents,
// MonacoEditor will have performance problems.
// It is planned to optimize it through `react-virtualized`
const LogsShow: React.FC<LogsShowProps> = (props) => {
const {code, refreshLogCallback} = props;
const restLogsShowProps = {
showFloatButton: true,
code,
refreshLogCallback,
};
return <>
{ code ? <CodeShow {...restLogsShowProps} {...CodeEditProps} />
: <Empty className={"code-content-empty"} description={l("sys.info.logList.tips")}/>
}
</>;
};
export default LogsShow;
/*
* 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 React from "react";
import {Empty, Tree} from "antd";
import {PageLoading} from "@ant-design/pro-components";
import {buildTreeData} from "@/utils/function";
type LogsTreeProps = {
treeData: Partial<any>[];
onNodeClick: (info: any) => void
}
const {DirectoryTree} = Tree;
const LogsTree: React.FC<LogsTreeProps> = (props) => {
const {treeData, onNodeClick} = props;
return <>
{
(treeData.length > 0) ?
<DirectoryTree
onSelect={(_, info) => onNodeClick(info)}
treeData={buildTreeData(treeData)}
/> : <Empty className={"code-content-empty"}/>
}
</>;
};
export default LogsTree;
/*
* 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 {Col, Row} from "antd";
import React, {useEffect, useState} from "react";
import LogsTree from "@/pages/SettingCenter/SystemInfo/TagInfo/LogList/LogsTree";
import LogsShow from "@/pages/SettingCenter/SystemInfo/TagInfo/LogList/LogsShow";
import {queryDataByParams} from "@/services/BusinessCrud";
import {API_CONSTANTS} from "@/services/constants";
const LogList = () => {
const [treeData, setTreeData] = useState<Partial<any>[]>([]);
const [log, setLog] = useState<string>("");
const [clickFileName, setClickFileName] = useState<any>();
const queryLogList = async () => {
await queryDataByParams(API_CONSTANTS.SYSTEM_ROOT_LOG_LIST).then(res => {
setTreeData(res);
});
};
const queryLogContent = async (fileName: string) => {
await queryDataByParams(API_CONSTANTS.SYSTEM_ROOT_LOG_READ, {path: fileName}).then(res => {
setLog(res);
});
};
useEffect(() => {
queryLogList();
}, []);
const handleNodeClick = async (info: any) => {
const {node: {path, isLeaf}} = info;
if (isLeaf) {
setClickFileName(path);
await queryLogContent(path);
}
};
const refreshLogByClickNode = async () => {
await queryLogContent(clickFileName);
};
return <>
<Row>
<Col span={4} className={"siderTree"}>
{/* tree */}
<LogsTree treeData={treeData} onNodeClick={(info: any) => handleNodeClick(info)}/>
{/*<SiderTree treeData={treeData} onNodeClick={(info: any) => handleNodeClick(info)} loading={loading}/>*/}
</Col>
<Col span={20}>
{/* code */}
<LogsShow code={log} refreshLogCallback={() => refreshLogByClickNode()}/>
{/*<CodeContent code={codeValue} current={currentGitProjectTreeNode}/>*/}
</Col>
</Row>
</>;
};
export default LogList;
/*
* 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 CodeShow from "@/components/CustomEditor/CodeShow";
import {useEffect, useState} from "react";
import {queryDataByParams} from "@/services/BusinessCrud";
import {API_CONSTANTS} from "@/services/constants";
/**
* code edit props
*/
const CodeEditProps = {
height: "75vh",
width: "100%",
lineNumbers: "on",
language: "java",
};
const RootLogs = () => {
const [code, setCode] = useState<string>("");
const queryLogs = async () => {
const result = await queryDataByParams(API_CONSTANTS.SYSTEM_ROOT_LOG);
setCode(result);
};
useEffect(() => {
queryLogs();
}, []);
const restRootLogProps = {
code: code,
showFloatButton: true,
refreshLogCallback: queryLogs,
};
return <>
<CodeShow {...restRootLogProps} {...CodeEditProps} />
</>;
};
export default RootLogs;
/*
* 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 {Tabs} from "antd";
import RootLogs from "@/pages/SettingCenter/SystemInfo/TagInfo/RootLogs";
import LogList from "@/pages/SettingCenter/SystemInfo/TagInfo/LogList";
const {TabPane} = Tabs;
const TagInfo = () => {
return <>
<Tabs >
<TabPane tab={" Root Logs "} key="logs">
<RootLogs/>
</TabPane>
<TabPane tab={" Log List "} key="logList">
<LogList/>
</TabPane>
</Tabs>
</>;
};
export default TagInfo;
/*
* 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 {PageContainer} from "@ant-design/pro-components";
import TagInfo from "@/pages/SettingCenter/SystemInfo/TagInfo";
export default () => {
return <PageContainer title={false}>
<TagInfo/>
</PageContainer>
}
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
import { import {
addOrUpdateData, putData, getDataByRequestBody, getInfoById, addOrUpdateData, putData, getDataByRequestBody, getInfoById,
postAll, postAll,
removeById, updateDataByParams, removeById, updateDataByParams, getData,
} from "@/services/api"; } from "@/services/api";
import {l} from "@/utils/intl"; import {l} from "@/utils/intl";
import {API_CONSTANTS, METHOD_CONSTANTS, RESPONSE_CODE} from "@/services/constants"; import {API_CONSTANTS, METHOD_CONSTANTS, RESPONSE_CODE} from "@/services/constants";
...@@ -190,7 +190,7 @@ export const handlePutData = async (url: string, fields: any) => { ...@@ -190,7 +190,7 @@ export const handlePutData = async (url: string, fields: any) => {
}; };
export const getDataByParams = async (url: string, params: any) => { export const getDataByParams = async (url: string, params?: any) => {
try { try {
const {datas} = await getDataByRequestBody(url, params); const {datas} = await getDataByRequestBody(url, params);
return datas; return datas;
...@@ -199,6 +199,16 @@ export const getDataByParams = async (url: string, params: any) => { ...@@ -199,6 +199,16 @@ export const getDataByParams = async (url: string, params: any) => {
} }
}; };
export const queryDataByParams = async (url: string, params?: any) => {
try {
const {datas} = await getData(url, params);
return datas;
} catch (error) {
return false;
}
};
export const handlePutDataByParams = async (url: string, title: string, params: any) => { export const handlePutDataByParams = async (url: string, title: string, params: any) => {
await LoadingMessageAsync(l("app.request.running") + title); await LoadingMessageAsync(l("app.request.running") + title);
try { try {
......
...@@ -126,6 +126,15 @@ export const API_CONSTANTS = { ...@@ -126,6 +126,15 @@ export const API_CONSTANTS = {
// ---- get project all build logs ---- // ---- get project all build logs ----
GIT_PROJECT_BUILD_ALL_LOGS: "/api/git/getAllBuildLog", GIT_PROJECT_BUILD_ALL_LOGS: "/api/git/getAllBuildLog",
// system config center
//-- system root logs
SYSTEM_ROOT_LOG: "/api/system/getRootLog",
// -- get logs list
SYSTEM_ROOT_LOG_LIST: "/api/system/listLogDir",
// -- READ LOG file
SYSTEM_ROOT_LOG_READ: "/api/system/readFile",
}; };
......
...@@ -266,3 +266,42 @@ export const renderLanguage = (type: string, splitChar: string) => { ...@@ -266,3 +266,42 @@ export const renderLanguage = (type: string, splitChar: string) => {
export const folderSeparator = () => { export const folderSeparator = () => {
return path.sep; return path.sep;
} }
/**
* build tree data
* @param data
* @returns {any}
*/
export const buildTreeData = (data: any): any => data?.map((item: any) => {
// build key
let buildKey = item.path + folderSeparator() + item.name;
// if has children , recursive build
if (item.children) {
return {
isLeaf: !item.leaf,
name: item.name,
parentId: item.path,
icon: renderIcon(item.name, ".", item.leaf),
content: item.content,
path: item.path,
title: item.name,
key: buildKey,
children: buildTreeData(item.children)
};
}
return {
isLeaf: !item.leaf,
name: item.name,
parentId: item.path,
icon: renderIcon(item.name, ".", item.leaf),
content: item.content,
path: item.path,
title: item.name,
key: buildKey,
};
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment