Browse Source

sort order vuetable on addhok

master
lefteris 4 years ago
parent
commit
cb065b8c73
  1. 41
      swarmlab-app/src/run/app.js

41
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();
});

Loading…
Cancel
Save