-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathnjsmap.js
96 lines (93 loc) · 3.91 KB
/
njsmap.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright 2024 Nuno Aguiar
// Requires openafsigil.js
// CSS: nJSMap.css
function nJSMap(aValue, aType) {
chartObj = void 0;
// If undefined
if ($$(aValue).isUnDef()) {
aValue = "not available";
aType = "undefined";
}
// If object
var _render = (aValue) => {
if (!($$(aValue).isObject())) {
if ($$(aValue).isNumber()) return "<span style=\"color: midnightblue\">" + aValue + "</span>";
if ($$(aValue).isString()) {
// If url
if (aValue.startsWith("http"))
return "<span style=\"color: DarkSlateGray\"><a href=\"" + aValue + "\" target=\"_blank\">" + aValue + "</a></span>"
else
return "<span style=\"color: DarkSlateGray\">" + aValue + "</span>"
}
if (typeof aValue == "boolean") return "<span style=\"color: steelblue\">" + aValue + "</span>";
return aValue;
} else {
// if date
if ("undefined" !== typeof (aValue).getDate) return String(aValue);
}
var _determineKeys = ar => {
return ar.reduce((keys, map) => {
if ("[object Object]" == Object.prototype.toString.call(map)) {
for (var key in map) {
keys.add(key)
}
}
return keys
}, new Set())
}
var out = "";
if ($$(aValue).isArray() && aValue.length > 0) {
var _keys = Array.from(_determineKeys(aValue))
var out = "";
if ($$(aValue[0]).isMap()) {
out += "<table class=\"njsmap_table\"><tr>";
for(var i in _keys) {
out += "<td class=\"njsmap_tablehead\" style=\"text-align: center\"><span style=\"color: darkblue;font-weight: bold;\">" + _keys[i] + "</span></td>";
}
out += "</tr>";
} else {
out += "<table class=\"njsmap_table\">";
}
for(var x in aValue) {
out += "<tr>";
if (!($$(aValue[x]).isMap()) && !($$(aValue[x]).isArray())) {
out += "<td class=\"njsmap_tablecell\" style=\"text-align: center\"><span style=\"color: darkblue;font-weight: bold;\">" + aValue[x] + "</span></td>";
} else {
for (var y in _keys) {
var _v = ""
if (aValue[x] != null && aValue[x][_keys[y]] != null) {
if ("undefined" != aValue[x][_keys[y]]) _v = aValue[x][_keys[y]]
if ("undefined" == typeof _v) _v = ""
}
out += "<td class=\"njsmap_tablecell\" style=\"text-align: center\">" + _render(_v) + "</td>";
}
}
out += "</tr>";
}
out += "</table>";
} else {
var out = "<table class=\"njsmap_table\">";
for (var i in aValue) {
var _v = ""
if (aValue[i] != null) {
if ("undefined" != aValue[i]) _v = aValue[i]
if ("undefined" == typeof _v) _v = ""
}
out += "<tr><td class=\"njsmap_tablecell\" style=\"text-align: right; vertical-align: top\"><span style=\"color: darkblue;font-weight: bold;\">" + i + "</span></td><td class=\"njsmap_tablecell\">" + _render(_v) + "</td></tr>";
}
out += "</table>";
}
return out;
};
if ($$(aValue).isObject()) {
var out = "";
out += _render(aValue);
aValue = out;
}
switch(aType) {
case "date" : return (new Date(aValue)).toLocaleString() + "";
case "undefined": return "<span class=\"avalueNA\">" + aValue + "</span>";
default:
return "<span class=\"avalue\">" + aValue + "</span>";
}
}