From cb065b8c73497bd2748a2a168530d58e4b7cec98 Mon Sep 17 00:00:00 2001 From: lefteris Date: Tue, 6 Apr 2021 17:40:38 +0300 Subject: [PATCH] sort order vuetable on addhok --- swarmlab-app/src/run/app.js | 41 +++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/swarmlab-app/src/run/app.js b/swarmlab-app/src/run/app.js index 01c41adc..d88d3eca 100644 --- a/swarmlab-app/src/run/app.js +++ b/swarmlab-app/src/run/app.js @@ -131,14 +131,20 @@ app.get("/test2", cors(corsOptions), (req, res) => { var sort = req.query["sort"]; var filter = req.query["filter"]; var type = req.query["type"]; - var sort = req.query["sort"]; var sorttmp1 = sort.split("|"); var sortname = sorttmp1[0]; var sortorder = sorttmp1[1]; - console.error("Sort: " + sort + "\n Type: " + type); + console.error( + "Sort: " + + sort + + "\n Sort Name: " + + sortname + + "\n Sort Order: " + + sortorder + ); var url = "mongodb://mongo:27017/"; - + var jsonfinal = []; MongoClient.connect(url, function (err, db) { if (err) throw err; var dbo = db.db("fluentdb"); @@ -149,12 +155,39 @@ app.get("/test2", cors(corsOptions), (req, res) => { if (err) throw err; // EPIDI EXW NESTED JSON PREPEI NA TO KANW PARSE DUO FORES var obj = JSON.parse(JSON.stringify(result)); - var jsonfinal = []; + obj.forEach((value) => { if (value.log.includes("app_name")) { jsonfinal.push(JSON.parse(value.log)); } }); + //console.log("Sending Data: " + jsonfinal); + if (sortname == "type") { + jsonfinal.sort(function (a, b) { + if (sortorder == "asc") { + return a.type.localeCompare(b.type); + } else { + return b.type.localeCompare(a.type); + } + }); + } else if (sortname == "message") { + jsonfinal.sort(function (a, b) { + if (sortorder == "asc") { + return a.message.localeCompare(b.message); + } else { + return b.message.localeCompare(a.message); + } + }); + } else if (sortname == "time") { + jsonfinal.sort(function (a, b) { + if (sortorder == "asc") { + return a.timestamp.localeCompare(b.timestamp); + } else { + return b.timestamp.localeCompare(a.timestamp); + } + }); + } + // console.log("Sending Data: " + jsonfinal); res.json(jsonfinal); db.close(); });