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

[Feature][dinky-web] added global var list for dinky-web (#1815)

* added global var list for dinky-web * delete some shell
parent f8c8d925
......@@ -23,6 +23,7 @@ import org.dinky.common.result.ProTableResult;
import org.dinky.common.result.Result;
import org.dinky.model.FragmentVariable;
import org.dinky.service.FragmentVariableService;
import org.dinky.utils.MessageResolverUtils;
import java.util.ArrayList;
import java.util.List;
......@@ -32,6 +33,7 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.databind.JsonNode;
......@@ -39,12 +41,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
/**
* FragmentVariableController
*
* @author zhumingye
* @since 2022/8/18
*/
/** FragmentVariableController */
@Slf4j
@RestController
@RequestMapping("/api/fragment")
......@@ -53,25 +50,71 @@ public class FragmentVariableController {
private final FragmentVariableService fragmentVariableService;
/** 新增或者更新 */
/**
* save or update
*
* @param fragmentVariable {@link FragmentVariable}
* @return {@link Result} of {@link Void}
*/
@PutMapping
public Result<Void> saveOrUpdate(@RequestBody FragmentVariable fragmentVariable)
throws Exception {
if (fragmentVariableService.saveOrUpdate(fragmentVariable)) {
return Result.succeed("保存成功");
return Result.succeed(MessageResolverUtils.getMessage("save.success"));
} else {
return Result.failed("保存失败");
return Result.failed(MessageResolverUtils.getMessage("save.failed"));
}
}
/** 动态查询列表 */
/**
* query list
*
* @param para {@link JsonNode}
* @return {@link ProTableResult} of {@link FragmentVariable}
*/
@PostMapping
public ProTableResult<FragmentVariable> listFragmentVariable(@RequestBody JsonNode para) {
return fragmentVariableService.selectForProTable(para);
}
/** 批量删除 */
/**
* delete by id
*
* @param id {@link Integer}
* @return {@link Result} of {@link Void}
*/
@DeleteMapping("/delete")
public Result<Void> deleteById(@RequestParam Integer id) {
if (fragmentVariableService.removeById(id)) {
return Result.succeed(MessageResolverUtils.getMessage("delete.success"));
} else {
return Result.failed(MessageResolverUtils.getMessage("delete.failed"));
}
}
/**
* enable or disable
*
* @param id {@link Integer}
* @return {@link Result} of {@link Void}
*/
@PutMapping("/enable")
public Result<Void> enable(@RequestParam Integer id) {
if (fragmentVariableService.enable(id)) {
return Result.succeed(MessageResolverUtils.getMessage("save.success"));
} else {
return Result.failed(MessageResolverUtils.getMessage("save.failed"));
}
}
/**
* batch delete , this method is deprecated, please use {@link #deleteById(Integer)}
*
* @param para {@link JsonNode}
* @return {@link Result} of {@link Void}
*/
@DeleteMapping
@Deprecated
public Result<Void> deleteMul(@RequestBody JsonNode para) {
if (para.size() > 0) {
List<Integer> error = new ArrayList<>();
......
......@@ -25,15 +25,28 @@ import org.dinky.model.FragmentVariable;
import java.util.List;
import java.util.Map;
/**
* FragmentVariableService
*
* @author zhumingye
* @since 2022/8/18
*/
/** FragmentVariableService */
public interface FragmentVariableService extends ISuperService<FragmentVariable> {
/**
* list enabled all
*
* @return {@link List<FragmentVariable>}
*/
List<FragmentVariable> listEnabledAll();
/**
* list enabled variables
*
* @return {@link Map<String, String>}
*/
Map<String, String> listEnabledVariables();
/**
* enable or disable
*
* @param id
* @return {@link Boolean}
*/
Boolean enable(Integer id);
}
......@@ -30,14 +30,9 @@ import java.util.Map;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
/**
* FragmentVariableServiceImpl
*
* @author zhumingye
* @since 2022/8/18
*/
/** FragmentVariableServiceImpl */
@Service
public class FragmentVariableServiceImpl
extends SuperServiceImpl<FragmentVariableMapper, FragmentVariable>
......@@ -45,7 +40,7 @@ public class FragmentVariableServiceImpl
@Override
public List<FragmentVariable> listEnabledAll() {
return list(new QueryWrapper<FragmentVariable>().eq("enabled", 1));
return list(new LambdaQueryWrapper<FragmentVariable>().eq(FragmentVariable::getEnabled, 1));
}
@Override
......@@ -56,4 +51,11 @@ public class FragmentVariableServiceImpl
}
return variables;
}
@Override
public Boolean enable(Integer id) {
FragmentVariable fragmentVariable = getById(id);
fragmentVariable.setEnabled(!fragmentVariable.getEnabled());
return updateById(fragmentVariable);
}
}
......@@ -41,3 +41,5 @@ screenshot
build
pnpm-lock.yaml
.husky
......@@ -114,12 +114,6 @@ export default [
},
],
},
{
path: '/registration/jar',
name: 'jar',
icon: 'FileZipOutlined',
// component: './RegistrationCenter/Jar',
},
{
path: '/registration/database',
name: 'database',
......@@ -153,7 +147,7 @@ export default [
path: '/registration/fragment',
name: 'fragment',
icon: 'RocketOutlined',
// component: './RegistrationCenter/FragmentVariable',
component: './RegCenter/GlobalVar',
},
],
},
......
......@@ -62,6 +62,7 @@
"react": "^18.2.0",
"react-custom-scrollbars": "^4.2.1",
"react-dev-inspector": "^1.8.1",
"react-monaco-editor": "^0.52.0",
"react-dom": "^18.0.0",
"react-draggable": "^4.4.5",
"react-helmet-async": "^1.3.0",
......@@ -85,15 +86,15 @@
"eslint": "^8.35.0",
"express": "^4.18.2",
"gh-pages": "^5.0.0",
"husky": "^8.0.3",
"husky": "^8",
"jest": "^29.4.3",
"jest-environment-jsdom": "^29.4.3",
"lint-staged": "^13.1.2",
"lint-staged": "^13",
"mockjs": "^1.1.0",
"prettier": "^2.8.4",
"prettier": "^2",
"swagger-ui-dist": "^4.16.1",
"ts-node": "^10.9.1",
"typescript": "^4.8.4",
"typescript": "^4",
"umi-presets-pro": "^2.0.0"
},
"engines": {
......
......@@ -16,7 +16,7 @@
*/
import Footer from "@/components/Footer";
import RightContent, {THEME} from "@/components/RightContent";
import RightContent from "@/components/RightContent";
import { Settings as LayoutSettings} from "@ant-design/pro-components";
// import {SettingDrawer} from "@ant-design/pro-components";
import type {RunTimeLayoutConfig} from "@umijs/max";
......@@ -25,6 +25,7 @@ import defaultSettings from "../config/defaultSettings";
import {errorConfig} from "./requestErrorConfig";
import {currentUser as queryCurrentUser} from "./services/BusinessCrud";
import {API_CONSTANTS} from "@/services/constants";
import {THEME} from "@/types/Public/data";
// const isDev = process.env.NODE_ENV === "development";
const loginPath = API_CONSTANTS.LOGIN_PATH;
......@@ -91,7 +92,7 @@ export const layout: RunTimeLayoutConfig = ({initialState, setInitialState}) =>
return {
rightContentRender: () => <RightContent />,
footerRender: () => <Footer />,
siderWidth: 155,
siderWidth: 180,
waterMarkProps: {
content: initialState?.currentUser?.user.username + " " + new Date().toLocaleString(),
fontColor: theme === THEME.light|| undefined ? "rgba(0, 0, 0, 0.15)" : "rgba(255, 255, 255, 0.15)",
......
/*
*
* 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 MonacoEditor from "react-monaco-editor";
import {ConvertCodeEditTheme} from "@/utils/function";
import {MonacoEditorOptions} from "@/types/Public/data";
export type CodeEditFormProps = {
height?: string;
width?: string;
language?: string;
options?: any;
onChange: (val: string) => void;
code: string;
readOnly?: boolean;
lineNumbers?: string;
theme?: string;
autoWrap?: string;
};
const CodeEdit = (props: CodeEditFormProps) => {
/**
* 1. height: edit height
* 2. width: edit width
* 3. language: edit language
* 4. options: edit options
* 5. onChange: edit change callback
* 6. code: content
* 7. readOnly: is readOnly, value: true | false
* 8. lineNumbers: is show lineNumbers, value: on | off | relative | interval
* 9. theme: edit theme , value: vs-dark | vs | hc-black
* 10. autoWrap: is auto wrap, value: on | off | wordWrapColumn | bounded
*/
const {
height = '100%', // if null or undefined, set default value
width = '100%', // if null or undefined, set default value
language, // edit language
options = {
...MonacoEditorOptions, // set default options
},
onChange, // edit change callback
code, // content
readOnly = false, // is readOnly
lineNumbers, // show lineNumbers
theme, // edit theme
autoWrap = 'on', // auto wrap
} = props;
return (<>
<MonacoEditor
width={width}
height={height}
value={code}
options={{
...options,
readOnly,
wordWrap: autoWrap,
lineNumbers,
language
}}
onChange={onChange}
theme={theme ? theme : ConvertCodeEditTheme()}
/>
</>)
};
export default CodeEdit;
/*
*
* 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 MonacoEditor from "react-monaco-editor";
import {ConvertCodeEditTheme} from "@/utils/function";
import {MonacoEditorOptions} from "@/types/Public/data";
export type CodeShowFormProps = {
height?: string;
width?: string;
language?: string;
options?: any;
code: string;
lineNumbers?: string;
theme?: string;
autoWrap?: string;
};
const CodeShow = (props: CodeShowFormProps) => {
/**
* 1. height: edit height
* 2. width: edit width
* 3. language: edit language
* 4. options: edit options
* 5. code: content
* 6. readOnly: is readOnly, value: true | false
* 7. lineNumbers: is show lineNumbers, value: on | off | relative | interval
* 8. theme: edit theme , value: vs-dark | vs | hc-black
* 9. autoWrap: is auto wrap, value: on | off | wordWrapColumn | bounded
*/
const {
height = '30vh', // if null or undefined, set default value
width = '100%', // if null or undefined, set default value
language,
options = {
...MonacoEditorOptions, // set default options
},
code, // content
lineNumbers, // show lineNumbers
theme, // edit theme
autoWrap = 'on', // auto wrap
} = props;
return (<>
<MonacoEditor
width={width}
height={height}
value={code}
options={{
...options,
readOnly: true,
wordWrap: autoWrap,
lineNumbers,
language
}}
theme={theme ? theme : ConvertCodeEditTheme()}
/>
</>)
};
export default CodeShow;
......@@ -16,7 +16,7 @@
*/
import {VERSION} from "@/services/constants";
import {parseJsonStr, setTenantStorageAndCookie} from "@/services/function";
import {parseJsonStr, setTenantStorageAndCookie} from "@/utils/function";
import {l} from "@/utils/intl";
import {
FullscreenExitOutlined,
......@@ -34,12 +34,8 @@ import Avatar from "./AvatarDropdown";
import {ThemeCloud, ThemeStar} from "@/components/ThemeSvg/ThemeSvg";
import {chooseTenantSubmit} from "@/services/BusinessCrud";
import {ErrorNotification, SuccessNotification} from "@/utils/messages";
import {THEME} from "@/types/Public/data";
export const THEME = {
NAV_THEME : "navTheme",
dark: "realDark",
light: "light",
}
const GlobalHeaderRight: React.FC = () => {
/**
......
......@@ -50,7 +50,7 @@ export default {
'menu.registration.alert.group': 'Alarm Group',
'menu.registration.document': 'Document',
'menu.registration.fragment': 'Global Variable',
'menu.auth': 'Authentication Center',
'menu.auth': 'Auth Center',
'menu.auth.user': 'User',
'menu.auth.role': 'Role',
'menu.auth.namespace': 'NameSpace',
......
......@@ -697,22 +697,16 @@ export default {
'rc.doc.subTypePlaceholder': 'Please select the function type this Document belongs to!',
'rc.doc.categoryPlaceholder': 'Please select the type of this Document!',
'rc.fv.Management': 'Global Variable Management',
'rc.fv.id': 'Global Variable ID',
'rc.fv.name': 'Name',
'rc.fv.fragmentValue': 'Global Variable value',
'rc.fv.create': 'Create Global Variable',
'rc.fv.modify': 'Modify Global Variables',
'rc.fv.delete': 'Delete Global Variable',
'rc.fv.deleteConfirm': 'Are you sure you want to delete the selected Global Variable? ',
'rc.fv.enable': 'Enable Global Variables',
'rc.fv.enableConfirm': 'Are you sure to enable the selected Global Variable? ',
'rc.fv.disable': 'Disable Global Variables',
'rc.fv.disableConfirm': 'Are you sure you want to disable the selected Global Variable? ',
'rc.fv.disableTotalOf': 'Total Of {total} Global Variables Is Disabled',
'rc.fv.namePlaceholder': 'Please enter a name!',
'rc.fv.fragmentValuePlaceholder': 'Please enter the Global Variable value',
'rc.fv.enabledPlaceholder': 'Please choose whether to enable!',
'rc.gv.Management': 'Global Variable Management',
'rc.gv.id': 'Global Variable ID',
'rc.gv.name': 'Name',
'rc.gv.value': 'Value',
'rc.gv.create': 'Create Global Variable',
'rc.gv.modify': 'Modify Global Variables',
'rc.gv.delete': 'Delete Global Variable',
'rc.gv.deleteConfirm': 'Are you sure you want to delete this Global Variable? ',
'rc.gv.namePlaceholder': 'Please enter a name!',
'rc.gv.valuePlaceholder': 'Please enter the Global Variable value',
'task.api.job.async' : 'Asynchronous submit',
'task.api.job.stop' : 'Stop job',
......
......@@ -691,22 +691,16 @@ export default {
'rc.doc.categoryPlaceholder': '请选择该文档所属类型!',
'rc.fv.Management': '全局变量管理',
'rc.fv.id': '全局变量 ID',
'rc.fv.name': '名称',
'rc.fv.fragmentValue': '全局变量值',
'rc.fv.create': '创建全局变量',
'rc.fv.modify': '修改全局变量',
'rc.fv.delete': '删除全局变量',
'rc.fv.deleteConfirm': '确定删除选中的全局变量吗?',
'rc.fv.enable': '启用全局变量',
'rc.fv.enableConfirm': '确定启用选中的全局变量吗?',
'rc.fv.disable': '禁用全局变量',
'rc.fv.disableConfirm': '确定禁用选中的全局变量吗?',
'rc.fv.disableTotalOf': '被禁用的全局变量共 {total} 个',
'rc.fv.namePlaceholder': '请输入名称!',
'rc.fv.fragmentValuePlaceholder': '请输入全局变量值',
'rc.fv.enabledPlaceholder': '请选择是否启用!',
'rc.gv.Management': '全局变量管理',
'rc.gv.id': '全局变量 ID',
'rc.gv.name': '名称',
'rc.gv.value': '变量值',
'rc.gv.create': '创建全局变量',
'rc.gv.modify': '修改全局变量',
'rc.gv.delete': '删除全局变量',
'rc.gv.deleteConfirm': '确定删除该全局变量吗?',
'rc.gv.namePlaceholder': '请输入名称!',
'rc.gv.valuePlaceholder': '请输入全局变量值',
'task.api.job.async' : '异步提交',
'task.api.job.stop' : '停止作业',
......
......@@ -29,7 +29,7 @@ import {queryList} from "@/services/api";
import {API_CONSTANTS, PROTABLE_OPTIONS_PUBLIC} from "@/services/constants";
import RoleForm from "./components/RoleForm";
import {DangerDeleteIcon} from "@/components/Icons/CustomIcons";
import {getTenantByLocalStorage} from "@/services/function";
import {getTenantByLocalStorage} from "@/utils/function";
const RoleList: React.FC = () => {
......
......@@ -100,7 +100,7 @@ const TenantFormList: React.FC = () => {
title={l('tenant.AssignUser')}
open={handleGrantTenant}
destroyOnClose
width={"90%"}
width={"75%"}
onCancel={() => {setHandleGrantTenant(false)}}
onOk={handleAssignUserSubmit}
>
......
......@@ -17,7 +17,7 @@
import Footer from '@/components/Footer';
import { setTenantStorageAndCookie } from '@/services/function';
import { setTenantStorageAndCookie } from '@/utils/function';
import { l } from '@/utils/intl';
import { LockOutlined, UserOutlined } from '@ant-design/icons';
import { CheckCard, LoginForm, ProFormCheckbox, ProFormText } from '@ant-design/pro-components';
......
/*
*
* 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, {useState} from 'react';
import {Form, Modal} from 'antd';
import {l} from "@/utils/intl";
import {GlobalVar} from "@/types/RegCenter/data";
import {ProForm, ProFormItem, ProFormSwitch, ProFormText, ProFormTextArea} from "@ant-design/pro-components";
import {FORM_LAYOUT_PUBLIC, NORMAL_MODAL_OPTIONS, PROTABLE_OPTIONS_PUBLIC} from "@/services/constants";
import CodeEdit from "@/components/CustomMonacoEditor/CodeEdit";
/**
* params
*/
export type GlobalVarFormProps = {
onCancel: (flag?: boolean) => void;
onSubmit: (values: GlobalVar) => void;
modalVisible: boolean;
values: Partial<GlobalVar>;
};
/**
* global variable code edit props
*/
const CodeEditProps ={
height : "25vh",
lineNumbers: "on",
}
const GlobalVarForm: React.FC<GlobalVarFormProps> = (props: any) => {
const [globalVarValue, setGlobalVarValue] = useState<string>(props.values.fragmentValue || '');
const [form] = Form.useForm();
const [formVals, setFormVals] = useState<GlobalVar>({
id: props.values.id,
name: props.values.name,
fragmentValue: props.values.fragmentValue,
note: props.values.note,
enabled: props.values.enabled,
createTime: props.values.createTime,
updateTime: props.values.updateTime,
});
const {
onSubmit: handleSubmit,
onCancel: handleModalVisible,
modalVisible,
} = props;
const submitForm = async () => {
const fieldsValue = await form.validateFields();
fieldsValue.id = formVals.id;
setFormVals({...formVals, ...fieldsValue});
handleSubmit({...formVals, ...fieldsValue});
};
const handleGlobalVarChange =(value: string) => {
setGlobalVarValue(value);
}
const GlobalVarRender = () => {
return (
<>
<ProFormText
name="name"
label={l('rc.gv.name')}
placeholder={l('rc.gv.namePlaceholder')}
rules={[{required: true, message: l('rc.gv.namePlaceholder')}]}
/>
<ProFormTextArea
name="note"
label={l('global.table.note')}
placeholder={l('global.table.notePlaceholder')}
allowClear
/>
<ProFormSwitch
name="enabled"
label={l('global.table.isEnable')}
checkedChildren={l('button.enable')} unCheckedChildren={l('button.disable')}
/>
<ProFormItem
name="fragmentValue"
label={l('rc.gv.value')}
rules={[{required: true, message: l('rc.gv.valuePlaceholder')}]}
>
<CodeEdit
onChange={(value =>{handleGlobalVarChange(value)})}
code={globalVarValue}
language={"sql"}
{...CodeEditProps}
/>
</ProFormItem>
</>
);
};
return (
<Modal
{...NORMAL_MODAL_OPTIONS}
title={formVals.id ? l('rc.gv.modify') : l('rc.gv.create')}
open={modalVisible}
onOk={() => submitForm()}
onCancel={() => handleModalVisible()}
>
<ProForm
{...FORM_LAYOUT_PUBLIC}
layout={"horizontal"}
submitter={false}
form={form}
initialValues={formVals}
>
{GlobalVarRender()}
</ProForm>
</Modal>
);
};
export default GlobalVarForm;
/*
*
* 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 {EditTwoTone, PlusOutlined} from '@ant-design/icons';
import {Button, Drawer, Form, Popconfirm, Space, Switch} from 'antd';
import React, {useRef, useState} from 'react';
import {PageContainer} from '@ant-design/pro-layout';
import type {ActionType, ProColumns} from '@ant-design/pro-table';
import ProTable from '@ant-design/pro-table';
import ProDescriptions from '@ant-design/pro-descriptions';
import {l} from "@/utils/intl";
import {GlobalVar} from "@/types/RegCenter/data";
import {API_CONSTANTS, PROTABLE_OPTIONS_PUBLIC, STATUS_ENUM, STATUS_MAPPING} from "@/services/constants";
import {DangerDeleteIcon} from "@/components/Icons/CustomIcons";
import {handleAddOrUpdate, handleRemoveById, updateEnabled} from "@/services/BusinessCrud";
import GlobalVarForm from "@/pages/RegCenter/GlobalVar/components/GlobalVarForm";
import {queryList} from "@/services/api";
import CodeShow from "@/components/CustomMonacoEditor/CodeShow";
const GlobalVarList: React.FC = (props: any) => {
/**
* state
*/
const [modalVisible, handleModalVisible] = useState<boolean>(false);
const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false);
const [formValues, setFormValues] = useState({});
const actionRef = useRef<ActionType>();
const [row, setRow] = useState<GlobalVar>();
const [loading, setLoading] = useState<boolean>(false);
/**
* var enable or disable
* @param value
*/
const handleChangeEnable = async (value: GlobalVar) => {
setLoading(true);
await updateEnabled(API_CONSTANTS.GLOBAL_VARIABLE_ENABLE, {id: value.id});
setLoading(false);
actionRef.current?.reload?.();
};
/**
* delete role by id
* @param id role id
*/
const handleDeleteSubmit = async (id: number) => {
await handleRemoveById(API_CONSTANTS.GLOBAL_VARIABLE_DELETE, id);
actionRef.current?.reloadAndRest?.();
}
/**
* added global var
* @param value
*/
const handleAddSubmit = async (value: GlobalVar) => {
const success = await handleAddOrUpdate(API_CONSTANTS.GLOBAL_VARIABLE, value);
if (success) {
handleModalVisible(!modalVisible);
setFormValues({});
if (actionRef.current) {
actionRef.current.reload();
}
}
}
/**
* update global var
* @param value
*/
const handleUpdateSubmit = async (value: GlobalVar) => {
const success = await handleAddOrUpdate(API_CONSTANTS.GLOBAL_VARIABLE, value);
if (success) {
handleUpdateModalVisible(!updateModalVisible);
setFormValues({});
if (actionRef.current) {
actionRef.current.reload();
}
}
}
/**
* columns
*/
const columns: ProColumns<GlobalVar>[] = [
{
title: l('rc.gv.name'),
dataIndex: 'name',
sorter: true,
render: (dom, entity) => {
return <a onClick={() => setRow(entity)}>{dom}</a>;
},
},
{
title: l('rc.gv.value'),
dataIndex: 'fragmentValue',
hideInTable: true,
render: (_, record) => {
return <CodeShow code={record.fragmentValue} />
},
},
{
title: l('global.table.note'),
dataIndex: 'note',
valueType: 'textarea',
},
{
title: l("global.table.isEnable"),
dataIndex: "enabled",
hideInSearch: true,
width: '15vh',
render: (_, record) => {
return <>
<Space>
<Switch
key={record.id}
checkedChildren={l("status.enabled")}
unCheckedChildren={l("status.disabled")}
checked={record.enabled}
onChange={() => handleChangeEnable(record)}/>
</Space>
</>;
},
filters: STATUS_MAPPING(),
filterMultiple: false,
valueEnum: STATUS_ENUM(),
},
{
title: l('global.table.createTime'),
dataIndex: 'createTime',
hideInSearch: true,
width: '20vh',
sorter: true,
valueType: 'dateTime',
},
{
title: l('global.table.lastUpdateTime'),
dataIndex: 'updateTime',
width: '20vh',
hideInSearch: true,
sorter: true,
valueType: 'dateTime',
},
{
title: l('global.table.operate'),
width: '20vh',
valueType: 'option',
render: (_, record) => [
<Button
className={"options-button"}
key={"GlobalVarEdit"}
icon={<EditTwoTone/>}
title={l("button.edit")}
onClick={() => {
setFormValues(record);
handleUpdateModalVisible(true);
}}
/>,
<Popconfirm
placement="topRight"
title={l("button.delete")}
description={l("rc.gv.deleteConfirm")}
onConfirm={() => {
handleDeleteSubmit(record.id);
}}
okText={l("button.confirm")}
cancelText={l("button.cancel")}
>
<Button key={'DeleteGlobalVarIcon'} icon={<DangerDeleteIcon/>}/>
</Popconfirm>
],
},
];
/**
* render
*/
return (
<PageContainer title={false}>
{/*table*/}
<ProTable<GlobalVar>
headerTitle={l('rc.gv.Management')}
actionRef={actionRef}
loading={loading}
{...PROTABLE_OPTIONS_PUBLIC}
toolBarRender={() => [
<Button type="primary" onClick={() => handleModalVisible(true)}>
<PlusOutlined/> {l('button.create')}
</Button>,
]}
request={(params, sorter, filter:any) => queryList(API_CONSTANTS.GLOBAL_VARIABLE, {...params, sorter, filter})}
columns={columns}
/>
{/*add*/}
<GlobalVarForm
onSubmit={ (value: GlobalVar) => {handleAddSubmit(value)}}
onCancel={() => {
handleModalVisible(!modalVisible)
}}
modalVisible={modalVisible}
values={{}}
/>
{/*update*/}
{formValues && Object.keys(formValues).length ? (
<GlobalVarForm
onSubmit={ (value:GlobalVar) => {handleUpdateSubmit(value)}}
onCancel={() => {
handleUpdateModalVisible(!updateModalVisible)
setFormValues({});
}}
modalVisible={updateModalVisible}
values={formValues}
/>
) : null
}
{/*drawer render*/}
<Drawer extra={undefined}
width={600}
visible={!!row}
onClose={() => {
setRow(undefined);
}}
closable={false}
>
{row?.name && (
<ProDescriptions<GlobalVar>
column={1}
title={row.name}
request={async () => ({
data: row,
})}
params={{
id: row.id,
}}
columns={columns as any}
/>
)}
</Drawer>
</PageContainer>
);
};
export default GlobalVarList;
......@@ -62,6 +62,13 @@ export const API_CONSTANTS = {
ROLE_ADDED_OR_UPDATE: "/api/role/addedOrUpdateRole",
ROLE_DELETE: "/api/role/delete",
// --- global variable ---
// global variable list
GLOBAL_VARIABLE: "/api/fragment",
// delete global variable by id
GLOBAL_VARIABLE_DELETE: "/api/fragment/delete",
// global variable enable or disable
GLOBAL_VARIABLE_ENABLE: "/api/fragment/enable",
};
......@@ -126,8 +133,8 @@ export const RESPONSE_CODE = {
* the form layout of public
*/
export const FORM_LAYOUT_PUBLIC = {
labelCol: {span: 7},
wrapperCol: {span: 13},
labelCol: {span: 5},
wrapperCol: {span: 15},
};
/**
......@@ -148,7 +155,7 @@ export const PROTABLE_OPTIONS_PUBLIC = {
*/
export const NORMAL_MODAL_OPTIONS = {
width: "40%",
bodyStyle: {padding: "32px 40px 48px"},
bodyStyle: {padding: "20px 10px 10px"},
destroyOnClose: true,
};
......
......@@ -15,33 +15,35 @@
* limitations under the License.
*/
import {TENANT_ID} from "@/services/constants";
import cookies from "js-cookie";
/**
* PUT tenantId TO localStorage & cookies
* @param tenantId
* theme of nav
*/
export function setTenantStorageAndCookie(tenantId: number) {
// save as localStorage
localStorage.setItem(TENANT_ID, tenantId.toString());
// save as cookies
cookies.set(TENANT_ID, tenantId.toString(), {path: "/"});
}
export const THEME = {
NAV_THEME : "navTheme",
dark: "realDark",
light: "light",
};
/**
* get tenant id
* @param tenantId
*/
export function getTenantByLocalStorage() {
return localStorage.getItem(TENANT_ID);
}
/**
* parseJsonStr
* @param jsonStr
* MonacoEditor of CodeEdit's theme
*/
export function parseJsonStr(jsonStr: string) {
return JSON.parse(JSON.stringify(jsonStr));
}
export const CODE_EDIT_THEME = {
VS: "vs",
DARK: "vs-dark",
HC_BLACK: "hc-black",
VS_CUSTOME: "vs-custom",
};
export const MonacoEditorOptions = {
// selectOnLineNumbers: true,
renderSideBySide: false, // side by side
autoIndent: 'None', // auto indent
fontSize: 16, // font size
automaticLayout: true, // auto layout
scrollBeyondLastLine:false, //is scroll beyond the last line
autoDetectHighContrast: true, // auto detect high contrast
}
/*
* 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.
*/
/**
* about alert
*/
declare namespace Alert {
/**
* alert group
*/
export type AlertGroup = {
id: number,
name: string,
alertInstanceIds: string,
note: string,
enabled: boolean,
createTime: Date,
updateTime: Date,
};
/**
* alert instance
*/
export type AlertInstance = {
id: number,
name: string,
type: string,
params: string,
enabled: boolean,
createTime: Date,
updateTime: Date,
};
}
/**
* about flink cluster
*/
declare namespace Cluster {
/**
* flink cluster instance
* mainly used for `yarn session` `standalone`
*/
export type ClusterInstance = {
id: number,
name: string,
alias: string,
type: string,
hosts: string,
jobManagerHost: string,
autoRegisters: boolean,
version: string,
status: number,
note: string,
enabled: boolean,
createTime: Date,
updateTime: Date,
};
/**
* flink cluster config
* mainly used for `projob` `application` `k8s` and start a new session cluster
*/
export type ClusterConfig = {
id: number,
name: string,
type: string,
config: any,
configJson: string,
isAvailable: boolean,
note: string,
enabled: boolean,
createTime: Date,
updateTime: Date,
};
}
/**
* about database and metadata
*/
declare namespace DataBases {
/**
* database info
*/
export type DataBase = {
id: number,
name: string,
groupName: string,
type: string,
url: string,
username: string,
password: string,
note: string,
flinkConfig: string,
flinkTemplate: string,
dbVersion: string,
status: boolean,
healthTime: Date,
heartbeatTime: Date,
enabled: boolean,
createTime: Date,
updateTime: Date,
};
/**
* table info
*/
export type Table = {
name: string,
schema: string,
catalog: string,
comment: string,
type: string,
engine: string,
options: string,
rows: number,
createTime: string,
updateTime: string,
};
/**
* table columns info
*/
export type Column = {
name: string,
type: string,
comment: string,
keyFlag: boolean,
autoIncrement: boolean,
defaultValue: string,
nullable: string,
javaType: string,
columnFamily: string,
position: number,
precision: number,
scale: number,
characterSet: string,
collation: string,
};
}
/**
* about document
*/
export type Document = {
id: number,
name: string,
category: string,
type: string,
subtype: string,
description: string,
fillValue: string,
version: string,
likeNum: number,
enabled: boolean,
createTime: Date,
updateTime: Date,
};
/**
* global variable
*/
export type GlobalVar = {
id: number,
name: string,
fragmentValue: string,
note: string,
enabled: boolean,
createTime: Date,
updateTime: Date,
};
/*
* 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 {TENANT_ID} from "@/services/constants";
import cookies from "js-cookie";
import {THEME,CODE_EDIT_THEME} from "@/types/Public/data";
import {editor} from "monaco-editor";
/**
* PUT tenantId TO localStorage & cookies
* @param tenantId
*/
export function setTenantStorageAndCookie(tenantId: number) {
// save as localStorage
localStorage.setItem(TENANT_ID, tenantId.toString());
// save as cookies
cookies.set(TENANT_ID, tenantId.toString(), {path: "/"});
}
/**
* get tenant id
* @param tenantId
*/
export function getTenantByLocalStorage() {
return localStorage.getItem(TENANT_ID);
}
/**
* parseJsonStr
* @param jsonStr
*/
export function parseJsonStr(jsonStr: string) {
return JSON.parse(JSON.stringify(jsonStr));
}
/**
* get theme by localStorage's theme
*/
export function getLocalTheme () {
return localStorage.getItem(THEME.NAV_THEME);
}
/**
* get code edit theme by localStorage's theme
* @constructor
*/
export function ConvertCodeEditTheme () {
/**
* user can define a new theme by calling the defineTheme method on the editor.
*/
editor.defineTheme(CODE_EDIT_THEME.VS_CUSTOME, {
base: 'vs', // 指定基础主题 , 可选值: 'vs', 'vs-dark', 'hc-black' , base theme
inherit: true, // 是否继承基础主题配置 , 默认为 true, is to inherit the base theme
// rules is an array of rules. The array must not be sparse (i.e. do not use holes).
rules: [
{ token: 'comment', foreground: '#008800', fontStyle: 'italic' },
{ token: 'keyword', foreground: '#f30282', fontStyle: 'bold' },
{ token: 'string', foreground: '#0b14cc' },
{ token: 'delimiter', foreground: '#ffffff' }
],
// colors is an object of color identifiers and their color values.
colors: {
'editor.background': '#141414', // editor background color
'editor.lineHighlightBackground': '#0000ff20', // editor line highlight background color
'editorLineNumber.foreground': '#ffffff', // editor line number color
'editorCursor.foreground': '#ffffff', // editor cursor color
'editorIndentGuide.background': '#ffffff', // editor indent guide color
'editor.foreground': '#ffffff', // editor selection highlight border color
}
});
const theme = getLocalTheme();
switch (theme) {
case THEME.dark:
return CODE_EDIT_THEME.VS_CUSTOME;
case THEME.light:
return CODE_EDIT_THEME.DARK;
default:
return CODE_EDIT_THEME.HC_BLACK;
}
}
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