Repository navigation
Expand file tree
/
Copy pathlocalData.js
More file actions
executable file
·73 lines (67 loc) · 2.09 KB
/
Copy pathlocalData.js
File metadata and controls
executable file
·73 lines (67 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { fromJS } from 'immutable'
import { handleActions } from 'redux-actions'
import { ConstPath } from '../constants'
import { FileTools } from '../native'
import { DatasetType, SMap, EngineType } from 'imobile_for_reactnative'
// Constants
// --------------------------------------------------
export const LOCAL_DATA_GET_DATASOURCES = 'LOCAL_DATA_GET_DATASOURCES'
// Actions
// --------------------------------------------------
export const getUdbAndDs = (params = {}, cb = () => {}) => async dispatch => {
let udbPath =
(await FileTools.appendingHomeDirectory(ConstPath.UserPath)) +
params.userName +
'/' +
ConstPath.RelativePath.Datasource
let udbs = await FileTools.getPathListByFilter(udbPath, {
extension: 'udb',
type: 'file',
})
let dataSourceAndSets = []
for (let i = 0; i < udbs.length; i++) {
let dataSource = udbs[i]
let alias = dataSource.path.substr(
dataSource.path.lastIndexOf('/') + 1,
dataSource.path.lastIndexOf('.') - dataSource.path.lastIndexOf('/') - 1,
)
let udbPath = await FileTools.appendingHomeDirectory(dataSource.path)
let datasets = await SMap.getDatasetsByExternalDatasource({
server: udbPath,
alias: alias,
engineType: EngineType.UDB,
})
let dss = []
for (let j = 0; j < datasets.length; j++) {
if (datasets[j].datasetType === DatasetType.Network) {
datasets[j].title = datasets[j].datasetName
datasets[j].parentTitle = datasets[j].datasourceName
dss.push(datasets[j])
}
}
if (dss.length > 0) {
dataSourceAndSets.push({
title: alias,
server: udbPath,
engineType: EngineType.UDB,
data: dss,
})
}
}
await dispatch({
type: LOCAL_DATA_GET_DATASOURCES,
payload: dataSourceAndSets,
})
cb && cb()
}
const initialState = fromJS({
userUdbAndDs: [], // 指定用户目录下的数据源和其中的数据集
})
export default handleActions(
{
[`${LOCAL_DATA_GET_DATASOURCES}`]: (state, { payload }) => {
return state.setIn(['userUdbAndDs'], fromJS(payload))
},
},
initialState,
)