From 9bffdf4923a20a443f28c74aa4b130a5bbf1bb34 Mon Sep 17 00:00:00 2001 From: Udo Walter Date: Wed, 25 Mar 2020 12:29:17 +0000 Subject: [webapp] show part of the path (full path on hover) in the select boxes for selecting groups and clients --- server/api/clients.js | 8 ++++++-- server/api/groups.js | 5 ++++- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'server/api') diff --git a/server/api/clients.js b/server/api/clients.js index 15e3b8d..4222f49 100644 --- a/server/api/clients.js +++ b/server/api/clients.js @@ -8,13 +8,17 @@ const { decorateApp } = require('@awaitjs/express') var router = decorateApp(express.Router()) const HttpResponse = require(path.join(__appdir, 'lib', 'httpresponse')) const log = require(path.join(__appdir, 'lib', 'log')) +const groupHelper = require(path.join(__appdir, 'lib', 'grouphelper')) // ############################################################################ // ########################### GET requests ################################# router.getAsync('', async (req, res) => { - const clients = await db.client.findAll({ order: [['name', 'ASC']] }) - res.status(200).send(clients) + const includePaths = req.query.path !== undefined && req.query.path !== 'false' + const include = includePaths ? ['groups'] : [] + let clients = await db.client.findAll({ order: [['name', 'ASC']], include }) + if (includePaths) clients = await groupHelper.addPathsToClients(clients, false) + res.send(clients) }) router.getAsync('/:id', async (req, res) => { diff --git a/server/api/groups.js b/server/api/groups.js index 88e7da8..64351cf 100644 --- a/server/api/groups.js +++ b/server/api/groups.js @@ -14,7 +14,10 @@ const log = require(path.join(__appdir, 'lib', 'log')) // ########################### GET requests ################################# router.getAsync('', async (req, res) => { - const groups = await db.group.findAll({ order: [['name', 'ASC']] }) + const includePaths = req.query.path !== undefined && req.query.path !== 'false' + const include = includePaths ? ['parents'] : [] + let groups = await db.group.findAll({ order: [['name', 'ASC']], include }) + if (includePaths) groups = await groupHelper.addPathsToGroups(groups, false) res.send(groups) }) -- cgit v1.2.3-55-g7522