Browse Source

(*)元数据检索功能完善

master
peng.peng 2 years ago
parent
commit
99b3497a91
  1. 16
      api/app/lib/controllers/latestMetadata/index.js
  2. 4
      web/client/src/sections/metadataManagement/containers/databasesTable.js
  3. 4
      web/client/src/sections/metadataManagement/containers/filesTable.js
  4. 40
      web/client/src/sections/metadataManagement/containers/latestMetadata.js
  5. 13
      web/client/src/sections/metadataManagement/containers/metadataTab.js
  6. 4
      web/client/src/sections/metadataManagement/containers/restapisTable.js
  7. 25
      web/client/src/sections/resourceRetrieval/containers/retrieval.js

16
api/app/lib/controllers/latestMetadata/index.js

@ -120,7 +120,7 @@ async function delResourceCatalog(ctx) {
async function getMetadataDatabases(ctx) {
try {
const models = ctx.fs.dc.models;
const { catalog, limit, offset, keywords, orderBy = 'createAt', orderDirection = 'desc', id = null } = ctx.query;
const { catalog, limit, offset, keywords, orderBy = 'createAt', orderDirection = 'desc', id = null, resourceId } = ctx.query;
const where = {};
if (catalog) {
where.catalog = catalog;
@ -128,6 +128,10 @@ async function getMetadataDatabases(ctx) {
if (id) {
where.parent = id;
}
if (resourceId) {
where.id = resourceId;
}
if (keywords) {
where['$or'] = [{ name: { $iLike: `%${keywords}%` } },
{ code: { $iLike: `%${keywords}%` } },
@ -168,13 +172,16 @@ async function getMetadataDatabases(ctx) {
async function getMetadataFiles(ctx) {
try {
const models = ctx.fs.dc.models;
const { catalog, limit, offset, keywords, orderBy = 'updateAt', orderDirection = 'desc' } = ctx.query;
const { catalog, limit, offset, keywords, orderBy = 'updateAt', orderDirection = 'desc', resourceId } = ctx.query;
const where = { catalog: catalog };
//文件类型关键字查询时需匹配fileName不能为空。
//因存在编辑时将文件删除,但未重新上传直接点击取消的情况,此时文件已删除不可恢复,数据字段fileName更新为null
if (keywords) {
where['$or'] = [{ name: { $iLike: `%${keywords}%` } }, { type: { $iLike: `%${keywords}%` }, fileName: { $not: null } }]
}
if (resourceId) {
where.id = resourceId;
}
const findObj = {
include: [
// {
@ -210,11 +217,14 @@ async function getMetadataFiles(ctx) {
async function getMetadataRestapis(ctx) {
try {
const models = ctx.fs.dc.models;
const { catalog, limit, offset, keywords, orderBy = 'createAt', orderDirection = 'desc' } = ctx.query;
const { catalog, limit, offset, keywords, orderBy = 'createAt', orderDirection = 'desc', resourceId } = ctx.query;
const where = { catalog: catalog };
if (keywords) {
where.name = { $iLike: `%${keywords}%` };
}
if (resourceId) {
where.id = resourceId;
}
const findObj = {
include: [
{

4
web/client/src/sections/metadataManagement/containers/databasesTable.js

@ -11,7 +11,7 @@ import MetadataResourceModal from '../components/metadataResourceModal';
const DatabaseTable = (props) => {
const { user, dispatch, actions, clientHeight, resourceCatalogId, resourceCatalogKey,
resourceCatalogPath, isRequesting, metadataModels, setView, tagList, metadataResourceApplications } = props;
resourceCatalogPath, isRequesting, metadataModels, setView, tagList, metadataResourceApplications, params } = props;
const { metadataManagement } = actions;
const SortValues = { 'ascend': 'asc', 'descend': 'desc' };
const [tableData, setTableData] = useState([]);
@ -36,7 +36,7 @@ const DatabaseTable = (props) => {
}, [resourceCatalogId]);
const initData = (query = {}) => {
dispatch(metadataManagement.getMetadataDatabases({ catalog: resourceCatalogId, keywords, orderBy: 'createAt', ...query })).then(res => {
dispatch(metadataManagement.getMetadataDatabases({ resourceId: params?.resourceId, catalog: resourceCatalogId, keywords, orderBy: 'createAt', ...query })).then(res => {
if (res.success) {
setTableData(res.payload.data.rows);
setTableDataCount(res.payload.data.count);

4
web/client/src/sections/metadataManagement/containers/filesTable.js

@ -12,7 +12,7 @@ import { RouteTable } from '$utils'
const FilesTable = (props) => {
const { user, dispatch, actions, clientHeight, resourceCatalogId, resourceCatalogKey,
isRequesting, metadataModels, tagList, metadataResourceApplications } = props;
isRequesting, metadataModels, tagList, metadataResourceApplications, params } = props;
const { metadataManagement } = actions;
const SortValues = { 'ascend': 'asc', 'descend': 'desc' };
const [tableData, setTableData] = useState([]);
@ -37,7 +37,7 @@ const FilesTable = (props) => {
}, []);
const initData = (query = {}) => {
dispatch(metadataManagement.getMetadataFiles({ catalog: resourceCatalogId, keywords, orderBy: 'updateAt', ...query })).then(res => {
dispatch(metadataManagement.getMetadataFiles({ resourceId: params?.resourceId, catalog: resourceCatalogId, keywords, orderBy: 'updateAt', ...query })).then(res => {
if (res.success) {
setTableData(res.payload.data.rows);
setTableDataCount(res.payload.data.count);

40
web/client/src/sections/metadataManagement/containers/latestMetadata.js

@ -20,6 +20,12 @@ const LatestMetadata = (props) => {
const [resourceCatalogId, setResourceCatalogId] = useState('');
const [resourceCatalogKey, setResourceCatalogKey] = useState('');
const [resourceCatalogPath, setResourceCatalogPath] = useState([]);
const params = GetRequest(location?.search);
useEffect(() => {
const jumpSelectedKey = sessionStorage.getItem('jumpSelectedKey') || null;
initData(true, jumpSelectedKey);
}, [location?.search])
useEffect(() => {
const jumpSelectedKey = sessionStorage.getItem('jumpSelectedKey') || null;
@ -37,8 +43,9 @@ const LatestMetadata = (props) => {
if (jumpSelectedKey || selectedKeys.length)
expandedKeysData = jumpSelectedKey ? [jumpSelectedKey] : selectedKeys;
let expandedKeys = getExpandKeys(expandedKeysData);
setSelectedKeys(expandedKeysData);
setExpandedKeys(expandedKeys);
params?.catalogKey ? setSelectedKeys([params?.catalogKey]) : setSelectedKeys(expandedKeysData);
params?.catalogKey ? setExpandedKeys(getExpandKeys([params?.catalogKey])) : setExpandedKeys(expandedKeys);
params?.treeId && setResourceCatalogId(params?.treeId);
expandedKeysData = [];
}
} else {
@ -52,7 +59,7 @@ const LatestMetadata = (props) => {
const keyArr = selectedData[0].split('-');
keyArr.shift();//['rc-2-5']->返回'rc';keyArr:['2','5']
const allExpandedKeys = allTreeNodeKeys.filter(k => keyArr.includes(k.id.toString()));
setResourceCatalogId(keyArr.pop());
!params?.treeId && setResourceCatalogId(keyArr.pop());
setResourceCatalogKey(selectedData[0]);
const resourceCatalogPath = allExpandedKeys.map(a => a.name);
setResourceCatalogPath(resourceCatalogPath);
@ -177,6 +184,8 @@ const LatestMetadata = (props) => {
const { value } = e.target;
onSearch(value);
};
return <Spin spinning={isRequesting}>
<Row>
<Col style={{ width: 240 }}>
@ -193,6 +202,7 @@ const LatestMetadata = (props) => {
expandedKeys={expandedKeys}
selectedKeys={selectedKeys}
onSelect={(keys, e) => {
history.push(`/metadataManagement/latestMetadata`);
if (e.selected) {
setSelectedKeys(keys);
getExpandKeys(keys);
@ -214,7 +224,14 @@ const LatestMetadata = (props) => {
match={match} /> :
<MetadataTab resourceCatalogId={resourceCatalogId}
resourceCatalogKey={resourceCatalogKey}
resourceCatalogPath={resourceCatalogPath} />
resourceCatalogPath={resourceCatalogPath}
params={params}
/>
// <MetadataTab resourceCatalogId={params?.treeId}
// resourceCatalogKey={params?.catalogKey}
// resourceCatalogPath={resourceCatalogPath}
// initTab={params?.type}
// />
}
</Col>
</Row>
@ -238,4 +255,17 @@ function mapStateToProps(state) {
isRequesting: resourceCatalog.isRequesting
};
}
export default connect(mapStateToProps)(LatestMetadata)
export default connect(mapStateToProps)(LatestMetadata)
function GetRequest(search) {
let url = search; //获取url中"?“符后的字串
let theRequest = new Object();
if (url.indexOf("?") != -1) {
let str = url.substr(1);
let strs = str.split("&");
for (let i = 0; i < strs.length; i++) {
theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
}
}
return theRequest;
}

13
web/client/src/sections/metadataManagement/containers/metadataTab.js

@ -7,10 +7,11 @@ import RestapisTable from './restapisTable';
import { push } from 'react-router-redux';
const MetadataTab = (props) => {
const { resourceCatalogId, resourceCatalogKey, resourceCatalogPath, actions, dispatch } = props;
const [activeKey, setActiveKey] = useState('databases');
const { resourceCatalogId, resourceCatalogKey, resourceCatalogPath, actions, dispatch, params } = props;
const [activeKey, setActiveKey] = useState(params?.type || 'databases');
useEffect(() => {
setActiveKey('databases');
if (!params?.type)
setActiveKey('databases');
}, [resourceCatalogId]);
const onTabChange = (key) => {
@ -40,11 +41,11 @@ const MetadataTab = (props) => {
]}>
</Tabs>
{
activeKey === 'databases' && resourceCatalogId ? <DatabaseTable resourceCatalogId={resourceCatalogId}
activeKey === 'databases' && resourceCatalogId ? <DatabaseTable params={params} resourceCatalogId={resourceCatalogId}
resourceCatalogKey={resourceCatalogKey} resourceCatalogPath={resourceCatalogPath} setView={onView} /> :
activeKey === 'files' && resourceCatalogId ? <FilesTable resourceCatalogId={resourceCatalogId}
activeKey === 'files' && resourceCatalogId ? <FilesTable params={params} resourceCatalogId={resourceCatalogId}
resourceCatalogKey={resourceCatalogKey} resourceCatalogPath={resourceCatalogPath} /> :
activeKey === 'restapis' && resourceCatalogId ? < RestapisTable resourceCatalogId={resourceCatalogId}
activeKey === 'restapis' && resourceCatalogId ? < RestapisTable params={params} resourceCatalogId={resourceCatalogId}
resourceCatalogKey={resourceCatalogKey} resourceCatalogPath={resourceCatalogPath} /> : null
}
</div>

4
web/client/src/sections/metadataManagement/containers/restapisTable.js

@ -8,7 +8,7 @@ import MetadataResourceModal from '../components/metadataResourceModal';
const RestapisTable = (props) => {
const { user, dispatch, actions, clientHeight, resourceCatalogId, resourceCatalogKey,
isRequesting, metadataModels, tagList, metadataResourceApplications } = props;
isRequesting, metadataModels, tagList, metadataResourceApplications, params } = props;
const { metadataManagement } = actions;
const [tableData, setTableData] = useState([]);
const [tableDataCount, setTableDataCount] = useState(0);//Table数据
@ -28,7 +28,7 @@ const RestapisTable = (props) => {
}, []);
const initData = (query = {}) => {
dispatch(metadataManagement.getMetadataRestapis({ catalog: resourceCatalogId, keywords, ...query })).then(res => {
dispatch(metadataManagement.getMetadataRestapis({ resourceId: params?.resourceId, catalog: resourceCatalogId, keywords, ...query })).then(res => {
if (res.success) {
setTableData(res.payload.data.rows);
setTableDataCount(res.payload.data.count);

25
web/client/src/sections/resourceRetrieval/containers/retrieval.js

@ -5,17 +5,27 @@ import { useFsRequest, ApiTable } from '$utils';
import { connect } from 'react-redux';
import { downloadImg } from '../utils/index'
import KeyModal from '../components/keyModal';
const METADTA_TYPE = {
'库': 'databases',
'表': 'databases',
'文件': 'files',
'接口': 'restapis',
}
import './style.less';
function Retrieval(props) {
const { user } = props;
const { user, catalogs, dispatch, actions } = props;
const [keywords, setKeywords] = useState()
const [firstInput, setFirstInput] = useState()
const [page, setPage] = useState(1)
const formRef = React.createRef();
const { data: catalogs = [] } = useFsRequest({
url: ApiTable.getResourceCatalog,
});
// const { data: catalogs = [] } = useFsRequest({
// url: ApiTable.getResourceCatalog,
// });
useEffect(() => {
dispatch(actions.metadataManagement.getResourceCatalog())
}, [])
//检索元数据
const { data: result = {} } = useFsRequest({
url: ApiTable.searchMetadata,
query: {
@ -25,6 +35,7 @@ function Retrieval(props) {
ready: !!keywords
});
//用户申请资源列表
const { data: approveList = {} } = useFsRequest({
url: ApiTable.approveList,
query: {
@ -103,7 +114,7 @@ function Retrieval(props) {
<span> 路径{renderText(catalogText)}</span>
<span> 标签{renderText(tagText)}</span>
</div>
<div className='column2'>相关操作<a onClick={() => { window.open('/metadataManagement/latestMetadata') }}>定位</a>
<div className='column2'>相关操作<a onClick={() => { window.open(`/metadataManagement/latestMetadata?type=${METADTA_TYPE[s.type]}&treeId=${s?.catalog}&resourceId=${s.id}&catalogKey=${s.catalogKey}`) }}>定位</a>
{s?.type == '表' || s?.type == '文件' ?
user?.role == '数据消费者' ?
<KeyModal
@ -130,9 +141,11 @@ function Retrieval(props) {
}
function mapStateToProps(state) {
const { auth, } = state;
const { auth, resourceCatalog, global } = state;
return {
catalogs: resourceCatalog?.data || [],
user: auth.user,
actions: global.actions,
};
}
export default connect(mapStateToProps)(Retrieval)

Loading…
Cancel
Save