diff --git a/extension.js b/extension.js index 4abe8f1..094e339 100644 --- a/extension.js +++ b/extension.js @@ -6,6 +6,7 @@ const provider = require('./treeProvider'); const externalUrls = require('./extraUrls').loadUrls; const clipboard = require('clipboardy'); const extensionSetting = require('./extensionSettings/settings'); +const modelDetection = require('./modelDetection'); /** * @param {string} stringToAdd @@ -79,11 +80,12 @@ function readAndDisplayUrls (projects) { }); // load pre defined url configurations - const extraUrlPatterns = externalUrls(projectPath, (error, file) => { + const detectedModels = settings.autoLoadModels? modelDetection.detect(projectPath, settings.registeredAppsOnly): new Map(); + const extraUrlPatterns = externalUrls(projectPath, settings, detectedModels, (error, file) => { vscode.window.showErrorMessage(`The configurations in ${file} are incorrect`); }, () => { vscode.window.showErrorMessage(`Wrong format on ${_project[0]}/.vscode/urlConfigs/models.json`) - }, settings); + }); // merge both patterns const mergedPatterns = [...extraUrlPatterns.keys()].length && realProject? new Map([...extraUrlPatterns, ...urlPatterns]): urlPatterns; diff --git a/extensionSettings/settings.js b/extensionSettings/settings.js index e10b43a..5ab5b3b 100644 --- a/extensionSettings/settings.js +++ b/extensionSettings/settings.js @@ -33,7 +33,8 @@ function cleanUpSettings (tempSettings) { adminUrls: boolean, autoLoadModels: boolean, builtInAuth: boolean, - expandApps: string + expandApps: string, + registeredAppsOnly: false }} extensionSettings */ function loadSettings (rootPath, errorWithSettings) { diff --git a/extraUrls.js b/extraUrls.js index 5c8624b..92d8c46 100644 --- a/extraUrls.js +++ b/extraUrls.js @@ -57,12 +57,13 @@ function _loadExtraUrls (files, errorCallBack) { /** * @param {string} home + * @param {{}} settings + * @param {Map} detectedModels * @param {() => void} handleExternalReadError * @param {() => void} wrongFormatModels - * @param {{}} settings * @returns {Map} */ -function loadUrls (home, handleExternalReadError, wrongFormatModels, settings) { +function loadUrls (home, settings, detectedModels, handleExternalReadError, wrongFormatModels) { // Read json files in extraUrls let userConfigs; @@ -85,7 +86,7 @@ function loadUrls (home, handleExternalReadError, wrongFormatModels, settings) { const urls = _loadExtraUrls(jFiles, handleExternalReadError); if (urls.has('admin')) { - const modelUrls = modelAdmin(home, wrongFormatModels, () => {}); + const modelUrls = modelAdmin(home, detectedModels, wrongFormatModels, () => {}); urls.set('admin', [...urls.get('admin'), ...modelUrls]); }; diff --git a/modelAdminLoad.js b/modelAdminLoad.js index bb5a4f2..9c1afa1 100644 --- a/modelAdminLoad.js +++ b/modelAdminLoad.js @@ -67,6 +67,7 @@ function createSingleModelUrls (model, appName, appLabel, extraLabel, objectId) /** *@param {string} home +*@param {Map} detectedModels *@param {() => void} wrongFomartCallback *@param {() => void} noModelsCallback *@returns {{ @@ -76,9 +77,12 @@ function createSingleModelUrls (model, appName, appLabel, extraLabel, objectId) hasArgs: boolean }[]} **/ -function loadModelAdminConfigs (home, wrongFomartCallback, noModelsCallback) { +function loadModelAdminConfigs (home, detectedModels, wrongFomartCallback, noModelsCallback) { let patterns = []; - const models = _getModels(home, wrongFomartCallback, noModelsCallback); + const extraModels = _getModels(home, wrongFomartCallback, noModelsCallback); + const models = detectedModels; + [...extraModels.keys()].forEach((key) => !models.has(key)? models.set(key, extraModels.get(key)): void 0); + const modelAdminUrls = [ ['changelist', false], ['add', false], @@ -92,6 +96,7 @@ function loadModelAdminConfigs (home, wrongFomartCallback, noModelsCallback) { if (Array.isArray(appModels)) { patterns = [...patterns, ...appModels.map((appModel) => { + appModel = appModel.toLowerCase(); return modelAdminUrls.map((url) => createSingleModelUrls(appModel, 'admin', model, url[0], url[1])) }).flat()]; };