fix(crowdsec-dashboard): Fix overview nav path and countries parsing
- Fix nav links to use correct path (security instead of services) - Add parseCountries() to convert top_countries_raw JSON to object - Fix geo data display in overview Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
e14ef7fa00
commit
5496ca1f3a
@ -13,9 +13,32 @@ return view.extend({
|
|||||||
return api.getOverview().catch(function() { return {}; });
|
return api.getOverview().catch(function() { return {}; });
|
||||||
},
|
},
|
||||||
|
|
||||||
|
parseCountries: function(data) {
|
||||||
|
var countries = {};
|
||||||
|
// Handle top_countries_raw (JSON string array)
|
||||||
|
if (data.top_countries_raw) {
|
||||||
|
try {
|
||||||
|
var arr = typeof data.top_countries_raw === 'string'
|
||||||
|
? JSON.parse(data.top_countries_raw)
|
||||||
|
: data.top_countries_raw;
|
||||||
|
if (Array.isArray(arr)) {
|
||||||
|
arr.forEach(function(item) {
|
||||||
|
if (item.country) countries[item.country] = item.count || 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
// Also handle direct countries object if present
|
||||||
|
if (data.countries && typeof data.countries === 'object') {
|
||||||
|
Object.assign(countries, data.countries);
|
||||||
|
}
|
||||||
|
return countries;
|
||||||
|
},
|
||||||
|
|
||||||
render: function(data) {
|
render: function(data) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var s = data || {};
|
var s = data || {};
|
||||||
|
s.countries = this.parseCountries(s);
|
||||||
|
|
||||||
var view = E('div', { 'class': 'cs-view' }, [
|
var view = E('div', { 'class': 'cs-view' }, [
|
||||||
// Header
|
// Header
|
||||||
@ -68,7 +91,7 @@ return view.extend({
|
|||||||
];
|
];
|
||||||
return E('div', { 'class': 'cs-nav' }, tabs.map(function(t) {
|
return E('div', { 'class': 'cs-nav' }, tabs.map(function(t) {
|
||||||
return E('a', {
|
return E('a', {
|
||||||
'href': L.url('admin/secubox/services/crowdsec/' + t.id),
|
'href': L.url('admin/secubox/security/crowdsec/' + t.id),
|
||||||
'class': active === t.id ? 'active' : ''
|
'class': active === t.id ? 'active' : ''
|
||||||
}, t.label);
|
}, t.label);
|
||||||
}));
|
}));
|
||||||
@ -154,6 +177,7 @@ return view.extend({
|
|||||||
pollData: function() {
|
pollData: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
return api.getOverview().then(function(s) {
|
return api.getOverview().then(function(s) {
|
||||||
|
s.countries = self.parseCountries(s);
|
||||||
var el = document.getElementById('cs-stats');
|
var el = document.getElementById('cs-stats');
|
||||||
if (el) dom.content(el, self.renderStats(s));
|
if (el) dom.content(el, self.renderStats(s));
|
||||||
el = document.getElementById('cs-alerts');
|
el = document.getElementById('cs-alerts');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user