|
|
|
@ -1,8 +1,6 @@ |
|
|
|
import { ItemManagerModule, ModuleConfig } from '../abstract/Module'; |
|
|
|
import { AddOptions, ObjectAny, RemoveOptions } from '../common'; |
|
|
|
import { AddOptions, RemoveOptions } from '../common'; |
|
|
|
import EditorModel from '../editor/model/Editor'; |
|
|
|
import { get, stringToPath } from '../utils/mixins'; |
|
|
|
import DataRecord from './model/DataRecord'; |
|
|
|
import DataSource from './model/DataSource'; |
|
|
|
import DataSources from './model/DataSources'; |
|
|
|
import { DataSourceProps, DataSourcesEvents } from './types'; |
|
|
|
@ -58,41 +56,4 @@ export default class DataSourceManager extends ItemManagerModule<ModuleConfig, D |
|
|
|
remove(id: string | DataSource, opts?: RemoveOptions) { |
|
|
|
return this.__remove(id, opts); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Get value from data sources by key |
|
|
|
* @param {String} key Path to value. |
|
|
|
* @param {any} defValue |
|
|
|
* @returns {any} |
|
|
|
* const value = dsm.getValue('ds_id.record_id.propName', 'defaultValue'); |
|
|
|
*/ |
|
|
|
getValue(key: string | string[], defValue: any) { |
|
|
|
return get(this.getContext(), key, defValue); |
|
|
|
} |
|
|
|
|
|
|
|
getContext() { |
|
|
|
return this.all.reduce((acc, ds) => { |
|
|
|
acc[ds.id] = ds.records.reduce((accR, dr, i) => { |
|
|
|
accR[i] = dr.attributes; |
|
|
|
accR[dr.id || i] = dr.attributes; |
|
|
|
return accR; |
|
|
|
}, {} as ObjectAny); |
|
|
|
return acc; |
|
|
|
}, {} as ObjectAny); |
|
|
|
} |
|
|
|
|
|
|
|
fromPath(path: string) { |
|
|
|
const result: [DataSource?, DataRecord?, string?] = []; |
|
|
|
const [dsId, drId, ...resPath] = stringToPath(path || ''); |
|
|
|
const dataSource = this.get(dsId); |
|
|
|
const dataRecord = dataSource?.records.get(drId); |
|
|
|
dataSource && result.push(dataSource); |
|
|
|
|
|
|
|
if (dataRecord) { |
|
|
|
result.push(dataRecord); |
|
|
|
resPath.length && result.push(resPath.join('.')); |
|
|
|
} |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|