SysOps: manual — 2026-07-30 09:33 UTC
This commit is contained in:
@@ -5,6 +5,12 @@ function exportIntelApp() {
|
||||
tabIndicatorH: 40,
|
||||
busy: false,
|
||||
syncMsg: '',
|
||||
syncMonitor: null,
|
||||
syncMonitorOpen: true,
|
||||
syncMonitorPoll: null,
|
||||
googleMapsKey: '',
|
||||
googleMapsKeySet: false,
|
||||
googleKeySaving: false,
|
||||
stats: {},
|
||||
regions: [],
|
||||
territories: [],
|
||||
@@ -27,6 +33,7 @@ function exportIntelApp() {
|
||||
mapHalalMin: 55,
|
||||
mapError: '',
|
||||
mapLoading: false,
|
||||
tabMapLoading: false,
|
||||
mapTruncated: false,
|
||||
halalTopMarkets: [],
|
||||
halalTopEntities: [],
|
||||
@@ -37,6 +44,11 @@ function exportIntelApp() {
|
||||
filterHasEmail: '',
|
||||
filterFavoritesOnly: false,
|
||||
filterCrmStatus: '',
|
||||
filterConfidenceMin: '',
|
||||
filterCity: '',
|
||||
filterTenderStatus: '',
|
||||
filterGovCategory: '',
|
||||
_cityTimer: null,
|
||||
selectedIds: [],
|
||||
crmPipeline: [],
|
||||
crmModalOpen: false,
|
||||
@@ -58,12 +70,65 @@ function exportIntelApp() {
|
||||
{ id: 'pipeline', icon: '🔗', label: 'Pipeline', color: '#fb923c', key: '8' },
|
||||
],
|
||||
|
||||
|
||||
TYPE_GROUPS: {
|
||||
b2b: ['distributor', 'wholesaler', 'importer', 'logistics', 'cold_storage', 'port_agent'],
|
||||
horeca: ['restaurant', 'doner_shoarma', 'butcher', 'foodservice'],
|
||||
caterer: ['contract_caterer'],
|
||||
},
|
||||
TYPE_CHIP_EXPAND: {
|
||||
distributor: 'b2b',
|
||||
importer: 'b2b',
|
||||
logistics: 'b2b',
|
||||
restaurant: 'horeca',
|
||||
doner_shoarma: 'horeca',
|
||||
butcher: 'horeca',
|
||||
foodservice: 'horeca',
|
||||
},
|
||||
|
||||
expandEntityTypes(typeOrList) {
|
||||
var self = this;
|
||||
var raw = Array.isArray(typeOrList) ? typeOrList : [typeOrList];
|
||||
var out = [];
|
||||
raw.forEach(function (v) {
|
||||
if (!v) return;
|
||||
var key = String(v).trim();
|
||||
var group = self.TYPE_CHIP_EXPAND[key];
|
||||
if (group && self.TYPE_GROUPS[group]) {
|
||||
out = out.concat(self.TYPE_GROUPS[group]);
|
||||
} else {
|
||||
out.push(key);
|
||||
}
|
||||
});
|
||||
return out.filter(function (v, i, a) { return a.indexOf(v) === i; });
|
||||
},
|
||||
|
||||
mapTypesParam() {
|
||||
if (this.entityTypeFilter) {
|
||||
var expanded = this.expandEntityTypes(this.entityTypeFilter);
|
||||
if (expanded.length === 1) return { entity_type: expanded[0] };
|
||||
if (expanded.length) return { entity_types: expanded.join(',') };
|
||||
}
|
||||
if (this.mapTypesSelected.length) {
|
||||
var all = this.expandEntityTypes(this.mapTypesSelected);
|
||||
if (all.length === 1) return { entity_type: all[0] };
|
||||
if (all.length) return { entity_types: all.join(',') };
|
||||
}
|
||||
return {};
|
||||
},
|
||||
|
||||
shouldAutoFitMap(featCount) {
|
||||
return !!(this.country || this.region || this.q || this.entityTypeFilter ||
|
||||
this.mapTypesSelected.length || this.mapHalalMode || this.filterFavoritesOnly ||
|
||||
this.filterCrmStatus || (featCount > 0 && featCount <= 800));
|
||||
},
|
||||
|
||||
mapTypeChips: [
|
||||
{ v: 'distributor', l: 'Distributeur', icon: '📦' },
|
||||
{ v: 'distributor', l: 'B2B / distri', icon: '📦' },
|
||||
{ v: 'wholesaler', l: 'Groothandel', icon: '🏪' },
|
||||
{ v: 'importer', l: 'Importeur', icon: '🚢' },
|
||||
{ v: 'logistics', l: 'Logistiek', icon: '🚚' },
|
||||
{ v: 'restaurant', l: 'Restaurant', icon: '🍽️' },
|
||||
{ v: 'restaurant', l: 'Horeca', icon: '🍽️' },
|
||||
{ v: 'doner_shoarma', l: 'Döner', icon: '🥙' },
|
||||
{ v: 'butcher', l: 'Slager', icon: '🥩' },
|
||||
{ v: 'contract_caterer', l: 'Cateraar', icon: '🏢' },
|
||||
@@ -75,11 +140,13 @@ function exportIntelApp() {
|
||||
var t = params.get('tab');
|
||||
if (t) this.tab = t;
|
||||
var self = this;
|
||||
window.__exportIntelApp = self;
|
||||
document.addEventListener('export-intel:open-entity', function (ev) {
|
||||
if (ev.detail && ev.detail.id) self.openEntity(ev.detail.id);
|
||||
});
|
||||
await this.loadMeta();
|
||||
await this.refresh();
|
||||
this.startSyncMonitor(true);
|
||||
this.$nextTick(() => this.updateTabIndicator());
|
||||
window.addEventListener('keydown', (e) => {
|
||||
if (e.target.matches('input, textarea, select')) return;
|
||||
@@ -94,6 +161,7 @@ function exportIntelApp() {
|
||||
async loadMeta() {
|
||||
try {
|
||||
this.regions = await fetch('/api/export-intel/regions').then((r) => r.json());
|
||||
await this.loadGoogleSettings();
|
||||
this.territories = await fetch('/api/export-intel/territories').then((r) => r.json());
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
@@ -141,6 +209,10 @@ function exportIntelApp() {
|
||||
this.filterHasEmail = '';
|
||||
this.filterFavoritesOnly = false;
|
||||
this.filterCrmStatus = '';
|
||||
this.filterConfidenceMin = '';
|
||||
this.filterCity = '';
|
||||
this.filterTenderStatus = '';
|
||||
this.filterGovCategory = '';
|
||||
this.selectedIds = [];
|
||||
this.applyMapFilters();
|
||||
},
|
||||
@@ -153,6 +225,14 @@ function exportIntelApp() {
|
||||
return this.tab === 'map';
|
||||
},
|
||||
|
||||
mapTypeCount(v) {
|
||||
var geo = (this.stats && this.stats.entity_types_geo) || {};
|
||||
var expanded = this.expandEntityTypes(v);
|
||||
var n = 0;
|
||||
expanded.forEach(function (t) { n += Number(geo[t] || 0); });
|
||||
return n;
|
||||
},
|
||||
|
||||
isMapTypeActive(v) {
|
||||
return this.mapTypesSelected.indexOf(v) >= 0;
|
||||
},
|
||||
@@ -170,14 +250,6 @@ function exportIntelApp() {
|
||||
this.applyMapFilters();
|
||||
},
|
||||
|
||||
mapTypesParam() {
|
||||
if (this.entityTypeFilter) return { entity_type: this.entityTypeFilter };
|
||||
if (this.mapTypesSelected.length) {
|
||||
return { entity_types: this.mapTypesSelected.join(',') };
|
||||
}
|
||||
return {};
|
||||
},
|
||||
|
||||
applyMapFilters() {
|
||||
if (this.tab !== 'map') {
|
||||
this.loadTabData();
|
||||
@@ -187,11 +259,31 @@ function exportIntelApp() {
|
||||
},
|
||||
|
||||
showEmailFilter() {
|
||||
return this.tab === 'contacts';
|
||||
return ['map', 'distributors', 'customers', 'caterers', 'contacts'].indexOf(this.tab) >= 0;
|
||||
},
|
||||
|
||||
showCrmFilter() {
|
||||
return this.tab === 'map' || this.tab === 'contacts';
|
||||
return ['map', 'distributors', 'customers', 'caterers', 'contacts', 'pipeline'].indexOf(this.tab) >= 0;
|
||||
},
|
||||
|
||||
showCollectionFilters() {
|
||||
return this.showCrmFilter() || this.showFavoritesFilter();
|
||||
},
|
||||
|
||||
showFavoritesFilter() {
|
||||
return ['map', 'distributors', 'customers', 'caterers', 'contacts'].indexOf(this.tab) >= 0;
|
||||
},
|
||||
|
||||
showConfidenceFilter() {
|
||||
return this.tab === 'distributors';
|
||||
},
|
||||
|
||||
showCityFilter() {
|
||||
return ['distributors', 'customers', 'caterers', 'contacts'].indexOf(this.tab) >= 0;
|
||||
},
|
||||
|
||||
showContextFilters() {
|
||||
return this.showEntityTypeFilter() || this.showEmailFilter() || this.showConfidenceFilter() || this.showCityFilter() || this.tab === 'tenders' || this.tab === 'gov';
|
||||
},
|
||||
|
||||
showSelectionBar() {
|
||||
@@ -210,6 +302,75 @@ function exportIntelApp() {
|
||||
return 'Bezig…';
|
||||
},
|
||||
|
||||
|
||||
displayEntities() {
|
||||
var list = this.entities || [];
|
||||
if (this.filterHasEmail === "yes") {
|
||||
list = list.filter(function (e) {
|
||||
return e.email || e.primary_email || e.phone || e.primary_phone || e.has_contact;
|
||||
});
|
||||
} else if (this.filterHasEmail === "no") {
|
||||
list = list.filter(function (e) {
|
||||
return !e.email && !e.primary_email && !e.phone && !e.primary_phone && !e.has_contact;
|
||||
});
|
||||
}
|
||||
if (this.filterConfidenceMin) {
|
||||
var min = Number(this.filterConfidenceMin);
|
||||
list = list.filter(function (e) { return (e.confidence || 0) >= min; });
|
||||
}
|
||||
if (this.filterCity && this.filterCity.trim()) {
|
||||
var c = this.filterCity.trim().toLowerCase();
|
||||
list = list.filter(function (e) { return (e.city || "").toLowerCase().includes(c); });
|
||||
}
|
||||
return list;
|
||||
},
|
||||
|
||||
displayCount() {
|
||||
if (this.tab === "contacts") return (this.contacts || []).length;
|
||||
return this.displayEntities().length;
|
||||
},
|
||||
|
||||
displayPipeline() {
|
||||
var list = this.crmPipeline || [];
|
||||
if (this.q && this.q.trim()) {
|
||||
var ql = this.q.trim().toLowerCase();
|
||||
list = list.filter(function (p) { return (p.name || "").toLowerCase().includes(ql); });
|
||||
}
|
||||
return list;
|
||||
},
|
||||
|
||||
hasActiveFilters() {
|
||||
return !!(this.q || this.entityTypeFilter || this.mapTypesSelected.length || this.mapHalalMode ||
|
||||
this.filterHasEmail || this.filterFavoritesOnly || this.filterCrmStatus ||
|
||||
this.filterConfidenceMin || this.filterCity || this.filterTenderStatus || this.filterGovCategory);
|
||||
},
|
||||
|
||||
applyEntityFilters() {
|
||||
if (this.tab === "map") this.applyMapFilters();
|
||||
else {
|
||||
this.loadTabData();
|
||||
}
|
||||
},
|
||||
|
||||
onCityFilterInput() {
|
||||
clearTimeout(this._cityTimer);
|
||||
},
|
||||
|
||||
onPipelineFilter() {
|
||||
clearTimeout(this._searchTimer);
|
||||
},
|
||||
|
||||
applyGovFilters() {
|
||||
this.loadTabData();
|
||||
},
|
||||
|
||||
visibleEntities() {
|
||||
if (this.tab === "map" && this.mapHalalMode && this.halalTopEntities.length) {
|
||||
return this.halalTopEntities;
|
||||
}
|
||||
return this.displayEntities();
|
||||
},
|
||||
|
||||
entityTypeOptions() {
|
||||
if (this.tab === 'distributors') {
|
||||
return [
|
||||
@@ -232,6 +393,15 @@ function exportIntelApp() {
|
||||
if (this.tab === 'caterers') {
|
||||
return [{ v: '', l: 'Alle types' }, { v: 'contract_caterer', l: 'Contract cateraar' }];
|
||||
}
|
||||
if (this.tab === 'pipeline') {
|
||||
return [
|
||||
{ v: '', l: 'Alle types' },
|
||||
{ v: 'distributor', l: 'Distributeur' },
|
||||
{ v: 'wholesaler', l: 'Groothandel' },
|
||||
{ v: 'contract_caterer', l: 'Cateraar' },
|
||||
{ v: 'restaurant', l: 'Restaurant' },
|
||||
];
|
||||
}
|
||||
if (this.tab === 'contacts') {
|
||||
return [
|
||||
{ v: '', l: 'Alle types' },
|
||||
@@ -253,6 +423,91 @@ function exportIntelApp() {
|
||||
];
|
||||
},
|
||||
|
||||
|
||||
tabMapId() {
|
||||
var tabs = ['distributors', 'customers', 'caterers', 'contacts', 'pipeline'];
|
||||
if (tabs.indexOf(this.tab) < 0) return null;
|
||||
return 'ei-map-' + this.tab;
|
||||
},
|
||||
|
||||
entitiesToGeojson(list) {
|
||||
var features = [];
|
||||
(list || []).forEach(function (e) {
|
||||
if (e.lat == null || e.lon == null) return;
|
||||
features.push({
|
||||
type: 'Feature',
|
||||
geometry: { type: 'Point', coordinates: [Number(e.lon), Number(e.lat)] },
|
||||
properties: {
|
||||
id: e.id,
|
||||
name: e.name,
|
||||
entity_type: e.entity_type,
|
||||
country_iso2: e.country_iso2,
|
||||
city: e.city,
|
||||
address_line: e.address_line,
|
||||
email: e.email || e.primary_email,
|
||||
phone: e.phone || e.primary_phone,
|
||||
website: e.website,
|
||||
confidence: e.confidence,
|
||||
halal_score: e.halal_score,
|
||||
halal_tier: e.halal_tier,
|
||||
contact_count: e.contact_count,
|
||||
pipeline_stage: e.pipeline_stage,
|
||||
volume_band: e.volume_band,
|
||||
},
|
||||
});
|
||||
});
|
||||
return { type: 'FeatureCollection', features: features };
|
||||
},
|
||||
|
||||
async fetchTabMapBundle() {
|
||||
var url = '/api/export-intel/map/bundle';
|
||||
var qs = [];
|
||||
if (this.country) qs.push('country=' + encodeURIComponent(this.country));
|
||||
if (this.region) qs.push('region=' + encodeURIComponent(this.region));
|
||||
if (this.q && this.q.trim()) qs.push('q=' + encodeURIComponent(this.q.trim()));
|
||||
if (this.filterFavoritesOnly) qs.push('favorite_only=true');
|
||||
if (this.filterCrmStatus === 'linked') qs.push('crm_linked=true');
|
||||
if (this.filterCrmStatus === 'not_linked') qs.push('crm_linked=false');
|
||||
var tabTypes = null;
|
||||
if (this.tab === 'distributors') tabTypes = this.TYPE_GROUPS.b2b;
|
||||
else if (this.tab === 'customers') tabTypes = this.TYPE_GROUPS.horeca;
|
||||
else if (this.tab === 'caterers') tabTypes = this.TYPE_GROUPS.caterer;
|
||||
if (this.entityTypeFilter) {
|
||||
var ef = this.expandEntityTypes(this.entityTypeFilter);
|
||||
tabTypes = ef;
|
||||
}
|
||||
if (tabTypes) {
|
||||
if (tabTypes.length === 1) qs.push('entity_type=' + encodeURIComponent(tabTypes[0]));
|
||||
else qs.push('entity_types=' + encodeURIComponent(tabTypes.join(',')));
|
||||
}
|
||||
if (this.tab === 'pipeline') qs.push('crm_linked=true');
|
||||
if (qs.length) url += '?' + qs.join('&');
|
||||
var bundle = await fetch(url).then(function (r) { return r.json(); });
|
||||
this._lastMapBundleMeta = bundle.meta || {};
|
||||
return bundle.entities || { type: 'FeatureCollection', features: [] };
|
||||
},
|
||||
|
||||
async loadTabMap() {
|
||||
var cid = this.tabMapId();
|
||||
if (!cid || !document.getElementById(cid)) return;
|
||||
if (!window.L || !window.ExportIntelMap) return;
|
||||
this.tabMapLoading = true;
|
||||
try {
|
||||
var geo = await this.fetchTabMapBundle();
|
||||
var featN = (geo.features || []).length;
|
||||
var self = this;
|
||||
await this.$nextTick();
|
||||
window.ExportIntelMap.init(cid);
|
||||
window.ExportIntelMap.setOnEntityClick(function (id) { self.openEntity(id); }, cid);
|
||||
window.ExportIntelMap.setHalalMode(false, cid);
|
||||
window.ExportIntelMap.setFeatures(geo, { autoFit: this.shouldAutoFitMap(featN) }, cid);
|
||||
if (window.ExportIntelMap.invalidateAll) window.ExportIntelMap.invalidateAll();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
this.tabMapLoading = false;
|
||||
},
|
||||
|
||||
async loadTabData(opts) {
|
||||
opts = opts || {};
|
||||
var base = '/api/export-intel';
|
||||
@@ -260,20 +515,18 @@ function exportIntelApp() {
|
||||
if (this.tab === 'map') {
|
||||
return;
|
||||
} else if (this.tab === 'distributors') {
|
||||
var types = 'distributor,wholesaler,importer,logistics';
|
||||
var et = this.entityTypeFilter ? '&entity_type=' + encodeURIComponent(this.entityTypeFilter) : '';
|
||||
var r = await fetch(base + '/entities?entity_types=' + types + '&limit=500' + fq.replace(/&?entity_type=[^&]*/g, '') + et).then((x) => x.json());
|
||||
var types = this.expandEntityTypes(this.entityTypeFilter || 'b2b').join(',');
|
||||
var r = await fetch(base + '/entities?entity_types=' + encodeURIComponent(types) + '&limit=500' + fq.replace(/&?entity_type=[^&]*/g, '')).then((x) => x.json());
|
||||
this.entities = r.items || [];
|
||||
this.resultCount = r.total != null ? r.total : this.entities.length;
|
||||
} else if (this.tab === 'customers') {
|
||||
var types2 = 'restaurant,doner_shoarma,butcher,foodservice';
|
||||
var et2 = this.entityTypeFilter ? '&entity_type=' + encodeURIComponent(this.entityTypeFilter) : '';
|
||||
var r2 = await fetch(base + '/entities?entity_types=' + types2 + '&limit=500' + fq.replace(/&?entity_type=[^&]*/g, '') + et2).then((x) => x.json());
|
||||
var types2 = this.expandEntityTypes(this.entityTypeFilter || 'horeca').join(',');
|
||||
var r2 = await fetch(base + '/entities?entity_types=' + encodeURIComponent(types2) + '&limit=500' + fq.replace(/&?entity_type=[^&]*/g, '')).then((x) => x.json());
|
||||
this.entities = r2.items || [];
|
||||
this.resultCount = r2.total != null ? r2.total : this.entities.length;
|
||||
} else if (this.tab === 'caterers') {
|
||||
var et3 = this.entityTypeFilter || 'contract_caterer';
|
||||
var r3 = await fetch(base + '/entities?entity_type=' + et3 + '&limit=500' + fq.replace(/&?entity_type=[^&]*/g, '')).then((x) => x.json());
|
||||
var types3 = this.expandEntityTypes(this.entityTypeFilter || 'contract_caterer').join(',');
|
||||
var r3 = await fetch(base + '/entities?entity_types=' + encodeURIComponent(types3) + '&limit=500' + fq.replace(/&?entity_type=[^&]*/g, '')).then((x) => x.json());
|
||||
this.entities = r3.items || [];
|
||||
this.resultCount = r3.total != null ? r3.total : this.entities.length;
|
||||
this.catererPresence = await fetch(base + '/caterers/presence' + (this.country ? '?country=' + this.country : '')).then((x) => x.json());
|
||||
@@ -297,6 +550,9 @@ function exportIntelApp() {
|
||||
var ql = this.q.trim().toLowerCase();
|
||||
items = items.filter((t) => (t.title || '').toLowerCase().includes(ql));
|
||||
}
|
||||
if (this.filterTenderStatus) {
|
||||
items = items.filter((t) => (t.status || '').toLowerCase() === this.filterTenderStatus);
|
||||
}
|
||||
this.tenders = items;
|
||||
this.resultCount = items.length;
|
||||
} else if (this.tab === 'gov') {
|
||||
@@ -313,6 +569,9 @@ function exportIntelApp() {
|
||||
this.crmPipeline = pipe.items || [];
|
||||
this.resultCount = this.crmPipeline.length;
|
||||
}
|
||||
if (['distributors','customers','caterers','contacts','pipeline'].indexOf(this.tab) >= 0) {
|
||||
this.$nextTick(() => this.loadTabMap());
|
||||
}
|
||||
},
|
||||
|
||||
async loadMap() {
|
||||
@@ -355,16 +614,25 @@ function exportIntelApp() {
|
||||
if (!document.getElementById('ei-map')) { this.mapLoading = false; return; }
|
||||
var self = this;
|
||||
window.ExportIntelMap.init('ei-map');
|
||||
window.ExportIntelMap.setOnEntityClick(function (id) { self.openEntity(id); });
|
||||
window.ExportIntelMap.setHalalMode(this.mapHalalMode);
|
||||
var autoFit = !!(this.country || this.region);
|
||||
window.ExportIntelMap.setFeatures(bundle.entities || { features: [] }, { autoFit: autoFit });
|
||||
window.ExportIntelMap.setOnEntityClick(function (id) { self.openEntity(id); }, 'ei-map');
|
||||
window.ExportIntelMap.setHalalMode(this.mapHalalMode, 'ei-map');
|
||||
var feats = (bundle.entities && bundle.entities.features) || [];
|
||||
var autoFit = this.shouldAutoFitMap(feats.length);
|
||||
window.ExportIntelMap.setFeatures(bundle.entities || { features: [] }, { autoFit: autoFit }, 'ei-map');
|
||||
if (this.country) {
|
||||
var t = this.territories.find((x) => x.country_iso2 === this.country);
|
||||
if (t && t.lat && t.lon) window.ExportIntelMap.flyTo(t.lat, t.lon, t.map_zoom || 6);
|
||||
if (t && t.lat && t.lon) window.ExportIntelMap.flyTo(t.lat, t.lon, t.map_zoom || 6, 'ei-map');
|
||||
}
|
||||
}
|
||||
this.mapLoading = false;
|
||||
var self2 = this;
|
||||
this.$nextTick(function () {
|
||||
requestAnimationFrame(function () {
|
||||
if (window.ExportIntelMap && window.ExportIntelMap.invalidateAll) {
|
||||
window.ExportIntelMap.invalidateAll();
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
setTab(id, el) {
|
||||
@@ -378,6 +646,9 @@ function exportIntelApp() {
|
||||
history.replaceState(null, '', u.pathname + u.search);
|
||||
this.loadTabData();
|
||||
if (id === 'map') this.$nextTick(() => this.loadMap());
|
||||
else if (['distributors','customers','caterers','contacts','pipeline'].indexOf(id) >= 0) {
|
||||
this.$nextTick(() => this.loadTabMap());
|
||||
}
|
||||
this.$nextTick(() => this.updateTabIndicator(el));
|
||||
},
|
||||
|
||||
@@ -440,34 +711,20 @@ function exportIntelApp() {
|
||||
this.listFocusDetail = null;
|
||||
},
|
||||
|
||||
async openEntity(id) {
|
||||
openEntity(id) {
|
||||
if (!id) return;
|
||||
this.drawerLoading = true;
|
||||
this.drawerOpen = true;
|
||||
try {
|
||||
if (this.listFocusDetail && this.listFocusDetail.id === id) {
|
||||
this.selected = this.listFocusDetail;
|
||||
} else {
|
||||
this.selected = await this.fetchEntityDetail(id);
|
||||
this.listFocusId = id;
|
||||
this.listFocusDetail = this.selected;
|
||||
}
|
||||
if (window.ExportIntelMap && this.selected.lat && this.selected.lon) {
|
||||
window.ExportIntelMap.flyTo(this.selected.lat, this.selected.lon, 14);
|
||||
window.ExportIntelMap.highlightEntity(this.selected.id);
|
||||
}
|
||||
if (window.ExportIntelMap && window.ExportIntelMap.closePopup) {
|
||||
window.ExportIntelMap.closePopup();
|
||||
}
|
||||
} catch (e) {
|
||||
this.syncMsg = 'Profiel laden mislukt: ' + e.message;
|
||||
this.drawerOpen = false;
|
||||
this.selected = null;
|
||||
if (window.ExportIntelProfile && typeof window.ExportIntelProfile.open === 'function') {
|
||||
window.ExportIntelProfile.open(id);
|
||||
return;
|
||||
}
|
||||
this.drawerLoading = false;
|
||||
this.syncMsg = 'Profiel-module niet geladen — ververs de pagina';
|
||||
},
|
||||
|
||||
closeDrawer() {
|
||||
if (window.ExportIntelProfile && typeof window.ExportIntelProfile.close === 'function') {
|
||||
window.ExportIntelProfile.close();
|
||||
return;
|
||||
}
|
||||
this.drawerOpen = false;
|
||||
this.selected = null;
|
||||
this.drawerLoading = false;
|
||||
@@ -528,7 +785,7 @@ function exportIntelApp() {
|
||||
|
||||
async syncKind(kind) {
|
||||
if (kind === 'world') {
|
||||
if (!confirm('Wereld-sync: Europa, Midden-Oosten, Afrika en Amerika. OSM + contacten — kan lang duren. Doorgaan?')) return;
|
||||
if (!confirm('Wereld-sync: alle regio\'s (Europa, MENA, Afrika, Amerika, Asia, Oceanië). OSM + horeca + contacten — kan uren duren. Doorgaan?')) return;
|
||||
}
|
||||
if (kind === 'region' && !this.region) {
|
||||
this.syncMsg = 'Selecteer eerst een regio in de filterbalk';
|
||||
@@ -542,7 +799,12 @@ function exportIntelApp() {
|
||||
region_code: kind === 'region' ? this.region : (this.region || null),
|
||||
max_priority: 2,
|
||||
};
|
||||
if (kind === 'world') body = { max_priority: 2 };
|
||||
if (kind === 'world') body = { max_priority: 3 };
|
||||
if (kind === 'places' && !this.country && !this.region) {
|
||||
this.syncMsg = 'Selecteer een land of regio voor Google Places';
|
||||
this.busy = false;
|
||||
return;
|
||||
}
|
||||
var endpoint = kind === 'region' ? 'region' : kind;
|
||||
var r = await fetch('/api/export-intel/sync/' + endpoint, {
|
||||
method: 'POST',
|
||||
@@ -604,7 +866,128 @@ function exportIntelApp() {
|
||||
},
|
||||
|
||||
typeLabel(t) {
|
||||
return (t || '').replace(/_/g, ' ');
|
||||
var labels = {
|
||||
distributor: 'Distrib.',
|
||||
wholesaler: 'Grooth.',
|
||||
contract_caterer: 'Cateraar',
|
||||
end_customer: 'Eindkl.',
|
||||
hotel: 'Hotel',
|
||||
restaurant: 'Rest.',
|
||||
retailer: 'Retail',
|
||||
importer: 'Import',
|
||||
};
|
||||
return labels[t] || (t || '').replace(/_/g, ' ');
|
||||
},
|
||||
|
||||
|
||||
filteredTerritories() {
|
||||
var list = (this.territories || []).filter(function (t) {
|
||||
return !this.region || t.region_code === this.region;
|
||||
}, this);
|
||||
var seen = {};
|
||||
var out = [];
|
||||
list.forEach(function (t) {
|
||||
var iso = t.country_iso2;
|
||||
if (!iso || seen[iso]) return;
|
||||
seen[iso] = true;
|
||||
out.push(t);
|
||||
});
|
||||
out.sort(function (a, b) {
|
||||
return (a.name_nl || a.country_iso2 || '').localeCompare(b.name_nl || b.country_iso2 || '', 'nl');
|
||||
});
|
||||
return out;
|
||||
},
|
||||
|
||||
countryEntityCount(iso2) {
|
||||
if (!iso2) return 0;
|
||||
var cc = (this.stats && this.stats.country_entity_counts) || {};
|
||||
return Number(cc[iso2] || 0);
|
||||
},
|
||||
|
||||
countryOptionLabel(t) {
|
||||
if (!t) return '';
|
||||
var n = this.countryEntityCount(t.country_iso2);
|
||||
return n > 0 ? (t.name_nl + ' (' + n + ')') : t.name_nl;
|
||||
},
|
||||
|
||||
|
||||
|
||||
async loadGoogleSettings() {
|
||||
try {
|
||||
var s = await fetch('/api/export-intel/settings').then(function (r) { return r.json(); });
|
||||
this.googleMapsKeySet = !!(s && s.google_maps_api_key_set);
|
||||
this.googleMapsKey = '';
|
||||
} catch (e) { console.error(e); }
|
||||
},
|
||||
|
||||
async saveGoogleMapsKey() {
|
||||
if (!this.googleMapsKey || !this.googleMapsKey.trim()) return;
|
||||
this.googleKeySaving = true;
|
||||
try {
|
||||
await fetch('/api/export-intel/settings', {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ google_maps_api_key: this.googleMapsKey.trim() }),
|
||||
});
|
||||
this.googleMapsKey = '';
|
||||
this.googleMapsKeySet = true;
|
||||
this.syncMsg = 'Google Places API-key opgeslagen';
|
||||
} catch (e) {
|
||||
this.syncMsg = 'API-key opslaan mislukt';
|
||||
}
|
||||
this.googleKeySaving = false;
|
||||
},
|
||||
|
||||
startSyncMonitor(silent) {
|
||||
var self = this;
|
||||
if (this.syncMonitorPoll) return;
|
||||
this.pollSyncStatus();
|
||||
this.syncMonitorPoll = setInterval(function () { self.pollSyncStatus(); }, 3000);
|
||||
},
|
||||
|
||||
stopSyncMonitor() {
|
||||
if (this.syncMonitorPoll) {
|
||||
clearInterval(this.syncMonitorPoll);
|
||||
this.syncMonitorPoll = null;
|
||||
}
|
||||
},
|
||||
|
||||
async pollSyncStatus() {
|
||||
try {
|
||||
var s = await fetch('/api/export-intel/sync/status').then(function (r) { return r.json(); });
|
||||
this.syncMonitor = s;
|
||||
if (s.any_running && s.active_jobs && s.active_jobs.length) {
|
||||
var j = s.active_jobs[0];
|
||||
this.syncMsg = (j.message || j.label || 'Sync bezig') + (j.percent ? ' · ' + j.percent + '%' : '');
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
},
|
||||
|
||||
toggleSyncMonitor() {
|
||||
this.syncMonitorOpen = !this.syncMonitorOpen;
|
||||
},
|
||||
|
||||
syncMonitorPercent() {
|
||||
var jobs = (this.syncMonitor && this.syncMonitor.active_jobs) || [];
|
||||
if (!jobs.length) return 0;
|
||||
return jobs[0].percent || 0;
|
||||
},
|
||||
|
||||
formatSyncTime(ts) {
|
||||
if (!ts) return '';
|
||||
var d = new Date(ts * 1000);
|
||||
return d.toLocaleTimeString('nl-NL', { hour: '2-digit', minute: '2-digit', second: '2-digit' });
|
||||
},
|
||||
|
||||
syncEventLabel(ev) {
|
||||
if (!ev) return '';
|
||||
var parts = [ev.event || ''];
|
||||
if (ev.message) parts.push(ev.message);
|
||||
else if (ev.country) parts.push(ev.country);
|
||||
if (ev.step) parts.push('(' + ev.step + ')');
|
||||
return parts.filter(Boolean).join(' · ');
|
||||
},
|
||||
|
||||
territoryName(iso2) {
|
||||
@@ -644,7 +1027,7 @@ function exportIntelApp() {
|
||||
}
|
||||
return;
|
||||
}
|
||||
var list = this.mapHalalMode && this.halalTopEntities.length ? this.halalTopEntities : this.entities;
|
||||
var list = this.visibleEntities();
|
||||
if (!list.length) return;
|
||||
var allSelected = list.every((e) => this.isSelected(e.id));
|
||||
if (allSelected) {
|
||||
|
||||
Reference in New Issue
Block a user