(url, nodeObj, treeNodeInfo, itemNodeData, params={}, transform=(data)=>data)
| 81 | * The options are cached for performance reasons. |
| 82 | */ |
| 83 | export function getNodeAjaxOptions(url, nodeObj, treeNodeInfo, itemNodeData, params={}, transform=(data)=>data) { |
| 84 | let otherParams = { |
| 85 | urlWithId: false, |
| 86 | jumpAfterNode: null, |
| 87 | useCache: true, |
| 88 | customGenerateUrl: null, |
| 89 | ...params |
| 90 | }; |
| 91 | return new Promise((resolve, reject)=>{ |
| 92 | const api = getApiInstance(); |
| 93 | let fullUrl = ''; |
| 94 | if(url) { |
| 95 | if(otherParams.customGenerateUrl) { |
| 96 | fullUrl = otherParams.customGenerateUrl.call( |
| 97 | nodeObj, treeNodeInfo, url, itemNodeData, otherParams.urlWithId, otherParams.jumpAfterNode |
| 98 | ); |
| 99 | } else { |
| 100 | fullUrl = generateNodeUrl.call( |
| 101 | nodeObj, treeNodeInfo, url, itemNodeData, otherParams.urlWithId, otherParams.jumpAfterNode |
| 102 | ); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | if (url) { |
| 107 | let cacheNode = pgAdmin.Browser.Nodes[otherParams.cacheNode] || nodeObj; |
| 108 | let cacheLevel = otherParams.cacheLevel || cacheNode.cache_level(treeNodeInfo, otherParams.urlWithId); |
| 109 | /* |
| 110 | * We needs to check, if we have already cached data for this url. |
| 111 | * If yes - use that, and do not bother about fetching it again, |
| 112 | * and use it. |
| 113 | */ |
| 114 | let data = cacheNode.cache(nodeObj.type + '#' + url, treeNodeInfo, cacheLevel); |
| 115 | |
| 116 | if (_.isUndefined(data) || _.isNull(data)) { |
| 117 | api.get(fullUrl, { |
| 118 | params: otherParams.urlParams, |
| 119 | }).then((res)=>{ |
| 120 | data = res.data; |
| 121 | if(res.data.data) { |
| 122 | data = res.data.data; |
| 123 | } |
| 124 | otherParams.useCache && cacheNode.cache(nodeObj.type + '#' + url, treeNodeInfo, cacheLevel, data); |
| 125 | resolve(transform(data)); |
| 126 | }).catch((err)=>{ |
| 127 | reject(err instanceof Error ? err : Error('Something went wrong')); |
| 128 | }); |
| 129 | } else { |
| 130 | // To fetch only options from cache, we do not need time from 'at' |
| 131 | // attribute but only options. |
| 132 | resolve(transform(data.data || [])); |
| 133 | } |
| 134 | } |
| 135 | }); |
| 136 | } |
| 137 | |
| 138 | /* Get the nodes list based on current selected node id */ |
| 139 | export function getNodeListById(nodeObj, treeNodeInfo, itemNodeData, params={}, filter=()=>true, postTransform=(res)=>res) { |
no test coverage detected