From 0dcbc17552e4f99692ad9daa793b78909e497b32 Mon Sep 17 00:00:00 2001 From: Udo Walter Date: Thu, 24 Oct 2019 14:40:41 +0000 Subject: [groups] Add first implementation of the new config path ui --- server/lib/confighelper.js | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to 'server/lib/confighelper.js') diff --git a/server/lib/confighelper.js b/server/lib/confighelper.js index 2771596..0e152a8 100644 --- a/server/lib/confighelper.js +++ b/server/lib/confighelper.js @@ -8,12 +8,12 @@ const url = config.https.host + ':' + config.https.port async function getConfig (uuid, list) { - const client = await db.client.findOne({ where: { uuid: uuid }, include: ['groups', 'events'] }) + const client = await db.client.findOne({ where: { uuid: uuid } }) let configPath = [] // client not known, start registration if (client === null) { - let config = { id: 'REGISTRATION', name: 'Registration Script' } + let config = { id: 'REGISTRATION', name: 'Client Registration' } if (!list) { config.script = fs.readFileSync(path.join(__appdir, 'ipxe', 'registration.ipxe'), 'utf8') return config @@ -49,7 +49,35 @@ async function getConfig (uuid, list) { else if (eventList.length) return eventList[0] else if (configList.length) return configList[0] } else { - configPath = configPath.concat(importantList, eventList, configList) + configPath.push(...importantList, ...eventList, ...configList) + } + + // No config found, use default config + let config = await _prepareConfig({ id: 'DEFAULT', source: { type: 'DEFAULT' } }) + if (!list) return config + + configPath.push(config) + return configPath +} + + +async function getGroupConfig (groupId, list) { + const group = await db.group.findOne({ where: { id: groupId } }) + if (!group) return + let configPath = [] + + // Check for event or direct configs + let importantList = [] + let eventList = [] + let configList = [] + await _checkParentConfigs([group.id], importantList, eventList, configList, !list) + + if (!list) { + if (importantList.length) return importantList[0] + else if (eventList.length) return eventList[0] + else if (configList.length) return configList[0] + } else { + configPath.push(...importantList, ...eventList, ...configList) } // No config found, use default config @@ -183,6 +211,8 @@ async function _createDynamicMenu (configInfos, noScript) { const ids = [] const idSourceMap = {} + console.log(configInfos) + configInfos.forEach(configInfo => { ids.push(configInfo.id) idSourceMap[configInfo.id] = configInfo.source @@ -192,6 +222,7 @@ async function _createDynamicMenu (configInfos, noScript) { const result = { merged: true, id: JSON.stringify(configs.map(x => x.id)), + name: configs.map(x => x.name).join(' + '), configs: configs.map(x => ({ id: x.id, name: x.name, source: idSourceMap[x.id] })) } if (noScript) return result @@ -224,4 +255,4 @@ async function _createDynamicMenu (configInfos, noScript) { } -module.exports = { getConfig } \ No newline at end of file +module.exports = { getConfig, getGroupConfig } \ No newline at end of file -- cgit v1.2.3-55-g7522